x/ibc: remove returning packet from channel keeper funcs (#6544)
* remove unnecessary return var * fix changes lost in merge
This commit is contained in:
parent
e8fb76ae44
commit
497b27305d
|
@ -142,14 +142,14 @@ func (k Keeper) RecvPacket(
|
|||
packet exported.PacketI,
|
||||
proof []byte,
|
||||
proofHeight uint64,
|
||||
) (exported.PacketI, error) {
|
||||
) error {
|
||||
channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel())
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel())
|
||||
return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel())
|
||||
}
|
||||
|
||||
if channel.State != types.OPEN {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidChannelState,
|
||||
"channel state is not OPEN (got %s)", channel.State.String(),
|
||||
)
|
||||
|
@ -160,14 +160,14 @@ func (k Keeper) RecvPacket(
|
|||
|
||||
// packet must come from the channel's counterparty
|
||||
if packet.GetSourcePort() != channel.Counterparty.PortID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet source port doesn't match the counterparty's port (%s ≠ %s)", packet.GetSourcePort(), channel.Counterparty.PortID,
|
||||
)
|
||||
}
|
||||
|
||||
if packet.GetSourceChannel() != channel.Counterparty.ChannelID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet source channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetSourceChannel(), channel.Counterparty.ChannelID,
|
||||
)
|
||||
|
@ -175,11 +175,11 @@ func (k Keeper) RecvPacket(
|
|||
|
||||
connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
|
||||
return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
|
||||
}
|
||||
|
||||
if connectionEnd.GetState() != int32(connectiontypes.OPEN) {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
connectiontypes.ErrInvalidConnectionState,
|
||||
"connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(),
|
||||
)
|
||||
|
@ -187,7 +187,7 @@ func (k Keeper) RecvPacket(
|
|||
|
||||
// check if packet timeouted by comparing it with the latest height of the chain
|
||||
if packet.GetTimeoutHeight() != 0 && uint64(ctx.BlockHeight()) >= packet.GetTimeoutHeight() {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrPacketTimeout,
|
||||
"block height >= packet timeout height (%d >= %d)", uint64(ctx.BlockHeight()), packet.GetTimeoutHeight(),
|
||||
)
|
||||
|
@ -195,7 +195,7 @@ func (k Keeper) RecvPacket(
|
|||
|
||||
// check if packet timeouted by comparing it with the latest timestamp of the chain
|
||||
if packet.GetTimeoutTimestamp() != 0 && uint64(ctx.BlockTime().UnixNano()) >= packet.GetTimeoutTimestamp() {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrPacketTimeout,
|
||||
"block timestamp >= packet timeout timestamp (%s >= %s)", ctx.BlockTime(), time.Unix(0, int64(packet.GetTimeoutTimestamp())),
|
||||
)
|
||||
|
@ -205,7 +205,7 @@ func (k Keeper) RecvPacket(
|
|||
if channel.Ordering == types.UNORDERED {
|
||||
_, found := k.GetPacketAcknowledgement(ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
|
||||
if found {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet sequence (%d) already has been received", packet.GetSequence(),
|
||||
)
|
||||
|
@ -217,11 +217,11 @@ func (k Keeper) RecvPacket(
|
|||
packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(),
|
||||
types.CommitPacket(packet),
|
||||
); err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "couldn't verify counterparty packet commitment")
|
||||
return sdkerrors.Wrap(err, "couldn't verify counterparty packet commitment")
|
||||
}
|
||||
|
||||
// NOTE: the remaining code is located in the PacketExecuted function
|
||||
return packet, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// PacketExecuted writes the packet execution acknowledgement to the state,
|
||||
|
@ -320,17 +320,17 @@ func (k Keeper) AcknowledgePacket(
|
|||
acknowledgement []byte,
|
||||
proof []byte,
|
||||
proofHeight uint64,
|
||||
) (exported.PacketI, error) {
|
||||
) error {
|
||||
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrChannelNotFound,
|
||||
packet.GetSourcePort(), packet.GetSourceChannel(),
|
||||
)
|
||||
}
|
||||
|
||||
if channel.State != types.OPEN {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidChannelState,
|
||||
"channel state is not OPEN (got %s)", channel.State.String(),
|
||||
)
|
||||
|
@ -341,14 +341,14 @@ func (k Keeper) AcknowledgePacket(
|
|||
|
||||
// packet must have been sent to the channel's counterparty
|
||||
if packet.GetDestPort() != channel.Counterparty.PortID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortID,
|
||||
)
|
||||
}
|
||||
|
||||
if packet.GetDestChannel() != channel.Counterparty.ChannelID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelID,
|
||||
)
|
||||
|
@ -356,11 +356,11 @@ func (k Keeper) AcknowledgePacket(
|
|||
|
||||
connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
|
||||
return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
|
||||
}
|
||||
|
||||
if connectionEnd.GetState() != int32(connectiontypes.OPEN) {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
connectiontypes.ErrInvalidConnectionState,
|
||||
"connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(),
|
||||
)
|
||||
|
@ -370,27 +370,27 @@ func (k Keeper) AcknowledgePacket(
|
|||
|
||||
// verify we sent the packet and haven't cleared it out yet
|
||||
if !bytes.Equal(commitment, types.CommitPacket(packet)) {
|
||||
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
}
|
||||
|
||||
if err := k.connectionKeeper.VerifyPacketAcknowledgement(
|
||||
ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(),
|
||||
packet.GetSequence(), acknowledgement,
|
||||
); err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "invalid acknowledgement on counterparty chain")
|
||||
return sdkerrors.Wrap(err, "invalid acknowledgement on counterparty chain")
|
||||
}
|
||||
|
||||
if channel.Ordering == types.ORDERED {
|
||||
nextSequenceAck, found := k.GetNextSequenceAck(ctx, packet.GetDestPort(), packet.GetDestChannel())
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrSequenceAckNotFound,
|
||||
"destination port: %s, destination channel: %s", packet.GetDestPort(), packet.GetDestChannel(),
|
||||
)
|
||||
}
|
||||
|
||||
if packet.GetSequence() != nextSequenceAck {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
sdkerrors.ErrInvalidSequence,
|
||||
"packet sequence ≠ next ack sequence (%d ≠ %d)", packet.GetSequence(), nextSequenceAck,
|
||||
)
|
||||
|
@ -400,7 +400,7 @@ func (k Keeper) AcknowledgePacket(
|
|||
}
|
||||
|
||||
// NOTE: the remaining code is located in the AcknowledgementExecuted function
|
||||
return packet, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// AcknowledgementExecuted deletes the packet commitment from this chain.
|
||||
|
|
|
@ -330,7 +330,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
|
|||
packetKey := host.KeyPacketCommitment(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
|
||||
proof, proofHeight := suite.chainA.QueryProof(packetKey)
|
||||
|
||||
_, err := suite.chainB.App.IBCKeeper.ChannelKeeper.RecvPacket(suite.chainB.GetContext(), packet, proof, proofHeight)
|
||||
err := suite.chainB.App.IBCKeeper.ChannelKeeper.RecvPacket(suite.chainB.GetContext(), packet, proof, proofHeight)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
|
@ -581,7 +581,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
|
|||
packetKey := host.KeyPacketAcknowledgement(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
|
||||
proof, proofHeight := suite.chainB.QueryProof(packetKey)
|
||||
|
||||
_, err := suite.chainA.App.IBCKeeper.ChannelKeeper.AcknowledgePacket(suite.chainA.GetContext(), packet, ack, proof, proofHeight)
|
||||
err := suite.chainA.App.IBCKeeper.ChannelKeeper.AcknowledgePacket(suite.chainA.GetContext(), packet, ack, proof, proofHeight)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
|
|
|
@ -25,17 +25,17 @@ func (k Keeper) TimeoutPacket(
|
|||
proof []byte,
|
||||
proofHeight,
|
||||
nextSequenceRecv uint64,
|
||||
) (exported.PacketI, error) {
|
||||
) error {
|
||||
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrChannelNotFound,
|
||||
packet.GetSourcePort(), packet.GetSourceChannel(),
|
||||
)
|
||||
}
|
||||
|
||||
if channel.State != types.OPEN {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidChannelState,
|
||||
"channel state is not OPEN (got %s)", channel.State.String(),
|
||||
)
|
||||
|
@ -45,14 +45,14 @@ func (k Keeper) TimeoutPacket(
|
|||
// so the capability authentication can be omitted here
|
||||
|
||||
if packet.GetDestPort() != channel.Counterparty.PortID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortID,
|
||||
)
|
||||
}
|
||||
|
||||
if packet.GetDestChannel() != channel.Counterparty.ChannelID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelID,
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ func (k Keeper) TimeoutPacket(
|
|||
|
||||
connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrap(
|
||||
return sdkerrors.Wrap(
|
||||
connectiontypes.ErrConnectionNotFound,
|
||||
channel.ConnectionHops[0],
|
||||
)
|
||||
|
@ -69,26 +69,26 @@ func (k Keeper) TimeoutPacket(
|
|||
// check that timeout height or timeout timestamp has passed on the other end
|
||||
proofTimestamp, err := k.connectionKeeper.GetTimestampAtHeight(ctx, connectionEnd, proofHeight)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if (packet.GetTimeoutHeight() == 0 || proofHeight < packet.GetTimeoutHeight()) &&
|
||||
(packet.GetTimeoutTimestamp() == 0 || proofTimestamp < packet.GetTimeoutTimestamp()) {
|
||||
return nil, sdkerrors.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp")
|
||||
return sdkerrors.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp")
|
||||
}
|
||||
|
||||
commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
|
||||
|
||||
// verify we sent the packet and haven't cleared it out yet
|
||||
if !bytes.Equal(commitment, types.CommitPacket(packet)) {
|
||||
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
}
|
||||
|
||||
switch channel.Ordering {
|
||||
case types.ORDERED:
|
||||
// check that packet has not been received
|
||||
if nextSequenceRecv > packet.GetSequence() {
|
||||
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
|
||||
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
|
||||
}
|
||||
|
||||
// check that the recv sequence is as claimed
|
||||
|
@ -106,11 +106,11 @@ func (k Keeper) TimeoutPacket(
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
// NOTE: the remaining code is located in the TimeoutExecuted function
|
||||
return packet, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// TimeoutExecuted deletes the commitment send from this chain after it verifies timeout.
|
||||
|
@ -172,29 +172,29 @@ func (k Keeper) TimeoutOnClose(
|
|||
proofClosed []byte,
|
||||
proofHeight,
|
||||
nextSequenceRecv uint64,
|
||||
) (exported.PacketI, error) {
|
||||
) error {
|
||||
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrapf(types.ErrChannelNotFound, packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
return sdkerrors.Wrapf(types.ErrChannelNotFound, packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
}
|
||||
|
||||
capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) {
|
||||
return nil, sdkerrors.Wrap(
|
||||
return sdkerrors.Wrap(
|
||||
types.ErrInvalidChannelCapability,
|
||||
"channel capability failed authentication",
|
||||
)
|
||||
}
|
||||
|
||||
if packet.GetDestPort() != channel.Counterparty.PortID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortID,
|
||||
)
|
||||
}
|
||||
|
||||
if packet.GetDestChannel() != channel.Counterparty.ChannelID {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrInvalidPacket,
|
||||
"packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelID,
|
||||
)
|
||||
|
@ -202,14 +202,14 @@ func (k Keeper) TimeoutOnClose(
|
|||
|
||||
connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
|
||||
if !found {
|
||||
return nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
|
||||
return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0])
|
||||
}
|
||||
|
||||
commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
|
||||
|
||||
// verify we sent the packet and haven't cleared it out yet
|
||||
if !bytes.Equal(commitment, types.CommitPacket(packet)) {
|
||||
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
}
|
||||
|
||||
counterpartyHops, found := k.CounterpartyHops(ctx, channel)
|
||||
|
@ -229,7 +229,7 @@ func (k Keeper) TimeoutOnClose(
|
|||
channel.Counterparty.PortID, channel.Counterparty.ChannelID,
|
||||
expectedChannel,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
|
@ -237,7 +237,7 @@ func (k Keeper) TimeoutOnClose(
|
|||
case types.ORDERED:
|
||||
// check that packet has not been received
|
||||
if nextSequenceRecv > packet.GetSequence() {
|
||||
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
|
||||
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
|
||||
}
|
||||
|
||||
// check that the recv sequence is as claimed
|
||||
|
@ -255,7 +255,7 @@ func (k Keeper) TimeoutOnClose(
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
|
||||
|
@ -276,5 +276,5 @@ func (k Keeper) TimeoutOnClose(
|
|||
),
|
||||
})
|
||||
|
||||
return packet, nil
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
|
|||
proof, proofHeight = suite.chainB.QueryProof(unorderedPacketKey)
|
||||
}
|
||||
|
||||
_, err := suite.chainA.App.IBCKeeper.ChannelKeeper.TimeoutPacket(suite.chainA.GetContext(), packet, proof, proofHeight, nextSeqRecv)
|
||||
err := suite.chainA.App.IBCKeeper.ChannelKeeper.TimeoutPacket(suite.chainA.GetContext(), packet, proof, proofHeight, nextSeqRecv)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
|
@ -350,7 +350,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
|
|||
proof, _ = suite.chainB.QueryProof(unorderedPacketKey)
|
||||
}
|
||||
|
||||
_, err := suite.chainA.App.IBCKeeper.ChannelKeeper.TimeoutOnClose(suite.chainA.GetContext(), chanCap, packet, proof, proofClosed, proofHeight, nextSeqRecv)
|
||||
err := suite.chainA.App.IBCKeeper.ChannelKeeper.TimeoutOnClose(suite.chainA.GetContext(), chanCap, packet, proof, proofClosed, proofHeight, nextSeqRecv)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
|
|
|
@ -32,11 +32,11 @@ func (pvr ProofVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
|
|||
case clientexported.MsgUpdateClient:
|
||||
_, err = pvr.clientKeeper.UpdateClient(ctx, msg.GetClientID(), msg.GetHeader())
|
||||
case *channel.MsgPacket:
|
||||
_, err = pvr.channelKeeper.RecvPacket(ctx, msg.Packet, msg.Proof, msg.ProofHeight)
|
||||
err = pvr.channelKeeper.RecvPacket(ctx, msg.Packet, msg.Proof, msg.ProofHeight)
|
||||
case *channel.MsgAcknowledgement:
|
||||
_, err = pvr.channelKeeper.AcknowledgePacket(ctx, msg.Packet, msg.Acknowledgement, msg.Proof, msg.ProofHeight)
|
||||
err = pvr.channelKeeper.AcknowledgePacket(ctx, msg.Packet, msg.Acknowledgement, msg.Proof, msg.ProofHeight)
|
||||
case *channel.MsgTimeout:
|
||||
_, err = pvr.channelKeeper.TimeoutPacket(ctx, msg.Packet, msg.Proof, msg.ProofHeight, msg.NextSequenceRecv)
|
||||
err = pvr.channelKeeper.TimeoutPacket(ctx, msg.Packet, msg.Proof, msg.ProofHeight, msg.NextSequenceRecv)
|
||||
default:
|
||||
// don't emit sender event for other msg types
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue