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

penumbra provider: fix getAnchor: don't query out of range heights #1358

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions relayer/chains/penumbra/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,12 @@ func (cc *PenumbraProvider) getAnchor(ctx context.Context) (*penumbracrypto.Merk
maxHeight := status.SyncInfo.LatestBlockHeight

// Generate a random block height to query between 1 and maxHeight
height := rand.Int63n(maxHeight-1) + 1
height := rand.Int63n(maxHeight - 1)
if height < 0 {
height = 0
}

path := fmt.Sprintf("shielded_pool/anchor/%d", height)
path := fmt.Sprintf("sct/anchor/%d", height)

req := abci.RequestQuery{
Path: "state/key",
Expand All @@ -263,20 +266,11 @@ func (cc *PenumbraProvider) getAnchor(ctx context.Context) (*penumbracrypto.Merk

res, err := cc.QueryABCI(ctx, req)
if err != nil {
path := fmt.Sprintf("sct/anchor/%d", height)

req := abci.RequestQuery{
Path: "state/key",
Height: maxHeight,
Data: []byte(path),
Prove: false,
}
res, err := cc.QueryABCI(ctx, req)
if err != nil {
return nil, err
}
return nil, err
}

return &penumbracrypto.MerkleRoot{Inner: res.Value[2:]}, nil
if res.Value == nil {
return nil, errors.New("no anchor found for height" + strconv.FormatInt(height, 10))
}

return &penumbracrypto.MerkleRoot{Inner: res.Value[2:]}, nil
Expand Down
Loading