-
Notifications
You must be signed in to change notification settings - Fork 583
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
Implement v2 RecvPacket rpc handler #7421
Implement v2 RecvPacket rpc handler #7421
Conversation
…nt-on-channelkeeperv2' into cian/issue#7354-implement-v2-recvpacket-rpc-handler
return errorsmod.Wrap(channeltypes.ErrInvalidPacket, "receipt not found for packet") | ||
} | ||
|
||
multiAckBz := k.cdc.MustMarshal(&ack) |
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.
rename to ackBz
suite.Require().Contains(err.Error(), tc.expError.Error()) | ||
|
||
_, ok := ck.GetPacketReceipt(path.EndpointB.Chain.GetContext(), recvPacket.SourceChannel, recvPacket.Sequence) | ||
suite.Require().False(ok) | ||
ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError) |
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.
Shouldn't line 261 be at 257 (and the current 257 can be removed?)
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.
merge conflict mistake I think, will fix!
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.
LGTM
Quality Gate passed for 'ibc-go'Issues Measures |
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.
I left a couple a comments, mostly nits, lgtm overall.
) | ||
|
||
// GetPacketAcknowledgement fetches the packet acknowledgement from the store. | ||
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, sourceID string, sequence uint64) []byte { |
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.
I think this will eventually be needed when we add the equivalent grpc queries for v2? Lets move to keeper.go?
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.
should be channelID
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 probs just make exported
cb := k.Router.Route(pd.DestinationPort) | ||
res := cb.OnRecvPacket(cacheCtx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, signer) | ||
|
||
if res.Status != channeltypesv2.PacketStatus_Failure { |
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.
would have a small preference for ==
here
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.
you mean
if res.Status == channeltypesv2.PacketStatus_Async || res.Status == channeltypesv2.PacketStatus_Success
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.
oh and flipping of handling. So if res.Status == channeltypesv2.PacketStatus_Faillure
do the current else handling.
// note this should never happen as the packet data would have had to be empty. | ||
if len(ack.AcknowledgementResults) == 0 { | ||
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results")) | ||
return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.FAILURE}, nil |
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.
would this mean that when we remove v1 stuff this would be a proto-breaking change? (i.e Result
type changing)
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, we'd need to add a V2 version I guess
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.
I think we should just return err here
@@ -296,3 +296,49 @@ func (k *Keeper) timeoutPacket( | |||
|
|||
return nil | |||
} | |||
|
|||
// WriteAcknowledgement writes the acknowledgement to the store. |
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.
nit, lets move under recv impl?
// packet sender is our channel's counterparty channel id. | ||
channel, ok := k.GetChannel(ctx, packet.DestinationChannel) | ||
if !ok { | ||
// TODO: figure out how aliasing will work when more than one packet data is sent. |
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.
lets create issue and potentially rm these TODOs?
// TODO: figure out how aliasing will work when more than one packet data is sent. | ||
channel, ok = k.convertV1Channel(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel) | ||
if !ok { | ||
return errorsmod.Wrap(channeltypes.ErrChannelNotFound, packet.DestinationChannel) |
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.
should use v2 types no? I.e channeltypesv2 (ditto for rest)
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.
aliasing/converting should happen in RecvPacket so this should never be reachable...
should just be error i think if not found
|
||
// set the acknowledgement so that it can be verified on the other side | ||
k.SetPacketAcknowledgement( | ||
ctx, packet.DestinationChannel, packet.GetSequence(), |
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.
lets use direct access? I think we should just not gen the getters here at the end of the day.
ctx, packet.DestinationChannel, packet.GetSequence(), | |
ctx, packet.DestinationChannel, packet.Sequence, |
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.
I always kinda liked the getters 😢 hot take... really I don't care tho
) | ||
|
||
// GetPacketAcknowledgement fetches the packet acknowledgement from the store. | ||
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, sourceID string, sequence uint64) []byte { |
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.
should be channelID
) | ||
|
||
// GetPacketAcknowledgement fetches the packet acknowledgement from the store. | ||
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, sourceID string, sequence uint64) []byte { |
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 probs just make exported
// note this should never happen as the packet data would have had to be empty. | ||
if len(ack.AcknowledgementResults) == 0 { | ||
sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results")) | ||
return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.FAILURE}, nil |
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.
I think we should just return err here
testing/utils.go
Outdated
@@ -87,6 +87,7 @@ func UnmarshalMsgResponses(cdc codec.Codec, data []byte, msgs ...codec.ProtoMars | |||
// RequireErrorIsOrContains verifies that the passed error is either a target error or contains its error message. | |||
func RequireErrorIsOrContains(t *testing.T, err, targetError error, msgAndArgs ...interface{}) { | |||
t.Helper() | |||
require.Error(t, err) |
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.
can we remove this?
|
||
// set the acknowledgement so that it can be verified on the other side | ||
k.SetPacketAcknowledgement( | ||
ctx, packet.DestinationChannel, packet.GetSequence(), |
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.
I always kinda liked the getters 😢 hot take... really I don't care tho
// TODO: figure out how aliasing will work when more than one packet data is sent. | ||
channel, ok = k.convertV1Channel(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel) | ||
if !ok { | ||
return errorsmod.Wrap(channeltypes.ErrChannelNotFound, packet.DestinationChannel) |
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.
aliasing/converting should happen in RecvPacket so this should never be reachable...
should just be error i think if not found
// the OnRecvPacket callback so we need to check if the acknowledgement is already | ||
// set on the store and return an error if so. | ||
if k.HasPacketAcknowledgement(ctx, packet.DestinationChannel, packet.Sequence) { | ||
return channeltypes.ErrAcknowledgementExists |
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.
should we wrap with channel id / sequence?
} | ||
|
||
if channel.CounterpartyChannelId != packet.SourceChannel { | ||
return channeltypes.ErrInvalidChannelIdentifier |
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.
same for wrapping
Description
closes: #7354
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
).godoc
comments.Files changed
in the GitHub PR explorer.SonarCloud Report
in the comment section below once CI passes.