-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: construct ics27 error acknowledgement with determinstic ABCI code #794
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
46ff2ae
refactor: construct ics27 error acknowledgement with determinstic ABC…
colin-axner 5426e3e
Merge branch 'main' into colin/701-ica-err-code-in-ack
colin-axner 433af0c
Merge branch 'main' into colin/701-ica-err-code-in-ack
colin-axner 50f8858
Update modules/apps/27-interchain-accounts/host/types/ack.go
colin-axner 4495a73
Merge branch 'main' into colin/701-ica-err-code-in-ack
colin-axner 7fed6e2
fix test from merge conflict
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" | ||
) | ||
|
||
const ( | ||
// ackErrorString defines a string constant included in error acknowledgements | ||
// NOTE: Changing this const is state machine breaking as acknowledgements are written into state | ||
ackErrorString = "error handling packet on host chain: see events for details" | ||
) | ||
|
||
// AcknowledgementErrorString returns a deterministic error string which may be used in | ||
// the packet acknowledgement. | ||
func NewErrorAcknowledgement(err error) channeltypes.Acknowledgement { | ||
// the ABCI code is included in the abcitypes.ResponseDeliverTx hash | ||
// constructed in Tendermint and is therefore determinstic | ||
_, code, _ := sdkerrors.ABCIInfo(err, false) // discard non-determinstic codespace and log values | ||
|
||
errorString := fmt.Sprintf("ABCI code: %d: %s", code, ackErrorString) | ||
|
||
return channeltypes.NewErrorAcknowledgement(errorString) | ||
} |
101 changes: 101 additions & 0 deletions
101
modules/apps/27-interchain-accounts/host/types/ack_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/stretchr/testify/suite" | ||
abcitypes "github.com/tendermint/tendermint/abci/types" | ||
tmprotostate "github.com/tendermint/tendermint/proto/tendermint/state" | ||
tmstate "github.com/tendermint/tendermint/state" | ||
|
||
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" | ||
ibctesting "github.com/cosmos/ibc-go/v3/testing" | ||
) | ||
|
||
const ( | ||
gasUsed = uint64(100) | ||
gasWanted = uint64(100) | ||
) | ||
|
||
type TypesTestSuite struct { | ||
suite.Suite | ||
|
||
coordinator *ibctesting.Coordinator | ||
|
||
chainA *ibctesting.TestChain | ||
chainB *ibctesting.TestChain | ||
} | ||
|
||
func (suite *TypesTestSuite) SetupTest() { | ||
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) | ||
|
||
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) | ||
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) | ||
} | ||
|
||
func TestTypesTestSuite(t *testing.T) { | ||
suite.Run(t, new(TypesTestSuite)) | ||
} | ||
|
||
// The safety of including ABCI error codes in the acknowledgement rests | ||
// on the inclusion of these ABCI error codes in the abcitypes.ResposneDeliverTx | ||
// hash. If the ABCI codes get removed from consensus they must no longer be used | ||
// in the packet acknowledgement. | ||
// | ||
// This test acts as an indicator that the ABCI error codes may no longer be deterministic. | ||
func (suite *TypesTestSuite) TestABCICodeDeterminism() { | ||
// same ABCI error code used | ||
err := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 1") | ||
errSameABCICode := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 2") | ||
|
||
// different ABCI error code used | ||
errDifferentABCICode := sdkerrors.ErrNotFound | ||
|
||
deliverTx := sdkerrors.ResponseDeliverTx(err, gasUsed, gasWanted, false) | ||
responses := tmprotostate.ABCIResponses{ | ||
DeliverTxs: []*abcitypes.ResponseDeliverTx{ | ||
&deliverTx, | ||
}, | ||
} | ||
|
||
deliverTxSameABCICode := sdkerrors.ResponseDeliverTx(errSameABCICode, gasUsed, gasWanted, false) | ||
responsesSameABCICode := tmprotostate.ABCIResponses{ | ||
DeliverTxs: []*abcitypes.ResponseDeliverTx{ | ||
&deliverTxSameABCICode, | ||
}, | ||
} | ||
|
||
deliverTxDifferentABCICode := sdkerrors.ResponseDeliverTx(errDifferentABCICode, gasUsed, gasWanted, false) | ||
responsesDifferentABCICode := tmprotostate.ABCIResponses{ | ||
DeliverTxs: []*abcitypes.ResponseDeliverTx{ | ||
&deliverTxDifferentABCICode, | ||
}, | ||
} | ||
|
||
hash := tmstate.ABCIResponsesResultsHash(&responses) | ||
hashSameABCICode := tmstate.ABCIResponsesResultsHash(&responsesSameABCICode) | ||
hashDifferentABCICode := tmstate.ABCIResponsesResultsHash(&responsesDifferentABCICode) | ||
|
||
suite.Require().Equal(hash, hashSameABCICode) | ||
suite.Require().NotEqual(hash, hashDifferentABCICode) | ||
} | ||
|
||
// TestAcknowledgementError will verify that only a constant string and | ||
// ABCI error code are used in constructing the acknowledgement error string | ||
func (suite *TypesTestSuite) TestAcknowledgementError() { | ||
// same ABCI error code used | ||
err := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 1") | ||
errSameABCICode := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 2") | ||
|
||
// different ABCI error code used | ||
errDifferentABCICode := sdkerrors.ErrNotFound | ||
|
||
ack := types.NewErrorAcknowledgement(err) | ||
ackSameABCICode := types.NewErrorAcknowledgement(errSameABCICode) | ||
ackDifferentABCICode := types.NewErrorAcknowledgement(errDifferentABCICode) | ||
|
||
suite.Require().Equal(ack, ackSameABCICode) | ||
suite.Require().NotEqual(ack, ackDifferentABCICode) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This is super useful :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is cool!