From 7f1890566d6f8181e8c13eaba7dcb099af2166b5 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 10 Sep 2024 13:24:32 -0700 Subject: [PATCH 1/2] fix: register all interfaces in encoding config (#2828) * fix: register all interfaces in encoding config * register more types --- app/encoding.go | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/app/encoding.go b/app/encoding.go index 5d4e7f5305..678a7b03e5 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -2,16 +2,52 @@ package app import ( "cosmossdk.io/simapp/params" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/authz" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" evmenc "github.com/evmos/ethermint/encoding" + ethermint "github.com/evmos/ethermint/types" + evmtypes "github.com/evmos/ethermint/x/evm/types" + + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" + emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" + fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" + lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) // MakeEncodingConfig creates an EncodingConfig for testing func MakeEncodingConfig() params.EncodingConfig { //encodingConfig := params.MakeEncodingConfig() encodingConfig := evmenc.MakeConfig(ModuleBasics) - //std.RegisterLegacyAminoCodec(encodingConfig.Amino) - //std.RegisterInterfaces(encodingConfig.InterfaceRegistry) - //ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) - //ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) + registry := encodingConfig.InterfaceRegistry + + cryptocodec.RegisterInterfaces(registry) + authtypes.RegisterInterfaces(registry) + authz.RegisterInterfaces(registry) + banktypes.RegisterInterfaces(registry) + stakingtypes.RegisterInterfaces(registry) + slashingtypes.RegisterInterfaces(registry) + upgradetypes.RegisterInterfaces(registry) + distrtypes.RegisterInterfaces(registry) + evidencetypes.RegisterInterfaces(registry) + crisistypes.RegisterInterfaces(registry) + evmtypes.RegisterInterfaces(registry) + ethermint.RegisterInterfaces(registry) + authoritytypes.RegisterInterfaces(registry) + crosschaintypes.RegisterInterfaces(registry) + emissionstypes.RegisterInterfaces(registry) + fungibletypes.RegisterInterfaces(registry) + observertypes.RegisterInterfaces(registry) + lightclienttypes.RegisterInterfaces(registry) + return encodingConfig } From 6a83fd9fe3aec20bd74a2175f9f0fe334d814df9 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 10 Sep 2024 09:35:57 -0700 Subject: [PATCH 2/2] fix(zetaclient): use on-chain chain struct (#2834) --- zetaclient/chains/evm/observer/observer.go | 9 +++--- .../chains/evm/observer/observer_test.go | 28 ++++++++++++++++--- zetaclient/chains/evm/signer/signer_test.go | 10 +++---- zetaclient/orchestrator/bootstrap.go | 6 +++- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/zetaclient/chains/evm/observer/observer.go b/zetaclient/chains/evm/observer/observer.go index 6dd1234018..82fc1e4d6d 100644 --- a/zetaclient/chains/evm/observer/observer.go +++ b/zetaclient/chains/evm/observer/observer.go @@ -21,11 +21,11 @@ import ( "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol" "github.com/zeta-chain/zetacore/pkg/bg" + "github.com/zeta-chain/zetacore/pkg/chains" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/chains/base" "github.com/zeta-chain/zetacore/zetaclient/chains/evm" "github.com/zeta-chain/zetacore/zetaclient/chains/interfaces" - "github.com/zeta-chain/zetacore/zetaclient/config" "github.com/zeta-chain/zetacore/zetaclient/db" "github.com/zeta-chain/zetacore/zetaclient/metrics" ) @@ -61,8 +61,9 @@ type priorityFeeConfig struct { // NewObserver returns a new EVM chain observer func NewObserver( ctx context.Context, - evmCfg config.EVMConfig, + chain chains.Chain, evmClient interfaces.EVMRPCClient, + evmJSONRPC interfaces.EVMJSONRPCClient, chainParams observertypes.ChainParams, zetacoreClient interfaces.ZetacoreClient, tss interfaces.TSSSigner, @@ -72,7 +73,7 @@ func NewObserver( ) (*Observer, error) { // create base observer baseObserver, err := base.NewObserver( - evmCfg.Chain, + chain, chainParams, zetacoreClient, tss, @@ -90,7 +91,7 @@ func NewObserver( ob := &Observer{ Observer: *baseObserver, evmClient: evmClient, - evmJSONRPC: ethrpc.NewEthRPC(evmCfg.Endpoint), + evmJSONRPC: evmJSONRPC, outboundConfirmedReceipts: make(map[string]*ethtypes.Receipt), outboundConfirmedTransactions: make(map[string]*ethtypes.Transaction), priorityFeeConfig: priorityFeeConfig{}, diff --git a/zetaclient/chains/evm/observer/observer_test.go b/zetaclient/chains/evm/observer/observer_test.go index 69ff6a977d..9bf7eb4265 100644 --- a/zetaclient/chains/evm/observer/observer_test.go +++ b/zetaclient/chains/evm/observer/observer_test.go @@ -100,6 +100,11 @@ func MockEVMObserver( evmClient = mocks.NewMockEvmClient().WithBlockNumber(1000) } + // use default mock evm client if not provided + if evmJSONRPC == nil { + evmJSONRPC = mocks.NewMockJSONRPCClient() + } + // use default mock zetacore client if not provided if zetacoreClient == nil { zetacoreClient = mocks.NewZetacoreClient(t). @@ -113,7 +118,7 @@ func MockEVMObserver( tss = mocks.NewTSSMainnet() } // create AppContext - appContext, evmCfg := getAppContext(t, chain, "", ¶ms) + appContext, _ := getAppContext(t, chain, "", ¶ms) database, err := db.NewFromSqliteInMemory(true) require.NoError(t, err) @@ -122,9 +127,19 @@ func MockEVMObserver( logger := base.Logger{Std: testLogger, Compliance: testLogger} // create observer - ob, err := observer.NewObserver(ctx, evmCfg, evmClient, params, zetacoreClient, tss, database, logger, nil) + ob, err := observer.NewObserver( + ctx, + chain, + evmClient, + evmJSONRPC, + params, + zetacoreClient, + tss, + database, + logger, + nil, + ) require.NoError(t, err) - ob.WithEvmJSONRPC(evmJSONRPC) ob.WithLastBlock(lastBlock) return ob, appContext @@ -143,6 +158,7 @@ func Test_NewObserver(t *testing.T) { evmCfg config.EVMConfig chainParams observertypes.ChainParams evmClient interfaces.EVMRPCClient + evmJSONRPC interfaces.EVMJSONRPCClient tss interfaces.TSSSigner logger base.Logger before func() @@ -159,6 +175,7 @@ func Test_NewObserver(t *testing.T) { }, chainParams: params, evmClient: mocks.NewMockEvmClient().WithBlockNumber(1000), + evmJSONRPC: mocks.NewMockJSONRPCClient(), tss: mocks.NewTSSMainnet(), logger: base.Logger{}, ts: nil, @@ -172,6 +189,7 @@ func Test_NewObserver(t *testing.T) { }, chainParams: params, evmClient: mocks.NewMockEvmClient().WithError(fmt.Errorf("error RPC")), + evmJSONRPC: mocks.NewMockJSONRPCClient(), tss: mocks.NewTSSMainnet(), logger: base.Logger{}, ts: nil, @@ -186,6 +204,7 @@ func Test_NewObserver(t *testing.T) { }, chainParams: params, evmClient: mocks.NewMockEvmClient().WithBlockNumber(1000), + evmJSONRPC: mocks.NewMockJSONRPCClient(), tss: mocks.NewTSSMainnet(), before: func() { envVar := base.EnvVarLatestBlockByChain(chain) @@ -222,8 +241,9 @@ func Test_NewObserver(t *testing.T) { // create observer ob, err := observer.NewObserver( ctx, - tt.evmCfg, + chain, tt.evmClient, + tt.evmJSONRPC, tt.chainParams, zetacoreClient, tt.tss, diff --git a/zetaclient/chains/evm/signer/signer_test.go b/zetaclient/chains/evm/signer/signer_test.go index 3297a301f3..9be86b949e 100644 --- a/zetaclient/chains/evm/signer/signer_test.go +++ b/zetaclient/chains/evm/signer/signer_test.go @@ -69,14 +69,11 @@ func getNewEvmChainObserver(t *testing.T, tss interfaces.TSSSigner) (*observer.O if tss == nil { tss = mocks.NewTSSMainnet() } - cfg := config.New(false) // prepare mock arguments to create observer - evmcfg := config.EVMConfig{Chain: chains.BscMainnet, Endpoint: "http://localhost:8545"} evmClient := mocks.NewMockEvmClient().WithBlockNumber(1000) - params := mocks.MockChainParams(evmcfg.Chain.ChainId, 10) - cfg.EVMChainConfigs[chains.BscMainnet.ChainId] = evmcfg - //appContext := context.New(cfg, zerolog.Nop()) + evmJSONRPCClient := mocks.NewMockJSONRPCClient() + params := mocks.MockChainParams(chains.BscMainnet.ChainId, 10) logger := base.Logger{} ts := &metrics.TelemetryServer{} @@ -85,8 +82,9 @@ func getNewEvmChainObserver(t *testing.T, tss interfaces.TSSSigner) (*observer.O return observer.NewObserver( ctx, - evmcfg, + chains.BscMainnet, evmClient, + evmJSONRPCClient, params, mocks.NewZetacoreClient(t), tss, diff --git a/zetaclient/orchestrator/bootstrap.go b/zetaclient/orchestrator/bootstrap.go index 238652f931..81ddaa9136 100644 --- a/zetaclient/orchestrator/bootstrap.go +++ b/zetaclient/orchestrator/bootstrap.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/ethclient" ethrpc "github.com/ethereum/go-ethereum/rpc" solrpc "github.com/gagliardetto/solana-go/rpc" + ethrpc2 "github.com/onrik/ethrpc" "github.com/pkg/errors" "github.com/zeta-chain/zetacore/zetaclient/chains/base" @@ -298,11 +299,14 @@ func syncObserverMap( continue } + evmJSONRPCClient := ethrpc2.NewEthRPC(cfg.Endpoint, ethrpc2.WithHttpClient(httpClient)) + // create EVM chain observer observer, err := evmobserver.NewObserver( ctx, - cfg, + *rawChain, evmClient, + evmJSONRPCClient, *params, client, tss,