Skip to content

Commit

Permalink
fix: poll authtx endpoint for sdk tx response (#843)
Browse files Browse the repository at this point in the history
Co-authored-by: Reece Williams <[email protected]>
  • Loading branch information
chatton and Reecepbcups authored Oct 25, 2023
1 parent 55007d0 commit 71fa3a9
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions chain/cosmos/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/strangelove-ventures/interchaintest/v8/internal/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -224,16 +224,22 @@ func BroadcastTx(ctx context.Context, broadcaster *Broadcaster, broadcastingUser
return sdk.TxResponse{}, err
}

resp, err := authTx.QueryTx(cc, respWithTxHash.TxHash)
if err != nil {
// if we fail to query the tx, it means an error occurred with the original message broadcast.
// we should return this instead.
originalResp, err := broadcaster.UnmarshalTxResponseBytes(ctx, txBytes)
return getFullyPopulatedResponse(cc, respWithTxHash.TxHash)
}

// getFullyPopulatedResponse returns a fully populated sdk.TxResponse.
// the QueryTx function is periodically called until a tx with the given hash
// has been included in a block.
func getFullyPopulatedResponse(cc client.Context, txHash string) (sdk.TxResponse, error) {
var resp sdk.TxResponse
err := testutil.WaitForCondition(time.Second*60, time.Second*5, func() (bool, error) {
fullyPopulatedTxResp, err := authtx.QueryTx(cc, txHash)
if err != nil {
return sdk.TxResponse{}, err
return false, nil
}
return originalResp, nil
}

return *resp, nil
resp = *fullyPopulatedTxResp
return true, nil
})
return resp, err
}

0 comments on commit 71fa3a9

Please sign in to comment.