Skip to content

Commit

Permalink
using single word for ZetaCoreContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed May 16, 2024
1 parent 169d3ee commit 3fe8e0f
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 101 deletions.
2 changes: 1 addition & 1 deletion cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ 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"
"github.com/zeta-chain/go-tss/keygen"
"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,
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/bitcoin/observer/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/bitcoin/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/bitcoin/observer/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/bitcoin/observer/outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

func MockBTCObserverMainnet() *Observer {
cfg := config.NewConfig()
coreContext := context.NewZetaCoreContext(cfg)
coreContext := context.NewZetacoreContext(cfg)

return &Observer{
chain: chains.BtcMainnetChain,
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/bitcoin/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ type Signer struct {
logger zerolog.Logger
loggerCompliance zerolog.Logger
ts *metrics.TelemetryServer
coreContext *context.ZetaCoreContext
coreContext *context.ZetacoreContext
}

func NewSigner(
cfg config.BTCConfig,
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,
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/bitcoin/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Check warning on line 115 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L115

Added line #L115 was not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/observer/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getNewEvmSigner() (*Signer, error) {
config.GetERC20CustodyABI(),
mpiAddress,
erc20CustodyAddress,
context.NewZetaCoreContext(cfg),
context.NewZetacoreContext(cfg),
logger,
ts)
}
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions zetaclient/context/app_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -26,14 +26,14 @@ func (a AppContext) Config() config.Config {
return a.config
}

func (a AppContext) ZetaCoreContext() *ZetaCoreContext {
func (a AppContext) ZetacoreContext() *ZetacoreContext {

Check warning on line 29 in zetaclient/context/app_context.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/context/app_context.go#L29

Added line #L29 was not covered by tests
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()

Check warning on line 36 in zetaclient/context/app_context.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/context/app_context.go#L36

Added line #L36 was not covered by tests

if !configEnabled || !paramsEnabled {
return chains.Chain{}, config.BTCConfig{}, false
Expand Down
Loading

0 comments on commit 3fe8e0f

Please sign in to comment.