-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
opts = append(opts, store.WithRequestID(requestID)) | ||
opts = append(opts, store.WithPeer(addr.ID)) | ||
|
||
result, err := wakuNode.Store().QueryByHash(ctx, []pb.MessageHash{b}, opts...) |
There was a problem hiding this comment.
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
?
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[:]))) |
There was a problem hiding this comment.
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
var b pb.MessageHash | ||
copy(b[:], msgHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var b pb.MessageHash | |
copy(b[:], msgHash) | |
b := pb.ToMessageHash(msgHash) |
msgHash, err := hexutil.Decode("0x081bf9e247a2c892a67a1e063ec2e7b4bb367e67e53aefce43e0a6465b0d3671") | ||
if err != nil { | ||
log.Error("Error decoding message hash", zap.Error(err)) | ||
return | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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
go-waku/waku/v2/node/wakunode2.go
Line 197 in 269417c
w.wakuFlag = enr.NewWakuEnrBitfield(w.opts.enableLightPush, w.opts.enableFilterFullNode, w.opts.enableStore, w.opts.enableRelay) |
msgHash, err := hexutil.Decode("0x081bf9e247a2c892a67a1e063ec2e7b4bb367e67e53aefce43e0a6465b0d3671") | ||
if err != nil { | ||
log.Error("Error decoding message hash", zap.Error(err)) | ||
return | ||
} |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
No description provided.