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

[POC] msgServerV2 implementation #7302

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6ad6131
chore: add MsgSendPacket and SendPacket RPC proto definitions
bznein Sep 17, 2024
030098c
create proto file for msg server v2
bznein Sep 17, 2024
1b746c4
add no-op PackMsh methods
bznein Sep 17, 2024
65633e4
chore: adding wiring for new message types
chatton Sep 17, 2024
e0cce22
added SendPacketV2 to packet-server
bznein Sep 17, 2024
373028a
Added AppRouterV2
bznein Sep 18, 2024
0c1c80c
Added ibc_module_v2 and ibc_app_v2
bznein Sep 18, 2024
c420214
Wiring of routerV2
bznein Sep 18, 2024
caaf324
Added TimeoutPacketV2 function
bznein Sep 18, 2024
877fd5b
chore: adding RecvPacketV2
chatton Sep 18, 2024
833cbcd
chore: added AcknowledgementV2 and WriteAsyncV2 functions
chatton Sep 18, 2024
cda2efa
chore: moved new handlers and functions into new files
chatton Sep 18, 2024
e5f20a5
msg server v2 test WIP
bznein Sep 18, 2024
9e767ab
chore: adding passing MessageServerV2 happy path test
chatton Sep 18, 2024
ba29b6e
chore: remove unused fields for proto
chatton Sep 18, 2024
974e097
added V2 transfer module
bznein Sep 18, 2024
7104c3e
wip: adding WIP test for msg server v2 transfer
chatton Sep 18, 2024
444c0fc
wip: experiementing with transfer test
chatton Sep 18, 2024
2f59a88
wip: got recv flow technically working with some hard coded hacks
chatton Sep 19, 2024
e0aa8a7
added constructors for MsgSendPacket and its fields
bznein Sep 19, 2024
382a08d
use constructor for FungibleTokenPacketDataV2 in test
bznein Sep 19, 2024
213e5ad
use consturctor for PacketData in test
bznein Sep 19, 2024
3ba3b6f
add constructor for MsgRecvPacket
bznein Sep 19, 2024
9d0ff03
Use consutrctor for MsgRecvPacket in test
bznein Sep 19, 2024
a004929
Add constructor for MsgAcknowledgement
bznein Sep 19, 2024
4de5e72
[WIP - POC] revert transfer test (#7315)
bznein Sep 19, 2024
d11f761
chore: fix signer parsing
chatton Sep 25, 2024
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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-go/modules/capability v1.0.1
github.com/cosmos/ics23/go v0.11.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down Expand Up @@ -114,6 +113,7 @@ require (
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
Expand Down Expand Up @@ -143,6 +143,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20240607163614-bb94eb51e7a7 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI=
github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down Expand Up @@ -462,6 +460,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
Expand Down Expand Up @@ -791,6 +790,7 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q=
Expand Down Expand Up @@ -1236,6 +1236,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1356,6 +1357,7 @@ golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82u
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
Expand Down
1 change: 0 additions & 1 deletion modules/apps/callbacks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions modules/apps/callbacks/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI=
github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down
25 changes: 25 additions & 0 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,31 @@ func (k *Keeper) deletePacketAcknowledgement(ctx context.Context, portID, channe
}
}

func (k *Keeper) SetMultiAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64, multiAck types.MultiAcknowledgement) {
store := k.storeService.OpenKVStore(ctx)
bz := k.cdc.MustMarshal(&multiAck)
if err := store.Set(host.MultiAckKey(portID, channelID, sequence), bz); err != nil {
panic(err)
}
}

// GetMultiAcknowledgement gets the multi ack result
func (k *Keeper) GetMultiAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64) (types.MultiAcknowledgement, bool) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(host.MultiAckKey(portID, channelID, sequence))
if err != nil {
panic(err)
}

if len(bz) == 0 {
return types.MultiAcknowledgement{}, false
}

var res types.MultiAcknowledgement
k.cdc.MustUnmarshal(bz, &res)
return res, true
}

// IteratePacketSequence provides an iterator over all send, receive or ack sequences.
// For each sequence, cb will be called. If the cb returns true, the iterator
// will close and stop.
Expand Down
15 changes: 0 additions & 15 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
"github.com/cosmos/ibc-go/v9/modules/core/legacy"
)

// SendPacket is called by a module in order to send an IBC packet on a channel.
Expand Down Expand Up @@ -284,20 +283,6 @@ func (k *Keeper) WriteAcknowledgement(
packet exported.PacketI,
acknowledgement exported.Acknowledgement,
) error {
v1Packet, ok := packet.(types.Packet)
if !ok {
return errorsmod.Wrapf(types.ErrInvalidPacket, "expected packet type %T, got %T", types.Packet{}, packet)
}

// if an acknowledgement is being written for a V2 packet, we need to ensure that the acknowledgement
// structure uses the multi ack structure.
// TODO: this is a bit gross / hacky, can we ensure that async acks will always have the correct structure?
if v1Packet.ProtocolVersion == types.IBC_VERSION_2 {
if _, ok := acknowledgement.(*legacy.MultiAck); !ok {
acknowledgement = legacy.NewLMultiAck(k.cdc, acknowledgement, packet.GetDestPort())
}
}

channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel())
if !found {
return errorsmod.Wrap(types.ErrChannelNotFound, packet.GetDestChannel())
Expand Down
23 changes: 18 additions & 5 deletions modules/core/04-channel/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ func hashPacketData(data PacketData) []byte {
}

func (p PacketV2) ValidateBasic() error {
// TODO: temporarily assume a single packet data
if len(p.Data) != 1 {
return errorsmod.Wrap(ErrInvalidPacket, "packet data length must be 1")
}

for _, pd := range p.Data {
if err := host.PortIdentifierValidator(pd.SourcePort); err != nil {
return errorsmod.Wrap(err, "invalid source port ID")
Expand Down Expand Up @@ -348,3 +343,21 @@ func ConvertPacketV1toV2(packet Packet) (PacketV2, error) {
},
}, nil
}

// NewPayload constructs and returns a new payload.
func NewPayload(version, encoding string, value []byte) *Payload {
return &Payload{
Version: version,
Encoding: encoding,
Value: value,
}
}

// NewPacketData constructs and returns a new PacketData.
func NewPacketData(sourcePort, destPort string, payload Payload) *PacketData {
return &PacketData{
SourcePort: sourcePort,
DestinationPort: destPort,
Payload: payload,
}
}
18 changes: 18 additions & 0 deletions modules/core/04-channel/v2/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package types

import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgSendPacket{},
&MsgRecvPacket{},
&MsgAcknowledgement{},
&MsgTimeout{},
)
msgservice.RegisterMsgServiceDesc(registry, &_PacketMsg_serviceDesc)
}
41 changes: 41 additions & 0 deletions modules/core/04-channel/v2/types/msgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
v1types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
)

var _ sdk.Msg = (*MsgSendPacket)(nil)

// NewMsgSendPacket constructs and returns a new MsgSendPacket.
func NewMsgSendPacket(sourceID string, timeoutTimestamp uint64, signer string, packetData ...v1types.PacketData) *MsgSendPacket {
return &MsgSendPacket{
SourceId: sourceID,
TimeoutTimestamp: timeoutTimestamp,
PacketData: packetData,
Signer: signer,
}
}

// NewMsgRecvPacket constructs and returns a new MsgRecvPacket
func NewMsgRecvPacket(packet v1types.PacketV2, proofCommitment []byte, proofHeight clienttypes.Height, signer string) *MsgRecvPacket {
return &MsgRecvPacket{
Packet: packet,
ProofCommitment: proofCommitment,
ProofHeight: proofHeight,
Signer: signer,
}
}

// NewMsgAcknowledgement constructs and returns a new MsgAcknowledgement
func NewMsgAcknoweldgement(packet v1types.PacketV2, multiAck v1types.MultiAcknowledgement, proofAcked []byte, proofHeight clienttypes.Height, signer string) *MsgAcknowledgement {
return &MsgAcknowledgement{
Packet: packet,
MultiAcknowledgement: multiAck,
ProofAcked: proofAcked,
ProofHeight: proofHeight,
Signer: signer,
}
}
20 changes: 20 additions & 0 deletions modules/core/04-channel/v2/types/packet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package types

import (
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
)

func NewPacketV2(
sequence uint64, sourceId,

Check failure on line 8 in modules/core/04-channel/v2/types/packet.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter sourceId should be sourceID (revive)

Check failure on line 8 in modules/core/04-channel/v2/types/packet.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter sourceId should be sourceID (revive)
destinationId string,

Check failure on line 9 in modules/core/04-channel/v2/types/packet.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter destinationId should be destinationID (revive)

Check failure on line 9 in modules/core/04-channel/v2/types/packet.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func parameter destinationId should be destinationID (revive)
timeoutTimestamp uint64,
data ...channeltypes.PacketData,
) channeltypes.PacketV2 {
return channeltypes.PacketV2{
Sequence: sequence,
SourceId: sourceId,
DestinationId: destinationId,
TimeoutTimestamp: timeoutTimestamp,
Data: data,
}
}
Loading
Loading