From 91a3676376e8236b452ae4a9eaa9cdeeca26dec8 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 28 May 2024 15:27:10 +0200 Subject: [PATCH 01/21] proto gen --- pkg/chains/chains.pb.go | 155 +++++++++++++----- .../zetacore/pkg/chains/chains.proto | 16 ++ 2 files changed, 128 insertions(+), 43 deletions(-) diff --git a/pkg/chains/chains.pb.go b/pkg/chains/chains.pb.go index 1153208c6d..fd32b67e8f 100644 --- a/pkg/chains/chains.pb.go +++ b/pkg/chains/chains.pb.go @@ -269,6 +269,36 @@ func (Consensus) EnumDescriptor() ([]byte, []int) { return fileDescriptor_236b85e7bff6130d, []int{5} } +// CCTXGateway describes for the chain the gateway used to handle CCTX outbounds +type CCTXGateway int32 + +const ( + // zevm is the internal CCTX gateway to process outbound on the ZEVM in + // ZetaChain only used for ZetaChain chains + CCTXGateway_zevm CCTXGateway = 0 + // observers is the CCTX gateway for chains relying on the observer set to + // observe inbounds and TSS for outbounds + CCTXGateway_observers CCTXGateway = 1 +) + +var CCTXGateway_name = map[int32]string{ + 0: "zevm", + 1: "observers", +} + +var CCTXGateway_value = map[string]int32{ + "zevm": 0, + "observers": 1, +} + +func (x CCTXGateway) String() string { + return proto.EnumName(CCTXGateway_name, int32(x)) +} + +func (CCTXGateway) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_236b85e7bff6130d, []int{6} +} + // Chain represents static data about a blockchain network // it is identified by a unique chain ID type Chain struct { @@ -286,6 +316,8 @@ type Chain struct { Consensus Consensus `protobuf:"varint,6,opt,name=consensus,proto3,enum=zetachain.zetacore.pkg.chains.Consensus" json:"consensus,omitempty"` // IsExternal describe if the chain is ZetaChain or external IsExternal bool `protobuf:"varint,7,opt,name=is_external,json=isExternal,proto3" json:"is_external,omitempty"` + // CCTXGateway is the gateway used to handle CCTX outbounds + CctxGateway CCTXGateway `protobuf:"varint,8,opt,name=cctx_gateway,json=cctxGateway,proto3,enum=zetachain.zetacore.pkg.chains.CCTXGateway" json:"cctx_gateway,omitempty"` } func (m *Chain) Reset() { *m = Chain{} } @@ -370,6 +402,13 @@ func (m *Chain) GetIsExternal() bool { return false } +func (m *Chain) GetCctxGateway() CCTXGateway { + if m != nil { + return m.CctxGateway + } + return CCTXGateway_zevm +} + func init() { proto.RegisterEnum("zetachain.zetacore.pkg.chains.ReceiveStatus", ReceiveStatus_name, ReceiveStatus_value) proto.RegisterEnum("zetachain.zetacore.pkg.chains.ChainName", ChainName_name, ChainName_value) @@ -377,6 +416,7 @@ func init() { proto.RegisterEnum("zetachain.zetacore.pkg.chains.NetworkType", NetworkType_name, NetworkType_value) proto.RegisterEnum("zetachain.zetacore.pkg.chains.Vm", Vm_name, Vm_value) proto.RegisterEnum("zetachain.zetacore.pkg.chains.Consensus", Consensus_name, Consensus_value) + proto.RegisterEnum("zetachain.zetacore.pkg.chains.CCTXGateway", CCTXGateway_name, CCTXGateway_value) proto.RegisterType((*Chain)(nil), "zetachain.zetacore.pkg.chains.Chain") } @@ -385,49 +425,51 @@ func init() { } var fileDescriptor_236b85e7bff6130d = []byte{ - // 658 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x6e, 0x13, 0x3b, - 0x14, 0xc6, 0x33, 0x93, 0xff, 0x27, 0x69, 0xea, 0xeb, 0x76, 0x91, 0x5b, 0xe9, 0xce, 0xed, 0xbd, - 0x0b, 0x14, 0x22, 0x91, 0x08, 0x58, 0xb2, 0x41, 0x54, 0x14, 0x81, 0x44, 0x17, 0x03, 0xaa, 0x04, - 0x9b, 0x68, 0xe2, 0x1c, 0x26, 0x56, 0x62, 0x7b, 0x34, 0x76, 0x02, 0xe1, 0x29, 0x58, 0xf2, 0x00, - 0x2c, 0x78, 0x14, 0x96, 0x5d, 0xb2, 0x44, 0xed, 0x03, 0xf0, 0x0a, 0xc8, 0xce, 0x78, 0x02, 0x0b, - 0x68, 0x57, 0x73, 0xfc, 0x9b, 0xef, 0x7c, 0xe7, 0xd8, 0x3e, 0x32, 0x0c, 0xdf, 0xa3, 0x49, 0xd8, - 0x3c, 0xe1, 0x72, 0xec, 0x22, 0x95, 0xe3, 0x38, 0x5b, 0xa4, 0x63, 0x87, 0x74, 0xf1, 0x19, 0x65, - 0xb9, 0x32, 0x8a, 0xfe, 0x53, 0x6a, 0x47, 0x5e, 0x3b, 0xca, 0x16, 0xe9, 0x68, 0x2b, 0x3a, 0x3a, - 0x4c, 0x55, 0xaa, 0x9c, 0x72, 0x6c, 0xa3, 0x6d, 0xd2, 0xff, 0x1f, 0xab, 0x50, 0x3f, 0xb1, 0x02, - 0xfa, 0x37, 0xb4, 0x9c, 0x72, 0xc2, 0x67, 0xfd, 0xf0, 0x38, 0x18, 0x54, 0xe3, 0xa6, 0x5b, 0x3f, - 0x9d, 0xd1, 0x27, 0x00, 0xdb, 0x5f, 0x32, 0x11, 0xd8, 0x0f, 0x8e, 0x83, 0x41, 0xef, 0xde, 0x60, - 0xf4, 0xc7, 0x72, 0x23, 0x67, 0x7a, 0x96, 0x08, 0x8c, 0xdb, 0xcc, 0x87, 0xf4, 0x21, 0x34, 0x25, - 0x9a, 0xb7, 0x2a, 0x5f, 0xf4, 0xab, 0xce, 0xe5, 0xd6, 0x35, 0x2e, 0x67, 0x5b, 0x75, 0xec, 0xd3, - 0xe8, 0x73, 0xe8, 0x16, 0xe1, 0xc4, 0x6c, 0x32, 0xec, 0xd7, 0x9c, 0xcd, 0xf0, 0x66, 0x36, 0x2f, - 0x37, 0x19, 0xc6, 0x1d, 0xb9, 0x5b, 0xd0, 0xbb, 0x10, 0xae, 0x45, 0xbf, 0xee, 0x4c, 0xfe, 0xbb, - 0xc6, 0xe4, 0x5c, 0xc4, 0xe1, 0x5a, 0xd0, 0x53, 0x68, 0x33, 0x25, 0x35, 0x4a, 0xbd, 0xd2, 0xfd, - 0xc6, 0xcd, 0xce, 0xc2, 0xeb, 0xe3, 0x5d, 0x2a, 0xfd, 0x17, 0x3a, 0x5c, 0x4f, 0xf0, 0x9d, 0xc1, - 0x5c, 0x26, 0xcb, 0x7e, 0xf3, 0x38, 0x18, 0xb4, 0x62, 0xe0, 0xfa, 0x71, 0x41, 0x86, 0x0f, 0x60, - 0x2f, 0x46, 0x86, 0x7c, 0x8d, 0x2f, 0x4c, 0x62, 0x56, 0x9a, 0x76, 0xa0, 0xc9, 0x72, 0x4c, 0x0c, - 0xce, 0x48, 0xc5, 0x2e, 0xf4, 0x8a, 0x31, 0xd4, 0x9a, 0x04, 0x14, 0xa0, 0xf1, 0x26, 0xe1, 0x4b, - 0x9c, 0x91, 0xf0, 0xa8, 0xf6, 0xf9, 0x53, 0x14, 0x0c, 0xbf, 0x87, 0xd0, 0x2e, 0xaf, 0x80, 0xb6, - 0xa1, 0x8e, 0x22, 0x33, 0x1b, 0x52, 0xa1, 0xfb, 0xd0, 0x41, 0x33, 0x9f, 0x88, 0x84, 0x4b, 0x89, - 0x86, 0x04, 0x94, 0x40, 0xd7, 0xf6, 0x5c, 0x92, 0xd0, 0x4a, 0xa6, 0x86, 0x95, 0xa0, 0x4a, 0x0f, - 0x60, 0x3f, 0x53, 0xcb, 0x4d, 0xaa, 0x64, 0x09, 0x6b, 0x4e, 0xa5, 0x77, 0xaa, 0x3a, 0xa5, 0xd0, - 0x4b, 0x15, 0xe6, 0x4b, 0x3e, 0x31, 0xa8, 0x8d, 0x65, 0x0d, 0xcb, 0xc4, 0x4a, 0x4c, 0x93, 0x1d, - 0x6b, 0xfa, 0x44, 0x0f, 0xa0, 0xec, 0xc0, 0x93, 0x8e, 0xef, 0xc0, 0x83, 0xae, 0xed, 0x40, 0x63, - 0xa6, 0x96, 0x7c, 0xa7, 0xda, 0xb3, 0xb0, 0x28, 0xb8, 0x54, 0x2c, 0x59, 0x5a, 0xd8, 0xf3, 0xa9, - 0x39, 0xa6, 0x56, 0x48, 0xf6, 0xad, 0x7b, 0x22, 0xd4, 0xa6, 0xcc, 0x23, 0xf4, 0x10, 0x88, 0xca, - 0x0c, 0x17, 0x5c, 0x8b, 0xb2, 0xfd, 0xbf, 0x7e, 0xa1, 0x45, 0x2d, 0x42, 0x6d, 0xf6, 0x34, 0xd1, - 0x58, 0xea, 0x0e, 0x4a, 0xe2, 0x35, 0x87, 0xc5, 0x89, 0xbf, 0x82, 0x66, 0x31, 0x66, 0xb4, 0x09, - 0x55, 0x34, 0x73, 0x52, 0xa1, 0x2d, 0xa8, 0xd9, 0x9d, 0x91, 0xc0, 0xa2, 0xa9, 0x61, 0x24, 0xb4, - 0xf7, 0x56, 0x9c, 0x25, 0xa9, 0x3a, 0xaa, 0x19, 0xa9, 0xd1, 0x2e, 0xb4, 0x7c, 0x71, 0x52, 0xb7, - 0x69, 0xb6, 0x04, 0x69, 0x14, 0xd6, 0xa7, 0xd0, 0xf9, 0x69, 0x82, 0xad, 0x85, 0x6f, 0xc7, 0xcd, - 0x81, 0xdf, 0x59, 0xe0, 0xcc, 0x73, 0xbe, 0xde, 0x5e, 0x23, 0x40, 0x63, 0x86, 0x2e, 0xae, 0x16, - 0x3e, 0x11, 0x84, 0xe7, 0xc2, 0x0e, 0x83, 0x54, 0x93, 0xb5, 0x20, 0x15, 0xd7, 0xe8, 0x5a, 0x90, - 0xa0, 0xf8, 0xff, 0x0c, 0xda, 0xe5, 0xa8, 0xda, 0x96, 0xd0, 0xcc, 0x31, 0xc7, 0x95, 0x55, 0xf6, - 0x00, 0x0c, 0xca, 0x19, 0xe6, 0x82, 0xcb, 0xa2, 0xd2, 0x94, 0x1b, 0xa6, 0xb8, 0x24, 0xe1, 0xb6, - 0xfb, 0x89, 0x36, 0x09, 0x5b, 0xf8, 0x5a, 0x8f, 0x4e, 0xbe, 0x5c, 0x46, 0xc1, 0xc5, 0x65, 0x14, - 0x7c, 0xbb, 0x8c, 0x82, 0x0f, 0x57, 0x51, 0xe5, 0xe2, 0x2a, 0xaa, 0x7c, 0xbd, 0x8a, 0x2a, 0xaf, - 0x6f, 0xa7, 0xdc, 0xcc, 0x57, 0xd3, 0x11, 0x53, 0xc2, 0x3d, 0x6a, 0x77, 0x7e, 0xfb, 0xbe, 0x4d, - 0x1b, 0xee, 0x91, 0xba, 0xff, 0x23, 0x00, 0x00, 0xff, 0xff, 0x15, 0x2a, 0x93, 0x8e, 0x07, 0x05, - 0x00, 0x00, + // 704 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x3d, 0x8f, 0x2b, 0x35, + 0x14, 0xcd, 0x4c, 0xbe, 0xef, 0x64, 0xb3, 0xc6, 0x6f, 0x8b, 0xe1, 0x49, 0x0c, 0x0b, 0x05, 0x0a, + 0x11, 0x24, 0x02, 0x4a, 0x1a, 0x44, 0xc4, 0x7b, 0x02, 0x89, 0x57, 0x0c, 0xab, 0x15, 0xd0, 0x8c, + 0x3c, 0xce, 0x65, 0x62, 0x25, 0x1e, 0x8f, 0xc6, 0x4e, 0x76, 0xc3, 0xaf, 0xe0, 0x47, 0x50, 0xf0, + 0x53, 0x28, 0xb7, 0xa4, 0x44, 0xbb, 0x05, 0x25, 0x7f, 0x01, 0xd9, 0xf3, 0x91, 0xa5, 0x80, 0xdd, + 0x2a, 0xd7, 0x67, 0xce, 0x39, 0xf7, 0xd8, 0xbe, 0x31, 0xcc, 0x7f, 0x46, 0xc3, 0xf8, 0x86, 0x89, + 0x7c, 0xe9, 0x2a, 0x55, 0xe2, 0xb2, 0xd8, 0x66, 0x4b, 0x07, 0xe9, 0xfa, 0x67, 0x51, 0x94, 0xca, + 0x28, 0xfa, 0x4e, 0xcb, 0x5d, 0x34, 0xdc, 0x45, 0xb1, 0xcd, 0x16, 0x15, 0xe9, 0xe5, 0x45, 0xa6, + 0x32, 0xe5, 0x98, 0x4b, 0x5b, 0x55, 0xa2, 0xf7, 0xff, 0xea, 0x42, 0x7f, 0x65, 0x09, 0xf4, 0x6d, + 0x18, 0x39, 0x66, 0x22, 0xd6, 0xa1, 0x7f, 0xe9, 0xcd, 0xba, 0xf1, 0xd0, 0xad, 0xbf, 0x5e, 0xd3, + 0xd7, 0x00, 0xd5, 0xa7, 0x9c, 0x49, 0x0c, 0xbd, 0x4b, 0x6f, 0x36, 0xfd, 0x74, 0xb6, 0xf8, 0xdf, + 0x76, 0x0b, 0x67, 0xfa, 0x86, 0x49, 0x8c, 0xc7, 0xbc, 0x29, 0xe9, 0x17, 0x30, 0xcc, 0xd1, 0xdc, + 0xa8, 0x72, 0x1b, 0x76, 0x9d, 0xcb, 0x07, 0x4f, 0xb8, 0xbc, 0xa9, 0xd8, 0x71, 0x23, 0xa3, 0xdf, + 0xc2, 0xa4, 0x2e, 0x13, 0x73, 0x2c, 0x30, 0xec, 0x39, 0x9b, 0xf9, 0xf3, 0x6c, 0xae, 0x8e, 0x05, + 0xc6, 0x41, 0x7e, 0x5a, 0xd0, 0x4f, 0xc0, 0x3f, 0xc8, 0xb0, 0xef, 0x4c, 0xde, 0x7b, 0xc2, 0xe4, + 0x5a, 0xc6, 0xfe, 0x41, 0xd2, 0x57, 0x30, 0xe6, 0x2a, 0xd7, 0x98, 0xeb, 0xbd, 0x0e, 0x07, 0xcf, + 0x3b, 0x8b, 0x86, 0x1f, 0x9f, 0xa4, 0xf4, 0x5d, 0x08, 0x84, 0x4e, 0xf0, 0xd6, 0x60, 0x99, 0xb3, + 0x5d, 0x38, 0xbc, 0xf4, 0x66, 0xa3, 0x18, 0x84, 0xfe, 0xaa, 0x46, 0xec, 0x56, 0x39, 0x37, 0xb7, + 0x49, 0xc6, 0x0c, 0xde, 0xb0, 0x63, 0x38, 0x7a, 0xd6, 0x56, 0x57, 0xab, 0xab, 0xef, 0x5f, 0x57, + 0x8a, 0x38, 0xb0, 0xfa, 0x7a, 0x31, 0xff, 0x1c, 0xce, 0x62, 0xe4, 0x28, 0x0e, 0xf8, 0x9d, 0x61, + 0x66, 0xaf, 0x69, 0x00, 0x43, 0x5e, 0x22, 0x33, 0xb8, 0x26, 0x1d, 0xbb, 0xd0, 0x7b, 0xce, 0x51, + 0x6b, 0xe2, 0x51, 0x80, 0xc1, 0x4f, 0x4c, 0xec, 0x70, 0x4d, 0xfc, 0x97, 0xbd, 0xdf, 0x7e, 0x8d, + 0xbc, 0xf9, 0xdf, 0x3e, 0x8c, 0xdb, 0x1b, 0xa5, 0x63, 0xe8, 0xa3, 0x2c, 0xcc, 0x91, 0x74, 0xe8, + 0x39, 0x04, 0x68, 0x36, 0x89, 0x64, 0x22, 0xcf, 0xd1, 0x10, 0x8f, 0x12, 0x98, 0xd8, 0x58, 0x2d, + 0xe2, 0x5b, 0x4a, 0x6a, 0x78, 0x0b, 0x74, 0xe9, 0x0b, 0x38, 0x2f, 0xd4, 0xee, 0x98, 0xa9, 0xbc, + 0x05, 0x7b, 0x8e, 0xa5, 0x4f, 0xac, 0x3e, 0xa5, 0x30, 0xcd, 0x14, 0x96, 0x3b, 0x91, 0x18, 0xd4, + 0xc6, 0x62, 0x03, 0x8b, 0xc9, 0xbd, 0x4c, 0xd9, 0x09, 0x1b, 0x36, 0xc2, 0x06, 0x80, 0x36, 0x41, + 0x83, 0x04, 0x4d, 0x82, 0x06, 0x98, 0xd8, 0x04, 0x1a, 0x0b, 0xb5, 0x13, 0x27, 0xd6, 0x99, 0x05, + 0xeb, 0x86, 0x3b, 0xc5, 0xd9, 0xce, 0x82, 0xd3, 0x46, 0x5a, 0x62, 0x66, 0x89, 0xe4, 0xdc, 0xba, + 0x33, 0xa9, 0x8e, 0xad, 0x8e, 0xd0, 0x0b, 0x20, 0xaa, 0x30, 0x42, 0x0a, 0x2d, 0xdb, 0xf8, 0x6f, + 0xfd, 0x0b, 0xad, 0x7b, 0x11, 0x6a, 0xd5, 0x29, 0xd3, 0xd8, 0xf2, 0x5e, 0xb4, 0x48, 0xc3, 0xb9, + 0xa8, 0x4f, 0xfc, 0x07, 0x18, 0xd6, 0x53, 0x4b, 0x87, 0xd0, 0x45, 0xb3, 0x21, 0x1d, 0x3a, 0x82, + 0x9e, 0xdd, 0x19, 0xf1, 0x2c, 0x94, 0x1a, 0x4e, 0x7c, 0x7b, 0x6f, 0xf5, 0x59, 0x92, 0xae, 0x43, + 0x35, 0x27, 0x3d, 0x3a, 0x81, 0x51, 0xd3, 0x9c, 0xf4, 0xad, 0xcc, 0xb6, 0x20, 0x83, 0xda, 0xfa, + 0x15, 0x04, 0x8f, 0xfe, 0x10, 0xd6, 0xa2, 0x89, 0xe3, 0xe6, 0xa0, 0xd9, 0x99, 0xe7, 0xcc, 0x4b, + 0x71, 0xa8, 0xae, 0x11, 0x60, 0xb0, 0x46, 0x57, 0x77, 0x6b, 0x9f, 0x08, 0xfc, 0x6b, 0x69, 0x87, + 0x21, 0x57, 0xc9, 0x41, 0x92, 0x8e, 0x0b, 0x7a, 0x90, 0xc4, 0xab, 0xbf, 0x7f, 0x03, 0xe3, 0x76, + 0xf2, 0x6d, 0x24, 0x34, 0x1b, 0x2c, 0x71, 0x6f, 0x99, 0x53, 0x00, 0x83, 0xf9, 0x1a, 0x4b, 0x29, + 0xf2, 0xba, 0x53, 0x2a, 0x0c, 0x57, 0x22, 0x27, 0x7e, 0x95, 0x3e, 0xd1, 0x86, 0xf1, 0x6d, 0xdb, + 0xeb, 0x23, 0x08, 0x1e, 0x4d, 0x76, 0x75, 0x12, 0xae, 0xe7, 0x19, 0x8c, 0x55, 0xaa, 0xb1, 0x3c, + 0x60, 0xa9, 0x9b, 0xce, 0x5f, 0xae, 0x7e, 0xbf, 0x8f, 0xbc, 0xbb, 0xfb, 0xc8, 0xfb, 0xf3, 0x3e, + 0xf2, 0x7e, 0x79, 0x88, 0x3a, 0x77, 0x0f, 0x51, 0xe7, 0x8f, 0x87, 0xa8, 0xf3, 0xe3, 0x87, 0x99, + 0x30, 0x9b, 0x7d, 0xba, 0xe0, 0x4a, 0xba, 0x17, 0xf5, 0xe3, 0xff, 0x7c, 0x5c, 0xd3, 0x81, 0x7b, + 0x21, 0x3f, 0xfb, 0x27, 0x00, 0x00, 0xff, 0xff, 0x05, 0xa7, 0x7f, 0x40, 0x84, 0x05, 0x00, 0x00, } func (m *Chain) Marshal() (dAtA []byte, err error) { @@ -450,6 +492,11 @@ func (m *Chain) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.CctxGateway != 0 { + i = encodeVarintChains(dAtA, i, uint64(m.CctxGateway)) + i-- + dAtA[i] = 0x40 + } if m.IsExternal { i-- if m.IsExternal { @@ -531,6 +578,9 @@ func (m *Chain) Size() (n int) { if m.IsExternal { n += 2 } + if m.CctxGateway != 0 { + n += 1 + sovChains(uint64(m.CctxGateway)) + } return n } @@ -703,6 +753,25 @@ func (m *Chain) Unmarshal(dAtA []byte) error { } } m.IsExternal = bool(v != 0) + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CctxGateway", wireType) + } + m.CctxGateway = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowChains + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CctxGateway |= CCTXGateway(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipChains(dAtA[iNdEx:]) diff --git a/proto/zetachain/zetacore/pkg/chains/chains.proto b/proto/zetachain/zetacore/pkg/chains/chains.proto index 1f2279af35..a146df4b73 100644 --- a/proto/zetachain/zetacore/pkg/chains/chains.proto +++ b/proto/zetachain/zetacore/pkg/chains/chains.proto @@ -88,6 +88,19 @@ enum Consensus { op_stack = 3; } +// CCTXGateway describes for the chain the gateway used to handle CCTX outbounds +enum CCTXGateway { + option (gogoproto.goproto_enum_stringer) = true; + + // zevm is the internal CCTX gateway to process outbound on the ZEVM in + // ZetaChain only used for ZetaChain chains + zevm = 0; + + // observers is the CCTX gateway for chains relying on the observer set to + // observe inbounds and TSS for outbounds + observers = 1; +} + // Chain represents static data about a blockchain network // it is identified by a unique chain ID message Chain { @@ -111,4 +124,7 @@ message Chain { // IsExternal describe if the chain is ZetaChain or external bool is_external = 7; + + // CCTXGateway is the gateway used to handle CCTX outbounds + CCTXGateway cctx_gateway = 8; } From 13367cbf87a543150fa6f758a4d641ee10f9a843 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 28 May 2024 15:30:00 +0200 Subject: [PATCH 02/21] add field to chains --- pkg/chains/chains.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/chains/chains.go b/pkg/chains/chains.go index 21718f874d..61fffece76 100644 --- a/pkg/chains/chains.go +++ b/pkg/chains/chains.go @@ -16,6 +16,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_tendermint, IsExternal: false, + CctxGateway: CCTXGateway_zevm, } // Ethereum is Ethereum mainnet @@ -27,6 +28,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // BscMainnet is Binance Smart Chain mainnet @@ -38,6 +40,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // BitcoinMainnet is Bitcoin mainnet @@ -49,6 +52,7 @@ var ( Vm: Vm_no_vm, Consensus: Consensus_bitcoin, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // Polygon is Polygon mainnet @@ -60,6 +64,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // OptimismMainnet is Optimism mainnet @@ -71,6 +76,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_op_stack, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // BaseMainnet is Base mainnet @@ -82,6 +88,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_op_stack, IsExternal: true, + CctxGateway: CCTXGateway_observers, } /** @@ -97,6 +104,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_tendermint, IsExternal: false, + CctxGateway: CCTXGateway_zevm, } // Sepolia is Ethereum sepolia testnet @@ -108,6 +116,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // BscTestnet is Binance Smart Chain testnet @@ -119,6 +128,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // BitcoinTestnet is Bitcoin testnet3 @@ -130,6 +140,7 @@ var ( Vm: Vm_no_vm, Consensus: Consensus_bitcoin, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // Amoy is Polygon amoy testnet @@ -141,6 +152,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // OptimismSepolia is Optimism sepolia testnet @@ -152,6 +164,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_op_stack, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // BaseSepolia is Base sepolia testnet @@ -163,6 +176,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_op_stack, IsExternal: true, + CctxGateway: CCTXGateway_observers, } /** @@ -179,6 +193,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_tendermint, IsExternal: false, + CctxGateway: CCTXGateway_zevm, } /** @@ -194,6 +209,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_tendermint, IsExternal: false, + CctxGateway: CCTXGateway_zevm, } // BitcoinRegtest is Bitcoin regtest (localnet) @@ -205,6 +221,7 @@ var ( Vm: Vm_no_vm, Consensus: Consensus_bitcoin, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // GoerliLocalnet is Ethereum local goerli (localnet) @@ -216,6 +233,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } /** @@ -231,6 +249,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } // Mumbai is Polygon mumbai testnet (deprecated for amoy) @@ -242,6 +261,7 @@ var ( Vm: Vm_evm, Consensus: Consensus_ethereum, IsExternal: true, + CctxGateway: CCTXGateway_observers, } ) From 42ea82cac75b67f89bb6c785a79539adc0ce95ed Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 28 May 2024 15:38:40 +0200 Subject: [PATCH 03/21] make generate --- docs/openapi/openapi.swagger.yaml | 15 ++++++++++ .../zetacore/pkg/chains/chains_pb.d.ts | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 92c7ac28c8..77d5e48ec9 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -56744,6 +56744,18 @@ definitions: description: |- QueryGetPoliciesResponse is the response type for the Query/Policies RPC method. + chainsCCTXGateway: + type: string + enum: + - zevm + - observers + default: zevm + description: |- + - zevm: zevm is the internal CCTX gateway to process outbound on the ZEVM in + ZetaChain only used for ZetaChain chains + - observers: observers is the CCTX gateway for chains relying on the observer set to + observe inbounds and TSS for outbounds + title: CCTXGateway describes for the chain the gateway used to handle CCTX outbounds chainsChain: type: object properties: @@ -56769,6 +56781,9 @@ definitions: is_external: type: boolean title: IsExternal describe if the chain is ZetaChain or external + cctx_gateway: + $ref: '#/definitions/chainsCCTXGateway' + title: CCTXGateway is the gateway used to handle CCTX outbounds title: |- Chain represents static data about a blockchain network it is identified by a unique chain ID diff --git a/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts b/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts index 6abe26cd04..07ddfb8617 100644 --- a/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts +++ b/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts @@ -253,6 +253,29 @@ export declare enum Consensus { op_stack = 3, } +/** + * CCTXGateway describes for the chain the gateway used to handle CCTX outbounds + * + * @generated from enum zetachain.zetacore.pkg.chains.CCTXGateway + */ +export declare enum CCTXGateway { + /** + * zevm is the internal CCTX gateway to process outbound on the ZEVM in + * ZetaChain only used for ZetaChain chains + * + * @generated from enum value: zevm = 0; + */ + zevm = 0, + + /** + * observers is the CCTX gateway for chains relying on the observer set to + * observe inbounds and TSS for outbounds + * + * @generated from enum value: observers = 1; + */ + observers = 1, +} + /** * Chain represents static data about a blockchain network * it is identified by a unique chain ID @@ -309,6 +332,13 @@ export declare class Chain extends Message { */ isExternal: boolean; + /** + * CCTXGateway is the gateway used to handle CCTX outbounds + * + * @generated from field: zetachain.zetacore.pkg.chains.CCTXGateway cctx_gateway = 8; + */ + cctxGateway: CCTXGateway; + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; From af4a6fdd61911f7199b2dd86d49ec90a6b5d28f0 Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 28 May 2024 15:41:10 +0200 Subject: [PATCH 04/21] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index fcbfee4d18..a8a5a47821 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ * [2113](https://github.com/zeta-chain/node/pull/2113) - add zetaclientd-supervisor process * [2154](https://github.com/zeta-chain/node/pull/2154) - add `ibccrosschain` module * [2258](https://github.com/zeta-chain/node/pull/2258) - add Optimism and Base in static chain information +* [2279](https://github.com/zeta-chain/node/pull/2279) - add a CCTXGateway field to chain static data ### Refactor From 1640324e0b1ba06b135d92c696276210d1078ccf Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 28 May 2024 18:55:42 +0200 Subject: [PATCH 05/21] fix test --- zetaclient/zetacore/tx_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zetaclient/zetacore/tx_test.go b/zetaclient/zetacore/tx_test.go index f12fcc8b6a..919f9cc058 100644 --- a/zetaclient/zetacore/tx_test.go +++ b/zetaclient/zetacore/tx_test.go @@ -247,7 +247,6 @@ func TestZetacore_UpdateZetacoreContext(t *testing.T) { WithPayload(observertypes.QuerySupportedChains{}). Return(observertypes.QuerySupportedChainsResponse{ Chains: []*chains.Chain{ - { chains.BitcoinMainnet.ChainId, chains.BitcoinMainnet.ChainName, @@ -256,6 +255,7 @@ func TestZetacore_UpdateZetacoreContext(t *testing.T) { chains.BscMainnet.Vm, chains.BscMainnet.Consensus, chains.BscMainnet.IsExternal, + chains.BscMainnet.CctxGateway, }, { chains.Ethereum.ChainId, @@ -265,6 +265,7 @@ func TestZetacore_UpdateZetacoreContext(t *testing.T) { chains.Ethereum.Vm, chains.Ethereum.Consensus, chains.Ethereum.IsExternal, + chains.Ethereum.CctxGateway, }, }, }) From fc6f66b8b0c9c283ee9e5fe08c57af54e6aebbe3 Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 29 May 2024 16:15:54 +0200 Subject: [PATCH 06/21] update comment --- proto/zetachain/zetacore/pkg/chains/chains.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/zetachain/zetacore/pkg/chains/chains.proto b/proto/zetachain/zetacore/pkg/chains/chains.proto index a146df4b73..e273fbab8c 100644 --- a/proto/zetachain/zetacore/pkg/chains/chains.proto +++ b/proto/zetachain/zetacore/pkg/chains/chains.proto @@ -92,8 +92,8 @@ enum Consensus { enum CCTXGateway { option (gogoproto.goproto_enum_stringer) = true; - // zevm is the internal CCTX gateway to process outbound on the ZEVM in - // ZetaChain only used for ZetaChain chains + // zevm is the internal CCTX gateway to process outbound on the ZEVM and read inbound events from the ZEVM + // only used for ZetaChain chains zevm = 0; // observers is the CCTX gateway for chains relying on the observer set to From dfd39e575040bbfa4df3d99b1627f729a4f3a81f Mon Sep 17 00:00:00 2001 From: lumtis Date: Wed, 29 May 2024 16:20:33 +0200 Subject: [PATCH 07/21] make format --- docs/openapi/openapi.swagger.yaml | 4 ++-- pkg/chains/chains.pb.go | 4 ++-- proto/zetachain/zetacore/pkg/chains/chains.proto | 4 ++-- typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 77d5e48ec9..bd966c07b2 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -56751,8 +56751,8 @@ definitions: - observers default: zevm description: |- - - zevm: zevm is the internal CCTX gateway to process outbound on the ZEVM in - ZetaChain only used for ZetaChain chains + - zevm: zevm is the internal CCTX gateway to process outbound on the ZEVM and read + inbound events from the ZEVM only used for ZetaChain chains - observers: observers is the CCTX gateway for chains relying on the observer set to observe inbounds and TSS for outbounds title: CCTXGateway describes for the chain the gateway used to handle CCTX outbounds diff --git a/pkg/chains/chains.pb.go b/pkg/chains/chains.pb.go index fd32b67e8f..848a7e1bc0 100644 --- a/pkg/chains/chains.pb.go +++ b/pkg/chains/chains.pb.go @@ -273,8 +273,8 @@ func (Consensus) EnumDescriptor() ([]byte, []int) { type CCTXGateway int32 const ( - // zevm is the internal CCTX gateway to process outbound on the ZEVM in - // ZetaChain only used for ZetaChain chains + // zevm is the internal CCTX gateway to process outbound on the ZEVM and read + // inbound events from the ZEVM only used for ZetaChain chains CCTXGateway_zevm CCTXGateway = 0 // observers is the CCTX gateway for chains relying on the observer set to // observe inbounds and TSS for outbounds diff --git a/proto/zetachain/zetacore/pkg/chains/chains.proto b/proto/zetachain/zetacore/pkg/chains/chains.proto index e273fbab8c..8075822471 100644 --- a/proto/zetachain/zetacore/pkg/chains/chains.proto +++ b/proto/zetachain/zetacore/pkg/chains/chains.proto @@ -92,8 +92,8 @@ enum Consensus { enum CCTXGateway { option (gogoproto.goproto_enum_stringer) = true; - // zevm is the internal CCTX gateway to process outbound on the ZEVM and read inbound events from the ZEVM - // only used for ZetaChain chains + // zevm is the internal CCTX gateway to process outbound on the ZEVM and read + // inbound events from the ZEVM only used for ZetaChain chains zevm = 0; // observers is the CCTX gateway for chains relying on the observer set to diff --git a/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts b/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts index 07ddfb8617..782e669d43 100644 --- a/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts +++ b/typescript/zetachain/zetacore/pkg/chains/chains_pb.d.ts @@ -260,8 +260,8 @@ export declare enum Consensus { */ export declare enum CCTXGateway { /** - * zevm is the internal CCTX gateway to process outbound on the ZEVM in - * ZetaChain only used for ZetaChain chains + * zevm is the internal CCTX gateway to process outbound on the ZEVM and read + * inbound events from the ZEVM only used for ZetaChain chains * * @generated from enum value: zevm = 0; */ From 5f626b8152937e1e9ae2ebfa36f8731327784fce Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 21:14:39 +0200 Subject: [PATCH 08/21] Add first version of cctx gateway interface and implementations --- app/app.go | 7 + x/crosschain/keeper/cctx_gateway_observers.go | 42 ++++++ x/crosschain/keeper/cctx_gateway_zevm.go | 78 +++++++++++ x/crosschain/keeper/initiate_inbound.go | 17 +++ ...bound_test.go => initiate_inbound_test.go} | 52 +++---- x/crosschain/keeper/keeper.go | 18 ++- .../keeper/msg_server_vote_inbound_tx.go | 4 +- x/crosschain/keeper/process_inbound.go | 131 ------------------ 8 files changed, 187 insertions(+), 162 deletions(-) create mode 100644 x/crosschain/keeper/cctx_gateway_observers.go create mode 100644 x/crosschain/keeper/cctx_gateway_zevm.go create mode 100644 x/crosschain/keeper/initiate_inbound.go rename x/crosschain/keeper/{process_inbound_test.go => initiate_inbound_test.go} (95%) delete mode 100644 x/crosschain/keeper/process_inbound.go diff --git a/app/app.go b/app/app.go index e6dfe90de1..424c6c6878 100644 --- a/app/app.go +++ b/app/app.go @@ -105,6 +105,7 @@ import ( "github.com/zeta-chain/zetacore/app/ante" "github.com/zeta-chain/zetacore/docs/openapi" + "github.com/zeta-chain/zetacore/pkg/chains" zetamempool "github.com/zeta-chain/zetacore/pkg/mempool" srvflags "github.com/zeta-chain/zetacore/server/flags" authoritymodule "github.com/zeta-chain/zetacore/x/authority" @@ -597,6 +598,12 @@ func New( app.LightclientKeeper, ) + cctxGateways := map[chains.CCTXGateway]crosschainkeeper.CCTXGateway{ + chains.CCTXGateway_observers: crosschainkeeper.NewCCTXGatewayObservers(app.CrosschainKeeper), + chains.CCTXGateway_zevm: crosschainkeeper.NewCCTXGatewayZEVM(app.CrosschainKeeper), + } + app.CrosschainKeeper.SetCCTXGateways(cctxGateways) + // initialize ibccrosschain keeper and set it to the crosschain keeper // there is a circular dependency between the two keepers, crosschain keeper must be initialized first diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go new file mode 100644 index 0000000000..4da27d2187 --- /dev/null +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -0,0 +1,42 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +type CCTXGatewayObservers struct { + crosschainKeeper Keeper +} + +func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { + return CCTXGatewayObservers{ + crosschainKeeper: crosschainKeeper, + } +} + +func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { + tmpCtx, commit := ctx.CacheContext() + outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId + err := func() error { + err := c.crosschainKeeper.PayGasAndUpdateCctx( + tmpCtx, + outboundReceiverChainID, + cctx, + cctx.InboundParams.Amount, + false, + ) + if err != nil { + return err + } + return c.crosschainKeeper.UpdateNonce(tmpCtx, outboundReceiverChainID, cctx) + }() + if err != nil { + // do not commit anything here as the CCTX should be aborted + cctx.SetAbort(err.Error()) + return nil + } + commit() + cctx.SetPendingOutbound("") + return nil +} diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go new file mode 100644 index 0000000000..27a9fbecbf --- /dev/null +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -0,0 +1,78 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +type CCTXGatewayZEVM struct { + crosschainKeeper Keeper +} + +func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { + return CCTXGatewayZEVM{ + crosschainKeeper: crosschainKeeper, + } +} + +func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { + tmpCtx, commit := ctx.CacheContext() + isContractReverted, err := c.crosschainKeeper.HandleEVMDeposit(tmpCtx, cctx) + + // further processing will be in validateOutbound(...), for now keeping it here + if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX + cctx.SetAbort(err.Error()) + return err + } else if err != nil && isContractReverted { // contract call reverted; should refund via a revert tx + revertMessage := err.Error() + senderChain := c.crosschainKeeper.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, cctx.InboundParams.SenderChainId) + if senderChain == nil { + cctx.SetAbort(fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId)) + return nil + } + gasLimit, err := c.crosschainKeeper.GetRevertGasLimit(ctx, *cctx) + if err != nil { + cctx.SetAbort(fmt.Sprintf("revert gas limit error: %s", err.Error())) + return nil + } + if gasLimit == 0 { + // use same gas limit of outbound as a fallback -- should not be required + gasLimit = cctx.GetCurrentOutboundParam().GasLimit + } + + err = cctx.AddRevertOutbound(gasLimit) + if err != nil { + cctx.SetAbort(fmt.Sprintf("revert outbound error: %s", err.Error())) + return nil + } + // we create a new cached context, and we don't commit the previous one with EVM deposit + tmpCtxRevert, commitRevert := ctx.CacheContext() + err = func() error { + err := c.crosschainKeeper.PayGasAndUpdateCctx( + tmpCtxRevert, + senderChain.ChainId, + cctx, + cctx.InboundParams.Amount, + false, + ) + if err != nil { + return err + } + // Update nonce using senderchain id as this is a revert tx and would go back to the original sender + return c.crosschainKeeper.UpdateNonce(tmpCtxRevert, senderChain.ChainId, cctx) + }() + if err != nil { + cctx.SetAbort(fmt.Sprintf("deposit revert message: %s err : %s", revertMessage, err.Error())) + return nil + } + commitRevert() + cctx.SetPendingRevert(revertMessage) + return nil + } + // successful HandleEVMDeposit; + commit() + cctx.SetOutBoundMined("Remote omnichain contract call completed") + return nil +} diff --git a/x/crosschain/keeper/initiate_inbound.go b/x/crosschain/keeper/initiate_inbound.go new file mode 100644 index 0000000000..b073792f5a --- /dev/null +++ b/x/crosschain/keeper/initiate_inbound.go @@ -0,0 +1,17 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +// InitiateOutbound processes the inbound CCTX. +// It does a conditional dispatch to observer or zevm CCTX gateway based on the receiver chain +// which handle the state changes and error handling. +func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { + chainInfo := chains.GetChainFromChainID(cctx.GetCurrentOutboundParam().ReceiverChainId) + + return k.cctxGateways[chainInfo.CctxGateway].InitiateOutbound(ctx, cctx) +} diff --git a/x/crosschain/keeper/process_inbound_test.go b/x/crosschain/keeper/initiate_inbound_test.go similarity index 95% rename from x/crosschain/keeper/process_inbound_test.go rename to x/crosschain/keeper/initiate_inbound_test.go index 0286290cc4..b727b833df 100644 --- a/x/crosschain/keeper/process_inbound_test.go +++ b/x/crosschain/keeper/initiate_inbound_test.go @@ -18,7 +18,7 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { +func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { t.Run("process zevm deposit successfully", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseFungibleMock: true, @@ -34,7 +34,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { mock.Anything, receiver, int64(0), amount, mock.Anything, mock.Anything).Return(nil, nil) - // call ProcessInbound + // call InitiateOutbound cctx := sample.CrossChainTx(t, "test") cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingInbound} cctx.GetCurrentOutboundParam().Receiver = receiver.String() @@ -42,7 +42,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_OutboundMined, cctx.CctxStatus.Status) }) @@ -61,7 +61,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { fungibleMock.On("ZETADepositAndCallContract", mock.Anything, mock.Anything, receiver, int64(0), amount, mock.Anything, mock.Anything). Return(nil, fmt.Errorf("deposit error")) - // call ProcessInbound + // call InitiateOutbound cctx := sample.CrossChainTx(t, "test") cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingInbound} cctx.GetCurrentOutboundParam().Receiver = receiver.String() @@ -69,7 +69,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal(t, "deposit error", cctx.CctxStatus.StatusMessage) }) @@ -98,10 +98,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId). Return(nil) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, "", amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -136,10 +136,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { fungibleMock.On("GetForeignCoinFromAsset", mock.Anything, asset, senderChain.ChainId). Return(fungibletypes.ForeignCoins{}, false) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -179,10 +179,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId). Return(nil).Once() - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -223,10 +223,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId). Return(nil).Once() - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -268,10 +268,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock.On("GetChainNonces", mock.Anything, senderChain.ChainName.String()). Return(observertypes.ChainNonces{}, false) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) @@ -306,10 +306,10 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { // mock successful UpdateNonce updatedNonce := keepertest.MockUpdateNonce(observerMock, *senderChain) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_PendingRevert, cctx.CctxStatus.Status) require.Equal(t, errDeposit.Error(), cctx.CctxStatus.StatusMessage) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) @@ -342,11 +342,11 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { // mock successful GetRevertGasLimit for ERC20 keepertest.MockGetRevertGasLimitForERC20(fungibleMock, asset, *senderChain, 100) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId cctx.OutboundParams = append(cctx.OutboundParams, cctx.GetCurrentOutboundParam()) - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Contains( t, @@ -357,7 +357,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { ) } -func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { +func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { t.Run("process crosschain msg passing successfully", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseFungibleMock: true, @@ -377,9 +377,9 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { // mock successful UpdateNonce updatedNonce := keepertest.MockUpdateNonce(observerMock, *receiverChain) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_PendingOutbound, cctx.CctxStatus.Status) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) }) @@ -400,9 +400,9 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, receiverChain.ChainId). Return(nil).Once() - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal(t, observertypes.ErrSupportedChains.Error(), cctx.CctxStatus.StatusMessage) }) @@ -427,9 +427,9 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock.On("GetChainNonces", mock.Anything, receiverChain.ChainName.String()). Return(observertypes.ChainNonces{}, false) - // call ProcessInbound + // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.ProcessInbound(ctx, cctx) + k.InitiateOutbound(ctx, cctx) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index fc483689b3..a18e92e5bd 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -8,14 +8,22 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/x/crosschain/types" ) +type CCTXGateway interface { + // Initiate a new outbound, this tells the CCTXGateway to carry out the action to execute the outbound + // TODO: how to do everything needed with just outboundParams? + InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error +} + type ( Keeper struct { - cdc codec.Codec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey + cdc codec.Codec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + cctxGateways map[chains.CCTXGateway]CCTXGateway stakingKeeper types.StakingKeeper authKeeper types.AccountKeeper @@ -100,6 +108,10 @@ func (k *Keeper) SetIBCCrosschainKeeper(ibcCrosschainKeeper types.IBCCrosschainK k.ibcCrosschainKeeper = ibcCrosschainKeeper } +func (k *Keeper) SetCCTXGateways(cctxGateways map[chains.CCTXGateway]CCTXGateway) { + k.cctxGateways = cctxGateways +} + func (k Keeper) GetStoreKey() storetypes.StoreKey { return k.storeKey } diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index 9b40097635..e10aa70e0d 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -106,9 +106,9 @@ func (k msgServer) VoteInbound( if err != nil { return nil, err } - // Process the inbound CCTX, the process function manages the state commit and cctx status change. + // Inititiate outboud, the process function manages the state commit and cctx status change. // If the process fails, the changes to the evm state are rolled back. - k.ProcessInbound(ctx, &cctx) + k.InitiateOutbound(ctx, &cctx) // Save the inbound CCTX to the store. This is called irrespective of the status of the CCTX or the outcome of the process function. k.SaveInbound(ctx, &cctx, msg.EventIndex) return &types.MsgVoteInboundResponse{}, nil diff --git a/x/crosschain/keeper/process_inbound.go b/x/crosschain/keeper/process_inbound.go deleted file mode 100644 index 2fe9bfb3c9..0000000000 --- a/x/crosschain/keeper/process_inbound.go +++ /dev/null @@ -1,131 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/zeta-chain/zetacore/pkg/chains" - "github.com/zeta-chain/zetacore/x/crosschain/types" -) - -// ProcessInbound processes the inbound CCTX. -// It does a conditional dispatch to ProcessZEVMDeposit or ProcessCrosschainMsgPassing based on the receiver chain. -// The internal functions handle the state changes and error handling. -func (k Keeper) ProcessInbound(ctx sdk.Context, cctx *types.CrossChainTx) { - if chains.IsZetaChain(cctx.GetCurrentOutboundParam().ReceiverChainId) { - k.processZEVMDeposit(ctx, cctx) - } else { - k.processCrosschainMsgPassing(ctx, cctx) - } -} - -/* -processZEVMDeposit processes the EVM deposit CCTX. A deposit is a cctx which has Zetachain as the receiver chain.It trasnsitions state according to the following rules: - - - If the deposit is successful, the CCTX status is changed to OutboundMined. - - - If the deposit returns an internal error i.e if HandleEVMDeposit() returns an error, but isContractReverted is false, the CCTX status is changed to Aborted. - - - If the deposit is reverted, the function tries to create a revert cctx with status PendingRevert. - - - If the creation of revert tx also fails it changes the status to Aborted. - -Note : Aborted CCTXs are not refunded in this function. The refund is done using a separate refunding mechanism. -We do not return an error from this function , as all changes need to be persisted to the state. -Instead we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to OutboundMined. -*/ -func (k Keeper) processZEVMDeposit(ctx sdk.Context, cctx *types.CrossChainTx) { - tmpCtx, commit := ctx.CacheContext() - isContractReverted, err := k.HandleEVMDeposit(tmpCtx, cctx) - - if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX - cctx.SetAbort(err.Error()) - return - } else if err != nil && isContractReverted { // contract call reverted; should refund via a revert tx - revertMessage := err.Error() - senderChain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, cctx.InboundParams.SenderChainId) - if senderChain == nil { - cctx.SetAbort(fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId)) - return - } - gasLimit, err := k.GetRevertGasLimit(ctx, *cctx) - if err != nil { - cctx.SetAbort(fmt.Sprintf("revert gas limit error: %s", err.Error())) - return - } - if gasLimit == 0 { - // use same gas limit of outbound as a fallback -- should not be required - gasLimit = cctx.GetCurrentOutboundParam().GasLimit - } - - err = cctx.AddRevertOutbound(gasLimit) - if err != nil { - cctx.SetAbort(fmt.Sprintf("revert outbound error: %s", err.Error())) - return - } - // we create a new cached context, and we don't commit the previous one with EVM deposit - tmpCtxRevert, commitRevert := ctx.CacheContext() - err = func() error { - err := k.PayGasAndUpdateCctx( - tmpCtxRevert, - senderChain.ChainId, - cctx, - cctx.InboundParams.Amount, - false, - ) - if err != nil { - return err - } - // Update nonce using senderchain id as this is a revert tx and would go back to the original sender - return k.UpdateNonce(tmpCtxRevert, senderChain.ChainId, cctx) - }() - if err != nil { - cctx.SetAbort(fmt.Sprintf("deposit revert message: %s err : %s", revertMessage, err.Error())) - return - } - commitRevert() - cctx.SetPendingRevert(revertMessage) - return - } - // successful HandleEVMDeposit; - commit() - cctx.SetOutBoundMined("Remote omnichain contract call completed") - return -} - -/* -processCrosschainMsgPassing processes the CCTX for crosschain message passing. A crosschain message passing is a cctx which has a non-Zetachain as the receiver chain.It trasnsitions state according to the following rules: - - - If the crosschain message passing is successful, the CCTX status is changed to PendingOutbound. - - - If the crosschain message passing returns an error, the CCTX status is changed to Aborted. - We do not return an error from this function, as all changes need to be persisted to the state. - - Instead, we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to PendingOutbound. -*/ -func (k Keeper) processCrosschainMsgPassing(ctx sdk.Context, cctx *types.CrossChainTx) { - tmpCtx, commit := ctx.CacheContext() - outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId - err := func() error { - err := k.PayGasAndUpdateCctx( - tmpCtx, - outboundReceiverChainID, - cctx, - cctx.InboundParams.Amount, - false, - ) - if err != nil { - return err - } - return k.UpdateNonce(tmpCtx, outboundReceiverChainID, cctx) - }() - if err != nil { - // do not commit anything here as the CCTX should be aborted - cctx.SetAbort(err.Error()) - return - } - commit() - cctx.SetPendingOutbound("") - return -} From 93b9fab020982c933842e690027668a53bbc2798 Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 22:04:53 +0200 Subject: [PATCH 09/21] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 584d3c2409..df79d3cd2b 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ * [2258](https://github.com/zeta-chain/node/pull/2258) - add Optimism and Base in static chain information * [2279](https://github.com/zeta-chain/node/pull/2279) - add a CCTXGateway field to chain static data * [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority +* [2291](https://github.com/zeta-chain/node/pull/2291) - cctx gateway interface ### Refactor From ea2cea297b55a73e44468e4dbba70ab816c4f9fd Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 22:06:29 +0200 Subject: [PATCH 10/21] make generate --- x/crosschain/keeper/cctx_gateway_observers.go | 1 + x/crosschain/keeper/cctx_gateway_zevm.go | 1 + 2 files changed, 2 insertions(+) diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index 4da27d2187..c11c723c54 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/crosschain/types" ) diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index 27a9fbecbf..b189470117 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/crosschain/types" ) From 1b347f2ef967718314b268150be8b21777f49fe0 Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 22:07:23 +0200 Subject: [PATCH 11/21] linter fix --- x/crosschain/keeper/msg_server_vote_inbound_tx.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index e10aa70e0d..6296f0b8b2 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -108,7 +108,10 @@ func (k msgServer) VoteInbound( } // Inititiate outboud, the process function manages the state commit and cctx status change. // If the process fails, the changes to the evm state are rolled back. - k.InitiateOutbound(ctx, &cctx) + err = k.InitiateOutbound(ctx, &cctx) + if err != nil { + return nil, err + } // Save the inbound CCTX to the store. This is called irrespective of the status of the CCTX or the outcome of the process function. k.SaveInbound(ctx, &cctx, msg.EventIndex) return &types.MsgVoteInboundResponse{}, nil From 365c2d4f741e88948e74248d31037023aec20d42 Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 22:12:27 +0200 Subject: [PATCH 12/21] comments --- x/crosschain/keeper/cctx_gateway_observers.go | 7 +++++++ x/crosschain/keeper/cctx_gateway_zevm.go | 12 ++++++++++++ x/crosschain/keeper/initiate_inbound.go | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index c11c723c54..f912977397 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -16,6 +16,13 @@ func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { } } +/* +InitiateOutbound updates the store so observers can use the PendingCCTX query: + - If the crosschain message passing is successful, the CCTX status is changed to PendingOutbound. + - If the crosschain message passing returns an error, the CCTX status is changed to Aborted. + We do not return an error from this function, as all changes need to be persisted to the state. + Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. +*/ func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { tmpCtx, commit := ctx.CacheContext() outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index b189470117..34a8530f7c 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -18,6 +18,18 @@ func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { } } +/* +InitiateOutbound handles evm deposit and then ValidateOutbound is called. +TODO: move this comment to ValidateOutbound once it's added + - If the deposit is successful, the CCTX status is changed to OutboundMined. + - If the deposit returns an internal error i.e if HandleEVMDeposit() returns an error, but isContractReverted is false, the CCTX status is changed to Aborted. + - If the deposit is reverted, the function tries to create a revert cctx with status PendingRevert. + - If the creation of revert tx also fails it changes the status to Aborted. + +Note : Aborted CCTXs are not refunded in this function. The refund is done using a separate refunding mechanism. +We do not return an error from this function , as all changes need to be persisted to the state. +Instead we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to OutboundMined. +*/ func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { tmpCtx, commit := ctx.CacheContext() isContractReverted, err := c.crosschainKeeper.HandleEVMDeposit(tmpCtx, cctx) diff --git a/x/crosschain/keeper/initiate_inbound.go b/x/crosschain/keeper/initiate_inbound.go index b073792f5a..4bba934d1d 100644 --- a/x/crosschain/keeper/initiate_inbound.go +++ b/x/crosschain/keeper/initiate_inbound.go @@ -8,7 +8,7 @@ import ( ) // InitiateOutbound processes the inbound CCTX. -// It does a conditional dispatch to observer or zevm CCTX gateway based on the receiver chain +// It does a conditional dispatch to correct CCTX gateway based on the receiver chain // which handle the state changes and error handling. func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { chainInfo := chains.GetChainFromChainID(cctx.GetCurrentOutboundParam().ReceiverChainId) From 5b047ee469ac4be6a10c65fd44a51adb882932b8 Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 22:20:19 +0200 Subject: [PATCH 13/21] make generate --- x/crosschain/keeper/cctx_gateway_observers.go | 3 +++ x/crosschain/keeper/cctx_gateway_zevm.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index f912977397..7cb9291db6 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -18,9 +18,12 @@ func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { /* InitiateOutbound updates the store so observers can use the PendingCCTX query: + - If the crosschain message passing is successful, the CCTX status is changed to PendingOutbound. + - If the crosschain message passing returns an error, the CCTX status is changed to Aborted. We do not return an error from this function, as all changes need to be persisted to the state. + Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. */ func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index 34a8530f7c..22ea009349 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -20,10 +20,14 @@ func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { /* InitiateOutbound handles evm deposit and then ValidateOutbound is called. -TODO: move this comment to ValidateOutbound once it's added +TODO: move remaining of this comment to ValidateOutbound once it's added. + - If the deposit is successful, the CCTX status is changed to OutboundMined. + - If the deposit returns an internal error i.e if HandleEVMDeposit() returns an error, but isContractReverted is false, the CCTX status is changed to Aborted. + - If the deposit is reverted, the function tries to create a revert cctx with status PendingRevert. + - If the creation of revert tx also fails it changes the status to Aborted. Note : Aborted CCTXs are not refunded in this function. The refund is done using a separate refunding mechanism. From 44bd0669c2000523df10e258383fc2675b8b75bf Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 29 May 2024 22:22:55 +0200 Subject: [PATCH 14/21] fix tests --- testutil/keeper/crosschain.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 0ff22a6250..5ca5acbaae 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -174,6 +174,13 @@ func CrosschainKeeperWithMocks( lightclientKeeper, ) + cctxGateways := map[chains.CCTXGateway]keeper.CCTXGateway{ + chains.CCTXGateway_observers: keeper.NewCCTXGatewayObservers(*k), + chains.CCTXGateway_zevm: keeper.NewCCTXGatewayZEVM(*k), + } + + k.SetCCTXGateways(cctxGateways) + // initialize ibccrosschain keeper and set it to the crosschain keeper // there is a circular dependency between the two keepers, crosschain keeper must be initialized first From c989a673e04c2097b7cf967c8e8557c637e41e57 Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 30 May 2024 16:36:34 +0200 Subject: [PATCH 15/21] PR comments --- app/app.go | 2 ++ changelog.md | 2 +- x/crosschain/keeper/cctx_gateway_observers.go | 1 + x/crosschain/keeper/cctx_gateway_zevm.go | 9 ++++++--- x/crosschain/keeper/initiate_inbound.go | 14 ++++++++++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index 424c6c6878..eaad38a8a2 100644 --- a/app/app.go +++ b/app/app.go @@ -598,6 +598,8 @@ func New( app.LightclientKeeper, ) + // initializing map of cctx gateways so crosschain module can decide which one to use + // based on chain info of destination chain cctxGateways := map[chains.CCTXGateway]crosschainkeeper.CCTXGateway{ chains.CCTXGateway_observers: crosschainkeeper.NewCCTXGatewayObservers(app.CrosschainKeeper), chains.CCTXGateway_zevm: crosschainkeeper.NewCCTXGatewayZEVM(app.CrosschainKeeper), diff --git a/changelog.md b/changelog.md index f9f563ee38..d887199203 100644 --- a/changelog.md +++ b/changelog.md @@ -19,7 +19,7 @@ * [2287](https://github.com/zeta-chain/node/pull/2287) - implement `MsgUpdateChainInfo` message * [2279](https://github.com/zeta-chain/node/pull/2279) - add a CCTXGateway field to chain static data * [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority -* [2291](https://github.com/zeta-chain/node/pull/2291) - cctx gateway interface +* [2291](https://github.com/zeta-chain/node/pull/2291) - initialize cctx gateway interface ### Refactor diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index 7cb9291db6..387afd9b89 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -10,6 +10,7 @@ type CCTXGatewayObservers struct { crosschainKeeper Keeper } +// NewCCTXGatewayObservers is implementation of CCTXGateway interface for observers func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { return CCTXGatewayObservers{ crosschainKeeper: crosschainKeeper, diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index 22ea009349..2c50d11db8 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -12,6 +12,7 @@ type CCTXGatewayZEVM struct { crosschainKeeper Keeper } +// NewCCTXGatewayZEVM is implementation of CCTXGateway interface for observers func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { return CCTXGatewayZEVM{ crosschainKeeper: crosschainKeeper, @@ -38,11 +39,13 @@ func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChai tmpCtx, commit := ctx.CacheContext() isContractReverted, err := c.crosschainKeeper.HandleEVMDeposit(tmpCtx, cctx) - // further processing will be in validateOutbound(...), for now keeping it here - if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX + // TODO: further processing will be in validateOutbound(...), for now keeping it here + if err != nil && !isContractReverted { + // exceptional case; internal error; should abort CCTX cctx.SetAbort(err.Error()) return err - } else if err != nil && isContractReverted { // contract call reverted; should refund via a revert tx + } else if err != nil && isContractReverted { + // contract call reverted; should refund via a revert tx revertMessage := err.Error() senderChain := c.crosschainKeeper.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, cctx.InboundParams.SenderChainId) if senderChain == nil { diff --git a/x/crosschain/keeper/initiate_inbound.go b/x/crosschain/keeper/initiate_inbound.go index 4bba934d1d..699021d091 100644 --- a/x/crosschain/keeper/initiate_inbound.go +++ b/x/crosschain/keeper/initiate_inbound.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/zeta-chain/zetacore/pkg/chains" @@ -11,7 +13,15 @@ import ( // It does a conditional dispatch to correct CCTX gateway based on the receiver chain // which handle the state changes and error handling. func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { - chainInfo := chains.GetChainFromChainID(cctx.GetCurrentOutboundParam().ReceiverChainId) + receiverChainId := cctx.GetCurrentOutboundParam().ReceiverChainId + chainInfo := chains.GetChainFromChainID(receiverChainId) + if chainInfo == nil { + return fmt.Errorf("chain info not found for %d", receiverChainId) + } - return k.cctxGateways[chainInfo.CctxGateway].InitiateOutbound(ctx, cctx) + cctxGateway, ok := k.cctxGateways[chainInfo.CctxGateway] + if !ok { + return fmt.Errorf("CCTXGateway not defined for receiver chain %d", receiverChainId) + } + return cctxGateway.InitiateOutbound(ctx, cctx) } From 66170b658aa2b7cd2e15a85df7e5eac2ddb98873 Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 30 May 2024 16:43:53 +0200 Subject: [PATCH 16/21] add failure tests for initiate outbound method --- x/crosschain/keeper/cctx_gateway_zevm.go | 2 +- ...itiate_inbound.go => initiate_outbound.go} | 0 ...ound_test.go => initiate_outbound_test.go} | 78 ++++++++++++++++--- 3 files changed, 67 insertions(+), 13 deletions(-) rename x/crosschain/keeper/{initiate_inbound.go => initiate_outbound.go} (100%) rename x/crosschain/keeper/{initiate_inbound_test.go => initiate_outbound_test.go} (88%) diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index 2c50d11db8..9a1897844c 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -43,7 +43,7 @@ func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChai if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX cctx.SetAbort(err.Error()) - return err + return nil } else if err != nil && isContractReverted { // contract call reverted; should refund via a revert tx revertMessage := err.Error() diff --git a/x/crosschain/keeper/initiate_inbound.go b/x/crosschain/keeper/initiate_outbound.go similarity index 100% rename from x/crosschain/keeper/initiate_inbound.go rename to x/crosschain/keeper/initiate_outbound.go diff --git a/x/crosschain/keeper/initiate_inbound_test.go b/x/crosschain/keeper/initiate_outbound_test.go similarity index 88% rename from x/crosschain/keeper/initiate_inbound_test.go rename to x/crosschain/keeper/initiate_outbound_test.go index b727b833df..1046614608 100644 --- a/x/crosschain/keeper/initiate_inbound_test.go +++ b/x/crosschain/keeper/initiate_outbound_test.go @@ -13,6 +13,7 @@ import ( "github.com/zeta-chain/zetacore/pkg/coin" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/crosschain/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" @@ -42,7 +43,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_OutboundMined, cctx.CctxStatus.Status) }) @@ -69,7 +71,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal(t, "deposit error", cctx.CctxStatus.StatusMessage) }) @@ -101,7 +104,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, "", amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -139,7 +143,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -182,7 +187,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -226,7 +232,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal( t, @@ -271,7 +278,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) @@ -309,7 +317,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_PendingRevert, cctx.CctxStatus.Status) require.Equal(t, errDeposit.Error(), cctx.CctxStatus.StatusMessage) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) @@ -346,7 +355,8 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId cctx.OutboundParams = append(cctx.OutboundParams, cctx.GetCurrentOutboundParam()) - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Contains( t, @@ -379,7 +389,8 @@ func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_PendingOutbound, cctx.CctxStatus.Status) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) }) @@ -402,7 +413,8 @@ func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Equal(t, observertypes.ErrSupportedChains.Error(), cctx.CctxStatus.StatusMessage) }) @@ -429,8 +441,50 @@ func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - k.InitiateOutbound(ctx, cctx) + err := k.InitiateOutbound(ctx, cctx) + require.Nil(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) } + +func TestKeeper_InitiateOutboundFailures(t *testing.T) { + t.Run("should fail if chain info can not be found for receiver chain id", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseFungibleMock: true, + UseObserverMock: true, + }) + + // Setup mock data + receiver := sample.EthAddress() + amount := big.NewInt(42) + receiverChain := getValidEthChain() + receiverChain.ChainId = 123 + // call InitiateOutbound + cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) + err := k.InitiateOutbound(ctx, cctx) + require.NotNil(t, err) + require.Contains(t, err.Error(), "chain info not found") + }) + + t.Run("should fail if cctx gateway not found for receiver chain id", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseFungibleMock: true, + UseObserverMock: true, + }) + + // reset cctx gateways + k.SetCCTXGateways(map[chains.CCTXGateway]keeper.CCTXGateway{}) + + // Setup mock data + receiver := sample.EthAddress() + amount := big.NewInt(42) + receiverChain := getValidEthChain() + // call InitiateOutbound + cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) + err := k.InitiateOutbound(ctx, cctx) + require.NotNil(t, err) + require.Contains(t, err.Error(), "CCTXGateway not defined for receiver chain") + }) + +} From def9670f9fc5349ed9fd426bd1b1f5660d96ebcf Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 30 May 2024 16:54:19 +0200 Subject: [PATCH 17/21] lint --- x/crosschain/keeper/initiate_outbound.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/crosschain/keeper/initiate_outbound.go b/x/crosschain/keeper/initiate_outbound.go index 699021d091..ef76b5490d 100644 --- a/x/crosschain/keeper/initiate_outbound.go +++ b/x/crosschain/keeper/initiate_outbound.go @@ -13,15 +13,15 @@ import ( // It does a conditional dispatch to correct CCTX gateway based on the receiver chain // which handle the state changes and error handling. func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { - receiverChainId := cctx.GetCurrentOutboundParam().ReceiverChainId - chainInfo := chains.GetChainFromChainID(receiverChainId) + receiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId + chainInfo := chains.GetChainFromChainID(receiverChainID) if chainInfo == nil { - return fmt.Errorf("chain info not found for %d", receiverChainId) + return fmt.Errorf("chain info not found for %d", receiverChainID) } cctxGateway, ok := k.cctxGateways[chainInfo.CctxGateway] if !ok { - return fmt.Errorf("CCTXGateway not defined for receiver chain %d", receiverChainId) + return fmt.Errorf("CCTXGateway not defined for receiver chain %d", receiverChainID) } return cctxGateway.InitiateOutbound(ctx, cctx) } From 812d62a0f107a06cc2c69fb1c81b504ee900a8c3 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 31 May 2024 20:17:50 +0200 Subject: [PATCH 18/21] PR comments --- app/ante/vesting_test.go | 2 +- pkg/chains/address_taproot_test.go | 14 ++-- pkg/crypto/pubkey_test.go | 16 ++--- x/authority/types/genesis_test.go | 2 +- x/crosschain/keeper/cctx_gateway_observers.go | 16 +++-- x/crosschain/keeper/cctx_gateway_zevm.go | 26 +++---- x/crosschain/keeper/initiate_outbound.go | 11 +-- x/crosschain/keeper/initiate_outbound_test.go | 72 +++++++++++-------- x/crosschain/keeper/keeper.go | 8 ++- .../keeper/msg_server_vote_inbound_tx.go | 4 +- x/fungible/keeper/evm_test.go | 2 +- .../msg_server_deploy_system_contract_test.go | 10 +-- x/observer/types/chain_params_test.go | 2 +- .../types/message_disable_cctx_flags_test.go | 4 +- .../types/message_enable_cctx_flags_test.go | 4 +- ...ge_update_gas_price_increase_flags_test.go | 4 +- zetaclient/chains/bitcoin/fee_test.go | 12 ++-- .../chains/bitcoin/observer/outbound_test.go | 32 ++++----- .../chains/bitcoin/signer/signer_test.go | 2 +- zetaclient/chains/evm/validation_test.go | 2 +- 20 files changed, 133 insertions(+), 112 deletions(-) diff --git a/app/ante/vesting_test.go b/app/ante/vesting_test.go index 280a128ca5..0adaaea014 100644 --- a/app/ante/vesting_test.go +++ b/app/ante/vesting_test.go @@ -95,7 +95,7 @@ func TestVesting_AnteHandle(t *testing.T) { if tt.wantHasErr { require.Error(t, err) - require.Contains(t, err.Error(), tt.wantErr) + require.ErrorContains(t, err, tt.wantErr) } else { require.NoError(t, err) } diff --git a/pkg/chains/address_taproot_test.go b/pkg/chains/address_taproot_test.go index 08de704937..c3742dcefc 100644 --- a/pkg/chains/address_taproot_test.go +++ b/pkg/chains/address_taproot_test.go @@ -13,7 +13,7 @@ func TestAddressTaproot(t *testing.T) { // should parse mainnet taproot address addrStr := "bc1p4ur084x8y63mj5hj7eydscuc4awals7ly749x8vhyquc0twcmvhquspa5c" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addrStr, addr.String()) require.Equal(t, addrStr, addr.EncodeAddress()) require.True(t, addr.IsForNet(&chaincfg.MainNetParams)) @@ -22,7 +22,7 @@ func TestAddressTaproot(t *testing.T) { // should parse testnet taproot address addrStr := "tb1pzeclkt6upu8xwuksjcz36y4q56dd6jw5r543eu8j8238yaxpvcvq7t8f33" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addrStr, addr.String()) require.Equal(t, addrStr, addr.EncodeAddress()) require.True(t, addr.IsForNet(&chaincfg.TestNet3Params)) @@ -31,7 +31,7 @@ func TestAddressTaproot(t *testing.T) { // should parse regtest taproot address addrStr := "bcrt1pqqqsyqcyq5rqwzqfpg9scrgwpugpzysnzs23v9ccrydpk8qarc0sj9hjuh" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addrStr, addr.String()) require.Equal(t, addrStr, addr.EncodeAddress()) require.True(t, addr.IsForNet(&chaincfg.RegressionNetParams)) @@ -50,7 +50,7 @@ func TestAddressTaproot(t *testing.T) { witnessProg[i] = byte(i) } _, err := newAddressTaproot("bcrt", witnessProg[:]) - require.Nil(t, err) + require.NoError(t, err) //t.Logf("addr: %v", addr) } { @@ -58,9 +58,9 @@ func TestAddressTaproot(t *testing.T) { // these hex string comes from link // https://mempool.space/tx/41f7cbaaf9a8d378d09ee86de32eebef455225520cb71015cc9a7318fb42e326 witnessProg, err := hex.DecodeString("af06f3d4c726a3b952f2f648d86398af5ddfc3df27aa531d97203987add8db2e") - require.Nil(t, err) + require.NoError(t, err) addr, err := NewAddressTaproot(witnessProg[:], &chaincfg.MainNetParams) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, addr.EncodeAddress(), "bc1p4ur084x8y63mj5hj7eydscuc4awals7ly749x8vhyquc0twcmvhquspa5c") } { @@ -69,7 +69,7 @@ func TestAddressTaproot(t *testing.T) { // https://blockstream.info/tx/09298a2f32f5267f419aeaf8a58c4807dcf6cac3edb59815a3b129cd8f1219b0?expand addrStr := "bc1p6pls9gpm24g8ntl37pajpjtuhd3y08hs5rnf9a4n0wq595hwdh9suw7m2h" addr, err := DecodeTaprootAddress(addrStr) - require.Nil(t, err) + require.NoError(t, err) require.Equal( t, "d07f02a03b555079aff1f07b20c97cbb62479ef0a0e692f6b37b8142d2ee6dcb", diff --git a/pkg/crypto/pubkey_test.go b/pkg/crypto/pubkey_test.go index 8f1a46f393..a29b405feb 100644 --- a/pkg/crypto/pubkey_test.go +++ b/pkg/crypto/pubkey_test.go @@ -207,15 +207,15 @@ func TestNewPubKey(t *testing.T) { t.Run("should create new pub key from string", func(t *testing.T) { _, pubKey, _ := testdata.KeyTestPubAddr() spk, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, pubKey) - require.Nil(t, err) + require.NoError(t, err) pk, err := NewPubKey(spk) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, PubKey(spk), pk) }) t.Run("should return empty pub key from empty string", func(t *testing.T) { pk, err := NewPubKey("") - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, EmptyPubKey, pk) }) @@ -230,9 +230,9 @@ func TestGetAddressFromPubkeyString(t *testing.T) { t.Run("should get address from pubkey string", func(t *testing.T) { _, pubKey, _ := testdata.KeyTestPubAddr() spk, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, pubKey) - require.Nil(t, err) + require.NoError(t, err) _, err = GetAddressFromPubkeyString(spk) - require.Nil(t, err) + require.NoError(t, err) }) t.Run("should get address from nonbech32 string", func(t *testing.T) { @@ -349,7 +349,7 @@ func TestGetEVMAddress(t *testing.T) { t.Run("should return empty if pubkey is empty", func(t *testing.T) { pubKey := PubKey("") e, err := pubKey.GetEVMAddress() - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, chains.NoAddress, e) }) @@ -359,13 +359,13 @@ func TestGetEVMAddress(t *testing.T) { pk, _ := NewPubKey(spk) _, err := pk.GetEVMAddress() - require.Nil(t, err) + require.NoError(t, err) }) t.Run("should error if non bech32", func(t *testing.T) { pk := PubKey("invalid") e, err := pk.GetEVMAddress() - require.NotNil(t, err) + require.Error(t, err) require.Equal(t, chains.NoAddress, e) }) } diff --git a/x/authority/types/genesis_test.go b/x/authority/types/genesis_test.go index 90aee92509..3d8dcd14df 100644 --- a/x/authority/types/genesis_test.go +++ b/x/authority/types/genesis_test.go @@ -72,7 +72,7 @@ func TestGenesisState_Validate(t *testing.T) { err := tt.gs.Validate() if tt.errContains != "" { require.Error(t, err) - require.Contains(t, err.Error(), tt.errContains) + require.ErrorContains(t, err, tt.errContains) } else { require.NoError(t, err) } diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index 387afd9b89..7eea68a992 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -6,11 +6,12 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/types" ) +// CCTXGatewayObservers is implementation of CCTXGateway interface for observers type CCTXGatewayObservers struct { crosschainKeeper Keeper } -// NewCCTXGatewayObservers is implementation of CCTXGateway interface for observers +// NewCCTXGatewayObservers returns new instance of CCTXGatewayObservers func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { return CCTXGatewayObservers{ crosschainKeeper: crosschainKeeper, @@ -20,14 +21,15 @@ func NewCCTXGatewayObservers(crosschainKeeper Keeper) CCTXGatewayObservers { /* InitiateOutbound updates the store so observers can use the PendingCCTX query: - - If the crosschain message passing is successful, the CCTX status is changed to PendingOutbound. + - If preprocessing of outbound is successful, the CCTX status is changed to PendingOutbound. - - If the crosschain message passing returns an error, the CCTX status is changed to Aborted. - We do not return an error from this function, as all changes need to be persisted to the state. + - if preprocessing of outbound, such as paying the gas fee for the destination fails, the state is reverted to aborted + We do not return an error from this function, as all changes need to be persisted to the state. Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. + New CCTX status after preprocessing is returned. */ -func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { +func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (newCCTXStatus types.CctxStatus) { tmpCtx, commit := ctx.CacheContext() outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId err := func() error { @@ -46,9 +48,9 @@ func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.Cros if err != nil { // do not commit anything here as the CCTX should be aborted cctx.SetAbort(err.Error()) - return nil + return types.CctxStatus_Aborted } commit() cctx.SetPendingOutbound("") - return nil + return types.CctxStatus_PendingOutbound } diff --git a/x/crosschain/keeper/cctx_gateway_zevm.go b/x/crosschain/keeper/cctx_gateway_zevm.go index 9a1897844c..89e7c5a152 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm.go +++ b/x/crosschain/keeper/cctx_gateway_zevm.go @@ -8,11 +8,12 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/types" ) +// CCTXGatewayZEVM is implementation of CCTXGateway interface for ZEVM type CCTXGatewayZEVM struct { crosschainKeeper Keeper } -// NewCCTXGatewayZEVM is implementation of CCTXGateway interface for observers +// NewCCTXGatewayZEVM returns new instance of CCTXGatewayZEVM func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { return CCTXGatewayZEVM{ crosschainKeeper: crosschainKeeper, @@ -20,8 +21,8 @@ func NewCCTXGatewayZEVM(crosschainKeeper Keeper) CCTXGatewayZEVM { } /* -InitiateOutbound handles evm deposit and then ValidateOutbound is called. -TODO: move remaining of this comment to ValidateOutbound once it's added. +InitiateOutbound handles evm deposit and call ValidateOutbound. +TODO (https://github.com/zeta-chain/node/issues/2278): move remaining of this comment to ValidateOutbound once it's added. - If the deposit is successful, the CCTX status is changed to OutboundMined. @@ -34,28 +35,29 @@ TODO: move remaining of this comment to ValidateOutbound once it's added. Note : Aborted CCTXs are not refunded in this function. The refund is done using a separate refunding mechanism. We do not return an error from this function , as all changes need to be persisted to the state. Instead we use a temporary context to make changes and then commit the context on for the happy path ,i.e cctx is set to OutboundMined. +New CCTX status after preprocessing is returned. */ -func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { +func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (newCCTXStatus types.CctxStatus) { tmpCtx, commit := ctx.CacheContext() isContractReverted, err := c.crosschainKeeper.HandleEVMDeposit(tmpCtx, cctx) - // TODO: further processing will be in validateOutbound(...), for now keeping it here + // TODO (https://github.com/zeta-chain/node/issues/2278): further processing will be in validateOutbound(...), for now keeping it here if err != nil && !isContractReverted { // exceptional case; internal error; should abort CCTX cctx.SetAbort(err.Error()) - return nil + return types.CctxStatus_Aborted } else if err != nil && isContractReverted { // contract call reverted; should refund via a revert tx revertMessage := err.Error() senderChain := c.crosschainKeeper.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, cctx.InboundParams.SenderChainId) if senderChain == nil { cctx.SetAbort(fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId)) - return nil + return types.CctxStatus_Aborted } gasLimit, err := c.crosschainKeeper.GetRevertGasLimit(ctx, *cctx) if err != nil { cctx.SetAbort(fmt.Sprintf("revert gas limit error: %s", err.Error())) - return nil + return types.CctxStatus_Aborted } if gasLimit == 0 { // use same gas limit of outbound as a fallback -- should not be required @@ -65,7 +67,7 @@ func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChai err = cctx.AddRevertOutbound(gasLimit) if err != nil { cctx.SetAbort(fmt.Sprintf("revert outbound error: %s", err.Error())) - return nil + return types.CctxStatus_Aborted } // we create a new cached context, and we don't commit the previous one with EVM deposit tmpCtxRevert, commitRevert := ctx.CacheContext() @@ -85,14 +87,14 @@ func (c CCTXGatewayZEVM) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChai }() if err != nil { cctx.SetAbort(fmt.Sprintf("deposit revert message: %s err : %s", revertMessage, err.Error())) - return nil + return types.CctxStatus_Aborted } commitRevert() cctx.SetPendingRevert(revertMessage) - return nil + return types.CctxStatus_PendingRevert } // successful HandleEVMDeposit; commit() cctx.SetOutBoundMined("Remote omnichain contract call completed") - return nil + return types.CctxStatus_OutboundMined } diff --git a/x/crosschain/keeper/initiate_outbound.go b/x/crosschain/keeper/initiate_outbound.go index ef76b5490d..3bad08b8f9 100644 --- a/x/crosschain/keeper/initiate_outbound.go +++ b/x/crosschain/keeper/initiate_outbound.go @@ -9,19 +9,20 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/types" ) -// InitiateOutbound processes the inbound CCTX. +// InitiateOutbound initiates the outbound for the CCTX depending on the CCTX gateway. // It does a conditional dispatch to correct CCTX gateway based on the receiver chain // which handle the state changes and error handling. -func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error { +func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (types.CctxStatus, error) { receiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId chainInfo := chains.GetChainFromChainID(receiverChainID) if chainInfo == nil { - return fmt.Errorf("chain info not found for %d", receiverChainID) + return cctx.CctxStatus.Status, fmt.Errorf("chain info not found for %d", receiverChainID) } cctxGateway, ok := k.cctxGateways[chainInfo.CctxGateway] if !ok { - return fmt.Errorf("CCTXGateway not defined for receiver chain %d", receiverChainID) + return cctx.CctxStatus.Status, fmt.Errorf("CCTXGateway not defined for receiver chain %d", receiverChainID) } - return cctxGateway.InitiateOutbound(ctx, cctx) + + return cctxGateway.InitiateOutbound(ctx, cctx), nil } diff --git a/x/crosschain/keeper/initiate_outbound_test.go b/x/crosschain/keeper/initiate_outbound_test.go index 1046614608..59d0eaee0b 100644 --- a/x/crosschain/keeper/initiate_outbound_test.go +++ b/x/crosschain/keeper/initiate_outbound_test.go @@ -43,9 +43,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_OutboundMined, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_OutboundMined, newStatus) }) t.Run("unable to process zevm deposit HandleEVMDeposit returns err without reverting", func(t *testing.T) { @@ -71,9 +72,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { cctx.GetInboundParams().Amount = sdkmath.NewUintFromBigInt(amount) cctx.InboundParams.CoinType = coin.CoinType_Zeta cctx.GetInboundParams().SenderChainId = 0 - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal(t, "deposit error", cctx.CctxStatus.StatusMessage) }) @@ -104,9 +106,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, "", amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("invalid sender chain id %d", cctx.InboundParams.SenderChainId), @@ -143,9 +146,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("revert gas limit error: %s", types.ErrForeignCoinNotFound), @@ -187,9 +191,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("deposit revert message: %s err : %s", errDeposit, observertypes.ErrSupportedChains), @@ -232,9 +237,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal( t, fmt.Sprintf("deposit revert message: %s err : %s", errDeposit, observertypes.ErrSupportedChains), @@ -278,9 +284,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) @@ -317,9 +324,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_PendingRevert, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_PendingRevert, newStatus) require.Equal(t, errDeposit.Error(), cctx.CctxStatus.StatusMessage) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) }) @@ -355,9 +363,10 @@ func TestKeeper_InitiateOutboundZEVMDeposit(t *testing.T) { cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) cctx.GetCurrentOutboundParam().ReceiverChainId = chains.ZetaChainPrivnet.ChainId cctx.OutboundParams = append(cctx.OutboundParams, cctx.GetCurrentOutboundParam()) - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Contains( t, cctx.CctxStatus.StatusMessage, @@ -389,9 +398,10 @@ func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_PendingOutbound, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_PendingOutbound, newStatus) require.Equal(t, updatedNonce, cctx.GetCurrentOutboundParam().TssNonce) }) @@ -413,9 +423,10 @@ func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Equal(t, observertypes.ErrSupportedChains.Error(), cctx.CctxStatus.StatusMessage) }) @@ -441,9 +452,10 @@ func TestKeeper_InitiateOutboundProcessCrosschainMsgPassing(t *testing.T) { // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - err := k.InitiateOutbound(ctx, cctx) - require.Nil(t, err) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.NoError(t, err) require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) require.Contains(t, cctx.CctxStatus.StatusMessage, "cannot find receiver chain nonce") }) } @@ -462,9 +474,10 @@ func TestKeeper_InitiateOutboundFailures(t *testing.T) { receiverChain.ChainId = 123 // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - err := k.InitiateOutbound(ctx, cctx) - require.NotNil(t, err) - require.Contains(t, err.Error(), "chain info not found") + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.Error(t, err) + require.Equal(t, types.CctxStatus_PendingInbound, newStatus) + require.ErrorContains(t, err, "chain info not found") }) t.Run("should fail if cctx gateway not found for receiver chain id", func(t *testing.T) { @@ -482,9 +495,10 @@ func TestKeeper_InitiateOutboundFailures(t *testing.T) { receiverChain := getValidEthChain() // call InitiateOutbound cctx := GetERC20Cctx(t, receiver, *receiverChain, "", amount) - err := k.InitiateOutbound(ctx, cctx) + newStatus, err := k.InitiateOutbound(ctx, cctx) + require.Equal(t, types.CctxStatus_PendingInbound, newStatus) require.NotNil(t, err) - require.Contains(t, err.Error(), "CCTXGateway not defined for receiver chain") + require.ErrorContains(t, err, "CCTXGateway not defined for receiver chain") }) } diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index a18e92e5bd..b32543126c 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -12,10 +12,12 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/types" ) +// CCTXGateway is interface implemented by every gateway. It is one of interfaces used for communication +// between CCTX gateways and crosschain module, and it is called by crosschain module. type CCTXGateway interface { - // Initiate a new outbound, this tells the CCTXGateway to carry out the action to execute the outbound - // TODO: how to do everything needed with just outboundParams? - InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) error + // Initiate a new outbound, this tells the CCTXGateway to carry out the action to execute the outbound. + // It is the only entry point to initiate an outbound and it returns new CCTX status after it is completed. + InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (newCCTXStatus types.CctxStatus) } type ( diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index 6296f0b8b2..10f65200e1 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -106,9 +106,9 @@ func (k msgServer) VoteInbound( if err != nil { return nil, err } - // Inititiate outboud, the process function manages the state commit and cctx status change. + // Inititiate outbound, the process function manages the state commit and cctx status change. // If the process fails, the changes to the evm state are rolled back. - err = k.InitiateOutbound(ctx, &cctx) + _, err = k.InitiateOutbound(ctx, &cctx) if err != nil { return nil, err } diff --git a/x/fungible/keeper/evm_test.go b/x/fungible/keeper/evm_test.go index a175943247..2ef0f4dfb9 100644 --- a/x/fungible/keeper/evm_test.go +++ b/x/fungible/keeper/evm_test.go @@ -575,7 +575,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) { // check reason is included for revert error // 0xbfb4ebcf is the hash of "Foo()" - require.Contains(t, err.Error(), "reason: 0xbfb4ebcf") + require.ErrorContains(t, err, "reason: 0xbfb4ebcf") res, err = k.CallEVM( ctx, diff --git a/x/fungible/keeper/msg_server_deploy_system_contract_test.go b/x/fungible/keeper/msg_server_deploy_system_contract_test.go index 6b11c46592..a472fbd6e3 100644 --- a/x/fungible/keeper/msg_server_deploy_system_contract_test.go +++ b/x/fungible/keeper/msg_server_deploy_system_contract_test.go @@ -73,7 +73,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if wzeta contract deployment fails", func(t *testing.T) { @@ -95,7 +95,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if uniswapv2router deployment fails", func(t *testing.T) { @@ -118,7 +118,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if connectorzevm deployment fails", func(t *testing.T) { @@ -142,7 +142,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) t.Run("should fail if system contract deployment fails", func(t *testing.T) { @@ -167,7 +167,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + require.ErrorContains(t, err, "failed to deploy") }) } diff --git a/x/observer/types/chain_params_test.go b/x/observer/types/chain_params_test.go index 9aab9dc9ff..1703b43f54 100644 --- a/x/observer/types/chain_params_test.go +++ b/x/observer/types/chain_params_test.go @@ -30,7 +30,7 @@ func TestChainParamsList_Validate(t *testing.T) { list.ChainParams = append(list.ChainParams, list.ChainParams[0]) err := list.Validate() require.Error(t, err) - require.Contains(t, err.Error(), "duplicated chain id") + require.ErrorContains(t, err, "duplicated chain id") }) } diff --git a/x/observer/types/message_disable_cctx_flags_test.go b/x/observer/types/message_disable_cctx_flags_test.go index 40a4d023d2..8a394a2bac 100644 --- a/x/observer/types/message_disable_cctx_flags_test.go +++ b/x/observer/types/message_disable_cctx_flags_test.go @@ -20,14 +20,14 @@ func TestMsgDisableCCTX_ValidateBasic(t *testing.T) { name: "invalid creator address", msg: types.NewMsgDisableCCTX("invalid", true, true), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { name: "invalid flags", msg: types.NewMsgDisableCCTX(sample.AccAddress(), false, false), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "at least one of DisableInbound or DisableOutbound must be true") + require.ErrorContains(t, err, "at least one of DisableInbound or DisableOutbound must be true") }, }, { diff --git a/x/observer/types/message_enable_cctx_flags_test.go b/x/observer/types/message_enable_cctx_flags_test.go index 2033837e7d..f1121c5fce 100644 --- a/x/observer/types/message_enable_cctx_flags_test.go +++ b/x/observer/types/message_enable_cctx_flags_test.go @@ -20,14 +20,14 @@ func TestMsgEnableCCTX_ValidateBasic(t *testing.T) { name: "invalid creator address", msg: types.NewMsgEnableCCTX("invalid", true, true), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { name: "invalid flags", msg: types.NewMsgEnableCCTX(sample.AccAddress(), false, false), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "at least one of EnableInbound or EnableOutbound must be true") + require.ErrorContains(t, err, "at least one of EnableInbound or EnableOutbound must be true") }, }, { diff --git a/x/observer/types/message_update_gas_price_increase_flags_test.go b/x/observer/types/message_update_gas_price_increase_flags_test.go index d432835b62..17f110958c 100644 --- a/x/observer/types/message_update_gas_price_increase_flags_test.go +++ b/x/observer/types/message_update_gas_price_increase_flags_test.go @@ -20,7 +20,7 @@ func TestMsgUpdateGasPriceIncreaseFlags_ValidateBasic(t *testing.T) { name: "invalid creator address", msg: types.NewMsgUpdateGasPriceIncreaseFlags("invalid", types.DefaultGasPriceIncreaseFlags), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { @@ -34,7 +34,7 @@ func TestMsgUpdateGasPriceIncreaseFlags_ValidateBasic(t *testing.T) { }, ), err: func(t require.TestingT, err error, i ...interface{}) { - require.Contains(t, err.Error(), "invalid request") + require.ErrorContains(t, err, "invalid request") }, }, { diff --git a/zetaclient/chains/bitcoin/fee_test.go b/zetaclient/chains/bitcoin/fee_test.go index bb6757ede2..160bdf6093 100644 --- a/zetaclient/chains/bitcoin/fee_test.go +++ b/zetaclient/chains/bitcoin/fee_test.go @@ -60,13 +60,13 @@ var exampleTxids = []string{ func generateKeyPair(t *testing.T, net *chaincfg.Params) (*btcec.PrivateKey, btcutil.Address, []byte) { privateKey, err := btcec.NewPrivateKey(btcec.S256()) - require.Nil(t, err) + require.NoError(t, err) pubKeyHash := btcutil.Hash160(privateKey.PubKey().SerializeCompressed()) addr, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, net) - require.Nil(t, err) + require.NoError(t, err) //fmt.Printf("New address: %s\n", addr.EncodeAddress()) pkScript, err := PayToAddrScript(addr) - require.Nil(t, err) + require.NoError(t, err) return privateKey, addr, pkScript } @@ -98,7 +98,7 @@ func addTxInputs(t *testing.T, tx *wire.MsgTx, txids []string) { preTxSize := tx.SerializeSize() for _, txid := range txids { hash, err := chainhash.NewHashFromStr(txid) - require.Nil(t, err) + require.NoError(t, err) outpoint := wire.NewOutPoint(hash, uint32(rand.Intn(100))) txIn := wire.NewTxIn(outpoint, nil, nil) tx.AddTxIn(txIn) @@ -158,9 +158,9 @@ func signTx(t *testing.T, tx *wire.MsgTx, payerScript []byte, privateKey *btcec. for ix := range tx.TxIn { amount := int64(1 + rand.Intn(100000000)) witnessHash, err := txscript.CalcWitnessSigHash(payerScript, sigHashes, txscript.SigHashAll, tx, ix, amount) - require.Nil(t, err) + require.NoError(t, err) sig, err := privateKey.Sign(witnessHash) - require.Nil(t, err) + require.NoError(t, err) pkCompressed := privateKey.PubKey().SerializeCompressed() txWitness := wire.TxWitness{append(sig.Serialize(), byte(txscript.SigHashAll)), pkCompressed} diff --git a/zetaclient/chains/bitcoin/observer/outbound_test.go b/zetaclient/chains/bitcoin/observer/outbound_test.go index 2f25575284..bad0997c0c 100644 --- a/zetaclient/chains/bitcoin/observer/outbound_test.go +++ b/zetaclient/chains/bitcoin/observer/outbound_test.go @@ -33,7 +33,7 @@ func MockBTCObserverMainnet() *Observer { func createObserverWithPrivateKey(t *testing.T) *Observer { skHex := "7b8507ba117e069f4a3f456f505276084f8c92aee86ac78ae37b4d1801d35fa8" privateKey, err := crypto.HexToECDSA(skHex) - require.Nil(t, err) + require.NoError(t, err) tss := &mocks.TSS{ PrivKey: privateKey, } @@ -241,7 +241,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0 // output: [0.01], 0.01 result, amount, _, _, err := ob.SelectUTXOs(0.01, 5, 0, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.01, amount) require.Equal(t, ob.utxos[0:1], result) @@ -249,7 +249,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: error result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - require.NotNil(t, err) + require.Error(t, err) require.Nil(t, result) require.Zero(t, amount) require.Equal(t, "getOutboundIDByNonce: cannot find outbound txid for nonce 0", err.Error()) @@ -259,7 +259,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: [0.00002, 0.01, 0.12, 0.18, 0.24], 0.55002 result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.55002, amount) require.Equal(t, ob.utxos[0:5], result) mineTxNSetNonceMark(ob, 1, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 1 @@ -268,7 +268,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 1.0, nonce = 2 // output: [0.00002001, 0.01, 0.12, 0.18, 0.24, 0.5], 1.05002001 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 2, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 1.05002001, amount, 1e-8) require.Equal(t, ob.utxos[0:6], result) mineTxNSetNonceMark(ob, 2, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 2 @@ -277,7 +277,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 8.05, nonce = 3 // output: [0.00002002, 0.24, 0.5, 1.26, 2.97, 3.28], 8.25002002 result, amount, _, _, err = ob.SelectUTXOs(8.05, 5, 3, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 8.25002002, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[0]}, ob.utxos[4:9]...) require.Equal(t, expected, result) @@ -287,7 +287,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.503, nonce = 24105432 // output: [0.24107432, 0.01, 0.12, 0.18, 0.24], 0.55002002 result, amount, _, _, err = ob.SelectUTXOs(0.503, 5, 24105432, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 0.79107431, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:4]...) require.Equal(t, expected, result) @@ -297,7 +297,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 1.0, nonce = 24105433 // output: [0.24107432, 0.12, 0.18, 0.24, 0.5], 1.28107432 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 24105433, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 1.28107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[1:4]...) expected = append(expected, ob.utxos[5]) @@ -307,7 +307,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 16.03 // output: [0.24107432, 1.26, 2.97, 3.28, 5.16, 8.72], 21.63107432 result, amount, _, _, err = ob.SelectUTXOs(16.03, 5, 24105433, math.MaxUint16, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 21.63107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[6:11]...) require.Equal(t, expected, result) @@ -316,7 +316,7 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 21.64 // output: error result, amount, _, _, err = ob.SelectUTXOs(21.64, 5, 24105433, math.MaxUint16, true) - require.NotNil(t, err) + require.Error(t, err) require.Nil(t, result) require.Zero(t, amount) require.Equal( @@ -336,7 +336,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 10, amount = 0.01, nonce = 1, rank = 10 // output: [0.00002, 0.01], 0.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 10, 1, 10, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.01002, amount) require.Equal(t, ob.utxos[0:2], result) require.Equal(t, uint16(0), clsdtUtxo) @@ -350,7 +350,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 9, amount = 0.01, nonce = 1, rank = 9 // output: [0.00002, 0.01, 0.12], 0.13002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 9, 1, 9, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 0.13002, amount) require.Equal(t, ob.utxos[0:3], result) require.Equal(t, uint16(1), clsdtUtxo) @@ -364,7 +364,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0, rank = 5 // output: [0.00002, 0.014, 1.26, 0.5, 0.2], 2.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 5, 1, 5, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 2.01002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) @@ -383,7 +383,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.01, nonce = 0, rank = 1 // output: [0.00002, 0.01, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18, 0.12], 22.44002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 12, 1, 1, true) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, 22.44002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) @@ -407,7 +407,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.13, nonce = 24105432, rank = 5 // output: [0.24107431, 0.01, 0.12, 1.26, 0.5, 0.24], 2.37107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 5, 24105432, 5, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 2.37107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) expected = append(expected, ob.utxos[6]) @@ -430,7 +430,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.13, nonce = 24105432, rank = 1 // output: [0.24107431, 0.01, 0.12, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18], 22.68107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 12, 24105432, 1, true) - require.Nil(t, err) + require.NoError(t, err) require.InEpsilon(t, 22.68107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) for i := 10; i >= 5; i-- { // append consolidated utxos in descending order diff --git a/zetaclient/chains/bitcoin/signer/signer_test.go b/zetaclient/chains/bitcoin/signer/signer_test.go index 76b46aef37..6d048c7bba 100644 --- a/zetaclient/chains/bitcoin/signer/signer_test.go +++ b/zetaclient/chains/bitcoin/signer/signer_test.go @@ -370,7 +370,7 @@ func TestAddWithdrawTxOutputs(t *testing.T) { if tt.fail { require.Error(t, err) if tt.message != "" { - require.Contains(t, err.Error(), tt.message) + require.ErrorContains(t, err, tt.message) } return } else { diff --git a/zetaclient/chains/evm/validation_test.go b/zetaclient/chains/evm/validation_test.go index 330d15f8f8..8077f8ab4e 100644 --- a/zetaclient/chains/evm/validation_test.go +++ b/zetaclient/chains/evm/validation_test.go @@ -296,7 +296,7 @@ func TestCheckEvmTransactionTable(t *testing.T) { err := evm.ValidateEvmTransaction(tt.tx) if tt.fail { require.Error(t, err) - require.Contains(t, err.Error(), tt.msg) + require.ErrorContains(t, err, tt.msg) return } require.NoError(t, err) From 35077f5c5cde966aa07df240b591f7c3973f87e8 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 31 May 2024 21:42:55 +0200 Subject: [PATCH 19/21] make generate --- x/crosschain/keeper/cctx_gateway_observers.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index 7eea68a992..3befd25593 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -29,7 +29,10 @@ InitiateOutbound updates the store so observers can use the PendingCCTX query: Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. New CCTX status after preprocessing is returned. */ -func (c CCTXGatewayObservers) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (newCCTXStatus types.CctxStatus) { +func (c CCTXGatewayObservers) InitiateOutbound( + ctx sdk.Context, + cctx *types.CrossChainTx, +) (newCCTXStatus types.CctxStatus) { tmpCtx, commit := ctx.CacheContext() outboundReceiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId err := func() error { From be0f3edb0cc548b71b9d87b9ced82b3b65127d80 Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 3 Jun 2024 12:15:51 +0200 Subject: [PATCH 20/21] make generate --- x/crosschain/keeper/cctx_gateway_observers.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/crosschain/keeper/cctx_gateway_observers.go b/x/crosschain/keeper/cctx_gateway_observers.go index 3befd25593..556d242214 100644 --- a/x/crosschain/keeper/cctx_gateway_observers.go +++ b/x/crosschain/keeper/cctx_gateway_observers.go @@ -26,6 +26,7 @@ InitiateOutbound updates the store so observers can use the PendingCCTX query: - if preprocessing of outbound, such as paying the gas fee for the destination fails, the state is reverted to aborted We do not return an error from this function, as all changes need to be persisted to the state. + Instead, we use a temporary context to make changes and then commit the context on for the happy path, i.e cctx is set to PendingOutbound. New CCTX status after preprocessing is returned. */ From 32388f00bf0d453babcb36a09ba2aa1519e98c85 Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 3 Jun 2024 17:06:54 +0200 Subject: [PATCH 21/21] PR comments --- app/ante/vesting_test.go | 1 - pkg/crypto/pubkey_test.go | 2 +- x/crosschain/keeper/initiate_outbound.go | 17 ++++++++++++++--- .../keeper/msg_server_vote_inbound_tx.go | 4 ++-- x/crosschain/types/errors.go | 1 + .../msg_server_deploy_system_contract_test.go | 1 - 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/ante/vesting_test.go b/app/ante/vesting_test.go index 0adaaea014..f174bb61c2 100644 --- a/app/ante/vesting_test.go +++ b/app/ante/vesting_test.go @@ -94,7 +94,6 @@ func TestVesting_AnteHandle(t *testing.T) { _, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle) if tt.wantHasErr { - require.Error(t, err) require.ErrorContains(t, err, tt.wantErr) } else { require.NoError(t, err) diff --git a/pkg/crypto/pubkey_test.go b/pkg/crypto/pubkey_test.go index a29b405feb..5f16f8142e 100644 --- a/pkg/crypto/pubkey_test.go +++ b/pkg/crypto/pubkey_test.go @@ -365,7 +365,7 @@ func TestGetEVMAddress(t *testing.T) { t.Run("should error if non bech32", func(t *testing.T) { pk := PubKey("invalid") e, err := pk.GetEVMAddress() - require.Error(t, err) + require.ErrorContains(t, err, "decoding bech32 failed") require.Equal(t, chains.NoAddress, e) }) } diff --git a/x/crosschain/keeper/initiate_outbound.go b/x/crosschain/keeper/initiate_outbound.go index 3bad08b8f9..8174f6ec4e 100644 --- a/x/crosschain/keeper/initiate_outbound.go +++ b/x/crosschain/keeper/initiate_outbound.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + cosmoserrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/zeta-chain/zetacore/pkg/chains" @@ -11,17 +12,27 @@ import ( // InitiateOutbound initiates the outbound for the CCTX depending on the CCTX gateway. // It does a conditional dispatch to correct CCTX gateway based on the receiver chain -// which handle the state changes and error handling. +// which handles the state changes and error handling. func (k Keeper) InitiateOutbound(ctx sdk.Context, cctx *types.CrossChainTx) (types.CctxStatus, error) { receiverChainID := cctx.GetCurrentOutboundParam().ReceiverChainId chainInfo := chains.GetChainFromChainID(receiverChainID) if chainInfo == nil { - return cctx.CctxStatus.Status, fmt.Errorf("chain info not found for %d", receiverChainID) + return cctx.CctxStatus.Status, cosmoserrors.Wrap( + types.ErrInitiatitingOutbound, + fmt.Sprintf( + "chain info not found for %d", receiverChainID, + ), + ) } cctxGateway, ok := k.cctxGateways[chainInfo.CctxGateway] if !ok { - return cctx.CctxStatus.Status, fmt.Errorf("CCTXGateway not defined for receiver chain %d", receiverChainID) + return cctx.CctxStatus.Status, cosmoserrors.Wrap( + types.ErrInitiatitingOutbound, + fmt.Sprintf( + "CCTXGateway not defined for receiver chain %d", receiverChainID, + ), + ) } return cctxGateway.InitiateOutbound(ctx, cctx), nil diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index 10f65200e1..b118d2bc43 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -106,8 +106,8 @@ func (k msgServer) VoteInbound( if err != nil { return nil, err } - // Inititiate outbound, the process function manages the state commit and cctx status change. - // If the process fails, the changes to the evm state are rolled back. + // Initiate outbound, the process function manages the state commit and cctx status change. + // If the process fails, the changes to the evm state are rolled back. _, err = k.InitiateOutbound(ctx, &cctx) if err != nil { return nil, err diff --git a/x/crosschain/types/errors.go b/x/crosschain/types/errors.go index ffeda3077c..232bf229db 100644 --- a/x/crosschain/types/errors.go +++ b/x/crosschain/types/errors.go @@ -48,4 +48,5 @@ var ( ErrUnableToDecodeMessageString = errorsmod.Register(ModuleName, 1151, "unable to decode message string") ErrInvalidRateLimiterFlags = errorsmod.Register(ModuleName, 1152, "invalid rate limiter flags") ErrMaxTxOutTrackerHashesReached = errorsmod.Register(ModuleName, 1153, "max tx out tracker hashes reached") + ErrInitiatitingOutbound = errorsmod.Register(ModuleName, 1154, "cannot initiate outbound") ) diff --git a/x/fungible/keeper/msg_server_deploy_system_contract_test.go b/x/fungible/keeper/msg_server_deploy_system_contract_test.go index a472fbd6e3..117ee0cc33 100644 --- a/x/fungible/keeper/msg_server_deploy_system_contract_test.go +++ b/x/fungible/keeper/msg_server_deploy_system_contract_test.go @@ -72,7 +72,6 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { mockFailedContractDeployment(ctx, t, k) _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) - require.Error(t, err) require.ErrorContains(t, err, "failed to deploy") })