From cf2754a79bbd8fb9a8e6143a33d45c14b806b0d2 Mon Sep 17 00:00:00 2001 From: Ava Howell Date: Thu, 7 Dec 2023 21:48:23 -0800 Subject: [PATCH] penumbra provider: fix getAnchor: don't query out of range heights (#1358) Co-authored-by: Justin Tieri <37750742+jtieri@users.noreply.github.com> --- relayer/chains/penumbra/tx.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/relayer/chains/penumbra/tx.go b/relayer/chains/penumbra/tx.go index de4def253..a01461757 100644 --- a/relayer/chains/penumbra/tx.go +++ b/relayer/chains/penumbra/tx.go @@ -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", @@ -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