Skip to content

Commit

Permalink
penumbra provider: fix getAnchor: don't query out of range heights (#…
Browse files Browse the repository at this point in the history
…1358)

Co-authored-by: Justin Tieri <37750742+jtieri@users.noreply.github.com>
  • Loading branch information
avahowell and jtieri committed Dec 8, 2023
1 parent dd40ff2 commit cf2754a
Showing 1 changed file with 9 additions and 15 deletions.
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

0 comments on commit cf2754a

Please sign in to comment.