diff --git a/cmd/zetaclientd/debug.go b/cmd/zetaclientd/debug.go index 0cad97f7d1..28a3932a8d 100644 --- a/cmd/zetaclientd/debug.go +++ b/cmd/zetaclientd/debug.go @@ -86,20 +86,20 @@ func debugCmd(_ *cobra.Command, args []string) error { if err != nil { return err } - chain := chains.GetChainFromChainID(chainID, appContext) - if chain == nil { + chain, found := chains.GetChainFromChainID(chainID, appContext.GetAdditionalChains()) + if !found { return fmt.Errorf("invalid chain id") } // get ballot identifier according to the chain type - if chains.IsEVMChain(chain.ChainId) { + if chains.IsEVMChain(chain.ChainId, appContext.GetAdditionalChains()) { evmObserver := evmobserver.Observer{} evmObserver.WithZetacoreClient(client) var ethRPC *ethrpc.EthRPC var client *ethclient.Client coinType := coin.CoinType_Cmd - for chain, evmConfig := range cfg.GetAllEVMConfigs() { - if chainID == chain { + for chainIDFromConfig, evmConfig := range cfg.GetAllEVMConfigs() { + if chainIDFromConfig == chainID { ethRPC = ethrpc.NewEthRPC(evmConfig.Endpoint) client, err = ethclient.Dial(evmConfig.Endpoint) if err != nil { @@ -107,7 +107,7 @@ func debugCmd(_ *cobra.Command, args []string) error { } evmObserver.WithEvmClient(client) evmObserver.WithEvmJSONRPC(ethRPC) - evmObserver.WithChain(*chains.GetChainFromChainID(chainID)) + evmObserver.WithChain(chain) } } hash := ethcommon.HexToHash(inboundHash) @@ -168,10 +168,10 @@ func debugCmd(_ *cobra.Command, args []string) error { fmt.Println("CoinType not detected") } fmt.Println("CoinType : ", coinType) - } else if chains.IsBitcoinChain(chain.ChainId) { + } else if chains.IsBitcoinChain(chain.ChainId, appContext.GetAdditionalChains()) { btcObserver := btcobserver.Observer{} btcObserver.WithZetacoreClient(client) - btcObserver.WithChain(*chains.GetChainFromChainID(chainID)) + btcObserver.WithChain(chain) connCfg := &rpcclient.ConnConfig{ Host: cfg.BitcoinConfig.RPCHost, User: cfg.BitcoinConfig.RPCUsername, diff --git a/zetaclient/chains/base/signer.go b/zetaclient/chains/base/signer.go index 0fc9ca4837..2ac38e048d 100644 --- a/zetaclient/chains/base/signer.go +++ b/zetaclient/chains/base/signer.go @@ -34,14 +34,14 @@ type Signer struct { // NewSigner creates a new base signer func NewSigner( chain chains.Chain, - zetacoreContext *context.AppContext, + appContext *context.AppContext, tss interfaces.TSSSigner, ts *metrics.TelemetryServer, logger Logger, ) *Signer { return &Signer{ chain: chain, - appContext: zetacoreContext, + appContext: appContext, tss: tss, ts: ts, logger: Logger{ diff --git a/zetaclient/chains/evm/observer/inbound.go b/zetaclient/chains/evm/observer/inbound.go index d278a11b72..889d2215ac 100644 --- a/zetaclient/chains/evm/observer/inbound.go +++ b/zetaclient/chains/evm/observer/inbound.go @@ -644,7 +644,7 @@ func (ob *Observer) BuildInboundVoteMsgForZetaSentEvent( ) *types.MsgVoteInbound { destChain, found := chains.GetChainFromChainID( event.DestinationChainId.Int64(), - ob.ZetacoreContext().GetAdditionalChains(), + ob.AppContext().GetAdditionalChains(), ) if !found { ob.Logger().Inbound.Warn().Msgf("chain id not supported %d", event.DestinationChainId.Int64()) diff --git a/zetaclient/chains/evm/signer/outbound_data.go b/zetaclient/chains/evm/signer/outbound_data.go index 9ca90276e3..3e84fa83db 100644 --- a/zetaclient/chains/evm/signer/outbound_data.go +++ b/zetaclient/chains/evm/signer/outbound_data.go @@ -112,7 +112,7 @@ func (txData *OutboundData) SetupGas( // cctx will be skipped and false otherwise. // 3. error func NewOutboundData( - coreContext *clientcontext.ZetacoreContext, + appontext *clientcontext.AppContext, cctx *types.CrossChainTx, evmObserver *observer.Observer, evmRPC interfaces.EVMRPCClient, @@ -134,7 +134,7 @@ func NewOutboundData( return nil, true, nil } - toChain, found := chains.GetChainFromChainID(txData.toChainID.Int64(), coreContext.GetAdditionalChains()) + toChain, found := chains.GetChainFromChainID(txData.toChainID.Int64(), appontext.GetAdditionalChains()) if !found { return nil, true, fmt.Errorf("unknown chain: %d", txData.toChainID.Int64()) } diff --git a/zetaclient/chains/evm/signer/outbound_data_test.go b/zetaclient/chains/evm/signer/outbound_data_test.go index f86cde53c4..f5e3d39d3b 100644 --- a/zetaclient/chains/evm/signer/outbound_data_test.go +++ b/zetaclient/chains/evm/signer/outbound_data_test.go @@ -76,7 +76,7 @@ func TestSigner_NewOutboundData(t *testing.T) { t.Run("NewOutboundData success", func(t *testing.T) { cctx := getCCTX(t) _, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -91,7 +91,7 @@ func TestSigner_NewOutboundData(t *testing.T) { cctx := getCCTX(t) cctx.CctxStatus.Status = types.CctxStatus_Aborted _, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -106,7 +106,7 @@ func TestSigner_NewOutboundData(t *testing.T) { cctx := getInvalidCCTX(t) require.NoError(t, err) _, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -122,7 +122,7 @@ func TestSigner_NewOutboundData(t *testing.T) { require.NoError(t, err) cctx.GetCurrentOutboundParam().GasPrice = "invalidGasPrice" _, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), diff --git a/zetaclient/chains/evm/signer/signer.go b/zetaclient/chains/evm/signer/signer.go index e42488cc13..db4a15c856 100644 --- a/zetaclient/chains/evm/signer/signer.go +++ b/zetaclient/chains/evm/signer/signer.go @@ -363,7 +363,7 @@ func (signer *Signer) TryProcessOutbound( } // Setup Transaction input - txData, skipTx, err := NewOutboundData(signer.ZetacoreContext(), cctx, evmObserver, signer.client, logger, height) + txData, skipTx, err := NewOutboundData(signer.AppContext(), cctx, evmObserver, signer.client, logger, height) if err != nil { logger.Err(err).Msg("error setting up transaction input fields") return @@ -374,7 +374,7 @@ func (signer *Signer) TryProcessOutbound( toChain, found := chains.GetChainFromChainID( txData.toChainID.Int64(), - signer.ZetacoreContext().GetAdditionalChains(), + signer.AppContext().GetAdditionalChains(), ) if !found { logger.Warn().Msgf("unknown chain: %d", txData.toChainID.Int64()) @@ -547,7 +547,7 @@ func (signer *Signer) BroadcastOutbound( // Get destination chain for logging toChain, found := chains.GetChainFromChainID( txData.toChainID.Int64(), - signer.ZetacoreContext().GetAdditionalChains(), + signer.AppContext().GetAdditionalChains(), ) if !found { logger.Warn().Msgf("BroadcastOutbound: unknown chain %d", txData.toChainID.Int64()) diff --git a/zetaclient/chains/evm/signer/signer_test.go b/zetaclient/chains/evm/signer/signer_test.go index 012ce0231e..fd412b4bfd 100644 --- a/zetaclient/chains/evm/signer/signer_test.go +++ b/zetaclient/chains/evm/signer/signer_test.go @@ -181,7 +181,7 @@ func TestSigner_SignOutbound(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -222,7 +222,7 @@ func TestSigner_SignRevertTx(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -267,7 +267,7 @@ func TestSigner_SignCancelTx(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -312,7 +312,7 @@ func TestSigner_SignWithdrawTx(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -355,7 +355,7 @@ func TestSigner_SignCommandTx(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, nil) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -407,7 +407,7 @@ func TestSigner_SignERC20WithdrawTx(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -452,7 +452,7 @@ func TestSigner_BroadcastOutbound(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, nil) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -509,7 +509,7 @@ func TestSigner_SignWhitelistERC20Cmd(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), @@ -559,7 +559,7 @@ func TestSigner_SignMigrateTssFundsCmd(t *testing.T) { mockObserver, err := getNewEvmChainObserver(t, tss) require.NoError(t, err) txData, skip, err := NewOutboundData( - evmSigner.ZetacoreContext(), + evmSigner.AppContext(), cctx, mockObserver, evmSigner.EvmClient(), diff --git a/zetaclient/context/app.go b/zetaclient/context/app.go index c40e769492..4888443ea9 100644 --- a/zetaclient/context/app.go +++ b/zetaclient/context/app.go @@ -25,6 +25,10 @@ type AppContext struct { currentTssPubkey string crosschainFlags observertypes.CrosschainFlags + // additionalChains is a list of additional static chain information to use when searching from chain IDs + // it is stored in the protocol to dynamically support new chains without doing an upgrade + additionalChain []chains.Chain + // blockHeaderEnabledChains is used to store the list of chains that have block header verification enabled // All chains in this list will have Enabled flag set to true blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain @@ -173,12 +177,12 @@ func (a *AppContext) GetBTCChainParams() (chains.Chain, *observertypes.ChainPara return chains.Chain{}, nil, false } - chain := chains.GetChainFromChainID(a.bitcoinChainParams.ChainId) - if chain == nil { + chain, found := chains.GetChainFromChainID(a.bitcoinChainParams.ChainId, a.additionalChain) + if !found { return chains.Chain{}, nil, false } - return *chain, a.bitcoinChainParams, true + return chain, a.bitcoinChainParams, true } // GetCrossChainFlags returns crosschain flags @@ -189,6 +193,13 @@ func (a *AppContext) GetCrossChainFlags() observertypes.CrosschainFlags { return a.crosschainFlags } +// GetAdditionalChains returns additional chains +func (a *AppContext) GetAdditionalChains() []chains.Chain { + a.mu.RLock() + defer a.mu.RUnlock() + return a.additionalChain +} + // GetAllHeaderEnabledChains returns all verification flags func (a *AppContext) GetAllHeaderEnabledChains() []lightclienttypes.HeaderSupportedChain { a.mu.RLock() @@ -220,6 +231,7 @@ func (a *AppContext) Update( btcChainParams *observertypes.ChainParams, tssPubKey string, crosschainFlags observertypes.CrosschainFlags, + additionalChains []chains.Chain, blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain, init bool, ) { @@ -249,6 +261,7 @@ func (a *AppContext) Update( a.chainsEnabled = newChains a.crosschainFlags = crosschainFlags + a.additionalChain = additionalChains a.blockHeaderEnabledChains = blockHeaderEnabledChains // update chain params for bitcoin if it has config in file diff --git a/zetaclient/context/app_test.go b/zetaclient/context/app_test.go index 4a86c2d921..640e5d7386 100644 --- a/zetaclient/context/app_test.go +++ b/zetaclient/context/app_test.go @@ -411,6 +411,7 @@ func TestGetBTCChainAndConfig(t *testing.T) { &observertypes.ChainParams{ChainId: 123}, "", observertypes.CrosschainFlags{}, + []chains.Chain{}, nil, true, ) @@ -428,6 +429,7 @@ func TestGetBTCChainAndConfig(t *testing.T) { &observertypes.ChainParams{ChainId: chains.BitcoinMainnet.ChainId}, "", observertypes.CrosschainFlags{}, + []chains.Chain{}, nil, true, ) @@ -471,6 +473,7 @@ func TestGetBlockHeaderEnabledChains(t *testing.T) { &observertypes.ChainParams{ChainId: chains.BitcoinMainnet.ChainId}, "", observertypes.CrosschainFlags{}, + []chains.Chain{}, []lightclienttypes.HeaderSupportedChain{ {ChainId: 1, Enabled: true}, }, @@ -493,6 +496,39 @@ func TestGetBlockHeaderEnabledChains(t *testing.T) { assert.Empty(t, chain) } +func TestGetAdditionalChains(t *testing.T) { + // ARRANGE + // Given app config + appContext := context.New(config.New(), zerolog.Nop()) + + additionalChains := []chains.Chain{ + sample.Chain(1), + sample.Chain(2), + sample.Chain(3), + } + + // That was eventually updated + appContext.Update( + &observertypes.Keygen{}, + []chains.Chain{}, + nil, + &observertypes.ChainParams{}, + "", + observertypes.CrosschainFlags{}, + additionalChains, + []lightclienttypes.HeaderSupportedChain{ + {ChainId: 1, Enabled: true}, + }, + true, + ) + + // ACT + found := appContext.GetAdditionalChains() + + // ASSERT + assert.EqualValues(t, additionalChains, found) +} + func makeAppContext( evmChain chains.Chain, evmChainParams *observertypes.ChainParams, @@ -519,6 +555,7 @@ func makeAppContext( nil, "", ccFlags, + []chains.Chain{}, headerSupportedChains, true, ) diff --git a/zetaclient/context/zetacore_context.go b/zetaclient/context/zetacore_context.go deleted file mode 100644 index 93ed5aa6e5..0000000000 --- a/zetaclient/context/zetacore_context.go +++ /dev/null @@ -1,266 +0,0 @@ -package context - -import ( - "sort" - "sync" - - "github.com/rs/zerolog" - - "github.com/zeta-chain/zetacore/pkg/chains" - lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" - "github.com/zeta-chain/zetacore/zetaclient/config" -) - -// ZetacoreContext contains zetacore context params -// these are initialized and updated at runtime at every height -type ZetacoreContext struct { - coreContextLock *sync.RWMutex - keygen observertypes.Keygen - chainsEnabled []chains.Chain - evmChainParams map[int64]*observertypes.ChainParams - bitcoinChainParams *observertypes.ChainParams - currentTssPubkey string - crosschainFlags observertypes.CrosschainFlags - - // additionalChains is a list of additional static chain information to use when searching from chain IDs - // it is stored in the protocol to dynamically support new chains without doing an upgrade - additionalChain []chains.Chain - - // blockHeaderEnabledChains is used to store the list of chains that have block header verification enabled - // All chains in this list will have Enabled flag set to true - blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain -} - -// NewZetacoreContext creates and returns new ZetacoreContext -// it is initializing chain params from provided config -func NewZetacoreContext(cfg config.Config) *ZetacoreContext { - evmChainParams := make(map[int64]*observertypes.ChainParams) - for _, e := range cfg.EVMChainConfigs { - evmChainParams[e.Chain.ChainId] = &observertypes.ChainParams{} - } - - var bitcoinChainParams *observertypes.ChainParams - _, found := cfg.GetBTCConfig() - if found { - bitcoinChainParams = &observertypes.ChainParams{} - } - - return &ZetacoreContext{ - coreContextLock: new(sync.RWMutex), - chainsEnabled: []chains.Chain{}, - evmChainParams: evmChainParams, - bitcoinChainParams: bitcoinChainParams, - crosschainFlags: observertypes.CrosschainFlags{}, - blockHeaderEnabledChains: []lightclienttypes.HeaderSupportedChain{}, - } -} - -// GetKeygen returns the current keygen -func (c *ZetacoreContext) GetKeygen() observertypes.Keygen { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - - var copiedPubkeys []string - if c.keygen.GranteePubkeys != nil { - copiedPubkeys = make([]string, len(c.keygen.GranteePubkeys)) - copy(copiedPubkeys, c.keygen.GranteePubkeys) - } - - return observertypes.Keygen{ - Status: c.keygen.Status, - GranteePubkeys: copiedPubkeys, - BlockNumber: c.keygen.BlockNumber, - } -} - -// GetCurrentTssPubkey returns the current tss pubkey -func (c *ZetacoreContext) GetCurrentTssPubkey() string { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - return c.currentTssPubkey -} - -// GetEnabledChains returns all enabled chains including zetachain -func (c *ZetacoreContext) GetEnabledChains() []chains.Chain { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - - copiedChains := make([]chains.Chain, len(c.chainsEnabled)) - copy(copiedChains, c.chainsEnabled) - return copiedChains -} - -// GetEnabledExternalChains returns all enabled external chains -func (c *ZetacoreContext) GetEnabledExternalChains() []chains.Chain { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - - externalChains := make([]chains.Chain, 0) - for _, chain := range c.chainsEnabled { - if chain.IsExternal { - externalChains = append(externalChains, chain) - } - } - return externalChains -} - -// GetEVMChainParams returns chain params for a specific EVM chain -func (c *ZetacoreContext) GetEVMChainParams(chainID int64) (*observertypes.ChainParams, bool) { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - - evmChainParams, found := c.evmChainParams[chainID] - return evmChainParams, found -} - -// GetAllEVMChainParams returns all chain params for EVM chains -func (c *ZetacoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainParams { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - - // deep copy evm chain params - copied := make(map[int64]*observertypes.ChainParams, len(c.evmChainParams)) - for chainID, evmConfig := range c.evmChainParams { - copied[chainID] = &observertypes.ChainParams{} - *copied[chainID] = *evmConfig - } - return copied -} - -// GetBTCChainParams returns (chain, chain params, found) for bitcoin chain -func (c *ZetacoreContext) GetBTCChainParams() (chains.Chain, *observertypes.ChainParams, bool) { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - - if c.bitcoinChainParams == nil { // bitcoin is not enabled - return chains.Chain{}, nil, false - } - - chain, found := chains.GetChainFromChainID(c.bitcoinChainParams.ChainId, c.additionalChain) - if !found { - return chains.Chain{}, nil, false - } - - return chain, c.bitcoinChainParams, true -} - -// GetCrossChainFlags returns crosschain flags -func (c *ZetacoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - return c.crosschainFlags -} - -// GetAdditionalChains returns additional chains -func (c *ZetacoreContext) GetAdditionalChains() []chains.Chain { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - return c.additionalChain -} - -// GetAllHeaderEnabledChains returns all verification flags -func (c *ZetacoreContext) GetAllHeaderEnabledChains() []lightclienttypes.HeaderSupportedChain { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - return c.blockHeaderEnabledChains -} - -// GetBlockHeaderEnabledChains checks if block header verification is enabled for a specific chain -func (c *ZetacoreContext) GetBlockHeaderEnabledChains(chainID int64) (lightclienttypes.HeaderSupportedChain, bool) { - c.coreContextLock.RLock() - defer c.coreContextLock.RUnlock() - for _, flags := range c.blockHeaderEnabledChains { - if flags.ChainId == chainID { - return flags, true - } - } - return lightclienttypes.HeaderSupportedChain{}, false -} - -// Update updates zetacore context and params for all chains -// this must be the ONLY function that writes to zetacore context -func (c *ZetacoreContext) Update( - keygen *observertypes.Keygen, - newChains []chains.Chain, - evmChainParams map[int64]*observertypes.ChainParams, - btcChainParams *observertypes.ChainParams, - tssPubKey string, - crosschainFlags observertypes.CrosschainFlags, - additionalChains []chains.Chain, - blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain, - init bool, - logger zerolog.Logger, -) { - c.coreContextLock.Lock() - defer c.coreContextLock.Unlock() - - // Ignore whatever order zetacore organizes chain list in state - sort.SliceStable(newChains, func(i, j int) bool { - return newChains[i].ChainId < newChains[j].ChainId - }) - - if len(newChains) == 0 { - logger.Warn().Msg("UpdateChainParams: No chains enabled in ZeroCore") - } - - // Add some warnings if chain list changes at runtime - if !init { - if len(c.chainsEnabled) != len(newChains) { - logger.Warn().Msgf( - "UpdateChainParams: ChainsEnabled changed at runtime!! current: %v, new: %v", - c.chainsEnabled, - newChains, - ) - } else { - for i, chain := range newChains { - if chain != c.chainsEnabled[i] { - logger.Warn().Msgf( - "UpdateChainParams: ChainsEnabled changed at runtime!! current: %v, new: %v", - c.chainsEnabled, - newChains, - ) - } - } - } - } - - if keygen != nil { - c.keygen = *keygen - } - - c.chainsEnabled = newChains - c.crosschainFlags = crosschainFlags - c.additionalChain = additionalChains - c.blockHeaderEnabledChains = blockHeaderEnabledChains - - // update chain params for bitcoin if it has config in file - if c.bitcoinChainParams != nil && btcChainParams != nil { - c.bitcoinChainParams = btcChainParams - } - - // update core params for evm chains we have configs in file - for _, params := range evmChainParams { - _, found := c.evmChainParams[params.ChainId] - if !found { - continue - } - c.evmChainParams[params.ChainId] = params - } - - if tssPubKey != "" { - c.currentTssPubkey = tssPubKey - } -} - -// IsOutboundObservationEnabled returns true if the chain is supported and outbound flag is enabled -func IsOutboundObservationEnabled(c *ZetacoreContext, chainParams observertypes.ChainParams) bool { - flags := c.GetCrossChainFlags() - return chainParams.IsSupported && flags.IsOutboundEnabled -} - -// IsInboundObservationEnabled returns true if the chain is supported and inbound flag is enabled -func IsInboundObservationEnabled(c *ZetacoreContext, chainParams observertypes.ChainParams) bool { - flags := c.GetCrossChainFlags() - return chainParams.IsSupported && flags.IsInboundEnabled -} diff --git a/zetaclient/orchestrator/orchestrator.go b/zetaclient/orchestrator/orchestrator.go index f0c4e0d004..b233c9d582 100644 --- a/zetaclient/orchestrator/orchestrator.go +++ b/zetaclient/orchestrator/orchestrator.go @@ -135,8 +135,9 @@ func (oc *Orchestrator) GetUpdatedSigner( return nil, fmt.Errorf("signer not found for chainID %d", chainID) } // update EVM signer parameters only. BTC signer doesn't use chain parameters for now. - if chains.IsEVMChain(chainID) { - evmParams, found := appContext.GetEVMChainParams(chainID)if found { + if chains.IsEVMChain(chainID, appContext.GetAdditionalChains()) { + evmParams, found := appContext.GetEVMChainParams(chainID) + if found { // update zeta connector and ERC20 custody addresses zetaConnectorAddress := ethcommon.HexToAddress(evmParams.GetConnectorContractAddress()) erc20CustodyAddress := ethcommon.HexToAddress(evmParams.GetErc20CustodyContractAddress()) @@ -166,14 +167,14 @@ func (oc *Orchestrator) GetUpdatedChainObserver( } // update chain observer chain parameters curParams := observer.GetChainParams() - if chains.IsEVMChain(chainID) { + if chains.IsEVMChain(chainID, appContext.GetAdditionalChains()) { evmParams, found := appContext.GetEVMChainParams(chainID) if found && !observertypes.ChainParamsEqual(curParams, *evmParams) { observer.SetChainParams(*evmParams) oc.logger.Std.Info().Msgf( "updated chain params for chainID %d, new params: %v", chainID, *evmParams) } - } else if chains.IsBitcoinChain(chainID) { + } else if chains.IsBitcoinChain(chainID, appContext.GetAdditionalChains()) { _, btcParams, found := appContext.GetBTCChainParams() if found && !observertypes.ChainParamsEqual(curParams, *btcParams) { @@ -318,9 +319,9 @@ func (oc *Orchestrator) StartCctxScheduler(appContext *context.AppContext) { // #nosec G701 range is verified zetaHeight := uint64(bn) - if chains.IsEVMChain(c.ChainId, coreContext.GetAdditionalChains()) { + if chains.IsEVMChain(c.ChainId, appContext.GetAdditionalChains()) { oc.ScheduleCctxEVM(zetaHeight, c.ChainId, cctxList, ob, signer) - } else if chains.IsBitcoinChain(c.ChainId, coreContext.GetAdditionalChains()) { + } else if chains.IsBitcoinChain(c.ChainId, appContext.GetAdditionalChains()) { oc.ScheduleCctxBTC(zetaHeight, c.ChainId, cctxList, ob, signer) } else { oc.logger.Std.Error().Msgf("StartCctxScheduler: unsupported chain %d", c.ChainId) diff --git a/zetaclient/supplychecker/zeta_supply_checker.go b/zetaclient/supplychecker/zeta_supply_checker.go index aa58d7efe1..3355d4ff5e 100644 --- a/zetaclient/supplychecker/zeta_supply_checker.go +++ b/zetaclient/supplychecker/zeta_supply_checker.go @@ -45,8 +45,6 @@ func NewZetaSupplyChecker( return ZetaSupplyChecker{}, err } - coreContext := appContext.ZetacoreContext() - zetaSupplyChecker := ZetaSupplyChecker{ stop: make(chan struct{}), ticker: dynamicTicker, @@ -69,10 +67,8 @@ func NewZetaSupplyChecker( zetaSupplyChecker.evmClient[evmConfig.Chain.ChainId] = client } - additionalChains := coreContext.GetAdditionalChains() - for chainID := range zetaSupplyChecker.evmClient { - chain, found := chains.GetChainFromChainID(chainID, additionalChains) + chain, found := chains.GetChainFromChainID(chainID, appContext.GetAdditionalChains()) if !found { return zetaSupplyChecker, fmt.Errorf("chain not found for chain id %d", chainID) }