From 823a308ce30851757e2ff4ed93290a12f787ccb9 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Sun, 6 Apr 2025 01:00:00 +0900 Subject: [PATCH] add keyring_backend and tm_chain_id attribute to Tendermint ChainConfig Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 12 +- chains/tendermint/cmd/config.go | 15 +- chains/tendermint/config.go | 14 ++ chains/tendermint/config.pb.go | 198 +++++++++++++----- chains/tendermint/light.go | 10 +- go.mod | 2 +- .../chains/tendermint/config/config.proto | 18 +- tests/cases/tm2tm/configs/demo/ibc-0.json | 2 + tests/cases/tm2tm/configs/demo/ibc-1.json | 2 + .../tmmock2tmmock/configs/demo/ibc-0.json | 2 + .../tmmock2tmmock/configs/demo/ibc-1.json | 2 + 11 files changed, 200 insertions(+), 77 deletions(-) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 0569d468..c1719d73 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -113,7 +113,13 @@ func (c *Chain) Path() *core.PathEnd { } func (c *Chain) Init(homePath string, timeout time.Duration, codec codec.ProtoCodecMarshaler, debug bool) error { - keybase, err := keys.New(c.config.ChainId, "test", keysDir(homePath, c.config.ChainId), nil, codec) + keybase, err := keys.New( + c.config.TmChainId, + c.config.KeyringBackend, + keysDir(homePath, c.config.TmChainId), + nil, + codec, + ) if err != nil { return err } @@ -515,7 +521,7 @@ func (c *Chain) CLIContext(height int64) sdkCtx.Context { txConfig := authtx.NewTxConfig(c.codec, authtx.DefaultSignModes) unlock() return sdkCtx.Context{}. - WithChainID(c.config.ChainId). + WithChainID(c.config.TmChainId). WithCodec(c.codec). WithInterfaceRegistry(c.codec.InterfaceRegistry()). WithTxConfig(txConfig). @@ -539,7 +545,7 @@ func (c *Chain) TxFactory(height int64) tx.Factory { ctx := c.CLIContext(height) return tx.Factory{}. WithAccountRetriever(ctx.AccountRetriever). - WithChainID(c.config.ChainId). + WithChainID(c.config.TmChainId). WithTxConfig(ctx.TxConfig). WithGasAdjustment(c.config.GasAdjustment). WithGasPrices(c.config.GasPrices). diff --git a/chains/tendermint/cmd/config.go b/chains/tendermint/cmd/config.go index 0a0926cd..5b84a73c 100644 --- a/chains/tendermint/cmd/config.go +++ b/chains/tendermint/cmd/config.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/hyperledger-labs/yui-relayer/chains/tendermint" "github.com/hyperledger-labs/yui-relayer/core" "github.com/spf13/cobra" @@ -30,12 +31,14 @@ func generateChainConfigCmd(m codec.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) (err error) { // TODO make it configurable c := tendermint.ChainConfig{ - Key: "testkey", - ChainId: args[0], - RpcAddr: "http://localhost:26557", - AccountPrefix: "cosmos", - GasAdjustment: 1.5, - GasPrices: "0.025stake", + KeyringBackend: keyring.BackendTest, + Key: "testkey", + ChainId: args[0], + TmChainId: args[0], + RpcAddr: "http://localhost:26557", + AccountPrefix: "cosmos", + GasAdjustment: 1.5, + GasPrices: "0.025stake", } p := tendermint.ProverConfig{ TrustingPeriod: "336h", diff --git a/chains/tendermint/config.go b/chains/tendermint/config.go index d403efd5..11127875 100644 --- a/chains/tendermint/config.go +++ b/chains/tendermint/config.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/hyperledger-labs/yui-relayer/core" ) @@ -23,12 +24,25 @@ func (c ChainConfig) Validate() error { } var errs []error + switch c.KeyringBackend { + case keyring.BackendFile: + case keyring.BackendOS: + case keyring.BackendKWallet: + case keyring.BackendPass: + case keyring.BackendTest: + case keyring.BackendMemory: + default: + errs = append(errs, fmt.Errorf("config attribute \"keyring_backend\" is unexpected: %s", c.KeyringBackend)) + } if isEmpty(c.Key) { errs = append(errs, fmt.Errorf("config attribute \"key\" is empty")) } if isEmpty(c.ChainId) { errs = append(errs, fmt.Errorf("config attribute \"chain_id\" is empty")) } + if isEmpty(c.TmChainId) { + errs = append(errs, fmt.Errorf("config attribute \"tm_chain_id\" is empty")) + } if isEmpty(c.RpcAddr) { errs = append(errs, fmt.Errorf("config attribute \"rpc_addr\" is empty")) } diff --git a/chains/tendermint/config.pb.go b/chains/tendermint/config.pb.go index 538204de..d109c126 100644 --- a/chains/tendermint/config.pb.go +++ b/chains/tendermint/config.pb.go @@ -25,14 +25,16 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type ChainConfig struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - RpcAddr string `protobuf:"bytes,3,opt,name=rpc_addr,json=rpcAddr,proto3" json:"rpc_addr,omitempty"` - AccountPrefix string `protobuf:"bytes,4,opt,name=account_prefix,json=accountPrefix,proto3" json:"account_prefix,omitempty"` - GasAdjustment float64 `protobuf:"fixed64,5,opt,name=gas_adjustment,json=gasAdjustment,proto3" json:"gas_adjustment,omitempty"` - GasPrices string `protobuf:"bytes,6,opt,name=gas_prices,json=gasPrices,proto3" json:"gas_prices,omitempty"` - AverageBlockTimeMsec uint64 `protobuf:"varint,7,opt,name=average_block_time_msec,json=averageBlockTimeMsec,proto3" json:"average_block_time_msec,omitempty"` - MaxRetryForCommit uint64 `protobuf:"varint,8,opt,name=max_retry_for_commit,json=maxRetryForCommit,proto3" json:"max_retry_for_commit,omitempty"` + KeyringBackend string `protobuf:"bytes,1,opt,name=keyring_backend,json=keyringBackend,proto3" json:"keyring_backend,omitempty"` + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + TmChainId string `protobuf:"bytes,4,opt,name=tm_chain_id,json=tmChainId,proto3" json:"tm_chain_id,omitempty"` + RpcAddr string `protobuf:"bytes,5,opt,name=rpc_addr,json=rpcAddr,proto3" json:"rpc_addr,omitempty"` + AccountPrefix string `protobuf:"bytes,6,opt,name=account_prefix,json=accountPrefix,proto3" json:"account_prefix,omitempty"` + GasAdjustment float64 `protobuf:"fixed64,7,opt,name=gas_adjustment,json=gasAdjustment,proto3" json:"gas_adjustment,omitempty"` + GasPrices string `protobuf:"bytes,8,opt,name=gas_prices,json=gasPrices,proto3" json:"gas_prices,omitempty"` + AverageBlockTimeMsec uint64 `protobuf:"varint,9,opt,name=average_block_time_msec,json=averageBlockTimeMsec,proto3" json:"average_block_time_msec,omitempty"` + MaxRetryForCommit uint64 `protobuf:"varint,10,opt,name=max_retry_for_commit,json=maxRetryForCommit,proto3" json:"max_retry_for_commit,omitempty"` } func (m *ChainConfig) Reset() { *m = ChainConfig{} } @@ -155,38 +157,40 @@ func init() { } var fileDescriptor_d67cd47cbc86ecb1 = []byte{ - // 482 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x6b, 0x13, 0x41, - 0x14, 0xc7, 0xb3, 0x6d, 0x6c, 0x93, 0x89, 0xad, 0xba, 0x04, 0x5d, 0x45, 0x97, 0x10, 0x10, 0x83, - 0xd0, 0x5d, 0x50, 0x3c, 0x78, 0x6c, 0x03, 0x05, 0x05, 0x21, 0x2c, 0x05, 0xc1, 0xcb, 0x38, 0x99, - 0x79, 0x99, 0x8c, 0xcd, 0xcc, 0x2c, 0x6f, 0x66, 0x4b, 0xf2, 0x2d, 0xbc, 0xfa, 0x15, 0xfc, 0x24, - 0x3d, 0xf6, 0xe8, 0x51, 0x93, 0x2f, 0x22, 0x3b, 0xd9, 0x58, 0x2f, 0xe2, 0x69, 0x66, 0x7f, 0xff, - 0xdf, 0x7b, 0x2c, 0x6f, 0x1e, 0x39, 0x41, 0x58, 0xb0, 0x15, 0x60, 0xce, 0xe7, 0x4c, 0x19, 0x97, - 0x7b, 0x30, 0x02, 0x50, 0x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x83, 0xb0, 0x74, 0xaf, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x58, 0x5a, 0x44, 0xe1, 0xdd, 0x02, - 0x00, 0x00, + // 515 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x9b, 0x6d, 0x6c, 0xad, 0xcb, 0x06, 0x58, 0x15, 0x64, 0x08, 0xa2, 0x6a, 0x12, 0x62, + 0x42, 0x5a, 0x22, 0x81, 0x38, 0x70, 0xdc, 0x2a, 0x4d, 0x02, 0x09, 0xa9, 0x8a, 0x26, 0x21, 0x71, + 0x31, 0xae, 0xfd, 0x9a, 0x9a, 0xd6, 0x76, 0xf4, 0xe2, 0x4c, 0xcb, 0xb7, 0xe0, 0xca, 0x37, 0xda, + 0x71, 0x47, 0x8e, 0xd0, 0x7e, 0x04, 0xbe, 0x00, 0x8a, 0x93, 0xb6, 0x5c, 0x10, 0x27, 0x3b, 0xbf, + 0xff, 0xef, 0x39, 0xd6, 0xcb, 0x0b, 0x39, 0x43, 0x58, 0xf0, 0x0a, 0x30, 0x11, 0x33, 0xae, 0x4c, + 0x91, 0x38, 0x30, 0x12, 0x50, 0x2b, 0xe3, 0x12, 0x61, 0xcd, 0x54, 0x65, 0xed, 0x12, 0xe7, 0x68, + 0x9d, 0xa5, 0xc3, 0x56, 0x8f, 0x1b, 0x3d, 0xde, 0xea, 0x71, 0xe3, 0x3d, 0x1d, 0x64, 0x36, 0xb3, + 0x5e, 0x4e, 0xea, 0x5d, 0x53, 0x77, 0xf2, 0x7b, 0x87, 0xf4, 0x47, 0x75, 0xc9, 0xc8, 0x5b, 0xf4, + 0x25, 0x79, 0x30, 0x87, 0x0a, 0x95, 0xc9, 0xd8, 0x84, 0x8b, 0x39, 0x18, 0x19, 0x06, 0xc3, 0xe0, + 0xb4, 0x97, 0x1e, 0xb5,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, 0x7b, 0x40, 0xee, 0x8f, 0xd1, 0x5e, 0x03, + 0x6e, 0xdb, 0xee, 0xb0, 0x2c, 0x5c, 0xdd, 0xf7, 0x1c, 0x50, 0xd9, 0x4d, 0xdb, 0xd7, 0x78, 0xec, + 0x29, 0xfd, 0x42, 0x1e, 0x23, 0x4c, 0x11, 0x8a, 0x19, 0x73, 0xb3, 0x7a, 0xb1, 0x0b, 0xc9, 0x90, + 0x3b, 0xf0, 0x5f, 0xa2, 0xff, 0xfa, 0x55, 0xfc, 0xbf, 0x41, 0x88, 0x2f, 0x91, 0x0b, 0xa7, 0xac, + 0x49, 0x07, 0xed, 0x49, 0x57, 0xeb, 0x83, 0x52, 0xee, 0xe0, 0xe4, 0x03, 0xe9, 0xae, 0x0d, 0xfa, + 0x8c, 0xf4, 0x4c, 0xa9, 0x01, 0xb9, 0xb3, 0xe8, 0x2f, 0xb4, 0x97, 0x6e, 0x01, 0x1d, 0x92, 0xbe, + 0x04, 0x63, 0xb5, 0x32, 0x3e, 0xdf, 0xf1, 0xf9, 0xdf, 0xe8, 0xe2, 0xd3, 0xed, 0xaf, 0xa8, 0x73, + 0xbb, 0x8c, 0x82, 0xbb, 0x65, 0x14, 0xfc, 0x5c, 0x46, 0xc1, 0xb7, 0x55, 0xd4, 0xb9, 0x5b, 0x45, + 0x9d, 0x1f, 0xab, 0xa8, 0xf3, 0xf9, 0x5d, 0xa6, 0xdc, 0xac, 0x9c, 0xc4, 0xc2, 0xea, 0x64, 0x56, + 0xe5, 0x80, 0x0b, 0x90, 0x19, 0xe0, 0xd9, 0x82, 0x4f, 0x8a, 0xa4, 0x2a, 0xd5, 0xbf, 0x7f, 0x81, + 0xc9, 0xbe, 0x9f, 0xde, 0x37, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x92, 0xa8, 0xab, 0x3c, 0x26, + 0x03, 0x00, 0x00, } func (m *ChainConfig) Marshal() (dAtA []byte, err error) { @@ -212,52 +216,66 @@ func (m *ChainConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.MaxRetryForCommit != 0 { i = encodeVarintConfig(dAtA, i, uint64(m.MaxRetryForCommit)) i-- - dAtA[i] = 0x40 + dAtA[i] = 0x50 } if m.AverageBlockTimeMsec != 0 { i = encodeVarintConfig(dAtA, i, uint64(m.AverageBlockTimeMsec)) i-- - dAtA[i] = 0x38 + dAtA[i] = 0x48 } if len(m.GasPrices) > 0 { i -= len(m.GasPrices) copy(dAtA[i:], m.GasPrices) i = encodeVarintConfig(dAtA, i, uint64(len(m.GasPrices))) i-- - dAtA[i] = 0x32 + dAtA[i] = 0x42 } if m.GasAdjustment != 0 { i -= 8 encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.GasAdjustment)))) i-- - dAtA[i] = 0x29 + dAtA[i] = 0x39 } if len(m.AccountPrefix) > 0 { i -= len(m.AccountPrefix) copy(dAtA[i:], m.AccountPrefix) i = encodeVarintConfig(dAtA, i, uint64(len(m.AccountPrefix))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x32 } if len(m.RpcAddr) > 0 { i -= len(m.RpcAddr) copy(dAtA[i:], m.RpcAddr) i = encodeVarintConfig(dAtA, i, uint64(len(m.RpcAddr))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x2a + } + if len(m.TmChainId) > 0 { + i -= len(m.TmChainId) + copy(dAtA[i:], m.TmChainId) + i = encodeVarintConfig(dAtA, i, uint64(len(m.TmChainId))) + i-- + dAtA[i] = 0x22 } if len(m.ChainId) > 0 { i -= len(m.ChainId) copy(dAtA[i:], m.ChainId) i = encodeVarintConfig(dAtA, i, uint64(len(m.ChainId))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.Key) > 0 { i -= len(m.Key) copy(dAtA[i:], m.Key) i = encodeVarintConfig(dAtA, i, uint64(len(m.Key))) i-- + dAtA[i] = 0x12 + } + if len(m.KeyringBackend) > 0 { + i -= len(m.KeyringBackend) + copy(dAtA[i:], m.KeyringBackend) + i = encodeVarintConfig(dAtA, i, uint64(len(m.KeyringBackend))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -355,6 +373,10 @@ func (m *ChainConfig) Size() (n int) { } var l int _ = l + l = len(m.KeyringBackend) + if l > 0 { + n += 1 + l + sovConfig(uint64(l)) + } l = len(m.Key) if l > 0 { n += 1 + l + sovConfig(uint64(l)) @@ -363,6 +385,10 @@ func (m *ChainConfig) Size() (n int) { if l > 0 { n += 1 + l + sovConfig(uint64(l)) } + l = len(m.TmChainId) + if l > 0 { + n += 1 + l + sovConfig(uint64(l)) + } l = len(m.RpcAddr) if l > 0 { n += 1 + l + sovConfig(uint64(l)) @@ -455,6 +481,38 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KeyringBackend", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KeyringBackend = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) } @@ -486,7 +544,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } m.Key = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) } @@ -518,7 +576,39 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } m.ChainId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TmChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TmChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field RpcAddr", wireType) } @@ -550,7 +640,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } m.RpcAddr = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AccountPrefix", wireType) } @@ -582,7 +672,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } m.AccountPrefix = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 5: + case 7: if wireType != 1 { return fmt.Errorf("proto: wrong wireType = %d for field GasAdjustment", wireType) } @@ -593,7 +683,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) iNdEx += 8 m.GasAdjustment = float64(math.Float64frombits(v)) - case 6: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field GasPrices", wireType) } @@ -625,7 +715,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } m.GasPrices = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 7: + case 9: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field AverageBlockTimeMsec", wireType) } @@ -644,7 +734,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { break } } - case 8: + case 10: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field MaxRetryForCommit", wireType) } diff --git a/chains/tendermint/light.go b/chains/tendermint/light.go index 6f45cf3e..acf19b88 100644 --- a/chains/tendermint/light.go +++ b/chains/tendermint/light.go @@ -35,7 +35,7 @@ var ErrLightNotInitialized = errors.New("light client is not initialized") func (pr *Prover) LightClient(db dbm.DB) (*light.Client, error) { prov := pr.LightHTTP() return light.NewClientFromTrustedStore( - pr.chain.config.ChainId, + pr.chain.config.TmChainId, pr.getTrustingPeriod(), prov, // TODO: provide actual witnesses! @@ -48,7 +48,7 @@ func (pr *Prover) LightClient(db dbm.DB) (*light.Client, error) { // LightHTTP returns the http client for light clients func (pr *Prover) LightHTTP() lightp.Provider { - cl, err := lighthttp.New(pr.chain.config.ChainId, pr.chain.config.RpcAddr) + cl, err := lighthttp.New(pr.chain.config.TmChainId, pr.chain.config.RpcAddr) if err != nil { panic(err) } @@ -58,7 +58,7 @@ func (pr *Prover) LightHTTP() lightp.Provider { func (pr *Prover) NewLightDB(ctx context.Context) (db *dbm.GoLevelDB, df func(), err error) { c := pr.chain if err := retry.Do(func() error { - db, err = dbm.NewGoLevelDB(c.config.ChainId, lightDir(c.HomePath)) + db, err = dbm.NewGoLevelDB(c.config.TmChainId, lightDir(c.HomePath)) if err != nil { return fmt.Errorf("can't open light client database: %w", err) } @@ -88,7 +88,7 @@ func (pr *Prover) LightClientWithTrust(ctx context.Context, db dbm.DB, to light. prov := pr.LightHTTP() return light.NewClient( ctx, - pr.chain.config.ChainId, + pr.chain.config.TmChainId, to, prov, // TODO: provide actual witnesses! @@ -135,7 +135,7 @@ func (pr *Prover) LightClientWithoutTrust(ctx context.Context, db dbm.DB) (*ligh } return light.NewClient( ctx, - pr.chain.config.ChainId, + pr.chain.config.TmChainId, light.TrustOptions{ Period: pr.getTrustingPeriod(), Height: height, diff --git a/go.mod b/go.mod index bcc2bc8c..d9d89ddf 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( go.opentelemetry.io/otel/metric v1.33.0 go.opentelemetry.io/otel/sdk/metric v1.33.0 golang.org/x/sync v0.10.0 + golang.org/x/sys v0.28.0 google.golang.org/grpc v1.62.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -181,7 +182,6 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/net v0.32.0 // indirect golang.org/x/oauth2 v0.24.0 // indirect - golang.org/x/sys v0.28.0 // indirect golang.org/x/term v0.27.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/time v0.5.0 // indirect diff --git a/proto/relayer/chains/tendermint/config/config.proto b/proto/relayer/chains/tendermint/config/config.proto index b3a03b98..c00d32ac 100644 --- a/proto/relayer/chains/tendermint/config/config.proto +++ b/proto/relayer/chains/tendermint/config/config.proto @@ -7,14 +7,16 @@ option go_package = "github.com/hyperledger-labs/yui-relayer/chains/tendermint"; option (gogoproto.goproto_getters_all) = false; message ChainConfig { - string key = 1; - string chain_id = 2; - string rpc_addr = 3; - string account_prefix = 4; - double gas_adjustment = 5; - string gas_prices = 6; - uint64 average_block_time_msec = 7; - uint64 max_retry_for_commit = 8; + string keyring_backend = 1; + string key = 2; + string chain_id = 3; + string tm_chain_id = 4; + string rpc_addr = 5; + string account_prefix = 6; + double gas_adjustment = 7; + string gas_prices = 8; + uint64 average_block_time_msec = 9; + uint64 max_retry_for_commit = 10; } message ProverConfig { diff --git a/tests/cases/tm2tm/configs/demo/ibc-0.json b/tests/cases/tm2tm/configs/demo/ibc-0.json index 9f2b22e1..85e79161 100644 --- a/tests/cases/tm2tm/configs/demo/ibc-0.json +++ b/tests/cases/tm2tm/configs/demo/ibc-0.json @@ -1,8 +1,10 @@ { "chain": { "@type": "/relayer.chains.tendermint.config.ChainConfig", + "keyring_backend": "test", "key": "testkey", "chain_id": "ibc0", + "tm_chain_id": "ibc0", "rpc_addr": "http://localhost:26657", "account_prefix": "cosmos", "gas_adjustment": 1.5, diff --git a/tests/cases/tm2tm/configs/demo/ibc-1.json b/tests/cases/tm2tm/configs/demo/ibc-1.json index eda642d4..95a5ff9a 100644 --- a/tests/cases/tm2tm/configs/demo/ibc-1.json +++ b/tests/cases/tm2tm/configs/demo/ibc-1.json @@ -1,8 +1,10 @@ { "chain": { "@type": "/relayer.chains.tendermint.config.ChainConfig", + "keyring_backend": "test", "key": "testkey", "chain_id": "ibc1", + "tm_chain_id": "ibc1", "rpc_addr": "http://localhost:26557", "account_prefix": "cosmos", "gas_adjustment": 1.5, diff --git a/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json b/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json index 123ff9e8..7c24bb92 100644 --- a/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json +++ b/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json @@ -1,8 +1,10 @@ { "chain": { "@type": "/relayer.chains.tendermint.config.ChainConfig", + "keyring_backend": "test", "key": "testkey", "chain_id": "ibc0", + "tm_chain_id": "ibc0", "rpc_addr": "http://localhost:26657", "account_prefix": "cosmos", "gas_adjustment": 1.5, diff --git a/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json b/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json index 7ca744da..f4fe6d29 100644 --- a/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json +++ b/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json @@ -1,8 +1,10 @@ { "chain": { "@type": "/relayer.chains.tendermint.config.ChainConfig", + "keyring_backend": "test", "key": "testkey", "chain_id": "ibc1", + "tm_chain_id": "ibc1", "rpc_addr": "http://localhost:26557", "account_prefix": "cosmos", "gas_adjustment": 1.5,