diff --git a/zetaclient/chains/interfaces/interfaces.go b/zetaclient/chains/interfaces/interfaces.go index 77c2cbd966..8b3cf97921 100644 --- a/zetaclient/chains/interfaces/interfaces.go +++ b/zetaclient/chains/interfaces/interfaces.go @@ -42,7 +42,9 @@ const ( type ChainObserver interface { Start() Stop() + OpenDB(dbPath string, dbName string) error LoadDB(dbPath string) error + SaveLastBlockScanned(blockNumber uint64) error IsOutboundProcessed(cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger) (bool, bool, error) SetChainParams(observertypes.ChainParams) GetChainParams() observertypes.ChainParams diff --git a/zetaclient/orchestrator/chain_activate_test.go b/zetaclient/orchestrator/chain_activate_test.go index 7df06647f5..4304398a17 100644 --- a/zetaclient/orchestrator/chain_activate_test.go +++ b/zetaclient/orchestrator/chain_activate_test.go @@ -124,6 +124,15 @@ func Test_ActivateChains(t *testing.T) { newObserverMap := make(map[int64]interfaces.ChainObserver) oc.CreateSignerObserverEVM(newSignerMap, newObserverMap) + // open db and save last block number to db to avoid RPC call + ob := newObserverMap[tt.evmChain.ChainId] + require.NotNil(t, ob) + err := ob.OpenDB(testutils.SQLiteMemory, tt.evmCfg.Chain.ChainName.String()) + require.NoError(t, err) + + err = ob.SaveLastBlockScanned(100) + require.NoError(t, err) + // activate chains oc.ActivateChains(newSignerMap, newObserverMap) @@ -189,11 +198,20 @@ func Test_DeactivateChains(t *testing.T) { newObserverMap := make(map[int64]interfaces.ChainObserver) oc.CreateSignerObserverEVM(newSignerMap, newObserverMap) + // open db and save last block number to db to avoid RPC call + ob := newObserverMap[tt.evmChain.ChainId] + require.NotNil(t, ob) + err := ob.OpenDB(testutils.SQLiteMemory, tt.evmCfg.Chain.ChainName.String()) + require.NoError(t, err) + + err = ob.SaveLastBlockScanned(100) + require.NoError(t, err) + // activate chains oc.ActivateChains(newSignerMap, newObserverMap) // assert signer/observer map - ob, err := oc.GetUpdatedChainObserver(tt.evmChain.ChainId) + ob, err = oc.GetUpdatedChainObserver(tt.evmChain.ChainId) require.NoError(t, err) require.NotNil(t, ob) diff --git a/zetaclient/testutils/mocks/chain_clients.go b/zetaclient/testutils/mocks/chain_clients.go index b9f75cf169..38690eda92 100644 --- a/zetaclient/testutils/mocks/chain_clients.go +++ b/zetaclient/testutils/mocks/chain_clients.go @@ -30,10 +30,18 @@ func (ob *EVMObserver) Start() { func (ob *EVMObserver) Stop() { } +func (ob *EVMObserver) OpenDB(_, _ string) error { + return nil +} + func (ob *EVMObserver) LoadDB(_ string) error { return nil } +func (ob *EVMObserver) SaveLastBlockScanned(_ uint64) error { + return nil +} + func (ob *EVMObserver) IsOutboundProcessed(_ *crosschaintypes.CrossChainTx, _ zerolog.Logger) (bool, bool, error) { return false, false, nil } @@ -75,10 +83,18 @@ func (ob *BTCObserver) Start() { func (ob *BTCObserver) Stop() { } +func (ob *BTCObserver) OpenDB(_, _ string) error { + return nil +} + func (ob *BTCObserver) LoadDB(_ string) error { return nil } +func (ob *BTCObserver) SaveLastBlockScanned(_ uint64) error { + return nil +} + func (ob *BTCObserver) IsOutboundProcessed(_ *crosschaintypes.CrossChainTx, _ zerolog.Logger) (bool, bool, error) { return false, false, nil } diff --git a/zetaclient/zetacore/client.go b/zetaclient/zetacore/client.go index 722e53d3b3..a8fffd9ea1 100644 --- a/zetaclient/zetacore/client.go +++ b/zetaclient/zetacore/client.go @@ -266,7 +266,8 @@ func (c *Client) UpdateAppContext(appContext *context.AppContext, logger zerolog // just in case (zetacore already validated) err := observertypes.ValidateChainParams(chainParam) if err != nil { - return errors.Wrapf(err, "Invalid chain params for chain %d", chainParam.ChainId) + logger.Error().Err(err).Msgf("Invalid chain params for chain %d", chainParam.ChainId) + continue } // zetaclient detects Bitcoin network (regnet, testnet, mainnet) from chain params in zetacore diff --git a/zetaclient/zetacore/tx_test.go b/zetaclient/zetacore/tx_test.go index 5bf8babb3d..92672f442c 100644 --- a/zetaclient/zetacore/tx_test.go +++ b/zetaclient/zetacore/tx_test.go @@ -4,14 +4,16 @@ import ( "bytes" "encoding/hex" "errors" - "github.com/zeta-chain/zetacore/testutil/sample" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "math/big" "net" "os" "testing" + "github.com/zeta-chain/zetacore/testutil/sample" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" sdktypes "github.com/cosmos/cosmos-sdk/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -228,12 +230,28 @@ func TestZetacore_UpdateAppContext(t *testing.T) { IsSupported: true, }, { - ChainId: chains.Ethereum.ChainId, - IsSupported: true, + ChainId: chains.Ethereum.ChainId, + ConfirmationCount: 32, + InboundTicker: 15, + OutboundTicker: 15, + GasPriceTicker: 300, + OutboundScheduleInterval: 64, + OutboundScheduleLookahead: 10, + BallotThreshold: sdk.MustNewDecFromStr("0.6"), + MinObserverDelegation: sdk.MustNewDecFromStr("1000000000000000000"), + IsSupported: true, }, { - ChainId: chains.BitcoinMainnet.ChainId, - IsSupported: true, + ChainId: chains.BitcoinMainnet.ChainId, + ConfirmationCount: 32, + InboundTicker: 15, + OutboundTicker: 15, + GasPriceTicker: 300, + OutboundScheduleInterval: 64, + OutboundScheduleLookahead: 10, + BallotThreshold: sdk.MustNewDecFromStr("0.6"), + MinObserverDelegation: sdk.MustNewDecFromStr("1000000000000000000"), + IsSupported: true, }, }, }})