Skip to content

Commit

Permalink
use explicit name ; use single word
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed May 10, 2024
1 parent f8e9ccb commit 973f378
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 143 deletions.
12 changes: 6 additions & 6 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ func GenerateTss(
}

newTss := mc.TSS{
Server: tss.Server,
Keys: tss.Keys,
CurrentPubkey: tss.CurrentPubkey,
Signers: tss.Signers,
CoreClient: nil,
Server: tss.Server,
Keys: tss.Keys,
CurrentPubkey: tss.CurrentPubkey,
Signers: tss.Signers,
ZetacoreClient: nil,
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
Expand Down Expand Up @@ -162,7 +162,7 @@ func keygenTss(keyGen observertypes.Keygen, tss *mc.TSS, keygenLogger zerolog.Lo
return err
}
index := fmt.Sprintf("keygen-%s-%d", digest, keyGen.BlockNumber)
zetaHash, err := tss.CoreClient.PostBlameData(&res.Blame, tss.CoreClient.Chain().ChainId, index)
zetaHash, err := tss.ZetacoreClient.PostBlameData(&res.Blame, tss.ZetacoreClient.Chain().ChainId, index)
if err != nil {
keygenLogger.Error().Err(err).Msg("error sending blame data to core")
return err
Expand Down
40 changes: 20 additions & 20 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,50 +93,50 @@ func start(_ *cobra.Command, _ []string) error {

// CreateZetaCoreClient: zetacore client is used for all communication to zetacore , which this client connects to.
// Zetacore accumulates votes , and provides a centralized source of truth for all clients
coreClient, err := CreateZetaCoreClient(cfg, telemetryServer, hotkeyPass)
zetacoreClient, err := CreateZetaCoreClient(cfg, telemetryServer, hotkeyPass)
if err != nil {
panic(err)
}
coreClient.WaitForCoreToCreateBlocks()
zetacoreClient.WaitForCoreToCreateBlocks()
startLogger.Info().Msgf("Zetacore client is ready")
coreClient.SetAccountNumber(authz.ZetaClientGranteeKey)
zetacoreClient.SetAccountNumber(authz.ZetaClientGranteeKey)

// cross-check chainid
res, err := coreClient.GetNodeInfo()
res, err := zetacoreClient.GetNodeInfo()
if err != nil {
panic(err)
}

if strings.Compare(res.GetDefaultNodeInfo().Network, cfg.ChainID) != 0 {
startLogger.Warn().Msgf("chain id mismatch, zeta-core chain id %s, zeta client chain id %s; reset zeta client chain id", res.GetDefaultNodeInfo().Network, cfg.ChainID)
cfg.ChainID = res.GetDefaultNodeInfo().Network
err := coreClient.UpdateChainID(cfg.ChainID)
err := zetacoreClient.UpdateChainID(cfg.ChainID)
if err != nil {
return err
}
}

// CreateAuthzSigner : which is used to sign all authz messages . All votes broadcast to zetacore are wrapped in authz exec .
// This is to ensure that the user does not need to keep their operator key online , and can use a cold key to sign votes
CreateAuthzSigner(coreClient.GetKeys().GetOperatorAddress().String(), coreClient.GetKeys().GetAddress())
CreateAuthzSigner(zetacoreClient.GetKeys().GetOperatorAddress().String(), zetacoreClient.GetKeys().GetAddress())
startLogger.Debug().Msgf("CreateAuthzSigner is ready")

// Initialize core parameters from zetacore
appContext := context.NewAppContext(context.NewZetaCoreContext(cfg), cfg)
err = coreClient.UpdateZetaCoreContext(appContext.ZetaCoreContext(), true, startLogger)
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 coreClient.CoreContextUpdater(appContext)
go zetacoreClient.CoreContextUpdater(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
// Each node processes a portion of the key stored in ~/.tss by default . Custom location can be specified in config file during init.
// After generating the key , the address is set on the zetacore
hotkeyPk, err := coreClient.GetKeys().GetPrivateKey(hotkeyPass)
hotkeyPk, err := zetacoreClient.GetKeys().GetPrivateKey(hotkeyPass)
if err != nil {
startLogger.Error().Err(err).Msg("zetacore client GetPrivateKey error")
}
Expand Down Expand Up @@ -173,13 +173,13 @@ func start(_ *cobra.Command, _ []string) error {
metrics.LastStartTime.SetToCurrentTime()

var tssHistoricalList []observerTypes.TSS
tssHistoricalList, err = coreClient.GetTssHistory()
tssHistoricalList, err = zetacoreClient.GetTssHistory()
if err != nil {
startLogger.Error().Err(err).Msg("GetTssHistory error")
}

telemetryServer.SetIPAddress(cfg.PublicIP)
tss, err := GenerateTss(appContext, masterLogger, coreClient, peers, priKey, telemetryServer, tssHistoricalList, tssKeyPass, hotkeyPass)
tss, err := GenerateTss(appContext, masterLogger, zetacoreClient, peers, priKey, telemetryServer, tssHistoricalList, tssKeyPass, hotkeyPass)
if err != nil {
return err
}
Expand All @@ -205,7 +205,7 @@ func start(_ *cobra.Command, _ []string) error {
// Update Current TSS value from zetacore, if TSS keygen is successful, the TSS address is set on zeta-core
// Returns err if the RPC call fails as zeta client needs the current TSS address to be set
// This is only needed in case of a new Keygen , as the TSS address is set on zetacore only after the keygen is successful i.e enough votes have been broadcast
currentTss, err := coreClient.GetCurrentTss()
currentTss, err := zetacoreClient.GetCurrentTss()
if err != nil {
startLogger.Error().Err(err).Msg("GetCurrentTSS error")
return err
Expand All @@ -221,14 +221,14 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String())
}

observerList, err := coreClient.GetObserverList()
observerList, err := zetacoreClient.GetObserverList()
if err != nil {
startLogger.Error().Err(err).Msg("GetObserverList error")
return err
}
isNodeActive := false
for _, observer := range observerList {
if observer == coreClient.GetKeys().GetOperatorAddress().String() {
if observer == zetacoreClient.GetKeys().GetOperatorAddress().String() {
isNodeActive = true
break
}
Expand All @@ -249,31 +249,31 @@ func start(_ *cobra.Command, _ []string) error {
dbpath := filepath.Join(userDir, ".zetaclient/chainobserver")

// Creates a map of all chain observers for each chain. Each chain observer is responsible for observing events on the chain and processing them.
observerMap, err := CreateChainObserverMap(appContext, coreClient, tss, dbpath, loggers, telemetryServer)
observerMap, err := CreateChainObserverMap(appContext, zetacoreClient, tss, dbpath, loggers, telemetryServer)
if err != nil {
startLogger.Err(err).Msg("CreateChainObserverMap")
return err
}

if !isNodeActive {
startLogger.Error().Msgf("Node %s is not an active observer external chain observers will not be started", coreClient.GetKeys().GetOperatorAddress().String())
startLogger.Error().Msgf("Node %s is not an active observer external chain observers will not be started", zetacoreClient.GetKeys().GetOperatorAddress().String())
} else {
startLogger.Debug().Msgf("Node %s is an active observer starting external chain observers", coreClient.GetKeys().GetOperatorAddress().String())
startLogger.Debug().Msgf("Node %s is an active observer starting external chain observers", zetacoreClient.GetKeys().GetOperatorAddress().String())
for _, observer := range observerMap {
observer.Start()
}
}

// Orchestrator wraps the zetacore client and adds the observers and signer maps to it . This is the high level object used for CCTX interactions
mo1 := orchestrator.NewOrchestrator(coreClient, signerMap, observerMap, masterLogger, telemetryServer)
mo1 := orchestrator.NewOrchestrator(zetacoreClient, signerMap, observerMap, masterLogger, telemetryServer)
mo1.MonitorCore(appContext)

// start zeta supply checker
// TODO: enable
// https://github.com/zeta-chain/node/issues/1354
// NOTE: this is disabled for now because we need to determine the frequency on how to handle invalid check
// The method uses GRPC query to the node we might need to improve for performance
//zetaSupplyChecker, err := mc.NewZetaSupplyChecker(cfg, coreClient, masterLogger)
//zetaSupplyChecker, err := mc.NewZetaSupplyChecker(cfg, zetacoreClient, masterLogger)
//if err != nil {
// startLogger.Err(err).Msg("NewZetaSupplyChecker")
//}
Expand All @@ -292,7 +292,7 @@ func start(_ *cobra.Command, _ []string) error {
for _, observer := range observerMap {
observer.Stop()
}
coreClient.Stop()
zetacoreClient.Stop()

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func CreateSignerMap(
// CreateChainObserverMap creates a map of ChainObservers for all chains in the config
func CreateChainObserverMap(
appContext *appcontext.AppContext,
coreClient *zetacore.Client,
zetacoreClient *zetacore.Client,
tss interfaces.TSSSigner,
dbpath string,
loggers clientcommon.ClientLogger,
Expand All @@ -121,7 +121,7 @@ func CreateChainObserverMap(
loggers.Std.Error().Msgf("ChainParam not found for chain %s", evmConfig.Chain.String())
continue
}
co, err := evmobserver.NewObserver(appContext, coreClient, tss, dbpath, loggers, evmConfig, ts)
co, err := evmobserver.NewObserver(appContext, zetacoreClient, tss, dbpath, loggers, evmConfig, ts)
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewObserver error for evm chain %s", evmConfig.Chain.String())
continue
Expand All @@ -131,7 +131,7 @@ func CreateChainObserverMap(
// BTC observer
btcChain, btcConfig, enabled := appContext.GetBTCChainAndConfig()
if enabled {
co, err := btcobserver.NewObserver(appContext, btcChain, coreClient, tss, dbpath, loggers, btcConfig, ts)
co, err := btcobserver.NewObserver(appContext, btcChain, zetacoreClient, tss, dbpath, loggers, btcConfig, ts)
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewObserver error for bitcoin chain %s", btcChain.String())

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetatool/filterdeposit/filterdeposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Deposit struct {
Amount uint64
}

// CheckForCCTX is querying zeta core for a cctx associated with a confirmed transaction hash. If the cctx is not found,
// CheckForCCTX is querying zetacore for a cctx associated with a confirmed transaction hash. If the cctx is not found,
// then the transaction hash is added to the list of missed inbound transactions.
func CheckForCCTX(list []Deposit, cfg *config.Config) ([]Deposit, error) {
var missedList []Deposit
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/bitcoin/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (

OutTxBytesMin = uint64(239) // 239vB == EstimateSegWitTxSize(2, 2, toP2WPKH)
OutTxBytesMax = uint64(1543) // 1543v == EstimateSegWitTxSize(21, 2, toP2TR)
OutTxBytesAvg = uint64(245) // 245vB is a suggested gas limit for zeta core
OutTxBytesAvg = uint64(245) // 245vB is a suggested gas limit for zetacore

DynamicDepositorFeeHeight = 834500 // DynamicDepositorFeeHeight contains the starting height (Bitcoin mainnet) from which dynamic depositor fee will take effect
)
Expand Down
20 changes: 10 additions & 10 deletions zetaclient/chains/bitcoin/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (ob *Observer) ObserveInTx() error {
for _, inTx := range inTxs {
msg := ob.GetInboundVoteMessageFromBtcEvent(inTx)
if msg != nil {
zetaHash, ballot, err := ob.coreClient.PostVoteInbound(zetacore.PostVoteInboundGasLimit, zetacore.PostVoteInboundExecutionGasLimit, msg)
zetaHash, ballot, err := ob.zetacoreClient.PostVoteInbound(zetacore.PostVoteInboundGasLimit, zetacore.PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.InTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zeta core for tx %s", inTx.TxHash)
ob.logger.InTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zetacore for tx %s", inTx.TxHash)
return err // we have to re-scan this block next time
} else if zetaHash != "" {
ob.logger.InTx.Info().Msgf("observeInTxBTC: PostVoteInbound zeta tx hash: %s inTx %s ballot %s fee %v",
Expand Down Expand Up @@ -180,9 +180,9 @@ func (ob *Observer) ObserveInTx() error {
for _, inTx := range inTxs {
msg := ob.GetInboundVoteMessageFromBtcEvent(inTx)
if msg != nil {
zetaHash, ballot, err := ob.coreClient.PostVoteInbound(zetacore.PostVoteInboundGasLimit, zetacore.PostVoteInboundExecutionGasLimit, msg)
zetaHash, ballot, err := ob.zetacoreClient.PostVoteInbound(zetacore.PostVoteInboundGasLimit, zetacore.PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.InTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zeta core for tx %s", inTx.TxHash)
ob.logger.InTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zetacore for tx %s", inTx.TxHash)
return err // we have to re-scan this block next time
} else if zetaHash != "" {
ob.logger.InTx.Info().Msgf("observeInTxBTC: PostVoteInbound zeta tx hash: %s inTx %s ballot %s fee %v",
Expand Down Expand Up @@ -232,7 +232,7 @@ func (ob *Observer) WatchIntxTracker() {

// ProcessInboundTrackers processes inbound trackers
func (ob *Observer) ProcessInboundTrackers() error {
trackers, err := ob.coreClient.GetInboundTrackersForChain(ob.chain.ChainId)
trackers, err := ob.zetacoreClient.GetInboundTrackersForChain(ob.chain.ChainId)
if err != nil {
return err
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func (ob *Observer) CheckReceiptForBtcTxHash(txHash string, vote bool) (string,
}

depositorFee := bitcoin.CalcDepositorFee(blockVb, ob.chain.ChainId, ob.netParams, ob.logger.InTx)
tss, err := ob.coreClient.GetBtcTssAddress(ob.chain.ChainId)
tss, err := ob.zetacoreClient.GetBtcTssAddress(ob.chain.ChainId)
if err != nil {
return "", err
}
Expand All @@ -300,9 +300,9 @@ func (ob *Observer) CheckReceiptForBtcTxHash(txHash string, vote bool) (string,
return msg.Digest(), nil
}

zetaHash, ballot, err := ob.coreClient.PostVoteInbound(zetacore.PostVoteInboundGasLimit, zetacore.PostVoteInboundExecutionGasLimit, msg)
zetaHash, ballot, err := ob.zetacoreClient.PostVoteInbound(zetacore.PostVoteInboundGasLimit, zetacore.PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.InTx.Error().Err(err).Msg("error posting to zeta core")
ob.logger.InTx.Error().Err(err).Msg("error posting to zetacore")
return "", err
} else if zetaHash != "" {
ob.logger.InTx.Info().Msgf("BTC deposit detected and reported: PostVoteInbound zeta tx hash: %s inTx %s ballot %s fee %v",
Expand Down Expand Up @@ -363,15 +363,15 @@ func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inTx *BTCInTxEvent) *cross
ob.chain.ChainId,
inTx.FromAddress,
inTx.FromAddress,
ob.coreClient.Chain().ChainId,
ob.zetacoreClient.Chain().ChainId,
cosmosmath.NewUintFromBigInt(amountInt),
message,
inTx.TxHash,
inTx.BlockNumber,
0,
coin.CoinType_Gas,
"",
ob.coreClient.GetKeys().GetOperatorAddress().String(),
ob.zetacoreClient.GetKeys().GetOperatorAddress().String(),
0,
)
}
Expand Down
16 changes: 8 additions & 8 deletions zetaclient/chains/bitcoin/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Observer struct {
chain chains.Chain
netParams *chaincfg.Params
rpcClient interfaces.BTCRPCClient
coreClient interfaces.ZetaCoreClient
zetacoreClient interfaces.ZetacoreClient
lastBlock int64
lastBlockScanned int64
pendingNonce uint64
Expand All @@ -137,7 +137,7 @@ type Observer struct {
func NewObserver(
appcontext *context.AppContext,
chain chains.Chain,
coreClient interfaces.ZetaCoreClient,
zetacoreClient interfaces.ZetacoreClient,
tss interfaces.TSSSigner,
dbpath string,
loggers clientcommon.ClientLogger,
Expand Down Expand Up @@ -170,7 +170,7 @@ func NewObserver(
Compliance: loggers.Compliance,
}

ob.coreClient = coreClient
ob.zetacoreClient = zetacoreClient
ob.Tss = tss
ob.coreContext = appcontext.ZetaCoreContext()
ob.includedTxHashes = make(map[string]bool)
Expand Down Expand Up @@ -224,7 +224,7 @@ func NewObserver(
func (ob *Observer) WithZetacoreClient(client *zetacore.Client) {
ob.Mu.Lock()
defer ob.Mu.Unlock()
ob.coreClient = client
ob.zetacoreClient = client
}

func (ob *Observer) WithLogger(logger zerolog.Logger) {
Expand Down Expand Up @@ -444,7 +444,7 @@ func (ob *Observer) PostGasPrice() error {
}

// #nosec G701 always in range
_, err = ob.coreClient.PostGasPrice(ob.chain, 1, "100", uint64(blockNumber))
_, err = ob.zetacoreClient.PostGasPrice(ob.chain, 1, "100", uint64(blockNumber))
if err != nil {
ob.logger.GasPrice.Err(err).Msg("PostGasPrice:")
return err
Expand All @@ -471,7 +471,7 @@ func (ob *Observer) PostGasPrice() error {
}

// #nosec G701 always positive
_, err = ob.coreClient.PostGasPrice(ob.chain, feeRatePerByte.Uint64(), "100", uint64(blockNumber))
_, err = ob.zetacoreClient.PostGasPrice(ob.chain, feeRatePerByte.Uint64(), "100", uint64(blockNumber))
if err != nil {
ob.logger.GasPrice.Err(err).Msg("PostGasPrice:")
return err
Expand Down Expand Up @@ -749,7 +749,7 @@ func (ob *Observer) isTssTransaction(txid string) bool {
func (ob *Observer) postBlockHeader(tip int64) error {
ob.logger.InTx.Info().Msgf("postBlockHeader: tip %d", tip)
bn := tip
res, err := ob.coreClient.GetBlockHeaderChainState(ob.chain.ChainId)
res, err := ob.zetacoreClient.GetBlockHeaderChainState(ob.chain.ChainId)
if err == nil && res.ChainState != nil && res.ChainState.EarliestHeight > 0 {
bn = res.ChainState.LatestHeight + 1
}
Expand All @@ -768,7 +768,7 @@ func (ob *Observer) postBlockHeader(tip int64) error {
return err
}
blockHash := res2.Header.BlockHash()
_, err = ob.coreClient.PostVoteBlockHeader(
_, err = ob.zetacoreClient.PostVoteBlockHeader(
ob.chain.ChainId,
blockHash[:],
res2.Block.Height,
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 @@ -72,13 +72,13 @@ func TestNewBitcoinObserver(t *testing.T) {
coreContext := context.NewZetaCoreContext(cfg)
appContext := context.NewAppContext(coreContext, cfg)
chain := chains.BtcMainnetChain
coreClient := mocks.NewMockZetaCoreClient()
zetacoreClient := mocks.NewMockZetaCoreClient()
tss := mocks.NewMockTSS(chains.BtcTestNetChain, sample.EthAddress().String(), "")
loggers := clientcommon.ClientLogger{}
btcCfg := cfg.BitcoinConfig
ts := metrics.NewTelemetryServer()

client, err := NewObserver(appContext, chain, coreClient, tss, tempSQLiteDbPath, loggers, btcCfg, ts)
client, err := NewObserver(appContext, chain, zetacoreClient, tss, tempSQLiteDbPath, loggers, btcCfg, ts)
require.ErrorContains(t, err, "btc chains params not initialized")
require.Nil(t, client)
})
Expand Down
Loading

0 comments on commit 973f378

Please sign in to comment.