diff --git a/client/helper.go b/client/helper.go index 22c63e6..c38c9de 100644 --- a/client/helper.go +++ b/client/helper.go @@ -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 { @@ -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 } diff --git a/client/rpc.go b/client/rpc.go index 9d4bc35..cfdcfc3 100644 --- a/client/rpc.go +++ b/client/rpc.go @@ -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{}{}