Skip to content

Commit

Permalink
dropped EVM Client and BTC Client; Used Observer instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed May 10, 2024
1 parent ea72fde commit 6a2a68a
Show file tree
Hide file tree
Showing 32 changed files with 416 additions and 417 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* [2097](https://github.com/zeta-chain/node/pull/2097) - refactor lightclient verification flags to account for individual chains
* [2071](https://github.com/zeta-chain/node/pull/2071) - Modify chains struct to add all chain related information
* [2124](https://github.com/zeta-chain/node/pull/2124) - removed unused variables and method
* [2150](https://github.com/zeta-chain/node/pull/2150) - created `chains` `zetacore` `orchestragor` packages in zetaclient and reorganized source files accordingly.
* [2150](https://github.com/zeta-chain/node/pull/2150) - created `chains` `zetacore` `orchestrator` packages in zetaclient and reorganized source files accordingly.

### Tests

Expand Down
34 changes: 17 additions & 17 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func DebugCmd() *cobra.Command {

if chains.IsEVMChain(chain.ChainId) {

ob := evm.Client{
evmObserver := evm.Observer{
Mu: &sync.Mutex{},
}
ob.WithZetacoreClient(client)
ob.WithLogger(chainLogger)
evmObserver.WithZetacoreClient(client)
evmObserver.WithLogger(chainLogger)
var ethRPC *ethrpc.EthRPC
var client *ethclient.Client
coinType := coin.CoinType_Cmd
Expand All @@ -112,13 +112,13 @@ func DebugCmd() *cobra.Command {
if err != nil {
return err
}
ob.WithEvmClient(client)
ob.WithEvmJSONRPC(ethRPC)
ob.WithChain(*chains.GetChainFromChainID(chainID))
evmObserver.WithEvmClient(client)
evmObserver.WithEvmJSONRPC(ethRPC)
evmObserver.WithChain(*chains.GetChainFromChainID(chainID))
}
}
hash := ethcommon.HexToHash(txHash)
tx, isPending, err := ob.TransactionByHash(txHash)
tx, isPending, err := evmObserver.TransactionByHash(txHash)
if err != nil {
return fmt.Errorf("tx not found on chain %s , %d", err.Error(), chain.ChainId)
}
Expand All @@ -132,7 +132,7 @@ func DebugCmd() *cobra.Command {

for _, chainParams := range chainParams {
if chainParams.ChainId == chainID {
ob.SetChainParams(observertypes.ChainParams{
evmObserver.SetChainParams(observertypes.ChainParams{
ChainId: chainID,
ConnectorContractAddress: chainParams.ConnectorContractAddress,
ZetaTokenContractAddress: chainParams.ZetaTokenContractAddress,
Expand All @@ -155,19 +155,19 @@ func DebugCmd() *cobra.Command {

switch coinType {
case coin.CoinType_Zeta:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenZeta(tx, receipt, false)
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenZeta(tx, receipt, false)
if err != nil {
return err
}

case coin.CoinType_ERC20:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenERC20(tx, receipt, false)
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenERC20(tx, receipt, false)
if err != nil {
return err
}

case coin.CoinType_Gas:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenGas(tx, receipt, false)
ballotIdentifier, err = evmObserver.CheckAndVoteInboundTokenGas(tx, receipt, false)
if err != nil {
return err
}
Expand All @@ -176,12 +176,12 @@ func DebugCmd() *cobra.Command {
}
fmt.Println("CoinType : ", coinType)
} else if chains.IsBitcoinChain(chain.ChainId) {
obBtc := bitcoin.Client{
btcObserver := bitcoin.Observer{
Mu: &sync.Mutex{},
}
obBtc.WithZetaCoreClient(client)
obBtc.WithLogger(chainLogger)
obBtc.WithChain(*chains.GetChainFromChainID(chainID))
btcObserver.WithZetacoreClient(client)
btcObserver.WithLogger(chainLogger)
btcObserver.WithChain(*chains.GetChainFromChainID(chainID))
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Expand All @@ -195,8 +195,8 @@ func DebugCmd() *cobra.Command {
if err != nil {
return err
}
obBtc.WithBtcClient(btcClient)
ballotIdentifier, err = obBtc.CheckReceiptForBtcTxHash(txHash, false)
btcObserver.WithBtcClient(btcClient)
ballotIdentifier, err = btcObserver.CheckReceiptForBtcTxHash(txHash, false)
if err != nil {
return err
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,24 @@ func start(_ *cobra.Command, _ []string) error {
}
dbpath := filepath.Join(userDir, ".zetaclient/chainobserver")

// 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, coreClient, tss, dbpath, loggers, telemetryServer)
// 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)
if err != nil {
startLogger.Err(err).Msg("CreateChainClientMap")
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())
} else {
startLogger.Debug().Msgf("Node %s is an active observer starting external chain observers", coreClient.GetKeys().GetOperatorAddress().String())
for _, v := range chainClientMap {
v.Start()
for _, observer := range observerMap {
observer.Start()
}
}

// CreateCoreObserver : Core observer wraps the zetacore client and adds the client and signer maps to it . This is the high level object used for CCTX interactions
mo1 := orchestrator.NewOrchestrator(coreClient, signerMap, chainClientMap, masterLogger, telemetryServer)
// 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.MonitorCore(appContext)

// start zeta supply checker
Expand All @@ -288,9 +288,9 @@ func start(_ *cobra.Command, _ []string) error {
sig := <-ch
startLogger.Info().Msgf("stop signal received: %s", sig)

// stop zetacore observer
for _, client := range chainClientMap {
client.Stop()
// stop chain observers
for _, observer := range observerMap {
observer.Stop()
}
coreClient.Stop()

Expand Down
25 changes: 13 additions & 12 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,17 @@ func CreateSignerMap(
return signerMap, nil
}

func CreateChainClientMap(
// CreateChainObserverMap creates a map of ChainObservers for all chains in the config
func CreateChainObserverMap(
appContext *appcontext.AppContext,
coreClient *zetacore.Client,
tss interfaces.TSSSigner,
dbpath string,
loggers clientcommon.ClientLogger,
ts *metrics.TelemetryServer,
) (map[int64]interfaces.ChainClient, error) {
clientMap := make(map[int64]interfaces.ChainClient)
// EVM clients
) (map[int64]interfaces.ChainObserver, error) {
observerMap := make(map[int64]interfaces.ChainObserver)
// EVM observers
for _, evmConfig := range appContext.Config().GetAllEVMConfigs() {
if evmConfig.Chain.IsZetaChain() {
continue
Expand All @@ -118,24 +119,24 @@ func CreateChainClientMap(
loggers.Std.Error().Msgf("ChainParam not found for chain %s", evmConfig.Chain.String())
continue
}
co, err := evm.NewClient(appContext, coreClient, tss, dbpath, loggers, evmConfig, ts)
co, err := evm.NewObserver(appContext, coreClient, tss, dbpath, loggers, evmConfig, ts)
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewEVMChainClient error for chain %s", evmConfig.Chain.String())
loggers.Std.Error().Err(err).Msgf("NewObserver error for evm chain %s", evmConfig.Chain.String())
continue
}
clientMap[evmConfig.Chain.ChainId] = co
observerMap[evmConfig.Chain.ChainId] = co
}
// BTC client
// BTC observer
btcChain, btcConfig, enabled := appContext.GetBTCChainAndConfig()
if enabled {
co, err := bitcoin.NewClient(appContext, btcChain, coreClient, tss, dbpath, loggers, btcConfig, ts)
co, err := bitcoin.NewObserver(appContext, btcChain, coreClient, tss, dbpath, loggers, btcConfig, ts)
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewBitcoinClient error for chain %s", btcChain.String())
loggers.Std.Error().Err(err).Msgf("NewObserver error for bitcoin chain %s", btcChain.String())

} else {
clientMap[btcChain.ChainId] = co
observerMap[btcChain.ChainId] = co
}
}

return clientMap, nil
return observerMap, nil
}
Loading

0 comments on commit 6a2a68a

Please sign in to comment.