Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [4144](https://github.com/zeta-chain/node/pull/4144) - standardize structured logging for zetaclient
* [4180](https://github.com/zeta-chain/node/pull/4180) - remove unused loggers and log fields
* [4174](https://github.com/zeta-chain/node/pull/4174) - add documentation for ZetaClient logging fields
* [4213](https://github.com/zeta-chain/node/pull/4213) - prepare the client interfaces of the observer-signers for dry mode

### Fixes

Expand Down
5 changes: 3 additions & 2 deletions cmd/zetatool/cctx/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/zeta-chain/node/zetaclient/chains/bitcoin/client"
zetaevmclient "github.com/zeta-chain/node/zetaclient/chains/evm/client"
"github.com/zeta-chain/node/zetaclient/chains/solana/observer"
solanarpc "github.com/zeta-chain/node/zetaclient/chains/solana/rpc"
solrepo "github.com/zeta-chain/node/zetaclient/chains/solana/repo"
zetaclientConfig "github.com/zeta-chain/node/zetaclient/config"
)

Expand Down Expand Up @@ -297,13 +297,14 @@ func (c *TrackingDetails) solanaInboundBallotIdentifier(ctx *context.Context) er
if solClient == nil {
return fmt.Errorf("error creating rpc client")
}
solRepo := solrepo.New(solClient)

signature, err := solana.SignatureFromBase58(inboundHash)
if err != nil {
return fmt.Errorf("error parsing signature: %w", err)
}

txResult, err := solanarpc.GetTransaction(goCtx, solClient, signature)
txResult, err := solRepo.GetTransaction(goCtx, signature)
if err != nil {
return fmt.Errorf("error getting transaction: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/zetatool/cctx/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/zetaclient/chains/bitcoin/client"
zetaevmclient "github.com/zeta-chain/node/zetaclient/chains/evm/client"
solanarpc "github.com/zeta-chain/node/zetaclient/chains/solana/rpc"
solrepo "github.com/zeta-chain/node/zetaclient/chains/solana/repo"
zetaclientConfig "github.com/zeta-chain/node/zetaclient/config"
)

Expand Down Expand Up @@ -96,9 +96,11 @@ func (c *TrackingDetails) checkSolanaOutboundTx(ctx *context.Context) error {
if solClient == nil {
return fmt.Errorf("error creating rpc client")
}
solRepo := solrepo.New(solClient)

for _, hash := range txHashList {
signature := solana.MustSignatureFromBase58(hash)
_, err := solanarpc.GetTransaction(goCtx, solClient, signature)
_, err := solRepo.GetTransaction(goCtx, signature)
if err != nil {
continue
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/mocks-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ go install github.com/vektra/mockery/[email protected]

MOCK_DIRS=(
"./testutil/keeper/mocks"
"./zetaclient/chains/bitcoin/client"
"./zetaclient/chains/interfaces"
"./zetaclient/chains/bitcoin/client"
"./zetaclient/chains/evm/observer"
"./zetaclient/chains/ton/observer"
"./zetaclient/chains/ton/signer"
"./zetaclient/testutils/mocks"
Expand All @@ -19,4 +20,4 @@ for dir in "${MOCK_DIRS[@]}"; do
done

# Print a message to indicate completion
echo "Mocks generated."
echo "Mocks generated."
14 changes: 7 additions & 7 deletions zetaclient/chains/base/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type Observer struct {
// zetacoreClient is the client to interact with ZetaChain
zetacoreClient interfaces.ZetacoreClient

// tss is the TSS signer
tss interfaces.TSSSigner
// tssSigner is the TSS signer
tssSigner interfaces.TSSSigner

// lastBlock is the last block height of the observed chain
lastBlock uint64
Expand Down Expand Up @@ -83,7 +83,7 @@ func NewObserver(
chain chains.Chain,
chainParams observertypes.ChainParams,
zetacoreClient interfaces.ZetacoreClient,
tss interfaces.TSSSigner,
tssSigner interfaces.TSSSigner,
blockCacheSize int,
ts *metrics.TelemetryServer,
database *db.DB,
Expand All @@ -98,7 +98,7 @@ func NewObserver(
chain: chain,
chainParams: chainParams,
zetacoreClient: zetacoreClient,
tss: tss,
tssSigner: tssSigner,
lastBlock: 0,
lastBlockScanned: 0,
lastTxScanned: "",
Expand Down Expand Up @@ -183,7 +183,7 @@ func (ob *Observer) ZetacoreClient() interfaces.ZetacoreClient {

// TSS returns the tss signer for the observer.
func (ob *Observer) TSS() interfaces.TSSSigner {
return ob.tss
return ob.tssSigner
}

// TSSAddressString returns the TSS address for the chain.
Expand All @@ -192,13 +192,13 @@ func (ob *Observer) TSS() interfaces.TSSSigner {
func (ob *Observer) TSSAddressString() string {
switch ob.chain.Consensus {
case chains.Consensus_bitcoin:
address, err := ob.tss.PubKey().AddressBTC(ob.Chain().ChainId)
address, err := ob.tssSigner.PubKey().AddressBTC(ob.Chain().ChainId)
if err != nil {
return ""
}
return address.EncodeAddress()
default:
return ob.tss.PubKey().AddressEVM().String()
return ob.tssSigner.PubKey().AddressEVM().String()
}
}

Expand Down
8 changes: 4 additions & 4 deletions zetaclient/chains/base/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestNewObserver(t *testing.T) {
chainParams observertypes.ChainParams
appContext *zctx.AppContext
zetacoreClient interfaces.ZetacoreClient
tss interfaces.TSSSigner
tssSigner interfaces.TSSSigner
blockCacheSize int
fail bool
message string
Expand All @@ -124,7 +124,7 @@ func TestNewObserver(t *testing.T) {
chainParams: chainParams,
appContext: appContext,
zetacoreClient: zetacoreClient,
tss: tss,
tssSigner: tss,
blockCacheSize: blockCacheSize,
fail: false,
},
Expand All @@ -134,7 +134,7 @@ func TestNewObserver(t *testing.T) {
chainParams: chainParams,
appContext: appContext,
zetacoreClient: zetacoreClient,
tss: tss,
tssSigner: tss,
blockCacheSize: 0,
fail: true,
message: "error creating block cache",
Expand All @@ -148,7 +148,7 @@ func TestNewObserver(t *testing.T) {
tt.chain,
tt.chainParams,
tt.zetacoreClient,
tt.tss,
tt.tssSigner,
tt.blockCacheSize,
nil,
database,
Expand Down
10 changes: 5 additions & 5 deletions zetaclient/chains/base/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Signer struct {
// chain contains static information about the external chain
chain chains.Chain

// tss is the TSS signer
tss interfaces.TSSSigner
// tssSigner is the TSS signer
tssSigner interfaces.TSSSigner

// logger contains the loggers used by signer
logger Logger
Expand All @@ -37,7 +37,7 @@ type Signer struct {
}

// NewSigner creates a new base signer.
func NewSigner(chain chains.Chain, tss interfaces.TSSSigner, logger Logger) *Signer {
func NewSigner(chain chains.Chain, tssSigner interfaces.TSSSigner, logger Logger) *Signer {
withLogFields := func(log zerolog.Logger) zerolog.Logger {
return log.With().
Str(logs.FieldModule, logs.ModNameSigner).
Expand All @@ -47,7 +47,7 @@ func NewSigner(chain chains.Chain, tss interfaces.TSSSigner, logger Logger) *Sig

return &Signer{
chain: chain,
tss: tss,
tssSigner: tssSigner,
outboundBeingReported: make(map[string]bool),
activeOutbounds: make(map[string]time.Time),
logger: Logger{
Expand All @@ -64,7 +64,7 @@ func (s *Signer) Chain() chains.Chain {

// TSS returns the tss signer for the signer.
func (s *Signer) TSS() interfaces.TSSSigner {
return s.tss
return s.tssSigner
}

// Logger returns the logger for the signer.
Expand Down
13 changes: 13 additions & 0 deletions zetaclient/chains/bitcoin/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package bitcoin

import (
"github.com/zeta-chain/node/zetaclient/chains/bitcoin/common"
"github.com/zeta-chain/node/zetaclient/chains/bitcoin/observer"
"github.com/zeta-chain/node/zetaclient/chains/bitcoin/signer"
)

type Client interface {
common.BitcoinClient
signer.BitcoinClient
observer.BitcoinClient
}
19 changes: 11 additions & 8 deletions zetaclient/chains/bitcoin/common/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
DefaultDepositorFee = DepositorFee(defaultDepositorFeeRate)
)

type RPC interface {
type BitcoinClient interface {
GetBlockCount(ctx context.Context) (int64, error)
GetBlockHash(ctx context.Context, blockHeight int64) (*chainhash.Hash, error)
GetBlockHeader(ctx context.Context, hash *chainhash.Hash) (*wire.BlockHeader, error)
Expand All @@ -66,7 +66,7 @@ type RPC interface {
}

// DepositorFeeCalculator is a function type to calculate the Bitcoin depositor fee
type DepositorFeeCalculator func(context.Context, RPC, *btcjson.TxRawResult, *chaincfg.Params) (float64, error)
type DepositorFeeCalculator func(context.Context, BitcoinClient, *btcjson.TxRawResult, *chaincfg.Params) (float64, error)

// FeeRateToSatPerByte converts a fee rate from BTC/KB to sat/vB.
func FeeRateToSatPerByte(rate float64) (uint64, error) {
Expand Down Expand Up @@ -237,7 +237,7 @@ func CalcBlockAvgFeeRate(blockVb *btcjson.GetBlockVerboseTxResult, netParams *ch
// CalcDepositorFee calculates the depositor fee for a given tx result
func CalcDepositorFee(
ctx context.Context,
rpc RPC,
bitcoinClient BitcoinClient,
rawResult *btcjson.TxRawResult,
netParams *chaincfg.Params,
) (float64, error) {
Expand All @@ -247,7 +247,7 @@ func CalcDepositorFee(
}

// get fee rate of the transaction
_, feeRate, err := rpc.GetTransactionFeeAndRate(ctx, rawResult)
_, feeRate, err := bitcoinClient.GetTransactionFeeAndRate(ctx, rawResult)
if err != nil {
return 0, errors.Wrapf(err, "error getting fee rate for tx %s", rawResult.Txid)
}
Expand All @@ -261,14 +261,17 @@ func CalcDepositorFee(

// GetRecentFeeRate gets the highest fee rate from recent blocks
// Note: this method should be used for testnet ONLY
func GetRecentFeeRate(ctx context.Context, rpc RPC, netParams *chaincfg.Params) (uint64, error) {
func GetRecentFeeRate(ctx context.Context,
bitcoinClient BitcoinClient,
netParams *chaincfg.Params,
) (uint64, error) {
// should avoid using this method for mainnet
if netParams.Name == chaincfg.MainNetParams.Name {
return 0, errors.New("GetRecentFeeRate should not be used for mainnet")
}

// get the current block number
blockNumber, err := rpc.GetBlockCount(ctx)
blockNumber, err := bitcoinClient.GetBlockCount(ctx)
if err != nil {
return 0, err
}
Expand All @@ -277,11 +280,11 @@ func GetRecentFeeRate(ctx context.Context, rpc RPC, netParams *chaincfg.Params)
highestRate := int64(0)
for i := int64(0); i < feeRateCountBackBlocks; i++ {
// get the block
hash, err := rpc.GetBlockHash(ctx, blockNumber-i)
hash, err := bitcoinClient.GetBlockHash(ctx, blockNumber-i)
if err != nil {
return 0, err
}
block, err := rpc.GetBlockVerbose(ctx, hash)
block, err := bitcoinClient.GetBlockVerbose(ctx, hash)
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/bitcoin/observer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (ob *Observer) LoadLastBlockScanned(ctx context.Context) error {
// 1. environment variable is set explicitly to "latest"
// 2. environment variable is empty and last scanned block is not found in DB
if ob.LastBlockScanned() == 0 {
blockNumber, err := ob.rpc.GetBlockCount(ctx)
blockNumber, err := ob.bitcoinClient.GetBlockCount(ctx)
if err != nil {
return errors.Wrap(err, "unable to get block count")
}
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/bitcoin/observer/gas_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func (ob *Observer) PostGasPrice(ctx context.Context) error {
feeRateEstimated = client.FeeRateRegnet
case chains.NetworkType_testnet:
// testnet RPC 'EstimateSmartFee' can return unreasonable high fee rate
feeRateEstimated, err = common.GetRecentFeeRate(ctx, ob.rpc, ob.netParams)
feeRateEstimated, err = common.GetRecentFeeRate(ctx, ob.bitcoinClient, ob.netParams)
if err != nil {
return errors.Wrapf(err, "unable to get recent fee rate")
}
case chains.NetworkType_mainnet:
feeRateEstimated, err = ob.rpc.GetEstimatedFeeRate(ctx, 1)
feeRateEstimated, err = ob.bitcoinClient.GetEstimatedFeeRate(ctx, 1)
if err != nil {
return errors.Wrap(err, "unable to get estimated fee rate")
}
Expand All @@ -39,7 +39,7 @@ func (ob *Observer) PostGasPrice(ctx context.Context) error {
}

// query the current block number
blockNumber, err := ob.rpc.GetBlockCount(ctx)
blockNumber, err := ob.bitcoinClient.GetBlockCount(ctx)
if err != nil {
return errors.Wrap(err, "GetBlockCount error")
}
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/bitcoin/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (ob *Observer) observeInboundInBlockRange(ctx context.Context, startBlock,
// #nosec G115 always positive
events, err := FilterAndParseIncomingTx(
ctx,
ob.rpc,
ob.bitcoinClient,
res.Block.Tx,
uint64(res.Block.Height),
tssAddress,
Expand Down Expand Up @@ -142,7 +142,7 @@ func (ob *Observer) observeInboundInBlockRange(ctx context.Context, startBlock,
// vout1: OP_RETURN memo, base64 encoded
func FilterAndParseIncomingTx(
ctx context.Context,
rpc RPC,
bitcoinClient BitcoinClient,
txs []btcjson.TxRawResult,
blockNumber uint64,
tssAddress string,
Expand All @@ -159,7 +159,7 @@ func FilterAndParseIncomingTx(

event, err := GetBtcEventWithWitness(
ctx,
rpc,
bitcoinClient,
tx,
tssAddress,
blockNumber,
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/bitcoin/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// mockDepositFeeCalculator returns a mock depositor fee calculator that returns the given fee and error.
func mockDepositFeeCalculator(fee float64, err error) common.DepositorFeeCalculator {
return func(_ context.Context, _ common.RPC, _ *btcjson.TxRawResult, _ *chaincfg.Params) (float64, error) {
return func(_ context.Context, _ common.BitcoinClient, _ *btcjson.TxRawResult, _ *chaincfg.Params) (float64, error) {
return fee, err
}
}
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/bitcoin/observer/inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string,
return "", errors.Wrap(err, "error parsing btc tx hash")
}

tx, err := ob.rpc.GetRawTransactionVerbose(ctx, hash)
tx, err := ob.bitcoinClient.GetRawTransactionVerbose(ctx, hash)
if err != nil {
return "", errors.Wrap(err, "error getting btc raw tx verbose")
}
Expand All @@ -49,7 +49,7 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string,
return "", errors.Wrap(err, "error parsing btc block hash")
}

blockVb, err := ob.rpc.GetBlockVerbose(ctx, blockHash)
blockVb, err := ob.bitcoinClient.GetBlockVerbose(ctx, blockHash)
if err != nil {
return "", errors.Wrap(err, "error getting btc block verbose")
}
Expand All @@ -72,7 +72,7 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string,
// #nosec G115 always positive
event, err := GetBtcEventWithWitness(
ctx,
ob.rpc,
ob.bitcoinClient,
*tx,
tss,
uint64(blockVb.Height),
Expand Down
Loading