diff --git a/cmd/zetaclientd/debug.go b/cmd/zetaclientd/debug.go index 90a3da3c13..c466ad744b 100644 --- a/cmd/zetaclientd/debug.go +++ b/cmd/zetaclientd/debug.go @@ -53,7 +53,7 @@ func DebugCmd() *cobra.Command { if err != nil { return err } - coreContext := clientcontext.NewZetaCoreContext(cfg) + coreContext := clientcontext.NewZetacoreContext(cfg) chainID, err := strconv.ParseInt(args[1], 10, 64) if err != nil { return err diff --git a/cmd/zetaclientd/keygen_tss.go b/cmd/zetaclientd/keygen_tss.go index 14b9ed768b..b07d7f6106 100644 --- a/cmd/zetaclientd/keygen_tss.go +++ b/cmd/zetaclientd/keygen_tss.go @@ -7,11 +7,6 @@ import ( "fmt" "time" - appcontext "github.com/zeta-chain/zetacore/zetaclient/context" - mc "github.com/zeta-chain/zetacore/zetaclient/tss" - "github.com/zeta-chain/zetacore/zetaclient/zetacore" - "golang.org/x/crypto/sha3" - "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/rs/zerolog" tsscommon "github.com/zeta-chain/go-tss/common" @@ -19,11 +14,15 @@ import ( "github.com/zeta-chain/go-tss/p2p" "github.com/zeta-chain/zetacore/pkg/chains" observertypes "github.com/zeta-chain/zetacore/x/observer/types" + "github.com/zeta-chain/zetacore/zetaclient/context" "github.com/zeta-chain/zetacore/zetaclient/metrics" + mc "github.com/zeta-chain/zetacore/zetaclient/tss" + "github.com/zeta-chain/zetacore/zetaclient/zetacore" + "golang.org/x/crypto/sha3" ) func GenerateTss( - appContext *appcontext.AppContext, + appContext *context.AppContext, logger zerolog.Logger, client *zetacore.Client, peers p2p.AddrList, @@ -74,7 +73,7 @@ func GenerateTss( // This loop will try keygen at the keygen block and then wait for keygen to be successfully reported by all nodes before breaking out of the loop. // If keygen is unsuccessful, it will reset the triedKeygenAtBlock flag and try again at a new keygen block. - keyGen := appContext.ZetaCoreContext().GetKeygen() + keyGen := appContext.ZetacoreContext().GetKeygen() if keyGen.Status == observertypes.KeygenStatus_KeyGenSuccess { return tss, nil } diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index ceecc96170..b16b9b7888 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -122,15 +122,15 @@ func start(_ *cobra.Command, _ []string) error { startLogger.Debug().Msgf("CreateAuthzSigner is ready") // Initialize core parameters from zetacore - appContext := context.NewAppContext(context.NewZetaCoreContext(cfg), cfg) - err = zetacoreClient.UpdateZetaCoreContext(appContext.ZetaCoreContext(), true, startLogger) + appContext := context.NewAppContext(context.NewZetacoreContext(cfg), cfg) + err = zetacoreClient.UpdateZetacoreContext(appContext.ZetacoreContext(), true, startLogger) if err != nil { startLogger.Error().Err(err).Msg("Error getting core parameters") return err } startLogger.Info().Msgf("Config is updated from zetacore %s", maskCfg(cfg)) - go zetacoreClient.CoreContextUpdater(appContext) + go zetacoreClient.ZetacoreContextUpdater(appContext) // Generate TSS address . The Tss address is generated through Keygen ceremony. The TSS key is used to sign all outbound transactions . // The hotkeyPk is private key for the Hotkey. The Hotkey is used to sign all inbound transactions @@ -194,7 +194,7 @@ func start(_ *cobra.Command, _ []string) error { // For existing keygen, this should directly proceed to the next step ticker := time.NewTicker(time.Second * 1) for range ticker.C { - keyGen := appContext.ZetaCoreContext().GetKeygen() + keyGen := appContext.ZetacoreContext().GetKeygen() if keyGen.Status != observerTypes.KeygenStatus_KeyGenSuccess { startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", keyGen.Status) continue @@ -217,7 +217,7 @@ func start(_ *cobra.Command, _ []string) error { startLogger.Error().Msg("TSS address is not set in zetacore") } startLogger.Info().Msgf("Current TSS address \n ETH : %s \n BTC : %s \n PubKey : %s ", tss.EVMAddress(), tss.BTCAddress(), tss.CurrentPubkey) - if len(appContext.ZetaCoreContext().GetEnabledChains()) == 0 { + if len(appContext.ZetacoreContext().GetEnabledChains()) == 0 { startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String()) } diff --git a/cmd/zetaclientd/utils.go b/cmd/zetaclientd/utils.go index f492c4693c..7f4ec66ce0 100644 --- a/cmd/zetaclientd/utils.go +++ b/cmd/zetaclientd/utils.go @@ -11,7 +11,7 @@ import ( "github.com/zeta-chain/zetacore/zetaclient/chains/interfaces" clientcommon "github.com/zeta-chain/zetacore/zetaclient/common" "github.com/zeta-chain/zetacore/zetaclient/config" - appcontext "github.com/zeta-chain/zetacore/zetaclient/context" + "github.com/zeta-chain/zetacore/zetaclient/context" "github.com/zeta-chain/zetacore/zetaclient/keys" "github.com/zeta-chain/zetacore/zetaclient/metrics" "github.com/zeta-chain/zetacore/zetaclient/zetacore" @@ -50,12 +50,12 @@ func CreateZetaCoreClient(cfg config.Config, telemetry *metrics.TelemetryServer, } func CreateSignerMap( - appContext *appcontext.AppContext, + appContext *context.AppContext, tss interfaces.TSSSigner, loggers clientcommon.ClientLogger, ts *metrics.TelemetryServer, ) (map[int64]interfaces.ChainSigner, error) { - coreContext := appContext.ZetaCoreContext() + coreContext := appContext.ZetacoreContext() signerMap := make(map[int64]interfaces.ChainSigner) // EVM signers @@ -103,7 +103,7 @@ func CreateSignerMap( // CreateChainObserverMap creates a map of ChainObservers for all chains in the config func CreateChainObserverMap( - appContext *appcontext.AppContext, + appContext *context.AppContext, zetacoreClient *zetacore.Client, tss interfaces.TSSSigner, dbpath string, @@ -116,7 +116,7 @@ func CreateChainObserverMap( if evmConfig.Chain.IsZetaChain() { continue } - _, found := appContext.ZetaCoreContext().GetEVMChainParams(evmConfig.Chain.ChainId) + _, found := appContext.ZetacoreContext().GetEVMChainParams(evmConfig.Chain.ChainId) if !found { loggers.Std.Error().Msgf("ChainParam not found for chain %s", evmConfig.Chain.String()) continue diff --git a/zetaclient/chains/bitcoin/observer/live_test.go b/zetaclient/chains/bitcoin/observer/live_test.go index 886467c836..1d9cfa1f5d 100644 --- a/zetaclient/chains/bitcoin/observer/live_test.go +++ b/zetaclient/chains/bitcoin/observer/live_test.go @@ -45,7 +45,7 @@ func (suite *BitcoinObserverTestSuite) SetupTest() { tss := &mocks.TSS{ PrivKey: privateKey, } - appContext := clientcontext.NewAppContext(&clientcontext.ZetaCoreContext{}, config.Config{}) + appContext := clientcontext.NewAppContext(&clientcontext.ZetacoreContext{}, config.Config{}) client, err := NewObserver(appContext, chains.BtcRegtestChain, nil, tss, tempSQLiteDbPath, clientcommon.DefaultLoggers(), config.BTCConfig{}, nil) suite.Require().NoError(err) diff --git a/zetaclient/chains/bitcoin/observer/observer.go b/zetaclient/chains/bitcoin/observer/observer.go index 347ccbbdc9..3008757393 100644 --- a/zetaclient/chains/bitcoin/observer/observer.go +++ b/zetaclient/chains/bitcoin/observer/observer.go @@ -116,7 +116,7 @@ type Observer struct { pendingNonce uint64 utxos []btcjson.ListUnspentResult params observertypes.ChainParams - coreContext *context.ZetaCoreContext + coreContext *context.ZetacoreContext // includedTxHashes indexes included tx with tx hash includedTxHashes map[string]bool @@ -172,13 +172,13 @@ func NewObserver( ob.zetacoreClient = zetacoreClient ob.Tss = tss - ob.coreContext = appcontext.ZetaCoreContext() + ob.coreContext = appcontext.ZetacoreContext() ob.includedTxHashes = make(map[string]bool) ob.includedTxResults = make(map[string]*btcjson.GetTransactionResult) ob.broadcastedTx = make(map[string]string) // set the Bitcoin chain params - _, chainParams, found := appcontext.ZetaCoreContext().GetBTCChainParams() + _, chainParams, found := appcontext.ZetacoreContext().GetBTCChainParams() if !found { return nil, fmt.Errorf("btc chains params not initialized") } diff --git a/zetaclient/chains/bitcoin/observer/observer_test.go b/zetaclient/chains/bitcoin/observer/observer_test.go index f199da7ba5..98bca623d1 100644 --- a/zetaclient/chains/bitcoin/observer/observer_test.go +++ b/zetaclient/chains/bitcoin/observer/observer_test.go @@ -67,9 +67,9 @@ func setupDBTxResults(t *testing.T) (*gorm.DB, map[string]btcjson.GetTransaction } func TestNewBitcoinObserver(t *testing.T) { - t.Run("should return error because zetacore doesn't update core context", func(t *testing.T) { + t.Run("should return error because zetacore doesn't update zetacore context", func(t *testing.T) { cfg := config.NewConfig() - coreContext := context.NewZetaCoreContext(cfg) + coreContext := context.NewZetacoreContext(cfg) appContext := context.NewAppContext(coreContext, cfg) chain := chains.BtcMainnetChain zetacoreClient := mocks.NewMockZetaCoreClient() diff --git a/zetaclient/chains/bitcoin/observer/outbound_test.go b/zetaclient/chains/bitcoin/observer/outbound_test.go index a38215694b..aaeab7366e 100644 --- a/zetaclient/chains/bitcoin/observer/outbound_test.go +++ b/zetaclient/chains/bitcoin/observer/outbound_test.go @@ -18,7 +18,7 @@ import ( func MockBTCObserverMainnet() *Observer { cfg := config.NewConfig() - coreContext := context.NewZetaCoreContext(cfg) + coreContext := context.NewZetacoreContext(cfg) return &Observer{ chain: chains.BtcMainnetChain, diff --git a/zetaclient/chains/bitcoin/signer/signer.go b/zetaclient/chains/bitcoin/signer/signer.go index d09800ed8b..fb8746f411 100644 --- a/zetaclient/chains/bitcoin/signer/signer.go +++ b/zetaclient/chains/bitcoin/signer/signer.go @@ -49,7 +49,7 @@ type Signer struct { logger zerolog.Logger loggerCompliance zerolog.Logger ts *metrics.TelemetryServer - coreContext *context.ZetaCoreContext + coreContext *context.ZetacoreContext } func NewSigner( @@ -57,7 +57,7 @@ func NewSigner( tssSigner interfaces.TSSSigner, loggers clientcommon.ClientLogger, ts *metrics.TelemetryServer, - coreContext *context.ZetaCoreContext) (*Signer, error) { + coreContext *context.ZetacoreContext) (*Signer, error) { connCfg := &rpcclient.ConnConfig{ Host: cfg.RPCHost, User: cfg.RPCUsername, diff --git a/zetaclient/chains/bitcoin/signer/signer_test.go b/zetaclient/chains/bitcoin/signer/signer_test.go index 0460e91948..e2627cdf63 100644 --- a/zetaclient/chains/bitcoin/signer/signer_test.go +++ b/zetaclient/chains/bitcoin/signer/signer_test.go @@ -53,7 +53,7 @@ func (s *BTCSignerSuite) SetUpTest(c *C) { tss, clientcommon.DefaultLoggers(), &metrics.TelemetryServer{}, - context.NewZetaCoreContext(cfg)) + context.NewZetacoreContext(cfg)) c.Assert(err, IsNil) } @@ -375,7 +375,7 @@ func TestNewBTCSigner(t *testing.T) { tss, clientcommon.DefaultLoggers(), &metrics.TelemetryServer{}, - context.NewZetaCoreContext(cfg)) + context.NewZetacoreContext(cfg)) require.NoError(t, err) require.NotNil(t, btcSigner) } diff --git a/zetaclient/chains/evm/observer/observer.go b/zetaclient/chains/evm/observer/observer.go index d289c8eaa3..bec85dc5a9 100644 --- a/zetaclient/chains/evm/observer/observer.go +++ b/zetaclient/chains/evm/observer/observer.go @@ -78,7 +78,7 @@ type Observer struct { outTXConfirmedTransactions map[string]*ethtypes.Transaction stop chan struct{} logger Logger - coreContext *clientcontext.ZetaCoreContext + coreContext *clientcontext.ZetacoreContext chainParams observertypes.ChainParams ts *metrics.TelemetryServer @@ -109,7 +109,7 @@ func NewObserver( Compliance: loggers.Compliance, } - ob.coreContext = appContext.ZetaCoreContext() + ob.coreContext = appContext.ZetacoreContext() chainParams, found := ob.coreContext.GetEVMChainParams(evmCfg.Chain.ChainId) if !found { return nil, fmt.Errorf("evm chains params not initialized for chain %d", evmCfg.Chain.ChainId) diff --git a/zetaclient/chains/evm/observer/observer_test.go b/zetaclient/chains/evm/observer/observer_test.go index a6ef377417..500cdfea90 100644 --- a/zetaclient/chains/evm/observer/observer_test.go +++ b/zetaclient/chains/evm/observer/observer_test.go @@ -35,8 +35,8 @@ func getAppContext(evmChain chains.Chain, evmChainParams *observertypes.ChainPar Chain: evmChain, Endpoint: "http://localhost:8545", } - // create core context - coreCtx := context.NewZetaCoreContext(cfg) + // create zetacore context + coreCtx := context.NewZetacoreContext(cfg) evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams diff --git a/zetaclient/chains/evm/signer/signer.go b/zetaclient/chains/evm/signer/signer.go index 86d76cd3b4..0f3569bc3f 100644 --- a/zetaclient/chains/evm/signer/signer.go +++ b/zetaclient/chains/evm/signer/signer.go @@ -48,7 +48,7 @@ type Signer struct { ethSigner ethtypes.Signer logger clientcommon.ClientLogger ts *metrics.TelemetryServer - coreContext *clientcontext.ZetaCoreContext + coreContext *clientcontext.ZetacoreContext // mu protects below fields from concurrent access mu *sync.Mutex @@ -67,7 +67,7 @@ func NewSigner( erc20CustodyABI string, zetaConnectorAddress ethcommon.Address, erc20CustodyAddress ethcommon.Address, - coreContext *clientcontext.ZetaCoreContext, + coreContext *clientcontext.ZetacoreContext, loggers clientcommon.ClientLogger, ts *metrics.TelemetryServer, ) (*Signer, error) { diff --git a/zetaclient/chains/evm/signer/signer_test.go b/zetaclient/chains/evm/signer/signer_test.go index 0fa0aeafbe..532deb344b 100644 --- a/zetaclient/chains/evm/signer/signer_test.go +++ b/zetaclient/chains/evm/signer/signer_test.go @@ -41,7 +41,7 @@ func getNewEvmSigner() (*Signer, error) { config.GetERC20CustodyABI(), mpiAddress, erc20CustodyAddress, - context.NewZetaCoreContext(cfg), + context.NewZetacoreContext(cfg), logger, ts) } @@ -54,7 +54,7 @@ func getNewEvmChainObserver() (*observer.Observer, error) { evmcfg := config.EVMConfig{Chain: chains.BscMainnetChain, Endpoint: "http://localhost:8545"} cfg.EVMChainConfigs[chains.BscMainnetChain.ChainId] = evmcfg - coreCTX := context.NewZetaCoreContext(cfg) + coreCTX := context.NewZetacoreContext(cfg) appCTX := context.NewAppContext(coreCTX, cfg) return observer.NewObserver(appCTX, mocks.NewMockZetaCoreClient(), tss, "", logger, evmcfg, ts) diff --git a/zetaclient/context/app_context.go b/zetaclient/context/app_context.go index e4ae9ca5f6..d47cd925e8 100644 --- a/zetaclient/context/app_context.go +++ b/zetaclient/context/app_context.go @@ -5,15 +5,15 @@ import ( "github.com/zeta-chain/zetacore/zetaclient/config" ) -// AppContext contains global app structs like config, core context and logger +// AppContext contains global app structs like config, zetacore context and logger type AppContext struct { - coreContext *ZetaCoreContext + coreContext *ZetacoreContext config config.Config } // NewAppContext creates and returns new AppContext func NewAppContext( - coreContext *ZetaCoreContext, + coreContext *ZetacoreContext, config config.Config, ) *AppContext { return &AppContext{ @@ -26,14 +26,14 @@ func (a AppContext) Config() config.Config { return a.config } -func (a AppContext) ZetaCoreContext() *ZetaCoreContext { +func (a AppContext) ZetacoreContext() *ZetacoreContext { return a.coreContext } // GetBTCChainAndConfig returns btc chain and config if enabled func (a AppContext) GetBTCChainAndConfig() (chains.Chain, config.BTCConfig, bool) { btcConfig, configEnabled := a.Config().GetBTCConfig() - btcChain, _, paramsEnabled := a.ZetaCoreContext().GetBTCChainParams() + btcChain, _, paramsEnabled := a.coreContext.GetBTCChainParams() if !configEnabled || !paramsEnabled { return chains.Chain{}, config.BTCConfig{}, false diff --git a/zetaclient/context/zeta_core_context.go b/zetaclient/context/zetacore_context.go similarity index 85% rename from zetaclient/context/zeta_core_context.go rename to zetaclient/context/zetacore_context.go index 26f0743072..493b075359 100644 --- a/zetaclient/context/zeta_core_context.go +++ b/zetaclient/context/zetacore_context.go @@ -12,9 +12,9 @@ import ( "github.com/zeta-chain/zetacore/zetaclient/config" ) -// ZetaCoreContext contains core context params +// ZetacoreContext contains zetacore context params // these are initialized and updated at runtime at every height -type ZetaCoreContext struct { +type ZetacoreContext struct { coreContextLock *sync.RWMutex keygen observertypes.Keygen chainsEnabled []chains.Chain @@ -28,9 +28,9 @@ type ZetaCoreContext struct { blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain } -// NewZetaCoreContext creates and returns new ZetaCoreContext +// NewZetacoreContext creates and returns new ZetacoreContext // it is initializing chain params from provided config -func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { +func NewZetacoreContext(cfg config.Config) *ZetacoreContext { evmChainParams := make(map[int64]*observertypes.ChainParams) for _, e := range cfg.EVMChainConfigs { evmChainParams[e.Chain.ChainId] = &observertypes.ChainParams{} @@ -42,7 +42,7 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { bitcoinChainParams = &observertypes.ChainParams{} } - return &ZetaCoreContext{ + return &ZetacoreContext{ coreContextLock: new(sync.RWMutex), chainsEnabled: []chains.Chain{}, evmChainParams: evmChainParams, @@ -52,7 +52,7 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext { } } -func (c *ZetaCoreContext) GetKeygen() observertypes.Keygen { +func (c *ZetacoreContext) GetKeygen() observertypes.Keygen { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -69,14 +69,14 @@ func (c *ZetaCoreContext) GetKeygen() observertypes.Keygen { } } -func (c *ZetaCoreContext) GetCurrentTssPubkey() string { +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 { +func (c *ZetacoreContext) GetEnabledChains() []chains.Chain { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -86,7 +86,7 @@ func (c *ZetaCoreContext) GetEnabledChains() []chains.Chain { } // GetEnabledExternalChains returns all enabled external chains -func (c *ZetaCoreContext) GetEnabledExternalChains() []chains.Chain { +func (c *ZetacoreContext) GetEnabledExternalChains() []chains.Chain { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -99,7 +99,7 @@ func (c *ZetaCoreContext) GetEnabledExternalChains() []chains.Chain { return externalChains } -func (c *ZetaCoreContext) GetEVMChainParams(chainID int64) (*observertypes.ChainParams, bool) { +func (c *ZetacoreContext) GetEVMChainParams(chainID int64) (*observertypes.ChainParams, bool) { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -107,7 +107,7 @@ func (c *ZetaCoreContext) GetEVMChainParams(chainID int64) (*observertypes.Chain return evmChainParams, found } -func (c *ZetaCoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainParams { +func (c *ZetacoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainParams { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -120,7 +120,7 @@ func (c *ZetaCoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainP return copied } -func (c *ZetaCoreContext) GetBTCChainParams() (chains.Chain, *observertypes.ChainParams, bool) { +func (c *ZetacoreContext) GetBTCChainParams() (chains.Chain, *observertypes.ChainParams, bool) { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -136,21 +136,21 @@ func (c *ZetaCoreContext) GetBTCChainParams() (chains.Chain, *observertypes.Chai return *chain, c.bitcoinChainParams, true } -func (c *ZetaCoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { +func (c *ZetacoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() return c.crossChainFlags } // GetAllHeaderEnabledChains returns all verification flags -func (c *ZetaCoreContext) GetAllHeaderEnabledChains() []lightclienttypes.HeaderSupportedChain { +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) { +func (c *ZetacoreContext) GetBlockHeaderEnabledChains(chainID int64) (lightclienttypes.HeaderSupportedChain, bool) { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() for _, flags := range c.blockHeaderEnabledChains { @@ -161,9 +161,9 @@ func (c *ZetaCoreContext) GetBlockHeaderEnabledChains(chainID int64) (lightclien return lightclienttypes.HeaderSupportedChain{}, false } -// Update updates core context and params for all chains -// this must be the ONLY function that writes to core context -func (c *ZetaCoreContext) Update( +// 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, @@ -235,13 +235,13 @@ func (c *ZetaCoreContext) Update( } // IsOutboundObservationEnabled returns true if the chain is supported and outbound flag is enabled -func IsOutboundObservationEnabled(c *ZetaCoreContext, chainParams observertypes.ChainParams) bool { +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 { +func IsInboundObservationEnabled(c *ZetacoreContext, chainParams observertypes.ChainParams) bool { flags := c.GetCrossChainFlags() return chainParams.IsSupported && flags.IsInboundEnabled } diff --git a/zetaclient/context/zeta_core_context_test.go b/zetaclient/context/zetacore_context_test.go similarity index 94% rename from zetaclient/context/zeta_core_context_test.go rename to zetaclient/context/zetacore_context_test.go index dd04f8a667..c21148fd80 100644 --- a/zetaclient/context/zeta_core_context_test.go +++ b/zetaclient/context/zetacore_context_test.go @@ -29,14 +29,14 @@ func getTestCoreContext( evmChainParams *observertypes.ChainParams, ccFlags observertypes.CrosschainFlags, headerSupportedChains []lightclienttypes.HeaderSupportedChain, -) *context.ZetaCoreContext { +) *context.ZetacoreContext { // create config cfg := config.NewConfig() cfg.EVMChainConfigs[evmChain.ChainId] = config.EVMConfig{ Chain: evmChain, } - // create core context - coreContext := context.NewZetaCoreContext(cfg) + // create zetacore context + coreContext := context.NewZetacoreContext(cfg) evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams @@ -59,7 +59,7 @@ func TestNewZetaCoreContext(t *testing.T) { t.Run("should create new zetacore context with empty config", func(t *testing.T) { testCfg := config.NewConfig() - zetaContext := context.NewZetaCoreContext(testCfg) + zetaContext := context.NewZetacoreContext(testCfg) require.NotNil(t, zetaContext) // assert keygen @@ -102,7 +102,7 @@ func TestNewZetaCoreContext(t *testing.T) { }, }, } - zetaContext := context.NewZetaCoreContext(testCfg) + zetaContext := context.NewZetacoreContext(testCfg) require.NotNil(t, zetaContext) // assert evm chain params @@ -128,7 +128,7 @@ func TestNewZetaCoreContext(t *testing.T) { RPCHost: "test host", RPCParams: "test params", } - zetaContext := context.NewZetaCoreContext(testCfg) + zetaContext := context.NewZetacoreContext(testCfg) require.NotNil(t, zetaContext) // assert btc chain params panic because chain params are not yet updated @@ -138,11 +138,11 @@ func TestNewZetaCoreContext(t *testing.T) { }) } -func TestUpdateZetaCoreContext(t *testing.T) { - t.Run("should update core context after being created from empty config", func(t *testing.T) { +func TestUpdateZetacoreContext(t *testing.T) { + t.Run("should update zetacore context after being created from empty config", func(t *testing.T) { testCfg := config.NewConfig() - zetaContext := context.NewZetaCoreContext(testCfg) + zetaContext := context.NewZetacoreContext(testCfg) require.NotNil(t, zetaContext) keyGenToUpdate := observertypes.Keygen{ @@ -221,7 +221,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { require.Equal(t, verificationFlags, verFlags) }) - t.Run("should update core context after being created from config with evm and btc chain params", func(t *testing.T) { + t.Run("should update zetacore context after being created from config with evm and btc chain params", func(t *testing.T) { testCfg := config.NewConfig() testCfg.EVMChainConfigs = map[int64]config.EVMConfig{ 1: { @@ -244,7 +244,7 @@ func TestUpdateZetaCoreContext(t *testing.T) { RPCParams: "test params", } - zetaContext := context.NewZetaCoreContext(testCfg) + zetaContext := context.NewZetacoreContext(testCfg) require.NotNil(t, zetaContext) keyGenToUpdate := observertypes.Keygen{ diff --git a/zetaclient/orchestrator/orchestrator.go b/zetaclient/orchestrator/orchestrator.go index 6558af21e9..1ef669b301 100644 --- a/zetaclient/orchestrator/orchestrator.go +++ b/zetaclient/orchestrator/orchestrator.go @@ -110,7 +110,7 @@ func (oc *Orchestrator) MonitorCore(appContext *context.AppContext) { } // GetUpdatedSigner returns signer with updated chain parameters -func (oc *Orchestrator) GetUpdatedSigner(coreContext *context.ZetaCoreContext, chainID int64) (interfaces.ChainSigner, error) { +func (oc *Orchestrator) GetUpdatedSigner(coreContext *context.ZetacoreContext, chainID int64) (interfaces.ChainSigner, error) { signer, found := oc.signerMap[chainID] if !found { return nil, fmt.Errorf("signer not found for chainID %d", chainID) @@ -138,7 +138,7 @@ func (oc *Orchestrator) GetUpdatedSigner(coreContext *context.ZetaCoreContext, c } // GetUpdatedChainObserver returns chain observer with updated chain parameters -func (oc *Orchestrator) GetUpdatedChainObserver(coreContext *context.ZetaCoreContext, chainID int64) (interfaces.ChainObserver, error) { +func (oc *Orchestrator) GetUpdatedChainObserver(coreContext *context.ZetacoreContext, chainID int64) (interfaces.ChainObserver, error) { observer, found := oc.observerMap[chainID] if !found { return nil, fmt.Errorf("chain observer not found for chainID %d", chainID) @@ -256,7 +256,7 @@ func (oc *Orchestrator) StartCctxScheduler(appContext *context.AppContext) { metrics.HotKeyBurnRate.Set(float64(oc.ts.HotKeyBurnRate.GetBurnRate().Int64())) // get supported external chains - coreContext := appContext.ZetaCoreContext() + coreContext := appContext.ZetacoreContext() externalChains := coreContext.GetEnabledExternalChains() // query pending cctxs across all external chains within rate limit diff --git a/zetaclient/orchestrator/orchestrator_test.go b/zetaclient/orchestrator/orchestrator_test.go index adc5888f1b..e28b4ee565 100644 --- a/zetaclient/orchestrator/orchestrator_test.go +++ b/zetaclient/orchestrator/orchestrator_test.go @@ -52,7 +52,7 @@ func MockOrchestrator( return orchestrator } -func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChainParams *observertypes.ChainParams) *context.ZetaCoreContext { +func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChainParams *observertypes.ChainParams) *context.ZetacoreContext { // new config cfg := config.NewConfig() cfg.EVMChainConfigs[evmChain.ChainId] = config.EVMConfig{ @@ -61,8 +61,8 @@ func CreateCoreContext(evmChain, btcChain chains.Chain, evmChainParams, btcChain cfg.BitcoinConfig = config.BTCConfig{ RPCHost: "localhost", } - // new core context - coreContext := context.NewZetaCoreContext(cfg) + // new zetacore context + coreContext := context.NewZetacoreContext(cfg) evmChainParamsMap := make(map[int64]*observertypes.ChainParams) evmChainParamsMap[evmChain.ChainId] = evmChainParams ccFlags := sample.CrosschainFlags() @@ -94,7 +94,7 @@ func Test_GetUpdatedSigner(t *testing.T) { } btcChainParams := &observertypes.ChainParams{} - // new chain params in core context + // new chain params in zetacore context evmChainParamsNew := &observertypes.ChainParams{ ChainId: evmChain.ChainId, ConnectorContractAddress: testutils.OtherAddress1, @@ -103,16 +103,16 @@ func Test_GetUpdatedSigner(t *testing.T) { t.Run("signer should not be found", func(t *testing.T) { orchestrator := MockOrchestrator(t, nil, evmChain, btcChain, evmChainParams, btcChainParams) - coreContext := CreateCoreContext(evmChain, btcChain, evmChainParamsNew, btcChainParams) + context := CreateCoreContext(evmChain, btcChain, evmChainParamsNew, btcChainParams) // BSC signer should not be found - _, err := orchestrator.GetUpdatedSigner(coreContext, chains.BscMainnetChain.ChainId) + _, err := orchestrator.GetUpdatedSigner(context, chains.BscMainnetChain.ChainId) require.ErrorContains(t, err, "signer not found") }) t.Run("should be able to update connector and erc20 custody address", func(t *testing.T) { orchestrator := MockOrchestrator(t, nil, evmChain, btcChain, evmChainParams, btcChainParams) - coreContext := CreateCoreContext(evmChain, btcChain, evmChainParamsNew, btcChainParams) + context := CreateCoreContext(evmChain, btcChain, evmChainParamsNew, btcChainParams) // update signer with new connector and erc20 custody address - signer, err := orchestrator.GetUpdatedSigner(coreContext, evmChain.ChainId) + signer, err := orchestrator.GetUpdatedSigner(context, evmChain.ChainId) require.NoError(t, err) require.Equal(t, testutils.OtherAddress1, signer.GetZetaConnectorAddress().Hex()) require.Equal(t, testutils.OtherAddress2, signer.GetERC20CustodyAddress().Hex()) @@ -132,7 +132,7 @@ func Test_GetUpdatedChainObserver(t *testing.T) { ChainId: btcChain.ChainId, } - // new chain params in core context + // new chain params in zetacore context evmChainParamsNew := &observertypes.ChainParams{ ChainId: evmChain.ChainId, ConfirmationCount: 10, diff --git a/zetaclient/supplychecker/zeta_supply_checker.go b/zetaclient/supplychecker/zeta_supply_checker.go index 709ad2371f..60438213c5 100644 --- a/zetaclient/supplychecker/zeta_supply_checker.go +++ b/zetaclient/supplychecker/zeta_supply_checker.go @@ -20,7 +20,7 @@ import ( // ZetaSupplyChecker is a utility to check the total supply of Zeta tokens type ZetaSupplyChecker struct { - coreContext *context.ZetaCoreContext + coreContext *context.ZetacoreContext evmClient map[int64]*ethclient.Client zetaClient *zetacore.Client ticker *clienttypes.DynamicTicker @@ -49,7 +49,7 @@ func NewZetaSupplyChecker( logger: logger.With(). Str("module", "ZetaSupplyChecker"). Logger(), - coreContext: appContext.ZetaCoreContext(), + coreContext: appContext.ZetacoreContext(), zetaClient: zetaClient, } diff --git a/zetaclient/tss/tss_signer.go b/zetaclient/tss/tss_signer.go index 61e822068b..610b93faf5 100644 --- a/zetaclient/tss/tss_signer.go +++ b/zetaclient/tss/tss_signer.go @@ -104,7 +104,7 @@ func NewTSS( newTss := TSS{ Server: server, Keys: make(map[string]*Key), - CurrentPubkey: appContext.ZetaCoreContext().GetCurrentTssPubkey(), + CurrentPubkey: appContext.ZetacoreContext().GetCurrentTssPubkey(), logger: logger, ZetacoreClient: client, KeysignsTracker: NewKeysignsTracker(logger), diff --git a/zetaclient/zetacore/client.go b/zetaclient/zetacore/client.go index ddf234ed97..0fb3d9bdc6 100644 --- a/zetaclient/zetacore/client.go +++ b/zetaclient/zetacore/client.go @@ -180,9 +180,9 @@ func (c *Client) WaitForCoreToCreateBlocks() { } } -// UpdateZetaCoreContext updates core context -// zetacore stores core context for all clients -func (c *Client) UpdateZetaCoreContext(coreContext *context.ZetaCoreContext, init bool, sampledLogger zerolog.Logger) error { +// UpdateZetacoreContext updates zetacore context +// zetacore stores zetacore context for all clients +func (c *Client) UpdateZetacoreContext(coreContext *context.ZetacoreContext, init bool, sampledLogger zerolog.Logger) error { bn, err := c.GetBlockHeight() if err != nil { return fmt.Errorf("failed to get zetablock height: %w", err) diff --git a/zetaclient/zetacore/tx.go b/zetaclient/zetacore/tx.go index 1a9e1b7152..e0851f5664 100644 --- a/zetaclient/zetacore/tx.go +++ b/zetaclient/zetacore/tx.go @@ -163,21 +163,21 @@ func (c *Client) SetTSS(tssPubkey string, keyGenZetaHeight int64, status chains. return "", fmt.Errorf("set tss failed | err %s", err.Error()) } -// CoreContextUpdater is a polling goroutine that checks and updates core context at every height -func (c *Client) CoreContextUpdater(appContext *appcontext.AppContext) { - c.logger.Info().Msg("CoreContextUpdater started") +// ZetacoreContextUpdater is a polling goroutine that checks and updates zetacore context at every height +func (c *Client) ZetacoreContextUpdater(appContext *appcontext.AppContext) { + c.logger.Info().Msg("ZetacoreContextUpdater started") ticker := time.NewTicker(time.Duration(appContext.Config().ConfigUpdateTicker) * time.Second) sampledLogger := c.logger.Sample(&zerolog.BasicSampler{N: 10}) for { select { case <-ticker.C: c.logger.Debug().Msg("Running Updater") - err := c.UpdateZetaCoreContext(appContext.ZetaCoreContext(), false, sampledLogger) + err := c.UpdateZetacoreContext(appContext.ZetacoreContext(), false, sampledLogger) if err != nil { - c.logger.Err(err).Msg("CoreContextUpdater failed to update config") + c.logger.Err(err).Msg("ZetacoreContextUpdater failed to update config") } case <-c.stop: - c.logger.Info().Msg("CoreContextUpdater stopped") + c.logger.Info().Msg("ZetacoreContextUpdater stopped") return } } diff --git a/zetaclient/zetacore/tx_test.go b/zetaclient/zetacore/tx_test.go index 301a144895..258a6f28d0 100644 --- a/zetaclient/zetacore/tx_test.go +++ b/zetaclient/zetacore/tx_test.go @@ -197,7 +197,7 @@ func TestZetacore_SetTSS(t *testing.T) { }) } -func TestZetacore_UpdateZetaCoreContext(t *testing.T) { +func TestZetacore_UpdateZetacoreContext(t *testing.T) { //Setup server for multiple grpc calls listener, err := net.Listen("tcp", "127.0.0.1:9090") require.NoError(t, err) @@ -329,11 +329,11 @@ func TestZetacore_UpdateZetaCoreContext(t *testing.T) { client.keys = keys.NewKeysWithKeybase(mocks.NewKeyring(), address, "", "") client.EnableMockSDKClient(mocks.NewSDKClientWithErr(nil, 0)) - t.Run("core context update success", func(t *testing.T) { + t.Run("zetacore update success", func(t *testing.T) { cfg := config.NewConfig() - coreCtx := context.NewZetaCoreContext(cfg) + coreCtx := context.NewZetacoreContext(cfg) zetacoreBroadcast = MockBroadcast - err := client.UpdateZetaCoreContext(coreCtx, false, zerolog.Logger{}) + err := client.UpdateZetacoreContext(coreCtx, false, zerolog.Logger{}) require.NoError(t, err) }) }