Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Feb 21, 2024
1 parent e977ee9 commit ddea482
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 32 deletions.
8 changes: 6 additions & 2 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Check failure on line 135 in cmd/zetaclientd/debug.go

View workflow job for this annotation

GitHub Actions / lint

printf: fmt.Errorf format %s has arg chainID of wrong type int64 (govet)

Check failure on line 135 in cmd/zetaclientd/debug.go

View workflow job for this annotation

GitHub Actions / build-and-test

fmt.Errorf format %s has arg chainID of wrong type int64

Check failure on line 135 in cmd/zetaclientd/debug.go

View workflow job for this annotation

GitHub Actions / build-and-test

fmt.Errorf format %s has arg chainID of wrong type int64
}
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) {
Expand Down
14 changes: 7 additions & 7 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ 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")
return err
}
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
Expand Down Expand Up @@ -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
Expand All @@ -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())
}

Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions zetaclient/app_context/app_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion zetaclient/bitcoin/bitcoin_client_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions zetaclient/core_context/zeta_core_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,16 +19,16 @@ 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),
BitcoinChainParams: &observertypes.ChainParams{},
}
}

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))
Expand All @@ -41,22 +41,28 @@ 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))
copy(copiedChains, c.ChainsEnabled)
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()

Expand All @@ -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()

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/evm/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion zetaclient/supplychecker/zeta_supply_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/tss/tss_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions zetaclient/zetabridge/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,19 @@ 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 {
case <-ticker.C:
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
}
}
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/zetabridge/zetacore_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ddea482

Please sign in to comment.