Skip to content

Commit

Permalink
Merge branch 'develop' into fix-signet-database-name
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie authored Nov 27, 2024
2 parents 75c2857 + 08ff881 commit 3647b5d
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ default_account:
bech32_address: "zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd"
evm_address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC"
private_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263"
solana_address: "37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ"
solana_private_key: "4yqSQxDeTBvn86BuxcN5jmZb2gaobFXrBqu8kiE9rZxNkVMe3LfXmFigRsU4sRp7vk4vVP1ZCFiejDKiXBNWvs2C"
additional_accounts:
user_erc20:
bech32_address: "zeta1datate7xmwm4uk032f9rmcu0cwy7ch7kg6y6zv"
Expand Down Expand Up @@ -106,7 +108,7 @@ contracts:
zevm:
system_contract: "0x91d18e54DAf4F677cB28167158d6dd21F6aB3921"
eth_zrc20: "0x13A0c5930C028511Dc02665E7285134B6d11A5f4"
erc20_zrc20: "0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb"
erc20_zrc20: "0x0cbe0dF132a6c6B4a2974Fa1b7Fb953CF0Cc798a"
btc_zrc20: "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891"
uniswap_factory: "0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c"
uniswap_router: "0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe"
Expand All @@ -115,6 +117,8 @@ contracts:
test_dapp: "0xA8D5060feb6B456e886F023709A2795373691E63"
gateway: "0xa825eAa55b497AF892faca73a3797046C10B7c23"
test_dapp_v2: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed"
sol_zrc20: "0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb"
spl_zrc20: "0x7c8dDa80bbBE1254a7aACf3219EBe1481c6E01d7"
evm:
zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9"
connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca"
Expand Down
54 changes: 52 additions & 2 deletions e2e/runner/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/btcsuite/btcd/btcutil"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/pkg/errors"
"github.com/zeta-chain/protocol-contracts/v2/pkg/zrc20.sol"
)
Expand All @@ -25,6 +27,8 @@ type AccountBalances struct {
EvmZETA *big.Int
EvmERC20 *big.Int
BtcBTC string
SolSOL *big.Int
SolSPL *big.Int
}

// AccountBalancesDiff is a struct that contains the difference in the balances of the accounts used in the E2E test
Expand Down Expand Up @@ -66,7 +70,7 @@ func (r *E2ERunner) GetAccountBalances(skipBTC bool) (AccountBalances, error) {
}
zetaSol, err := r.getZRC20BalanceSafe(r.SOLZRC20)
if err != nil {
r.Logger.Error("get SOL balance: %v", err)
return AccountBalances{}, err
}

// evm
Expand All @@ -91,6 +95,44 @@ func (r *E2ERunner) GetAccountBalances(skipBTC bool) (AccountBalances, error) {
}
}

// solana
var solSOL *big.Int
var solSPL *big.Int
if r.Account.SolanaAddress != "" && r.Account.SolanaPrivateKey != "" {
solanaAddr := solana.MustPublicKeyFromBase58(r.Account.SolanaAddress.String())
privateKey := solana.MustPrivateKeyFromBase58(r.Account.SolanaPrivateKey.String())
solSOLBalance, err := r.SolanaClient.GetBalance(
r.Ctx,
solanaAddr,
rpc.CommitmentFinalized,
)
if err != nil {
return AccountBalances{}, err
}

// #nosec G115 always in range
solSOL = big.NewInt(int64(solSOLBalance.Value))

if r.SPLAddr != (solana.PublicKey{}) {
ata := r.ResolveSolanaATA(
privateKey,
solanaAddr,
r.SPLAddr,
)
splBalance, err := r.SolanaClient.GetTokenAccountBalance(r.Ctx, ata, rpc.CommitmentFinalized)
if err != nil {
return AccountBalances{}, err
}

solSPLParsed, ok := new(big.Int).SetString(splBalance.Value.Amount, 10)
if !ok {
return AccountBalances{}, errors.New("can't parse spl balance")
}

solSPL = solSPLParsed
}
}

return AccountBalances{
ZetaETH: zetaEth,
ZetaZETA: zetaZeta,
Expand All @@ -102,6 +144,8 @@ func (r *E2ERunner) GetAccountBalances(skipBTC bool) (AccountBalances, error) {
EvmZETA: evmZeta,
EvmERC20: evmErc20,
BtcBTC: BtcBTC,
SolSOL: solSOL,
SolSPL: solSPL,
}, nil
}

Expand Down Expand Up @@ -145,6 +189,7 @@ func (r *E2ERunner) PrintAccountBalances(balances AccountBalances) {
r.Logger.Print("* ETH balance: %s", balances.ZetaETH.String())
r.Logger.Print("* ERC20 balance: %s", balances.ZetaERC20.String())
r.Logger.Print("* BTC balance: %s", balances.ZetaBTC.String())
r.Logger.Print("* SOL balance: %s", balances.ZetaSOL.String())

// evm
r.Logger.Print("EVM:")
Expand All @@ -158,7 +203,12 @@ func (r *E2ERunner) PrintAccountBalances(balances AccountBalances) {

// solana
r.Logger.Print("Solana:")
r.Logger.Print("* SOL balance: %s", balances.ZetaSOL.String())
if balances.SolSOL != nil {
r.Logger.Print("* SOL balance: %s", balances.SolSOL.String())
}
if balances.SolSPL != nil {
r.Logger.Print("* SPL balance: %s", balances.SolSPL.String())
}
}

// PrintTotalDiff shows the difference in the account balances of the accounts used in the e2e test from two balances structs
Expand Down
3 changes: 2 additions & 1 deletion zetaclient/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type TONConfig struct {
// ComplianceConfig is the config for compliance
type ComplianceConfig struct {
LogPath string `json:"LogPath"`
RestrictedAddresses []string `json:"RestrictedAddresses"`
RestrictedAddresses []string `json:"RestrictedAddresses" mask:"zero"`
}

// Config is the config for ZetaClient
Expand Down Expand Up @@ -167,6 +167,7 @@ func (c Config) StringMasked() string {
// create a masker
masker := mask.NewMasker()
masker.RegisterMaskStringFunc(mask.MaskTypeFilled, masker.MaskFilledString)
masker.RegisterMaskAnyFunc(mask.MaskTypeFilled, masker.MaskZero)

// mask the config
masked, err := masker.Mask(c)
Expand Down
29 changes: 28 additions & 1 deletion zetaclient/metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type TelemetryServer struct {
status types.Status
ipAddress string
HotKeyBurnRate *BurnRate
knownPeers []peer.AddrInfo
connectedPeers []peer.AddrInfo
rtt map[peer.ID]int64
}
Expand All @@ -42,6 +43,7 @@ func NewTelemetryServer() *TelemetryServer {
lastScannedBlockNumber: make(map[int64]uint64),
lastStartTimestamp: time.Now(),
HotKeyBurnRate: NewBurnRate(100),
knownPeers: make([]peer.AddrInfo, 0),
connectedPeers: make([]peer.AddrInfo, 0),
rtt: make(map[peer.ID]int64),
}
Expand All @@ -67,6 +69,18 @@ func (t *TelemetryServer) GetPingRTT() map[peer.ID]int64 {
return t.rtt
}

func (t *TelemetryServer) SetKnownPeers(peers []peer.AddrInfo) {
t.mu.Lock()
defer t.mu.Unlock()
t.knownPeers = peers
}

func (t *TelemetryServer) GetKnownPeers() []peer.AddrInfo {
t.mu.Lock()
defer t.mu.Unlock()
return t.knownPeers
}

func (t *TelemetryServer) SetConnectedPeers(peers []peer.AddrInfo) {
t.mu.Lock()
defer t.mu.Unlock()
Expand Down Expand Up @@ -175,6 +189,7 @@ func (t *TelemetryServer) Handlers() http.Handler {
router.Handle("/ip", http.HandlerFunc(t.ipHandler)).Methods(http.MethodGet)
router.Handle("/hotkeyburnrate", http.HandlerFunc(t.hotKeyFeeBurnRate)).Methods(http.MethodGet)
router.Handle("/connectedpeers", http.HandlerFunc(t.connectedPeersHandler)).Methods(http.MethodGet)
router.Handle("/knownpeers", http.HandlerFunc(t.knownPeersHandler)).Methods(http.MethodGet)
router.Handle("/pingrtt", http.HandlerFunc(t.pingRTTHandler)).Methods(http.MethodGet)
router.Use(logMiddleware())

Expand Down Expand Up @@ -283,7 +298,19 @@ func (t *TelemetryServer) connectedPeersHandler(w http.ResponseWriter, _ *http.R
peers := t.GetConnectedPeers()
data, err := json.Marshal(peers)
if err != nil {
t.logger.Error().Err(err).Msg("Failed to marshal connected peers")
t.logger.Error().Err(err).Msg("Failed to marshal known peers")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "%s", string(data))
}

func (t *TelemetryServer) knownPeersHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
peers := t.GetKnownPeers()
data, err := json.Marshal(peers)
if err != nil {
t.logger.Error().Err(err).Msg("Failed to marshal known peers")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down
23 changes: 19 additions & 4 deletions zetaclient/tss/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"sync"
"time"

libp2p_network "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
maddr "github.com/multiformats/go-multiaddr"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"github.com/samber/lo"
"gitlab.com/thorchain/tss/go-tss/tss"

"github.com/zeta-chain/node/pkg/bg"
Expand Down Expand Up @@ -89,16 +92,28 @@ func HealthcheckWorker(ctx context.Context, server *tss.TssServer, p Healthcheck
return nil
}

peersCounter := func(_ context.Context, _ *ticker.Ticker) error {
knownPeersCounter := func(_ context.Context, _ *ticker.Ticker) error {
peers := server.GetKnownPeers()
p.NumConnectedPeersMetric.Set(float64(len(peers)))
p.Telemetry.SetConnectedPeers(peers)
p.Telemetry.SetKnownPeers(peers)
return nil
}

connectedPeersCounter := func(_ context.Context, _ *ticker.Ticker) error {
p2pHost := server.GetP2PHost()
connectedPeers := lo.Map(p2pHost.Network().Conns(), func(conn libp2p_network.Conn, _ int) peer.AddrInfo {
return peer.AddrInfo{
ID: conn.RemotePeer(),
Addrs: []maddr.Multiaddr{conn.RemoteMultiaddr()},
}
})
p.Telemetry.SetConnectedPeers(connectedPeers)
p.NumConnectedPeersMetric.Set(float64(len(connectedPeers)))
return nil
}

runBackgroundTicker(ctx, pinger, p.Interval, "TSSHealthcheckPeersPing", logger)
runBackgroundTicker(ctx, peersCounter, p.Interval, "TSSHealthcheckPeersCounter", logger)
runBackgroundTicker(ctx, knownPeersCounter, p.Interval, "TSSHealthcheckKnownPeersCounter", logger)
runBackgroundTicker(ctx, connectedPeersCounter, p.Interval, "TSSHealthcheckConnectedPeersCounter", logger)

return nil
}
Expand Down
1 change: 1 addition & 0 deletions zetaclient/tss/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Zetacore interface {
type Telemetry interface {
SetP2PID(id string)
SetConnectedPeers(peers []peer.AddrInfo)
SetKnownPeers(peers []peer.AddrInfo)
SetPingRTT(peers map[peer.ID]int64)
}

Expand Down

0 comments on commit 3647b5d

Please sign in to comment.