Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: store hash query example #1117

Closed
wants to merge 1 commit into from
Closed

chore: store hash query example #1117

wants to merge 1 commit into from

Conversation

kaichaosun
Copy link
Contributor

No description provided.

@status-im-auto
Copy link

Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ b6a7606 #1 2024-05-31 02:02:50 ~1 min nix-flake 📄log

opts = append(opts, store.WithRequestID(requestID))
opts = append(opts, store.WithPeer(addr.ID))

result, err := wakuNode.Store().QueryByHash(ctx, []pb.MessageHash{b}, opts...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're looking for a single hash, maybe it's better to use Store().Exists?

Comment on lines +96 to +101
if len(result.Messages()) == 0 {
log.Warn("store.queryByHash result empty")
return
}
resHash := result.Messages()[0].MessageHash
log.Info("store.queryByHash result hash", zap.String("hash", hexutil.Encode(resHash[:])))
Copy link
Member

@richard-ramos richard-ramos May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally since when you use queryByHash, you might receive more than one page of results, for the sake of having a more complete example, it's probably a good idea to do:

for !result.IsComplete() {
    for _, m := range result.Messages() {
       resHash := m.WakuMessageHash()
        log.Info("store.queryByHash result hash", zap.Stringer("hash", resHash))
    }

    err := result.Next(ctx)
    if err != nil {
	log.Warn("store.next failed", zap.Error(err))
        return
    }
}

Do note that i'm using WakuMessageHash() which automatically converts the hash into a MessageHash that has a String() function

Comment on lines +80 to +81
var b pb.MessageHash
copy(b[:], msgHash)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var b pb.MessageHash
copy(b[:], msgHash)
b := pb.ToMessageHash(msgHash)

Comment on lines +75 to +79
msgHash, err := hexutil.Decode("0x081bf9e247a2c892a67a1e063ec2e7b4bb367e67e53aefce43e0a6465b0d3671")
if err != nil {
log.Error("Error decoding message hash", zap.Error(err))
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this hash a real value? if so, it will probably dissapear in 30d. and the example will fail.
I guess this is okay because at the end of the day, it's an example, but if you want the example to always work, consider publishing a message before the query.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or ask for hash to be passed as an argument to the binary.

node.WithPrivateKey(prvKey),
node.WithHostAddress(hostAddr),
node.WithNTP(),
node.WithWakuStore(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean localNode is also acting as storeNode ?

As per

w.wakuFlag = enr.NewWakuEnrBitfield(w.opts.enableLightPush, w.opts.enableFilterFullNode, w.opts.enableStore, w.opts.enableRelay)
it seems we take this flag to enable Store in ENR bitfield which indicates local node is a store node.

Comment on lines +75 to +79
msgHash, err := hexutil.Decode("0x081bf9e247a2c892a67a1e063ec2e7b4bb367e67e53aefce43e0a6465b0d3671")
if err != nil {
log.Error("Error decoding message hash", zap.Error(err))
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or ask for hash to be passed as an argument to the binary.


time.Sleep(3 * time.Second)

addr, err := peer.AddrInfoFromString("/dns4/store-02.ac-cn-hongkong-c.shards.test.status.im/tcp/30303/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could optionally be taken as an arg if someone wants to override.

@kaichaosun kaichaosun closed this Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants