Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: zetaclient re-organization #1640

Merged
merged 18 commits into from
Feb 12, 2024
Merged
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
### Refactoring

* [1628](https://github.com/zeta-chain/node/pull/1628) optimize return and simplify code
* [1640](https://github.com/zeta-chain/node/pull/1640) zetaclient re-organization
kevinssgh marked this conversation as resolved.
Show resolved Hide resolved

### Refactoring
* [1619](https://github.com/zeta-chain/node/pull/1619) - Add evm fee calculation to tss migration of evm chains
Expand Down
18 changes: 12 additions & 6 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"strings"
"sync"

"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
"github.com/zeta-chain/zetacore/zetaclient/keys"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
"github.com/zeta-chain/zetacore/zetaclient/zetabridge"

"github.com/zeta-chain/zetacore/zetaclient/evm"

kevinssgh marked this conversation as resolved.
Show resolved Hide resolved
"github.com/btcsuite/btcd/rpcclient"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -17,7 +24,6 @@ import (
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/testutil/sample"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
)

Expand Down Expand Up @@ -54,16 +60,16 @@ func DebugCmd() *cobra.Command {
var ballotIdentifier string
chainLogger := zerolog.New(io.Discard).Level(zerolog.Disabled)

telemetryServer := zetaclient.NewTelemetryServer()
telemetryServer := metrics.NewTelemetryServer()
go func() {
err := telemetryServer.Start()
if err != nil {
panic("telemetryServer error")
}
}()

bridge, err := zetaclient.NewZetaCoreBridge(
&zetaclient.Keys{OperatorAddress: sdk.MustAccAddressFromBech32(sample.AccAddress())},
bridge, err := zetabridge.NewZetaCoreBridge(
&keys.Keys{OperatorAddress: sdk.MustAccAddressFromBech32(sample.AccAddress())},
debugArgs.zetaNode,
"",
debugArgs.zetaChainID,
Expand All @@ -89,7 +95,7 @@ func DebugCmd() *cobra.Command {

if common.IsEVMChain(chain.ChainId) {

ob := zetaclient.EVMChainClient{
ob := evm.ChainClient{
Mu: &sync.Mutex{},
}
ob.WithZetaClient(bridge)
Expand Down Expand Up @@ -159,7 +165,7 @@ func DebugCmd() *cobra.Command {
}
fmt.Println("CoinType : ", coinType)
} else if common.IsBitcoinChain(chain.ChainId) {
obBtc := zetaclient.BitcoinChainClient{
obBtc := bitcoin.ChainClient{
Mu: &sync.Mutex{},
}
obBtc.WithZetaClient(bridge)
Expand Down
10 changes: 6 additions & 4 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"fmt"
"time"

mc "github.com/zeta-chain/zetacore/zetaclient/tss"
"github.com/zeta-chain/zetacore/zetaclient/zetabridge"

"github.com/rs/zerolog"
"github.com/tendermint/crypto/sha3"
"github.com/tendermint/tendermint/crypto/secp256k1"
Expand All @@ -15,17 +18,16 @@ import (
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
mc "github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
)

func GenerateTss(logger zerolog.Logger,
cfg *config.Config,
zetaBridge *mc.ZetaCoreBridge,
zetaBridge *zetabridge.ZetaCoreBridge,
peers p2p.AddrList,
priKey secp256k1.PrivKey,
ts *mc.TelemetryServer,
ts *metrics.TelemetryServer,
tssHistoricalList []observertypes.TSS,
metrics *metrics.Metrics) (*mc.TSS, error) {
keygenLogger := logger.With().Str("module", "keygen").Logger()
Expand Down Expand Up @@ -59,7 +61,7 @@ func GenerateTss(logger zerolog.Logger,
// Set TSS block to 0 using genesis file to disable this feature
// Note : The TSS generation is done through the "hotkey" or "Zeta-clientGrantee" This key needs to be present on the machine for the TSS signing to happen .
// "ZetaClientGrantee" key is different from the "operator" key .The "Operator" key gives all zetaclient related permissions such as TSS generation ,reporting and signing, INBOUND and OUTBOUND vote signing, to the "ZetaClientGrantee" key.
// The votes to signify a successful TSS generation (Or unsuccessful) is signed by the operator key and broadcast to zetacore by the zetcalientGrantee key on behalf of the operator .
// The votes to signify a successful TSS generation (Or unsuccessful) is signed by the operator key and broadcast to zetabridge by the zetcalientGrantee key on behalf of the operator .
ticker := time.NewTicker(time.Second * 1)
triedKeygenAtBlock := false
lastBlock := int64(0)
Expand Down
7 changes: 4 additions & 3 deletions cmd/zetaclientd/p2p_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sync"
"time"

"github.com/zeta-chain/zetacore/zetaclient/metrics"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
libp2p "github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
Expand All @@ -21,7 +23,6 @@ import (
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common/cosmos"
mc "github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
)

Expand All @@ -38,7 +39,7 @@ func RunDiagnostics(startLogger zerolog.Logger, peers p2p.AddrList, bridgePk cry
}
startLogger.Warn().Msgf("my pubkey %s", pubkeyBech32)

var s *mc.TelemetryServer
var s *metrics.TelemetryServer
if len(peers) == 0 {
startLogger.Warn().Msg("No seed peer specified; assuming I'm the host")

Expand Down Expand Up @@ -83,7 +84,7 @@ func RunDiagnostics(startLogger zerolog.Logger, peers p2p.AddrList, bridgePk cry
}
startLogger.Info().Msgf("host created: ID %s", host.ID().String())
if len(peers) == 0 {
s = mc.NewTelemetryServer()
s = metrics.NewTelemetryServer()
s.SetP2PID(host.ID().String())
go func() {
startLogger.Info().Msg("Starting TSS HTTP Server...")
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func start(_ *cobra.Command, _ []string) error {
waitForZetaCore(cfg, startLogger)
startLogger.Info().Msgf("ZetaCore is ready , Trying to connect to %s", cfg.Peer)

telemetryServer := mc.NewTelemetryServer()
telemetryServer := metrics2.NewTelemetryServer()
go func() {
err := telemetryServer.Start()
if err != nil {
Expand Down
44 changes: 25 additions & 19 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ import (
"github.com/rs/zerolog"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/authz"
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
"github.com/zeta-chain/zetacore/zetaclient/config"
"github.com/zeta-chain/zetacore/zetaclient/interfaces"
"github.com/zeta-chain/zetacore/zetaclient/keys"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
"github.com/zeta-chain/zetacore/zetaclient/zetabridge"

"github.com/zeta-chain/zetacore/zetaclient/evm"
)

func CreateAuthzSigner(granter string, grantee sdk.AccAddress) {
zetaclient.SetupAuthZSignerList(granter, grantee)
authz.SetupAuthZSignerList(granter, grantee)
}

func CreateZetaBridge(cfg *config.Config, telemetry *zetaclient.TelemetryServer) (*zetaclient.ZetaCoreBridge, error) {
func CreateZetaBridge(cfg *config.Config, telemetry *metrics.TelemetryServer) (*zetabridge.ZetaCoreBridge, error) {
hotKey := cfg.AuthzHotkey
if cfg.HsmMode {
hotKey = cfg.HsmHotKey
}

chainIP := cfg.ZetaCoreURL

kb, _, err := zetaclient.GetKeyringKeybase(cfg)
kb, _, err := keys.GetKeyringKeybase(cfg)
if err != nil {
return nil, err
}
Expand All @@ -33,9 +39,9 @@ func CreateZetaBridge(cfg *config.Config, telemetry *zetaclient.TelemetryServer)
return nil, err
}

k := zetaclient.NewKeysWithKeybase(kb, granterAddreess, cfg.AuthzHotkey)
k := keys.NewKeysWithKeybase(kb, granterAddreess, cfg.AuthzHotkey)

bridge, err := zetaclient.NewZetaCoreBridge(k, chainIP, hotKey, cfg.ChainID, cfg.HsmMode, telemetry)
bridge, err := zetabridge.NewZetaCoreBridge(k, chainIP, hotKey, cfg.ChainID, cfg.HsmMode, telemetry)
if err != nil {
return nil, err
}
Expand All @@ -44,20 +50,20 @@ func CreateZetaBridge(cfg *config.Config, telemetry *zetaclient.TelemetryServer)
}

func CreateSignerMap(
tss zetaclient.TSSSigner,
tss interfaces.TSSSigner,
logger zerolog.Logger,
cfg *config.Config,
ts *zetaclient.TelemetryServer,
) (map[common.Chain]zetaclient.ChainSigner, error) {
signerMap := make(map[common.Chain]zetaclient.ChainSigner)
ts *metrics.TelemetryServer,
) (map[common.Chain]interfaces.ChainSigner, error) {
signerMap := make(map[common.Chain]interfaces.ChainSigner)
// EVM signers
for _, evmConfig := range cfg.GetAllEVMConfigs() {
if evmConfig.Chain.IsZetaChain() {
continue
}
mpiAddress := ethcommon.HexToAddress(evmConfig.ChainParams.ConnectorContractAddress)
erc20CustodyAddress := ethcommon.HexToAddress(evmConfig.ChainParams.Erc20CustodyContractAddress)
signer, err := zetaclient.NewEVMSigner(evmConfig.Chain, evmConfig.Endpoint, tss, config.GetConnectorABI(), config.GetERC20CustodyABI(), mpiAddress, erc20CustodyAddress, logger, ts)
signer, err := evm.NewEVMSigner(evmConfig.Chain, evmConfig.Endpoint, tss, config.GetConnectorABI(), config.GetERC20CustodyABI(), mpiAddress, erc20CustodyAddress, logger, ts)
if err != nil {
logger.Error().Err(err).Msgf("NewEVMSigner error for chain %s", evmConfig.Chain.String())
continue
Expand All @@ -67,7 +73,7 @@ func CreateSignerMap(
// BTC signer
btcChain, btcConfig, enabled := cfg.GetBTCConfig()
if enabled {
signer, err := zetaclient.NewBTCSigner(btcConfig, tss, logger, ts)
signer, err := bitcoin.NewBTCSigner(btcConfig, tss, logger, ts)
if err != nil {
logger.Error().Err(err).Msgf("NewBTCSigner error for chain %s", btcChain.String())
} else {
Expand All @@ -79,21 +85,21 @@ func CreateSignerMap(
}

func CreateChainClientMap(
bridge *zetaclient.ZetaCoreBridge,
tss zetaclient.TSSSigner,
bridge *zetabridge.ZetaCoreBridge,
tss interfaces.TSSSigner,
dbpath string,
metrics *metrics.Metrics,
logger zerolog.Logger,
cfg *config.Config,
ts *zetaclient.TelemetryServer,
) (map[common.Chain]zetaclient.ChainClient, error) {
clientMap := make(map[common.Chain]zetaclient.ChainClient)
ts *metrics.TelemetryServer,
) (map[common.Chain]interfaces.ChainClient, error) {
clientMap := make(map[common.Chain]interfaces.ChainClient)
// EVM clients
for _, evmConfig := range cfg.GetAllEVMConfigs() {
if evmConfig.Chain.IsZetaChain() {
continue
}
co, err := zetaclient.NewEVMChainClient(bridge, tss, dbpath, metrics, logger, cfg, *evmConfig, ts)
co, err := evm.NewEVMChainClient(bridge, tss, dbpath, metrics, logger, cfg, *evmConfig, ts)
if err != nil {
logger.Error().Err(err).Msgf("NewEVMChainClient error for chain %s", evmConfig.Chain.String())
continue
Expand All @@ -103,7 +109,7 @@ func CreateChainClientMap(
// BTC client
btcChain, btcConfig, enabled := cfg.GetBTCConfig()
if enabled {
co, err := zetaclient.NewBitcoinClient(btcChain, bridge, tss, dbpath, metrics, logger, btcConfig, ts)
co, err := bitcoin.NewBitcoinClient(btcChain, bridge, tss, dbpath, metrics, logger, btcConfig, ts)
if err != nil {
logger.Error().Err(err).Msgf("NewBitcoinClient error for chain %s", btcChain.String())

Expand Down
13 changes: 7 additions & 6 deletions contrib/localnet/orchestrator/smoketest/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"math/big"
"time"

"github.com/zeta-chain/zetacore/common/bitcoin"

"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"

Expand All @@ -19,9 +21,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/rs/zerolog/log"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/common/bitcoin"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient"
zc_btc "github.com/zeta-chain/zetacore/zetaclient/bitcoin"
kevinssgh marked this conversation as resolved.
Show resolved Hide resolved
)

var blockHeaderBTCTimeout = 5 * time.Minute
Expand Down Expand Up @@ -62,12 +63,12 @@ func (sm *SmokeTestRunner) DepositBTC(testHeader bool) {
sm.Logger.Info("Now sending two txs to TSS address...")

// send two transactions to the TSS address
amount1 := 1.1 + zetaclient.BtcDepositorFeeMin
amount1 := 1.1 + zc_btc.BtcDepositorFeeMin
txHash1, err := sm.SendToTSSFromDeployerToDeposit(sm.BTCTSSAddress, amount1, utxos[:2], btc, sm.BTCDeployerAddress)
if err != nil {
panic(err)
}
amount2 := 0.05 + zetaclient.BtcDepositorFeeMin
amount2 := 0.05 + zc_btc.BtcDepositorFeeMin
txHash2, err := sm.SendToTSSFromDeployerToDeposit(sm.BTCTSSAddress, amount2, utxos[2:4], btc, sm.BTCDeployerAddress)
if err != nil {
panic(err)
Expand All @@ -80,7 +81,7 @@ func (sm *SmokeTestRunner) DepositBTC(testHeader bool) {
0.11,
utxos[4:5],
btc,
[]byte(zetaclient.DonationMessage),
[]byte(zc_btc.DonationMessage),
sm.BTCDeployerAddress,
)
if err != nil {
Expand Down Expand Up @@ -226,7 +227,7 @@ func (sm *SmokeTestRunner) SendToTSSFromDeployerWithMemo(
panic(err)
}

events := zetaclient.FilterAndParseIncomingTx(
events := zc_btc.FilterAndParseIncomingTx(
[]btcjson.TxRawResult{*rawtx},
0,
sm.BTCTSSAddress.EncodeAddress(),
Expand Down
4 changes: 2 additions & 2 deletions contrib/localnet/orchestrator/smoketest/runner/setup_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"time"

"github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/evm"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (sm *SmokeTestRunner) SetupEVM(contractsDeployed bool) {

// donate to the TSS address to avoid account errors because deploying gas token ZRC20 will automatically mint
// gas token on ZetaChain to initialize the pool
txDonation, err := sm.SendEther(sm.TSSAddress, big.NewInt(101000000000000000), []byte(zetaclient.DonationMessage))
txDonation, err := sm.SendEther(sm.TSSAddress, big.NewInt(101000000000000000), []byte(evm.DonationMessage))
if err != nil {
panic(err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package zetaclient
package authz

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/common"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

type AuthZSigner struct {
type Signer struct {
KeyType common.KeyType
GranterAddress string
GranteeAddress sdk.AccAddress
}

func (a AuthZSigner) String() string {
func (a Signer) String() string {
return a.KeyType.String() + " " + a.GranterAddress + " " + a.GranteeAddress.String()
}

var signers map[string]AuthZSigner
var signers map[string]Signer

func init() {
signersList := make(map[string]AuthZSigner)
signersList := make(map[string]Signer)
for _, tx := range crosschaintypes.GetAllAuthzZetaclientTxTypes() {
signersList[tx] = AuthZSigner{KeyType: common.ZetaClientGranteeKey}
signersList[tx] = Signer{KeyType: common.ZetaClientGranteeKey}
}
signers = signersList
}
Expand All @@ -34,6 +34,6 @@ func SetupAuthZSignerList(granter string, grantee sdk.AccAddress) {
}
}

func GetSigner(msgURL string) AuthZSigner {
func GetSigner(msgURL string) Signer {
return signers[msgURL]
}
Loading
Loading