Skip to content
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

Add flush status check in SendPacket #3912

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (k Keeper) SendPacket(
)
}

if channel.FlushStatus != types.NOTINFLUSH {
return 0, errorsmod.Wrapf(types.ErrInvalidFlushStatus, "expected flush status to be %s during packet send, got %s", types.NOTINFLUSH, channel.FlushStatus)
}

if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) {
return 0, errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel)
}
Expand Down
36 changes: 36 additions & 0 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,42 @@ func (suite *KeeperTestSuite) TestSendPacket() {

channelCap = capabilitytypes.NewCapability(5)
}, false},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to add an additional check for channel state? I.e:

{
    "channel is in INITUPGRADE stage", 
    func() {
	suite.coordinator.Setup(path)

	path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion
	path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion

	err := path.EndpointA.ChanUpgradeInit()
	suite.Require().NoError(err)
    }, 
    false
},

"invalid flush status: FLUSHING",
func() {
suite.coordinator.Setup(path)
sourceChannel = path.EndpointA.ChannelID

channel := path.EndpointA.GetChannel()
channel.FlushStatus = types.FLUSHING
path.EndpointA.SetChannel(channel)
},
false,
},
{
"invalid flush status: FLUSHCOMPLETE",
func() {
suite.coordinator.Setup(path)
sourceChannel = path.EndpointA.ChannelID

channel := path.EndpointA.GetChannel()
channel.FlushStatus = types.FLUSHCOMPLETE
path.EndpointA.SetChannel(channel)
},
false,
},
{
"channel is in INITUPGRADE stage",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"channel is in INITUPGRADE stage",
"channel is in INITUPGRADE state",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state stage tomato tomago

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤠

func() {
suite.coordinator.Setup(path)

path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion

err := path.EndpointA.ChanUpgradeInit()
suite.Require().NoError(err)
},
false,
},
}

for i, tc := range testCases {
Expand Down
Loading