-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
perf: minimize logic on rechecktx for recvpacket #6280
Merged
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
041e66c
perf: minimize logic on rechecktx for recvpacket
colin-axner c0e4496
refactor: rework layout for recvpacket rechecktx
colin-axner 9d70011
test: add tests for 04-channel rechecktx func
colin-axner 3b521c7
test: add tests for core ante handler
colin-axner d972605
Merge branch 'main' into colin/6232-perf-rechecktx-recvpacket
colin-axner 5cf09c7
chore: add comment explaining is rechecktx usage
colin-axner 41b2dfb
linter appeasement
colin-axner 2bd15dd
Merge branch 'colin/6232-perf-rechecktx-recvpacket' of github.com:cos…
colin-axner 5917ec3
Merge branch 'main' of github.com:cosmos/ibc-go into colin/6232-perf-…
colin-axner dfcf58b
Merge branch 'main' of github.com:cosmos/ibc-go into colin/6232-perf-…
colin-axner 252be4b
chore: add changelog entry
colin-axner cfeed70
Update modules/core/ante/ante.go
colin-axner 0e6287c
imp: use cached ctx for consistency
colin-axner 5bd6933
refactor: change added test to use expected errors
colin-axner ec73618
Merge branch 'colin/6232-perf-rechecktx-recvpacket' of github.com:cos…
colin-axner a3283b7
lint
colin-axner f5abe9d
Merge branch 'main' into colin/6232-perf-rechecktx-recvpacket
colin-axner 2a83e8d
Merge branch 'main' into colin/6232-perf-rechecktx-recvpacket
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package keeper | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
) | ||
|
||
// RecvPacketReCheckTx applies replay protection ensuring that when relay messages are | ||
// re-executed in ReCheckTx, we can appropriately filter out redundant relay transactions. | ||
func (k *Keeper) RecvPacketReCheckTx(ctx sdk.Context, packet types.Packet) error { | ||
channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) | ||
if !found { | ||
return errorsmod.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) | ||
} | ||
|
||
if err := k.applyReplayProtection(ctx, packet, channel); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
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,66 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
ibctesting "github.com/cosmos/ibc-go/v8/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestRecvPacketReCheckTx() { | ||
var ( | ||
path *ibctesting.Path | ||
packet types.Packet | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expError error | ||
}{ | ||
{ | ||
"success", | ||
func() {}, | ||
nil, | ||
}, | ||
{ | ||
"channel not found", | ||
func() { | ||
packet.DestinationPort = "invalid-port" | ||
}, | ||
channeltypes.ErrChannelNotFound, | ||
}, | ||
{ | ||
"redundant relay", | ||
func() { | ||
err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.RecvPacketReCheckTx(suite.chainB.GetContext(), packet) | ||
suite.Require().NoError(err) | ||
}, | ||
channeltypes.ErrNoOpMsg, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() // reset | ||
path = ibctesting.NewPath(suite.chainA, suite.chainB) | ||
path.Setup() | ||
|
||
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) | ||
suite.Require().NoError(err) | ||
packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) | ||
|
||
tc.malleate() | ||
|
||
err = suite.chainB.App.GetIBCKeeper().ChannelKeeper.RecvPacketReCheckTx(suite.chainB.GetContext(), packet) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().ErrorIs(err, tc.expError) | ||
} | ||
}) | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.
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.
Wondering if there would be an alternative way to implement this where we don't need to increase the public API of the channel keeper...
Also, for my understanding: why what we do in
ReCheckTx
is different from what we do inCheckTx
?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.
Outside of copy pasting the code, you would need to increase the public API of the channel keeper. I do not recommend copy pasting the code due to the codes sensitivity. It'd be nice to limit the channel keeper API, but we need to do some restructuring and make use of the
internal
package more. I'd say we should start by addressing #19 and moving the respective msg servers to their respective keepersThere 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.
ReCheckTx is rerun on the mempool after every block commit. It is redundant to recheck proofs and other logic which will not change between commits