Skip to content

Commit

Permalink
fix: poll 8 times over 2 blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 7, 2024
1 parent 4b11a17 commit 9243e84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,29 @@ func (tn *ChainNode) ExecTx(ctx context.Context, keyName string, command ...stri
if output.Code != 0 {
return output.TxHash, fmt.Errorf("transaction failed with code %d: %s", output.Code, output.RawLog)
}
if err := testutil.WaitForBlocks(ctx, 1, tn); err != nil {

var txHash string
err = retry.Do(
func() error {
txHash, err = tn.queryForTxHash(ctx, output)
if err != nil {
return err
}
return nil
},
retry.Delay(blockTime/4),
retry.Attempts(8), // 2 blocks, 8 polls
)
if err != nil {
return "", err
}

return txHash, nil
}

func (tn *ChainNode) queryForTxHash(ctx context.Context, output CosmosTx) (string, error) {
// The transaction can at first appear to succeed, but then fail when it's actually included in a block.
stdout, _, err = tn.ExecQuery(ctx, "tx", output.TxHash)
stdout, _, err := tn.ExecQuery(ctx, "tx", output.TxHash)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/rly/cosmos_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type CosmosRelayerChainConfigValue struct {
RPCAddr string `json:"rpc-addr"`
SignMode string `json:"sign-mode"`
Timeout string `json:"timeout"`
MinLoopDuration time.Duration `json:"min-loop-duration" default:"100ms"`
MinLoopDuration time.Duration `json:"min-loop-duration"`
}

type CosmosRelayerChainConfig struct {
Expand Down

0 comments on commit 9243e84

Please sign in to comment.