Skip to content

Commit

Permalink
Merge pull request #2862 from zeta-chain/v20-more-fixes
Browse files Browse the repository at this point in the history
chore: backport more fixes for v20
  • Loading branch information
gartnera authored Sep 10, 2024
2 parents 34d9695 + 6a83fd9 commit 7876616
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
44 changes: 40 additions & 4 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand All @@ -72,7 +73,7 @@ func NewObserver(
) (*Observer, error) {
// create base observer
baseObserver, err := base.NewObserver(
evmCfg.Chain,
chain,
chainParams,
zetacoreClient,
tss,
Expand All @@ -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{},
Expand Down
28 changes: 24 additions & 4 deletions zetaclient/chains/evm/observer/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -113,7 +118,7 @@ func MockEVMObserver(
tss = mocks.NewTSSMainnet()
}
// create AppContext
appContext, evmCfg := getAppContext(t, chain, "", &params)
appContext, _ := getAppContext(t, chain, "", &params)

database, err := db.NewFromSqliteInMemory(true)
require.NoError(t, err)
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions zetaclient/chains/evm/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion zetaclient/orchestrator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7876616

Please sign in to comment.