From ddea482cbcf12fadd58d7ff2f9b576a7ce05c435 Mon Sep 17 00:00:00 2001 From: skosito Date: Wed, 21 Feb 2024 15:53:27 +0100 Subject: [PATCH] Fix PR comments --- cmd/zetaclientd/debug.go | 8 ++++-- cmd/zetaclientd/start.go | 14 +++++----- zetaclient/app_context/app_context.go | 6 ++--- zetaclient/bitcoin/bitcoin_client_rpc_test.go | 2 +- zetaclient/core_context/zeta_core_context.go | 26 ++++++++++++------- zetaclient/evm/evm_client.go | 2 +- .../supplychecker/zeta_supply_checker.go | 2 +- zetaclient/tss/tss_signer.go | 2 +- zetaclient/zetabridge/tx.go | 8 +++--- zetaclient/zetabridge/zetacore_bridge.go | 4 +-- 10 files changed, 42 insertions(+), 32 deletions(-) diff --git a/cmd/zetaclientd/debug.go b/cmd/zetaclientd/debug.go index 1565623f8d..9624ba0b21 100644 --- a/cmd/zetaclientd/debug.go +++ b/cmd/zetaclientd/debug.go @@ -52,7 +52,7 @@ func DebugCmd() *cobra.Command { if err != nil { return err } - coreContext := corecontext.NewZeraCoreContext() + coreContext := corecontext.NewZetaCoreContext() chainID, err := strconv.ParseInt(args[1], 10, 64) if err != nil { return err @@ -130,7 +130,11 @@ func DebugCmd() *cobra.Command { ZetaTokenContractAddress: chainParams.ZetaTokenContractAddress, Erc20CustodyContractAddress: chainParams.Erc20CustodyContractAddress, }) - coreContext.EVMChainParams[chainID].ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress + evmChainParams, found := coreContext.GetEVMChainParams(chainID) + if !found { + return fmt.Errorf("missing chain params for chain %s", chainID) + } + evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress if strings.EqualFold(tx.To().Hex(), chainParams.ConnectorContractAddress) { coinType = common.CoinType_Zeta } else if strings.EqualFold(tx.To().Hex(), chainParams.Erc20CustodyContractAddress) { diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 4bfc6a903d..02dfc331d0 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -115,7 +115,7 @@ func start(_ *cobra.Command, _ []string) error { startLogger.Debug().Msgf("CreateAuthzSigner is ready") // Initialize core parameters from zetacore - appContext := appcontext.NewAppContext(corecontext.NewZeraCoreContext(), cfg, masterLogger) + appContext := appcontext.NewAppContext(corecontext.NewZetaCoreContext(), cfg, masterLogger) err = zetaBridge.UpdateZetaCoreContext(appContext.ZetaCoreContext(), true) if err != nil { startLogger.Error().Err(err).Msg("Error getting core parameters") @@ -123,8 +123,8 @@ func start(_ *cobra.Command, _ []string) error { } startLogger.Info().Msgf("Config is updated from ZetaCore %s", maskCfg(cfg)) - // UpdateAppContext: A polling goroutine checks and updates core context at every height. Zetacore stores core context for all clients - go zetaBridge.UpdateAppContext(appContext) + // CoreContextUpdater: A polling goroutine checks and updates core context at every height. Zetacore stores core context for all clients + go zetaBridge.CoreContextUpdater(appContext) // Generate TSS address . The Tss address is generated through Keygen ceremony. The TSS key is used to sign all outbound transactions . // The bridgePk is private key for the Hotkey. The Hotkey is used to sign all inbound transactions @@ -185,8 +185,8 @@ 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 { - if appContext.ZetaCoreContext().Keygen.Status != observerTypes.KeygenStatus_KeyGenSuccess { - startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", appContext.ZetaCoreContext().Keygen.Status) + if appContext.ZetaCoreContext().GetKeygen().Status != observerTypes.KeygenStatus_KeyGenSuccess { + startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", appContext.ZetaCoreContext().GetKeygen().Status) continue } break @@ -204,7 +204,7 @@ func start(_ *cobra.Command, _ []string) error { // Defensive check: Make sure the tss address is set to the current TSS address and not the newly generated one tss.CurrentPubkey = currentTss.TssPubkey 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().ChainsEnabled) == 0 { + if len(appContext.ZetaCoreContext().GetEnabledChains()) == 0 { startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String()) } @@ -238,7 +238,7 @@ func start(_ *cobra.Command, _ []string) error { // CreateChainClientMap : This creates a map of all chain clients . Each chain client is responsible for listening to events on the chain and processing them chainClientMap, err := CreateChainClientMap(appContext, zetaBridge, tss, dbpath, metrics, telemetryServer) if err != nil { - startLogger.Err(err).Msg("CreateSignerMap") + startLogger.Err(err).Msg("CreateChainClientMap") return err } diff --git a/zetaclient/app_context/app_context.go b/zetaclient/app_context/app_context.go index 8b8658803b..97c539221f 100644 --- a/zetaclient/app_context/app_context.go +++ b/zetaclient/app_context/app_context.go @@ -8,13 +8,13 @@ import ( ) type AppContext struct { - coreContext *corecontext.ZeraCoreContext + coreContext *corecontext.ZetaCoreContext config *config.Config logger zerolog.Logger } func NewAppContext( - coreContext *corecontext.ZeraCoreContext, + coreContext *corecontext.ZetaCoreContext, config *config.Config, logger zerolog.Logger, ) *AppContext { @@ -29,7 +29,7 @@ func (a *AppContext) Config() *config.Config { return a.config } -func (a *AppContext) ZetaCoreContext() *corecontext.ZeraCoreContext { +func (a *AppContext) ZetaCoreContext() *corecontext.ZetaCoreContext { return a.coreContext } diff --git a/zetaclient/bitcoin/bitcoin_client_rpc_test.go b/zetaclient/bitcoin/bitcoin_client_rpc_test.go index 6077ca65f5..aed7b26a7d 100644 --- a/zetaclient/bitcoin/bitcoin_client_rpc_test.go +++ b/zetaclient/bitcoin/bitcoin_client_rpc_test.go @@ -45,7 +45,7 @@ func (suite *BitcoinClientTestSuite) SetupTest() { tss := interfaces.TestSigner{ PrivKey: privateKey, } - appContext := appcontext.NewAppContext(&corecontext.ZeraCoreContext{}, &config.Config{}, log.Logger) + appContext := appcontext.NewAppContext(&corecontext.ZetaCoreContext{}, &config.Config{}, log.Logger) client, err := NewBitcoinClient(appContext, common.BtcRegtestChain(), nil, tss, "/tmp", nil, nil) suite.Require().NoError(err) suite.BitcoinChainClient = client diff --git a/zetaclient/core_context/zeta_core_context.go b/zetaclient/core_context/zeta_core_context.go index c9325d277a..1d1cb250a4 100644 --- a/zetaclient/core_context/zeta_core_context.go +++ b/zetaclient/core_context/zeta_core_context.go @@ -10,7 +10,7 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -type ZeraCoreContext struct { +type ZetaCoreContext struct { coreContextLock *sync.RWMutex Keygen *observertypes.Keygen ChainsEnabled []common.Chain @@ -19,8 +19,8 @@ type ZeraCoreContext struct { CurrentTssPubkey string } -func NewZeraCoreContext() *ZeraCoreContext { - return &ZeraCoreContext{ +func NewZetaCoreContext() *ZetaCoreContext { + return &ZetaCoreContext{ coreContextLock: new(sync.RWMutex), ChainsEnabled: []common.Chain{}, EVMChainParams: make(map[int64]*observertypes.ChainParams), @@ -28,7 +28,7 @@ func NewZeraCoreContext() *ZeraCoreContext { } } -func (c *ZeraCoreContext) GetKeygen() observertypes.Keygen { +func (c *ZetaCoreContext) GetKeygen() observertypes.Keygen { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() copiedPubkeys := make([]string, len(c.Keygen.GranteePubkeys)) @@ -41,7 +41,13 @@ func (c *ZeraCoreContext) GetKeygen() observertypes.Keygen { } } -func (c *ZeraCoreContext) GetEnabledChains() []common.Chain { +func (c *ZetaCoreContext) GetCurrentTssPubkey() string { + c.coreContextLock.RLock() + defer c.coreContextLock.RUnlock() + return c.CurrentTssPubkey +} + +func (c *ZetaCoreContext) GetEnabledChains() []common.Chain { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() copiedChains := make([]common.Chain, len(c.ChainsEnabled)) @@ -49,14 +55,14 @@ func (c *ZeraCoreContext) GetEnabledChains() []common.Chain { return copiedChains } -func (c *ZeraCoreContext) GetEVMChainParams(chainID int64) (*observertypes.ChainParams, bool) { +func (c *ZetaCoreContext) GetEVMChainParams(chainID int64) (*observertypes.ChainParams, bool) { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() evmChainParams, found := c.EVMChainParams[chainID] return evmChainParams, found } -func (c *ZeraCoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainParams { +func (c *ZetaCoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainParams { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -69,7 +75,7 @@ func (c *ZeraCoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainP return copied } -func (c *ZeraCoreContext) GetBTCChainParams() (common.Chain, *observertypes.ChainParams, bool) { +func (c *ZetaCoreContext) GetBTCChainParams() (common.Chain, *observertypes.ChainParams, bool) { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -83,9 +89,9 @@ func (c *ZeraCoreContext) GetBTCChainParams() (common.Chain, *observertypes.Chai return *chain, c.BitcoinChainParams, true } -// UpdateCoreContext updates core context and params for all chains +// Update updates core context and params for all chains // this must be the ONLY function that writes to core context -func (c *ZeraCoreContext) UpdateCoreContext( +func (c *ZetaCoreContext) Update( keygen *observertypes.Keygen, newChains []common.Chain, evmChainParams map[int64]*observertypes.ChainParams, diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index 5fdfb109d3..229626ca5d 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -97,7 +97,7 @@ type ChainClient struct { stop chan struct{} fileLogger *zerolog.Logger // for critical info logger Log - coreContext *corecontext.ZeraCoreContext + coreContext *corecontext.ZetaCoreContext chainParams observertypes.ChainParams ts *metricsPkg.TelemetryServer diff --git a/zetaclient/supplychecker/zeta_supply_checker.go b/zetaclient/supplychecker/zeta_supply_checker.go index f364e598aa..86ffccdc1f 100644 --- a/zetaclient/supplychecker/zeta_supply_checker.go +++ b/zetaclient/supplychecker/zeta_supply_checker.go @@ -22,7 +22,7 @@ import ( ) type ZetaSupplyChecker struct { - coreContext *corecontext.ZeraCoreContext + coreContext *corecontext.ZetaCoreContext evmClient map[int64]*ethclient.Client zetaClient *zetabridge.ZetaCoreBridge ticker *clienttypes.DynamicTicker diff --git a/zetaclient/tss/tss_signer.go b/zetaclient/tss/tss_signer.go index 63572f5019..4621268287 100644 --- a/zetaclient/tss/tss_signer.go +++ b/zetaclient/tss/tss_signer.go @@ -101,7 +101,7 @@ func NewTSS( newTss := TSS{ Server: server, Keys: make(map[string]*Key), - CurrentPubkey: appContext.ZetaCoreContext().CurrentTssPubkey, + CurrentPubkey: appContext.ZetaCoreContext().GetCurrentTssPubkey(), logger: log.With().Str("module", "tss_signer").Logger(), CoreBridge: bridge, BitcoinChainID: bitcoinChainID, diff --git a/zetaclient/zetabridge/tx.go b/zetaclient/zetabridge/tx.go index ca9b52a60e..c5018cacbe 100644 --- a/zetaclient/zetabridge/tx.go +++ b/zetaclient/zetabridge/tx.go @@ -151,8 +151,8 @@ func (b *ZetaCoreBridge) SetTSS(tssPubkey string, keyGenZetaHeight int64, status return "", fmt.Errorf("set tss failed | err %s", err.Error()) } -func (b *ZetaCoreBridge) UpdateAppContext(appContext *appcontext.AppContext) { - b.logger.Info().Msg("UpdateAppContext started") +func (b *ZetaCoreBridge) CoreContextUpdater(appContext *appcontext.AppContext) { + b.logger.Info().Msg("CoreContextUpdater started") ticker := time.NewTicker(time.Duration(appContext.Config().ConfigUpdateTicker) * time.Second) for { select { @@ -160,10 +160,10 @@ func (b *ZetaCoreBridge) UpdateAppContext(appContext *appcontext.AppContext) { b.logger.Debug().Msg("Running Updater") err := b.UpdateZetaCoreContext(appContext.ZetaCoreContext(), false) if err != nil { - b.logger.Err(err).Msg("UpdateAppContext failed to update config") + b.logger.Err(err).Msg("CoreContextUpdater failed to update config") } case <-b.stop: - b.logger.Info().Msg("UpdateAppContext stopped") + b.logger.Info().Msg("CoreContextUpdater stopped") return } } diff --git a/zetaclient/zetabridge/zetacore_bridge.go b/zetaclient/zetabridge/zetacore_bridge.go index 2f8d504135..4e9aab7516 100644 --- a/zetaclient/zetabridge/zetacore_bridge.go +++ b/zetaclient/zetabridge/zetacore_bridge.go @@ -190,7 +190,7 @@ func (b *ZetaCoreBridge) GetKeys() *keys.Keys { return b.keys } -func (b *ZetaCoreBridge) UpdateZetaCoreContext(coreContext *corecontext.ZeraCoreContext, init bool) error { +func (b *ZetaCoreBridge) UpdateZetaCoreContext(coreContext *corecontext.ZetaCoreContext, init bool) error { bn, err := b.GetZetaBlockHeight() if err != nil { return err @@ -244,7 +244,7 @@ func (b *ZetaCoreBridge) UpdateZetaCoreContext(coreContext *corecontext.ZeraCore if err != nil { b.logger.Info().Msg("Unable to fetch keygen from zetabridge") } - coreContext.UpdateCoreContext(keyGen, newChains, newEVMParams, newBTCParams, init, b.logger) + coreContext.Update(keyGen, newChains, newEVMParams, newBTCParams, init, b.logger) tss, err := b.GetCurrentTss() if err != nil {