Skip to content

Commit

Permalink
fix getRequestProofByID
Browse files Browse the repository at this point in the history
  • Loading branch information
nkitlabs committed Jun 6, 2024
1 parent 7d44d93 commit 4cb031e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
27 changes: 14 additions & 13 deletions client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/pkg/errors"
)

func NewClientCtx(chainID string) client.Context {
Expand Down Expand Up @@ -132,26 +133,26 @@ func convertSigningResultToSigningInfo(res *tsstypes.SigningResult) SigningInfo
}
}

func getRequestProof(clientCtx client.Context, reqID uint64, height int64) ([]byte, error) {
func getRequestProof(clientCtx client.Context, reqID uint64) ([]byte, error) {
queryClient := proofservice.NewProofServer(clientCtx)
resp, err := queryClient.Proof(
context.Background(), &proofservice.QueryProofRequest{RequestId: reqID, Height: height},
context.Background(), &proofservice.QueryProofRequest{RequestId: reqID, Height: 0},
)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "failed to get proof")
}

return resp.Result.EvmProofBytes, nil
}

func getProofHeight(clientCtx client.Context, reqID uint64) (int64, error) {
queryClient := proofservice.NewProofServer(clientCtx)
resp, err := queryClient.Proof(
context.Background(), &proofservice.QueryProofRequest{RequestId: reqID, Height: 0},
)
b, err := clientCtx.Client.Block(context.Background(), nil)
if err != nil {
return 0, err
return nil, errors.Wrapf(err, "failed to get current block")
}
if resp.Height >= b.Block.Height {
return nil, fmt.Errorf(
"proof is not ready; current height: %d, proof height: %d",
b.Block.Height,
resp.Height,
)
}

return resp.Height, nil
return resp.Result.EvmProofBytes, nil
}
24 changes: 1 addition & 23 deletions client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,29 +433,7 @@ func (c RPC) GetRequestProofByID(reqID uint64) ([]byte, error) {

for _, node := range c.nodes {
go func(node *rpchttp.HTTP) {
height, err := getProofHeight(c.ctx.WithClient(node), reqID)
if err != nil {
c.logger.Warning("GetRequestProofByID", "can't get proof height from %s; %s", node.Remote(), err)
failCh <- struct{}{}
return
}

b, err := c.ctx.WithClient(node).Client.Block(context.Background(), nil)
if err != nil {
c.logger.Warning("GetRequestProofByID", "can't get latest block from %s; %s", node.Remote(), err)
failCh <- struct{}{}
return
} else if b.Block.Height <= height {
c.logger.Warning(
"GetRequestProofByID",
"latest block height is less than proof height from %s",
node.Remote(),
)
failCh <- struct{}{}
return
}

evmProofBytes, err := getRequestProof(c.ctx.WithClient(node), reqID, height)
evmProofBytes, err := getRequestProof(c.ctx.WithClient(node), reqID)
if err != nil {
c.logger.Warning("GetRequestProofByID", "can't get proof bytes from %s; %s", node.Remote(), err)
failCh <- struct{}{}
Expand Down

0 comments on commit 4cb031e

Please sign in to comment.