diff --git a/changelog.md b/changelog.md index 3d0194dc28..db3d2475f4 100644 --- a/changelog.md +++ b/changelog.md @@ -98,6 +98,10 @@ * [2335](https://github.com/zeta-chain/node/pull/2335) - ci: updated the artillery report to publish to artillery cloud * [2377](https://github.com/zeta-chain/node/pull/2377) - ci: adjusted sast-linters.yml to not scan itself, nor alert on removal of nosec. +### Documentation + +* [2321](https://github.com/zeta-chain/node/pull/2321) - improve documentation for ZetaClient functions and packages + ## v17.0.0 ### Fixes diff --git a/zetaclient/authz/authz_signer.go b/zetaclient/authz/authz_signer.go index 5f1221f9a9..7f9dc4d471 100644 --- a/zetaclient/authz/authz_signer.go +++ b/zetaclient/authz/authz_signer.go @@ -1,3 +1,5 @@ +// Package authz provides a signer object for transactions using grants +// grants are used to allow a hotkey to sign transactions on behalf of the observers package authz import ( @@ -7,18 +9,22 @@ import ( crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" ) +// Signer represents a signer for a grantee key type Signer struct { KeyType authz.KeyType GranterAddress string GranteeAddress sdk.AccAddress } +// String returns a string representation of a Signer func (a Signer) String() string { return a.KeyType.String() + " " + a.GranterAddress + " " + a.GranteeAddress.String() } +// signers is a map of all the signers for the different tx types var signers map[string]Signer +// init initializes the signers map with all the crosschain tx types using the ZetaClientGranteeKey func init() { signersList := make(map[string]Signer) for _, tx := range crosschaintypes.GetAllAuthzZetaclientTxTypes() { @@ -27,6 +33,7 @@ func init() { signers = signersList } +// SetupAuthZSignerList sets the granter and grantee for all the signers func SetupAuthZSignerList(granter string, grantee sdk.AccAddress) { for k, v := range signers { v.GranterAddress = granter @@ -35,6 +42,7 @@ func SetupAuthZSignerList(granter string, grantee sdk.AccAddress) { } } +// GetSigner returns the signer for a given msgURL func GetSigner(msgURL string) Signer { return signers[msgURL] } diff --git a/zetaclient/authz/authz_signer_test.go b/zetaclient/authz/authz_signer_test.go index 00a25722c4..1cc70b3116 100644 --- a/zetaclient/authz/authz_signer_test.go +++ b/zetaclient/authz/authz_signer_test.go @@ -1 +1,3 @@ package authz_test + +// NOTE: test file currently created empty to add the package in the test coverage scope diff --git a/zetaclient/chains/bitcoin/observer/inbound.go b/zetaclient/chains/bitcoin/observer/inbound.go index 2438411b5b..037fd11cd1 100644 --- a/zetaclient/chains/bitcoin/observer/inbound.go +++ b/zetaclient/chains/bitcoin/observer/inbound.go @@ -26,6 +26,8 @@ import ( ) // WatchInbound watches Bitcoin chain for inbounds on a ticker +// It starts a ticker and run ObserveInbound +// TODO(revamp): move all ticker related methods in the same file func (ob *Observer) WatchInbound() { ticker, err := types.NewDynamicTicker("Bitcoin_WatchInbound", ob.GetChainParams().InboundTicker) if err != nil { @@ -37,6 +39,7 @@ func (ob *Observer) WatchInbound() { ob.logger.Inbound.Info().Msgf("WatchInbound started for chain %d", ob.Chain().ChainId) sampledLogger := ob.logger.Inbound.Sample(&zerolog.BasicSampler{N: 10}) + // ticker loop for { select { case <-ticker.C(): @@ -58,6 +61,7 @@ func (ob *Observer) WatchInbound() { } // ObserveInbound observes the Bitcoin chain for inbounds and post votes to zetacore +// TODO(revamp): simplify this function into smaller functions func (ob *Observer) ObserveInbound() error { // get and update latest block height cnt, err := ob.btcClient.GetBlockCount() @@ -171,6 +175,7 @@ func (ob *Observer) ObserveInbound() error { } // WatchInboundTracker watches zetacore for bitcoin inbound trackers +// TODO(revamp): move all ticker related methods in the same file func (ob *Observer) WatchInboundTracker() { ticker, err := types.NewDynamicTicker("Bitcoin_WatchInboundTracker", ob.GetChainParams().InboundTicker) if err != nil { @@ -200,6 +205,7 @@ func (ob *Observer) WatchInboundTracker() { } // ProcessInboundTrackers processes inbound trackers +// TODO(revamp): move inbound tracker logic in a specific file func (ob *Observer) ProcessInboundTrackers() error { trackers, err := ob.ZetacoreClient().GetInboundTrackersForChain(ob.Chain().ChainId) if err != nil { @@ -328,6 +334,7 @@ func FilterAndParseIncomingTx( return inbounds, nil } +// GetInboundVoteMessageFromBtcEvent converts a BTCInboundEvent to a MsgVoteInbound to enable voting on the inbound on zetacore func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inbound *BTCInboundEvent) *crosschaintypes.MsgVoteInbound { ob.logger.Inbound.Debug().Msgf("Processing inbound: %s", inbound.TxHash) amount := big.NewFloat(inbound.Value) @@ -360,6 +367,7 @@ func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inbound *BTCInboundEvent) } // DoesInboundContainsRestrictedAddress returns true if the inbound contains restricted addresses +// TODO(revamp): move all compliance related functions in a specific file func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent) bool { receiver := "" parsedAddress, _, err := chains.ParseAddressAndData(hex.EncodeToString(inTx.MemoBytes)) @@ -376,6 +384,7 @@ func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent) // GetBtcEvent either returns a valid BTCInboundEvent or nil // Note: the caller should retry the tx on error (e.g., GetSenderAddressByVin failed) +// TODO(revamp): simplify this function func GetBtcEvent( rpcClient interfaces.BTCRPCClient, tx btcjson.TxRawResult, diff --git a/zetaclient/chains/bitcoin/observer/observer.go b/zetaclient/chains/bitcoin/observer/observer.go index 5d6e308dfe..11ccc5460a 100644 --- a/zetaclient/chains/bitcoin/observer/observer.go +++ b/zetaclient/chains/bitcoin/observer/observer.go @@ -1,3 +1,4 @@ +// Package observer implements the Bitcoin chain observer package observer import ( @@ -54,6 +55,7 @@ type Logger struct { } // BTCInboundEvent represents an incoming transaction event +// TODO(revamp): Move to inbound type BTCInboundEvent struct { // FromAddress is the first input address FromAddress string @@ -69,7 +71,7 @@ type BTCInboundEvent struct { TxHash string } -// BTCOutboundEvent contains bitcoin block and the header +// BTCBlockNHeader contains bitcoin block and the header type BTCBlockNHeader struct { Header *wire.BlockHeader Block *btcjson.GetBlockVerboseTxResult @@ -190,7 +192,7 @@ func (ob *Observer) GetChainParams() observertypes.ChainParams { return ob.ChainParams() } -// Start starts the Go routine to observe the Bitcoin chain +// Start starts the Go routine processes to observe the Bitcoin chain func (ob *Observer) Start() { ob.Logger().Chain.Info().Msgf("observer is starting for chain %d", ob.Chain().ChainId) @@ -214,6 +216,8 @@ func (ob *Observer) Start() { } // WatchRPCStatus watches the RPC status of the Bitcoin chain +// TODO(revamp): move ticker related functions to a specific file +// TODO(revamp): move inner logic in a separate function func (ob *Observer) WatchRPCStatus() { ob.logger.Chain.Info().Msgf("RPCStatus is starting") ticker := time.NewTicker(60 * time.Second) @@ -297,6 +301,8 @@ func (ob *Observer) ConfirmationsThreshold(amount *big.Int) int64 { } // WatchGasPrice watches Bitcoin chain for gas rate and post to zetacore +// TODO(revamp): move ticker related functions to a specific file +// TODO(revamp): move inner logic in a separate function func (ob *Observer) WatchGasPrice() { // report gas price right away as the ticker takes time to kick in err := ob.PostGasPrice() @@ -333,6 +339,7 @@ func (ob *Observer) WatchGasPrice() { } // PostGasPrice posts gas price to zetacore +// TODO(revamp): move to gas price file func (ob *Observer) PostGasPrice() error { // hardcode gas price here since this RPC is not available on regtest if chains.IsBitcoinRegnet(ob.Chain().ChainId) { @@ -379,6 +386,7 @@ func (ob *Observer) PostGasPrice() error { } // GetSenderAddressByVin get the sender address from the previous transaction +// TODO(revamp): move in upper package to separate file (e.g., rpc.go) func GetSenderAddressByVin(rpcClient interfaces.BTCRPCClient, vin btcjson.Vin, net *chaincfg.Params) (string, error) { // query previous raw transaction by txid // GetTransaction requires reconfiguring the bitcoin node (txindex=1), so we use GetRawTransaction instead @@ -421,6 +429,7 @@ func GetSenderAddressByVin(rpcClient interfaces.BTCRPCClient, vin btcjson.Vin, n } // WatchUTXOs watches bitcoin chain for UTXOs owned by the TSS address +// TODO(revamp): move ticker related functions to a specific file func (ob *Observer) WatchUTXOs() { ticker, err := clienttypes.NewDynamicTicker("Bitcoin_WatchUTXOs", ob.GetChainParams().WatchUtxoTicker) if err != nil { @@ -448,6 +457,7 @@ func (ob *Observer) WatchUTXOs() { } // FetchUTXOs fetches TSS-owned UTXOs from the Bitcoin node +// TODO(revamp): move to UTXO file func (ob *Observer) FetchUTXOs() error { defer func() { if err := recover(); err != nil { @@ -511,6 +521,7 @@ func (ob *Observer) FetchUTXOs() error { } // SaveBroadcastedTx saves successfully broadcasted transaction +// TODO(revamp): move to db file func (ob *Observer) SaveBroadcastedTx(txHash string, nonce uint64) { outboundID := ob.GetTxID(nonce) ob.Mu().Lock() @@ -641,6 +652,7 @@ func (ob *Observer) isTssTransaction(txid string) bool { } // postBlockHeader posts block header to zetacore +// TODO(revamp): move to block header file func (ob *Observer) postBlockHeader(tip int64) error { ob.logger.Inbound.Info().Msgf("postBlockHeader: tip %d", tip) bn := tip diff --git a/zetaclient/chains/bitcoin/observer/outbound.go b/zetaclient/chains/bitcoin/observer/outbound.go index 5bf20c8e7d..5f4684f50f 100644 --- a/zetaclient/chains/bitcoin/observer/outbound.go +++ b/zetaclient/chains/bitcoin/observer/outbound.go @@ -27,6 +27,8 @@ func (ob *Observer) GetTxID(nonce uint64) string { } // WatchOutbound watches Bitcoin chain for outgoing txs status +// TODO(revamp): move ticker functions to a specific file +// TODO(revamp): move into a separate package func (ob *Observer) WatchOutbound() { ticker, err := types.NewDynamicTicker("Bitcoin_WatchOutbound", ob.GetChainParams().OutboundTicker) if err != nil { @@ -111,6 +113,7 @@ func (ob *Observer) WatchOutbound() { } // IsOutboundProcessed returns isIncluded(or inMempool), isConfirmed, Error +// TODO(revamp): rename as it vote the outbound and doesn't only check if outbound is processed func (ob *Observer) IsOutboundProcessed(cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger) (bool, bool, error) { params := *cctx.GetCurrentOutboundParam() sendHash := cctx.Index @@ -213,6 +216,8 @@ func (ob *Observer) IsOutboundProcessed(cctx *crosschaintypes.CrossChainTx, logg // - the total value of the selected UTXOs. // - the number of consolidated UTXOs. // - the total value of the consolidated UTXOs. +// +// TODO(revamp): move to utxo file func (ob *Observer) SelectUTXOs( amount float64, utxosToSpend uint16, @@ -329,6 +334,8 @@ func (ob *Observer) refreshPendingNonce() { } } +// getOutboundIDByNonce gets the outbound ID from the nonce of the outbound transaction +// test is true for unit test only func (ob *Observer) getOutboundIDByNonce(nonce uint64, test bool) (string, error) { // There are 2 types of txids an observer can trust // 1. The ones had been verified and saved by observer self. @@ -363,6 +370,7 @@ func (ob *Observer) getOutboundIDByNonce(nonce uint64, test bool) (string, error return "", fmt.Errorf("getOutboundIDByNonce: cannot find outbound txid for nonce %d", nonce) } +// findNonceMarkUTXO finds the nonce-mark UTXO in the list of UTXOs. func (ob *Observer) findNonceMarkUTXO(nonce uint64, txid string) (int, error) { tssAddress := ob.TSS().BTCAddressWitnessPubkeyHash().EncodeAddress() amount := chains.NonceMarkAmount(nonce) diff --git a/zetaclient/chains/bitcoin/signer/signer.go b/zetaclient/chains/bitcoin/signer/signer.go index 6ad9bfc2a6..eae11a68ce 100644 --- a/zetaclient/chains/bitcoin/signer/signer.go +++ b/zetaclient/chains/bitcoin/signer/signer.go @@ -1,3 +1,4 @@ +// Package signer implements the ChainSigner interface for BTC package signer import ( @@ -168,6 +169,7 @@ func (signer *Signer) AddWithdrawTxOutputs( } // SignWithdrawTx receives utxos sorted by value, amount in BTC, feeRate in BTC per Kb +// TODO(revamp): simplify the function func (signer *Signer) SignWithdrawTx( to btcutil.Address, amount float64, @@ -291,6 +293,7 @@ func (signer *Signer) SignWithdrawTx( return tx, nil } +// Broadcast sends the signed transaction to the network func (signer *Signer) Broadcast(signedTx *wire.MsgTx) error { fmt.Printf("BTCSigner: Broadcasting: %s\n", signedTx.TxHash().String()) @@ -311,6 +314,8 @@ func (signer *Signer) Broadcast(signedTx *wire.MsgTx) error { return nil } +// TryProcessOutbound signs and broadcasts a BTC transaction from a new outbound +// TODO(revamp): simplify the function func (signer *Signer) TryProcessOutbound( cctx *types.CrossChainTx, outboundProcessor *outboundprocessor.Processor, diff --git a/zetaclient/chains/bitcoin/utils.go b/zetaclient/chains/bitcoin/utils.go index fe2bb2481b..8c37e01fad 100644 --- a/zetaclient/chains/bitcoin/utils.go +++ b/zetaclient/chains/bitcoin/utils.go @@ -8,6 +8,9 @@ import ( "github.com/pkg/errors" ) +// TODO(revamp): Remove utils.go and move the functions to the appropriate files + +// PrettyPrintStruct returns a pretty-printed string representation of a struct func PrettyPrintStruct(val interface{}) (string, error) { prettyStruct, err := json.MarshalIndent( val, @@ -20,6 +23,7 @@ func PrettyPrintStruct(val interface{}) (string, error) { return string(prettyStruct), nil } +// GetSatoshis converts a bitcoin amount to satoshis func GetSatoshis(btc float64) (int64, error) { // The amount is only considered invalid if it cannot be represented // as an integer type. This may happen if f is NaN or +-Infinity. @@ -39,6 +43,7 @@ func GetSatoshis(btc float64) (int64, error) { return round(btc * btcutil.SatoshiPerBitcoin), nil } +// round rounds a float64 to the nearest integer func round(f float64) int64 { if f < 0 { // #nosec G701 always in range diff --git a/zetaclient/chains/evm/observer/inbound.go b/zetaclient/chains/evm/observer/inbound.go index 41ada01375..40844ddbd7 100644 --- a/zetaclient/chains/evm/observer/inbound.go +++ b/zetaclient/chains/evm/observer/inbound.go @@ -34,6 +34,7 @@ import ( ) // WatchInbound watches evm chain for incoming txs and post votes to zetacore +// TODO(revamp): move ticker function to a separate file func (ob *Observer) WatchInbound() { ticker, err := clienttypes.NewDynamicTicker( fmt.Sprintf("EVM_WatchInbound_%d", ob.Chain().ChainId), @@ -70,6 +71,7 @@ func (ob *Observer) WatchInbound() { // WatchInboundTracker gets a list of Inbound tracker suggestions from zeta-core at each tick and tries to check if the in-tx was confirmed. // If it was, it tries to broadcast the confirmation vote. If this zeta client has previously broadcast the vote, the tx would be rejected +// TODO(revamp): move inbound tracker function to a separate file func (ob *Observer) WatchInboundTracker() { ticker, err := clienttypes.NewDynamicTicker( fmt.Sprintf("EVM_WatchInboundTracker_%d", ob.Chain().ChainId), @@ -101,6 +103,7 @@ func (ob *Observer) WatchInboundTracker() { } // ProcessInboundTrackers processes inbound trackers from zetacore +// TODO(revamp): move inbound tracker function to a separate file func (ob *Observer) ProcessInboundTrackers() error { trackers, err := ob.ZetacoreClient().GetInboundTrackersForChain(ob.Chain().ChainId) if err != nil { @@ -152,6 +155,7 @@ func (ob *Observer) ProcessInboundTrackers() error { return nil } +// ObserveInbound observes the evm chain for inbounds and posts votes to zetacore func (ob *Observer) ObserveInbound(sampledLogger zerolog.Logger) error { // get and update latest block height blockNumber, err := ob.evmClient.BlockNumber(context.Background()) diff --git a/zetaclient/chains/evm/observer/observer.go b/zetaclient/chains/evm/observer/observer.go index 3db0538870..0a33603196 100644 --- a/zetaclient/chains/evm/observer/observer.go +++ b/zetaclient/chains/evm/observer/observer.go @@ -1,3 +1,4 @@ +// Package observer implements the EVM chain observer package observer import ( @@ -147,6 +148,7 @@ func (ob *Observer) GetERC20CustodyContract() (ethcommon.Address, *erc20custody. } // FetchConnectorContractEth returns the Eth connector address and binder +// TODO(revamp): move this to a contract package func FetchConnectorContractEth( addr ethcommon.Address, client interfaces.EVMRPCClient, @@ -155,6 +157,7 @@ func FetchConnectorContractEth( } // FetchZetaTokenContract returns the non-Eth ZETA token binder +// TODO(revamp): move this to a contract package func FetchZetaTokenContract( addr ethcommon.Address, client interfaces.EVMRPCClient, @@ -183,6 +186,8 @@ func (ob *Observer) Start() { } // WatchRPCStatus watches the RPC status of the evm chain +// TODO(revamp): move ticker to ticker file +// TODO(revamp): move inner logic to a separate function func (ob *Observer) WatchRPCStatus() { ob.Logger().Chain.Info().Msgf("Starting RPC status check for chain %d", ob.Chain().ChainId) ticker := time.NewTicker(60 * time.Second) @@ -288,6 +293,8 @@ func (ob *Observer) CheckTxInclusion(tx *ethtypes.Transaction, receipt *ethtypes } // WatchGasPrice watches evm chain for gas prices and post to zetacore +// TODO(revamp): move ticker to ticker file +// TODO(revamp): move inner logic to a separate function func (ob *Observer) WatchGasPrice() { // report gas price right away as the ticker takes time to kick in err := ob.PostGasPrice() @@ -326,6 +333,8 @@ func (ob *Observer) WatchGasPrice() { } } +// PostGasPrice posts gas price to zetacore +// TODO(revamp): move to gas price file func (ob *Observer) PostGasPrice() error { // GAS PRICE gasPrice, err := ob.evmClient.SuggestGasPrice(context.TODO()) @@ -353,6 +362,7 @@ func (ob *Observer) PostGasPrice() error { } // TransactionByHash query transaction by hash via JSON-RPC +// TODO(revamp): update this method as a pure RPC method that takes two parameters (jsonRPC, and txHash) and move to upper package to file rpc.go func (ob *Observer) TransactionByHash(txHash string) (*ethrpc.Transaction, bool, error) { tx, err := ob.evmJSONRPC.EthGetTransactionByHash(txHash) if err != nil { @@ -365,6 +375,7 @@ func (ob *Observer) TransactionByHash(txHash string) (*ethrpc.Transaction, bool, return tx, tx.BlockNumber == nil, nil } +// GetBlockHeaderCached get block header by number from cache func (ob *Observer) GetBlockHeaderCached(blockNumber uint64) (*ethtypes.Header, error) { if result, ok := ob.HeaderCache().Get(blockNumber); ok { if header, ok := result.(*ethtypes.Header); ok { @@ -422,6 +433,7 @@ func (ob *Observer) BlockByNumber(blockNumber int) (*ethrpc.Block, error) { } // LoadDB open sql database and load data into EVM observer +// TODO(revamp): move to a db file func (ob *Observer) LoadDB(dbPath string) error { if dbPath == "" { return errors.New("empty db path") @@ -450,6 +462,7 @@ func (ob *Observer) LoadDB(dbPath string) error { } // LoadLastBlockScanned loads the last scanned block from the database +// TODO(revamp): move to a db file func (ob *Observer) LoadLastBlockScanned() error { err := ob.Observer.LoadLastBlockScanned(ob.Logger().Chain) if err != nil { @@ -471,6 +484,8 @@ func (ob *Observer) LoadLastBlockScanned() error { return nil } +// postBlockHeader posts the block header to zetacore +// TODO(revamp): move to a block header file func (ob *Observer) postBlockHeader(tip uint64) error { bn := tip diff --git a/zetaclient/chains/evm/observer/outbound.go b/zetaclient/chains/evm/observer/outbound.go index 9c3bd1c66b..2f3d3c136f 100644 --- a/zetaclient/chains/evm/observer/outbound.go +++ b/zetaclient/chains/evm/observer/outbound.go @@ -34,6 +34,8 @@ func (ob *Observer) GetTxID(nonce uint64) string { } // WatchOutbound watches evm chain for outgoing txs status +// TODO(revamp): move ticker function to ticker file +// TODO(revamp): move inner logic to a separate function func (ob *Observer) WatchOutbound() { ticker, err := clienttypes.NewDynamicTicker( fmt.Sprintf("EVM_WatchOutbound_%d", ob.Chain().ChainId), @@ -130,6 +132,7 @@ func (ob *Observer) PostVoteOutbound( // IsOutboundProcessed checks outbound status and returns (isIncluded, isConfirmed, error) // It also posts vote to zetacore if the tx is confirmed +// TODO(revamp): rename as it also vote the outbound func (ob *Observer) IsOutboundProcessed(cctx *crosschaintypes.CrossChainTx, logger zerolog.Logger) (bool, bool, error) { // skip if outbound is not confirmed nonce := cctx.GetCurrentOutboundParam().TssNonce diff --git a/zetaclient/chains/evm/signer/signer.go b/zetaclient/chains/evm/signer/signer.go index d50b214b03..3ea7852766 100644 --- a/zetaclient/chains/evm/signer/signer.go +++ b/zetaclient/chains/evm/signer/signer.go @@ -1,3 +1,4 @@ +// Package signer implements the ChainSigner interface for EVM chains package signer import ( @@ -329,6 +330,7 @@ func (signer *Signer) SignCommandTx(txData *OutboundData, cmd string, params str // TryProcessOutbound - signer interface implementation // This function will attempt to build and sign an evm transaction using the TSS signer. // It will then broadcast the signed transaction to the outbound chain. +// TODO(revamp): simplify function func (signer *Signer) TryProcessOutbound( cctx *types.CrossChainTx, outboundProc *outboundprocessor.Processor, @@ -618,14 +620,19 @@ func (signer *Signer) GetReportedTxList() *map[string]bool { return &signer.outboundHashBeingReported } +// EvmClient returns the EVM RPC client func (signer *Signer) EvmClient() interfaces.EVMRPCClient { return signer.client } +// EvmSigner returns the EVM signer object for the signer func (signer *Signer) EvmSigner() ethtypes.Signer { + // TODO(revamp): rename field into evmSigner return signer.ethSigner } +// IsSenderZetaChain checks if the sender chain is ZetaChain +// TODO(revamp): move to another package more general for cctx functions func IsSenderZetaChain( cctx *types.CrossChainTx, zetacoreClient interfaces.ZetacoreClient, @@ -635,6 +642,7 @@ func IsSenderZetaChain( cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound && flags.IsOutboundEnabled } +// ErrorMsg returns a error message for SignOutbound failure with cctx data func ErrorMsg(cctx *types.CrossChainTx) string { return fmt.Sprintf( "signer SignOutbound error: nonce %d chain %d", @@ -643,6 +651,8 @@ func ErrorMsg(cctx *types.CrossChainTx) string { ) } +// SignWhitelistERC20Cmd signs a whitelist command for ERC20 token +// TODO(revamp): move the cmd in a specific file func (signer *Signer) SignWhitelistERC20Cmd(txData *OutboundData, params string) (*ethtypes.Transaction, error) { outboundParams := txData.outboundParams erc20 := ethcommon.HexToAddress(params) @@ -672,6 +682,8 @@ func (signer *Signer) SignWhitelistERC20Cmd(txData *OutboundData, params string) return tx, nil } +// SignMigrateTssFundsCmd signs a migrate TSS funds command +// TODO(revamp): move the cmd in a specific file func (signer *Signer) SignMigrateTssFundsCmd(txData *OutboundData) (*ethtypes.Transaction, error) { tx, _, _, err := signer.Sign( nil, @@ -689,6 +701,7 @@ func (signer *Signer) SignMigrateTssFundsCmd(txData *OutboundData) (*ethtypes.Tr } // reportToOutboundTracker reports outboundHash to tracker only when tx receipt is available +// TODO(revamp): move outbound tracker function to a outbound tracker file func (signer *Signer) reportToOutboundTracker( zetacoreClient interfaces.ZetacoreClient, chainID int64, @@ -821,6 +834,7 @@ func getEVMRPC(endpoint string) (interfaces.EVMRPCClient, ethtypes.Signer, error return client, ethSigner, nil } +// roundUpToNearestGwei rounds up the gas price to the nearest Gwei func roundUpToNearestGwei(gasPrice *big.Int) *big.Int { oneGwei := big.NewInt(1_000_000_000) // 1 Gwei mod := new(big.Int) diff --git a/zetaclient/chains/interfaces/interfaces.go b/zetaclient/chains/interfaces/interfaces.go index 1ef94ec8de..2272ef1dfe 100644 --- a/zetaclient/chains/interfaces/interfaces.go +++ b/zetaclient/chains/interfaces/interfaces.go @@ -1,3 +1,4 @@ +// Package interfaces provides interfaces for clients and signers for the chain to interact with package interfaces import ( @@ -96,7 +97,6 @@ type ZetacoreClient interface { GetKeys() keyinterfaces.ObserverKeys GetKeyGen() (*observertypes.Keygen, error) GetBlockHeight() (int64, error) - GetLastBlockHeightByChain(chain chains.Chain) (*crosschaintypes.LastBlockHeight, error) ListPendingCctx(chainID int64) ([]*crosschaintypes.CrossChainTx, uint64, error) ListPendingCctxWithinRatelimit() ([]*crosschaintypes.CrossChainTx, uint64, int64, string, bool, error) GetRateLimiterInput(window int64) (crosschaintypes.QueryRateLimiterInputResponse, error) diff --git a/zetaclient/compliance/compliance.go b/zetaclient/compliance/compliance.go index e085b6954b..849d56742b 100644 --- a/zetaclient/compliance/compliance.go +++ b/zetaclient/compliance/compliance.go @@ -1,3 +1,4 @@ +// Package compliance provides functions to check for compliance of cross-chain transactions package compliance import ( diff --git a/zetaclient/config/config.go b/zetaclient/config/config.go index 7dcf1b00f3..6efd149628 100644 --- a/zetaclient/config/config.go +++ b/zetaclient/config/config.go @@ -1,3 +1,4 @@ +// Package config provides functions to load and save ZetaClient config package config import ( @@ -11,7 +12,10 @@ import ( // restrictedAddressBook is a map of restricted addresses var restrictedAddressBook = map[string]bool{} +// filename is config file name for ZetaClient const filename string = "zetaclient_config.json" + +// folder is the folder name for ZetaClient config const folder string = "config" // Save saves ZetaClient config @@ -78,10 +82,12 @@ func Load(path string) (Config, error) { return cfg, nil } +// LoadComplianceConfig loads compliance data (restricted addresses) from config func LoadComplianceConfig(cfg Config) { restrictedAddressBook = cfg.GetRestrictedAddressBook() } +// GetPath returns the absolute path of the input path func GetPath(inputPath string) string { path := strings.Split(inputPath, "/") if len(path) > 0 { @@ -94,6 +100,7 @@ func GetPath(inputPath string) string { return filepath.Join(path...) } } + return inputPath } diff --git a/zetaclient/config/config_chain.go b/zetaclient/config/config_chain.go index 12c889f6af..5c2ed1d077 100644 --- a/zetaclient/config/config_chain.go +++ b/zetaclient/config/config_chain.go @@ -7,20 +7,29 @@ const ( ) const ( + // ConnectorAbiString is the ABI of the connector contract + // TODO(revamp): we should be able to use info from Go binding ConnectorAbiString = ` [{"inputs":[{"internalType":"address","name":"_zetaTokenAddress","type":"address"},{"internalType":"address","name":"_tssAddress","type":"address"},{"internalType":"address","name":"_tssAddressUpdater","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"originSenderAddress","type":"bytes"},{"indexed":true,"internalType":"uint256","name":"originChainId","type":"uint256"},{"indexed":true,"internalType":"address","name":"destinationAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":true,"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"ZetaReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"originSenderAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"originChainId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":true,"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":true,"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"ZetaReverted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"originSenderAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"gasLimit","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"zetaParams","type":"bytes"}],"name":"ZetaSent","type":"event"},{"inputs":[],"name":"getLockedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"originSenderAddress","type":"bytes"},{"internalType":"uint256","name":"originChainId","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"onReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"originSenderAddress","type":"address"},{"internalType":"uint256","name":"originChainId","type":"uint256"},{"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"onRevert","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceTssAddressUpdater","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"internalType":"bytes","name":"zetaParams","type":"bytes"}],"internalType":"struct ZetaInterfaces.SendInput","name":"input","type":"tuple"}],"name":"send","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tssAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tssAddressUpdater","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tssAddress","type":"address"}],"name":"updateTssAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"zetaToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]` + + // ERC20CustodyAbiString is the ABI of the erc20 custodu contract + // TODO(revamp): we should be able to use info from Go binding ERC20CustodyAbiString = ` [{"inputs":[{"internalType":"address","name":"_TSSAddress","type":"address"},{"internalType":"address","name":"_TSSAddressUpdater","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidSender","type":"error"},{"inputs":[],"name":"InvalidTSSUpdater","type":"error"},{"inputs":[],"name":"IsPaused","type":"error"},{"inputs":[],"name":"NotPaused","type":"error"},{"inputs":[],"name":"NotWhitelisted","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"recipient","type":"bytes"},{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"Unwhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"Whitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[],"name":"TSSAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TSSAddressUpdater","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"recipient","type":"bytes"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceTSSAddressUpdater","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"unwhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateTSSAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"whitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]` ) +// GetConnectorABI returns the ABI of the connector contract func GetConnectorABI() string { return ConnectorAbiString } +// GetERC20CustodyABI returns the ABI of the erc20 custody contract func GetERC20CustodyABI() string { return ERC20CustodyAbiString } +// New returns a new config +// It is initialize with default chain configs func New() Config { return Config{ EVMChainConfigs: evmChainsConfigs, @@ -28,6 +37,7 @@ func New() Config { } } +// bitcoinConfigRegnet contains Bitcoin config for regnet var bitcoinConfigRegnet = BTCConfig{ RPCUsername: "smoketest", // smoketest is the previous name for E2E test, we keep this name for compatibility between client versions in upgrade test RPCPassword: "123", @@ -35,6 +45,8 @@ var bitcoinConfigRegnet = BTCConfig{ RPCParams: "regtest", } +// evmChainsConfigs contains EVM chain configs +// it contains list of EVM chains with empty endpoint except for localnet var evmChainsConfigs = map[int64]EVMConfig{ chains.Ethereum.ChainId: { Chain: chains.Ethereum, diff --git a/zetaclient/config/types.go b/zetaclient/config/types.go index b14cc8191b..96cdf24a4c 100644 --- a/zetaclient/config/types.go +++ b/zetaclient/config/types.go @@ -12,9 +12,14 @@ import ( type KeyringBackend string const ( + // KeyringBackendUndefined is undefined keyring backend KeyringBackendUndefined KeyringBackend = "" - KeyringBackendTest KeyringBackend = "test" - KeyringBackendFile KeyringBackend = "file" + + // KeyringBackendTest is the test Cosmos keyring backend + KeyringBackendTest KeyringBackend = "test" + + // KeyringBackendFile is the file Cosmos keyring backend + KeyringBackendFile KeyringBackend = "file" ) // ClientConfiguration is a subset of zetaclient config that is used by zetacore client @@ -27,11 +32,13 @@ type ClientConfiguration struct { HsmMode bool `json:"hsm_mode"` } +// EVMConfig is the config for EVM chain type EVMConfig struct { Chain chains.Chain Endpoint string } +// BTCConfig is the config for Bitcoin chain type BTCConfig struct { // the following are rpcclient ConnConfig fields RPCUsername string @@ -40,6 +47,7 @@ type BTCConfig struct { RPCParams string // "regtest", "mainnet", "testnet3" } +// ComplianceConfig is the config for compliance type ComplianceConfig struct { LogPath string `json:"LogPath"` RestrictedAddresses []string `json:"RestrictedAddresses"` @@ -78,6 +86,8 @@ type Config struct { ComplianceConfig ComplianceConfig `json:"ComplianceConfig"` } +// NewConfig returns a new Config with initialize EVM chain mapping and a new mutex +// TODO(revamp): consolidate with New function func NewConfig() Config { return Config{ cfgLock: &sync.RWMutex{}, @@ -85,6 +95,7 @@ func NewConfig() Config { } } +// GetEVMConfig returns the EVM config for the given chain ID func (c Config) GetEVMConfig(chainID int64) (EVMConfig, bool) { c.cfgLock.RLock() defer c.cfgLock.RUnlock() @@ -92,6 +103,7 @@ func (c Config) GetEVMConfig(chainID int64) (EVMConfig, bool) { return evmCfg, found } +// GetAllEVMConfigs returns a map of all EVM configs func (c Config) GetAllEVMConfigs() map[int64]EVMConfig { c.cfgLock.RLock() defer c.cfgLock.RUnlock() @@ -104,6 +116,7 @@ func (c Config) GetAllEVMConfigs() map[int64]EVMConfig { return copied } +// GetBTCConfig returns the BTC config func (c Config) GetBTCConfig() (BTCConfig, bool) { c.cfgLock.RLock() defer c.cfgLock.RUnlock() @@ -111,6 +124,7 @@ func (c Config) GetBTCConfig() (BTCConfig, bool) { return c.BitcoinConfig, c.BitcoinConfig != (BTCConfig{}) } +// String returns the string representation of the config func (c Config) String() string { s, err := json.MarshalIndent(c, "", "\t") if err != nil { @@ -131,6 +145,7 @@ func (c Config) GetRestrictedAddressBook() map[string]bool { return restrictedAddresses } +// GetKeyringBackend returns the keyring backend func (c *Config) GetKeyringBackend() KeyringBackend { c.cfgLock.RLock() defer c.cfgLock.RUnlock() diff --git a/zetaclient/context/app_context.go b/zetaclient/context/app_context.go index d47cd925e8..ffdfa05604 100644 --- a/zetaclient/context/app_context.go +++ b/zetaclient/context/app_context.go @@ -1,3 +1,4 @@ +// Package context provides global app context for ZetaClient package context import ( @@ -22,10 +23,12 @@ func NewAppContext( } } +// Config returns the config of the app func (a AppContext) Config() config.Config { return a.config } +// ZetacoreContext returns the context for ZetaChain func (a AppContext) ZetacoreContext() *ZetacoreContext { return a.coreContext } diff --git a/zetaclient/context/zetacore_context.go b/zetaclient/context/zetacore_context.go index 73ad83ff29..17d4cc5c3d 100644 --- a/zetaclient/context/zetacore_context.go +++ b/zetaclient/context/zetacore_context.go @@ -52,6 +52,7 @@ func NewZetacoreContext(cfg config.Config) *ZetacoreContext { } } +// GetKeygen returns the current keygen func (c *ZetacoreContext) GetKeygen() observertypes.Keygen { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -69,6 +70,7 @@ func (c *ZetacoreContext) GetKeygen() observertypes.Keygen { } } +// GetCurrentTssPubkey returns the current tss pubkey func (c *ZetacoreContext) GetCurrentTssPubkey() string { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -99,6 +101,7 @@ func (c *ZetacoreContext) GetEnabledExternalChains() []chains.Chain { return externalChains } +// GetEVMChainParams returns chain params for a specific EVM chain func (c *ZetacoreContext) GetEVMChainParams(chainID int64) (*observertypes.ChainParams, bool) { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -107,6 +110,7 @@ func (c *ZetacoreContext) GetEVMChainParams(chainID int64) (*observertypes.Chain return evmChainParams, found } +// GetAllEVMChainParams returns all chain params for EVM chains func (c *ZetacoreContext) GetAllEVMChainParams() map[int64]*observertypes.ChainParams { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() @@ -137,6 +141,7 @@ func (c *ZetacoreContext) GetBTCChainParams() (chains.Chain, *observertypes.Chai return *chain, c.bitcoinChainParams, true } +// GetCrossChainFlags returns crosschain flags func (c *ZetacoreContext) GetCrossChainFlags() observertypes.CrosschainFlags { c.coreContextLock.RLock() defer c.coreContextLock.RUnlock() diff --git a/zetaclient/hsm/hsm_signer.go b/zetaclient/hsm/hsm_signer.go index a6d513a353..7d11952716 100644 --- a/zetaclient/hsm/hsm_signer.go +++ b/zetaclient/hsm/hsm_signer.go @@ -1,3 +1,5 @@ +// Package hsm is used to interact with chains with a HSM +// it is currently not used package hsm import ( @@ -158,6 +160,7 @@ func SignWithHSM( return txBuilder.SetSignatures(prevSignatures...) } +// GetPKCS11Config returns the PKCS11 configuration from the environment variables func GetPKCS11Config() (config *crypto11.Config, err error) { config = &crypto11.Config{} config.Path = os.Getenv(hsmPath) diff --git a/zetaclient/keys/keys.go b/zetaclient/keys/keys.go index 3532c12233..0fdef6c204 100644 --- a/zetaclient/keys/keys.go +++ b/zetaclient/keys/keys.go @@ -23,8 +23,11 @@ import ( ) var ( + // ErrBech32ifyPubKey is an error when Bech32ifyPubKey fails ErrBech32ifyPubKey = errors.New("Bech32ifyPubKey fail in main") - ErrNewPubKey = errors.New("NewPubKey error from string") + + // ErrNewPubKey is an error when NewPubKey fails + ErrNewPubKey = errors.New("NewPubKey error from string") ) var _ interfaces.ObserverKeys = &Keys{} @@ -52,6 +55,7 @@ func NewKeysWithKeybase( } } +// GetGranteeKeyName return the grantee name func GetGranteeKeyName(signerName string) string { return signerName } @@ -110,6 +114,7 @@ func (k *Keys) GetSignerInfo() *ckeys.Record { return info } +// GetOperatorAddress return the operator address func (k *Keys) GetOperatorAddress() sdk.AccAddress { return k.OperatorAddress } diff --git a/zetaclient/metrics/metrics.go b/zetaclient/metrics/metrics.go index 1170d16f68..1da10d10e8 100644 --- a/zetaclient/metrics/metrics.go +++ b/zetaclient/metrics/metrics.go @@ -1,3 +1,4 @@ +// Package metrics provides metrics functionalities for the zetaclient package metrics import ( @@ -11,79 +12,93 @@ import ( "github.com/rs/zerolog/log" ) +// Metrics is a struct that contains the http server for metrics type Metrics struct { s *http.Server } +// ZetaClientNamespace is the namespace for the metrics const ZetaClientNamespace = "zetaclient" var ( + // PendingTxsPerChain is a gauge that contains the number of pending transactions per chain PendingTxsPerChain = promauto.NewGaugeVec(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "pending_txs_total", Help: "Number of pending transactions per chain", }, []string{"chain"}) + // GetFilterLogsPerChain is a counter that contains the number of getLogs per chain GetFilterLogsPerChain = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: ZetaClientNamespace, Name: "rpc_getFilterLogs_count", Help: "Count of getLogs per chain", }, []string{"chain"}) + // GetBlockByNumberPerChain is a counter that contains the number of getBlockByNumber per chain GetBlockByNumberPerChain = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: ZetaClientNamespace, Name: "rpc_getBlockByNumber_count", Help: "Count of getLogs per chain", }, []string{"chain"}) + // TssNodeBlamePerPubKey is a counter that contains the number of tss node blame per pubkey TssNodeBlamePerPubKey = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: ZetaClientNamespace, Name: "tss_node_blame_count", Help: "Tss node blame counter per pubkey", }, []string{"pubkey"}) + // HotKeyBurnRate is a gauge that contains the fee burn rate of the hotkey HotKeyBurnRate = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "hotkey_burn_rate", Help: "Fee burn rate of the hotkey", }) + // NumberOfUTXO is a gauge that contains the number of UTXOs NumberOfUTXO = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "utxo_number", Help: "Number of UTXOs", }) + // LastScannedBlockNumber is a gauge that contains the last scanned block number per chain LastScannedBlockNumber = promauto.NewGaugeVec(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "last_scanned_block_number", Help: "Last scanned block number per chain", }, []string{"chain"}) + // LastCoreBlockNumber is a gauge that contains the last core block number LastCoreBlockNumber = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "last_core_block_number", Help: "Last core block number", }) + // Info is a gauge that contains information about the zetaclient environment Info = promauto.NewGaugeVec(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "info", Help: "Information about Zetaclient environment", }, []string{"version"}) + // LastStartTime is a gauge that contains the start time in Unix time LastStartTime = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "last_start_timestamp_seconds", Help: "Start time in Unix time", }) + // NumActiveMsgSigns is a gauge that contains the number of concurrent key signs NumActiveMsgSigns = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "num_active_message_signs", Help: "Number of concurrent key signs", }) + // PercentageOfRateReached is a gauge that contains the percentage of the rate limiter rate reached PercentageOfRateReached = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: ZetaClientNamespace, Name: "percentage_of_rate_reached", @@ -91,6 +106,7 @@ var ( }) ) +// NewMetrics creates a new Metrics instance func NewMetrics() (*Metrics, error) { handler := promhttp.InstrumentMetricHandler( prometheus.DefaultRegisterer, @@ -111,6 +127,7 @@ func NewMetrics() (*Metrics, error) { }, nil } +// Start starts the metrics server func (m *Metrics) Start() { log.Info().Msg("metrics server starting") go func() { @@ -120,6 +137,7 @@ func (m *Metrics) Start() { }() } +// Stop stops the metrics server func (m *Metrics) Stop() error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) defer cancel() diff --git a/zetaclient/metrics/telemetry.go b/zetaclient/metrics/telemetry.go index f49c1bf7b1..ebf62d887c 100644 --- a/zetaclient/metrics/telemetry.go +++ b/zetaclient/metrics/telemetry.go @@ -176,10 +176,12 @@ func (t *TelemetryServer) Stop() error { return err } +// pingHandler returns a 200 OK response func (t *TelemetryServer) pingHandler(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) } +// p2pHandler returns the p2p id func (t *TelemetryServer) p2pHandler(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) t.mu.Lock() @@ -187,6 +189,7 @@ func (t *TelemetryServer) p2pHandler(w http.ResponseWriter, _ *http.Request) { fmt.Fprintf(w, "%s", t.p2pid) } +// ipHandler returns the ip address func (t *TelemetryServer) ipHandler(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) t.mu.Lock() @@ -248,6 +251,7 @@ func (t *TelemetryServer) hotKeyFeeBurnRate(w http.ResponseWriter, _ *http.Reque fmt.Fprintf(w, "%v", t.HotKeyBurnRate.GetBurnRate()) } +// logMiddleware logs the incoming HTTP request func logMiddleware() mux.MiddlewareFunc { return func(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/zetaclient/orchestrator/orchestrator.go b/zetaclient/orchestrator/orchestrator.go index 1407557d3e..2c5ea2d2de 100644 --- a/zetaclient/orchestrator/orchestrator.go +++ b/zetaclient/orchestrator/orchestrator.go @@ -1,3 +1,4 @@ +// Package orchestrator provides the orchestrator for orchestrating cross-chain transactions package orchestrator import ( @@ -32,6 +33,8 @@ const ( loggerSamplingRate = 10 ) +// Log is a struct that contains the logger +// TODO(revamp): rename to logger type Log struct { Std zerolog.Logger Sampled zerolog.Logger @@ -42,8 +45,10 @@ type Orchestrator struct { // zetacore client zetacoreClient interfaces.ZetacoreClient - // chain signers and observers - signerMap map[int64]interfaces.ChainSigner + // signerMap contains the chain signers indexed by chainID + signerMap map[int64]interfaces.ChainSigner + + // observerMap contains the chain observers indexed by chainID observerMap map[int64]interfaces.ChainObserver // outbound processor @@ -94,6 +99,7 @@ func NewOrchestrator( return &oc } +// MonitorCore starts the orchestrator for CCTXs func (oc *Orchestrator) MonitorCore(appContext *context.AppContext) error { signerAddress, err := oc.zetacoreClient.GetKeys().GetAddress() if err != nil { @@ -231,6 +237,7 @@ func (oc *Orchestrator) GetPendingCctxsWithinRatelimit( } // StartCctxScheduler schedules keysigns for cctxs on each ZetaChain block (the ticker) +// TODO(revamp): make this function simpler func (oc *Orchestrator) StartCctxScheduler(appContext *context.AppContext) { observeTicker := time.NewTicker(3 * time.Second) var lastBlockNum int64 diff --git a/zetaclient/outboundprocessor/outbound_processor.go b/zetaclient/outboundprocessor/outbound_processor.go index feb4caafa7..75a9a6a19f 100644 --- a/zetaclient/outboundprocessor/outbound_processor.go +++ b/zetaclient/outboundprocessor/outbound_processor.go @@ -1,3 +1,4 @@ +// Package outboundprocessor provides functionalities to track outbound processing package outboundprocessor import ( @@ -8,6 +9,9 @@ import ( "github.com/rs/zerolog" ) +// Processor is a struct that contains data about outbound being processed +// TODO(revamp): rename this struct as it is not used to process outbound but track their processing +// We can also consider removing it once we refactor chain client to contains common logic to sign outbounds type Processor struct { outboundStartTime map[string]time.Time outboundEndTime map[string]time.Time @@ -17,6 +21,7 @@ type Processor struct { numActiveProcessor int64 } +// NewProcessor creates a new Processor func NewProcessor(logger zerolog.Logger) *Processor { return &Processor{ outboundStartTime: make(map[string]time.Time), @@ -28,6 +33,7 @@ func NewProcessor(logger zerolog.Logger) *Processor { } } +// StartTryProcess register a new outbound ID to track func (p *Processor) StartTryProcess(outboundID string) { p.mu.Lock() defer p.mu.Unlock() @@ -37,6 +43,7 @@ func (p *Processor) StartTryProcess(outboundID string) { p.Logger.Info().Msgf("StartTryProcess %s, numActiveProcessor %d", outboundID, p.numActiveProcessor) } +// EndTryProcess remove the outbound ID from tracking func (p *Processor) EndTryProcess(outboundID string) { p.mu.Lock() defer p.mu.Unlock() @@ -47,6 +54,7 @@ func (p *Processor) EndTryProcess(outboundID string) { Msgf("EndTryProcess %s, numActiveProcessor %d, time elapsed %s", outboundID, p.numActiveProcessor, time.Since(p.outboundStartTime[outboundID])) } +// IsOutboundActive checks if the outbound ID is being processed func (p *Processor) IsOutboundActive(outboundID string) bool { p.mu.Lock() defer p.mu.Unlock() @@ -54,6 +62,7 @@ func (p *Processor) IsOutboundActive(outboundID string) bool { return found } +// TimeInTryProcess returns the time elapsed since the outbound ID is being processed func (p *Processor) TimeInTryProcess(outboundID string) time.Duration { p.mu.Lock() defer p.mu.Unlock() diff --git a/zetaclient/ratelimiter/rate_limiter.go b/zetaclient/ratelimiter/rate_limiter.go index 0ddb3b378b..e3c69898fa 100644 --- a/zetaclient/ratelimiter/rate_limiter.go +++ b/zetaclient/ratelimiter/rate_limiter.go @@ -1,3 +1,4 @@ +// Package ratelimiter provides functionalities for rate limiting the cross-chain transactions package ratelimiter import ( diff --git a/zetaclient/supplychecker/logger.go b/zetaclient/supplychecker/logger.go index 223e43eab8..89da0300d6 100644 --- a/zetaclient/supplychecker/logger.go +++ b/zetaclient/supplychecker/logger.go @@ -21,6 +21,7 @@ type ZetaSupplyCheckLogs struct { SupplyCheckSuccess bool `json:"supply_check_success"` } +// LogOutput logs the output of the ZetaSupplyChecker func (z ZetaSupplyCheckLogs) LogOutput() { output, err := bitcoin.PrettyPrintStruct(z) if err != nil { diff --git a/zetaclient/supplychecker/validate.go b/zetaclient/supplychecker/validate.go index d70bda8c34..f9e4dbaf79 100644 --- a/zetaclient/supplychecker/validate.go +++ b/zetaclient/supplychecker/validate.go @@ -5,6 +5,7 @@ import ( "github.com/rs/zerolog" ) +// ValidateZetaSupply validates the zeta supply from the checked values func ValidateZetaSupply( logger zerolog.Logger, abortedTxAmounts, zetaInTransit, genesisAmounts, externalChainTotalSupply, zetaTokenSupplyOnNode, ethLockedAmount sdkmath.Int, diff --git a/zetaclient/supplychecker/zeta_supply_checker.go b/zetaclient/supplychecker/zeta_supply_checker.go index 952c0df16f..10ad1d5db1 100644 --- a/zetaclient/supplychecker/zeta_supply_checker.go +++ b/zetaclient/supplychecker/zeta_supply_checker.go @@ -1,3 +1,5 @@ +// Package supplychecker provides functionalities to check the total supply of Zeta tokens +// Currently not used in the codebase package supplychecker import ( @@ -92,6 +94,7 @@ func NewZetaSupplyChecker( return zetaSupplyChecker, nil } +// Start starts the ZetaSupplyChecker func (zs *ZetaSupplyChecker) Start() { defer zs.ticker.Stop() for { @@ -107,11 +110,13 @@ func (zs *ZetaSupplyChecker) Start() { } } +// Stop stops the ZetaSupplyChecker func (zs *ZetaSupplyChecker) Stop() { zs.logger.Info().Msgf("ZetaSupplyChecker is stopping") close(zs.stop) } +// CheckZetaTokenSupply checks the total supply of Zeta tokens func (zs *ZetaSupplyChecker) CheckZetaTokenSupply() error { externalChainTotalSupply := sdkmath.ZeroInt() for _, chain := range zs.externalEvmChain { @@ -193,6 +198,7 @@ func (zs *ZetaSupplyChecker) CheckZetaTokenSupply() error { return nil } +// AbortedTxAmount returns the amount of Zeta tokens in aborted transactions func (zs *ZetaSupplyChecker) AbortedTxAmount() (sdkmath.Int, error) { amount, err := zs.zetaClient.GetAbortedZetaAmount() if err != nil { @@ -205,6 +211,7 @@ func (zs *ZetaSupplyChecker) AbortedTxAmount() (sdkmath.Int, error) { return amountInt, nil } +// GetAmountOfZetaInTransit returns the amount of Zeta tokens in transit func (zs *ZetaSupplyChecker) GetAmountOfZetaInTransit() (sdkmath.Int, error) { chainsToCheck := make([]chains.Chain, len(zs.externalEvmChain)+1) chainsToCheck = append(append(chainsToCheck, zs.externalEvmChain...), zs.ethereumChain) @@ -222,6 +229,7 @@ func (zs *ZetaSupplyChecker) GetAmountOfZetaInTransit() (sdkmath.Int, error) { return amountInt, nil } +// GetPendingCCTXInTransit returns the pending CCTX in transit func (zs *ZetaSupplyChecker) GetPendingCCTXInTransit(receivingChains []chains.Chain) []*types.CrossChainTx { cctxInTransit := make([]*types.CrossChainTx, 0) for _, chain := range receivingChains { diff --git a/zetaclient/testutils/mempool_client.go b/zetaclient/testutils/mempool_client.go index 03c79120dc..a49ff45e78 100644 --- a/zetaclient/testutils/mempool_client.go +++ b/zetaclient/testutils/mempool_client.go @@ -15,6 +15,7 @@ const ( APIURLBlockTxsTestnet = "https://mempool.space/testnet/api/block/%s/txs" ) +// MempoolBlock represents a block in the mempool type MempoolBlock struct { ID string `json:"id"` Height int `json:"height"` @@ -32,6 +33,7 @@ type MempoolBlock struct { Extras BlockExtra `json:"extras"` } +// Vin represents a Bitcoin transaction input type Vin struct { TxID string `json:"txid"` Vout uint32 `json:"vout"` @@ -47,6 +49,7 @@ type Vin struct { Sequence uint32 `json:"sequence"` } +// Vout represents a Bitcoin transaction output type Vout struct { Scriptpubkey string `json:"scriptpubkey"` ScriptpubkeyAsm string `json:"scriptpubkey_asm"` @@ -54,6 +57,7 @@ type Vout struct { Value int64 `json:"value"` } +// MempoolTx represents a transaction in the mempool type MempoolTx struct { TxID string `json:"txid"` Version int `json:"version"` @@ -65,6 +69,7 @@ type MempoolTx struct { Fee int `json:"fee"` } +// BlockExtra represents extra information about a block type BlockExtra struct { TotalFees int `json:"totalFees"` MedianFee float64 `json:"medianFee"` @@ -105,6 +110,7 @@ type BlockExtra struct { ExpectedWeight int `json:"expectedWeight"` } +// Get makes a GET request to the given path and decodes the response func Get(ctx context.Context, path string, v interface{}) error { req, err := http.NewRequest("GET", path, nil) if err != nil { diff --git a/zetaclient/testutils/mocks/zetacore_client.go b/zetaclient/testutils/mocks/zetacore_client.go index 953d8ce287..2f413a8764 100644 --- a/zetaclient/testutils/mocks/zetacore_client.go +++ b/zetaclient/testutils/mocks/zetacore_client.go @@ -145,13 +145,6 @@ func (m *MockZetacoreClient) GetBlockHeight() (int64, error) { return 0, nil } -func (m *MockZetacoreClient) GetLastBlockHeightByChain(_ chains.Chain) (*crosschaintypes.LastBlockHeight, error) { - if m.paused { - return nil, errors.New(ErrMsgPaused) - } - return &crosschaintypes.LastBlockHeight{}, nil -} - func (m *MockZetacoreClient) GetRateLimiterInput(_ int64) (crosschaintypes.QueryRateLimiterInputResponse, error) { if m.paused { return crosschaintypes.QueryRateLimiterInputResponse{}, errors.New(ErrMsgPaused) diff --git a/zetaclient/testutils/testdata.go b/zetaclient/testutils/testdata.go index fc028bf0ec..620eb16b17 100644 --- a/zetaclient/testutils/testdata.go +++ b/zetaclient/testutils/testdata.go @@ -48,6 +48,8 @@ func LoadObjectFromJSONFile(t *testing.T, obj interface{}, filename string) { require.NoError(t, err) } +// ComplianceConfigTest returns a test compliance config +// TODO(revamp): move to sample package func ComplianceConfigTest() config.ComplianceConfig { return config.ComplianceConfig{ RestrictedAddresses: []string{RestrictedEVMAddressTest, RestrictedBtcAddressTest}, diff --git a/zetaclient/tss/tss_signer.go b/zetaclient/tss/tss_signer.go index 8fdd0384ee..08d48833db 100644 --- a/zetaclient/tss/tss_signer.go +++ b/zetaclient/tss/tss_signer.go @@ -1,3 +1,4 @@ +// Package tss provides the TSS signer functionalities for the zetaclient to sign transactions on external chains package tss import ( @@ -37,15 +38,18 @@ import ( ) const ( + // envFlagPostBlame is the environment flag to enable posting blame data to core envFlagPostBlame = "POST_BLAME" ) +// Key is a struct that holds the public key, bech32 pubkey, and address for the TSS type Key struct { PubkeyInBytes []byte PubkeyInBech32 string AddressInHex string } +// NewTSSKey creates a new TSS key func NewTSSKey(pk string) (*Key, error) { TSSKey := &Key{ PubkeyInBech32: pk, @@ -141,6 +145,8 @@ func NewTSS( return &newTss, nil } +// SetupTSSServer creates a new TSS server +// TODO(revamp): move to TSS server file func SetupTSSServer( peer p2p.AddrList, privkey tmcrypto.PrivKey, @@ -207,6 +213,7 @@ func SetupTSSServer( return tssServer, nil } +// Pubkey returns the current pubkey func (tss *TSS) Pubkey() []byte { return tss.Keys[tss.CurrentPubkey].PubkeyInBytes } @@ -404,6 +411,7 @@ func (tss *TSS) SignBatch(digests [][]byte, height uint64, nonce uint64, chainID return sigBytes, nil } +// Validate validates the TSS func (tss *TSS) Validate() error { evmAddress := tss.EVMAddress() blankAddress := ethcommon.Address{} @@ -419,6 +427,7 @@ func (tss *TSS) Validate() error { return nil } +// EVMAddress generates an EVM address from pubkey func (tss *TSS) EVMAddress() ethcommon.Address { addr, err := GetTssAddrEVM(tss.CurrentPubkey) if err != nil { @@ -438,6 +447,7 @@ func (tss *TSS) BTCAddress() string { return addr } +// BTCAddressWitnessPubkeyHash generates a bech32 p2wpkh address from pubkey func (tss *TSS) BTCAddressWitnessPubkeyHash() *btcutil.AddressWitnessPubKeyHash { addrWPKH, err := getKeyAddrBTCWitnessPubkeyHash(tss.CurrentPubkey, tss.BitcoinChainID) if err != nil { @@ -447,6 +457,7 @@ func (tss *TSS) BTCAddressWitnessPubkeyHash() *btcutil.AddressWitnessPubKeyHash return addrWPKH } +// PubKeyCompressedBytes returns the compressed bytes of the current pubkey func (tss *TSS) PubKeyCompressedBytes() []byte { pubk, err := cosmos.GetPubKeyFromBech32(cosmos.Bech32PubKeyTypeAccPub, tss.CurrentPubkey) if err != nil { @@ -466,6 +477,7 @@ func (tss *TSS) InsertPubKey(pk string) error { return nil } +// VerifyKeysharesForPubkeys verifies the keyshares present on the node. It checks whether the node has TSS key shares for the TSS ceremonies it was part of. func (tss *TSS) VerifyKeysharesForPubkeys(tssList []observertypes.TSS, granteePubKey32 string) error { for _, t := range tssList { if wasNodePartOfTss(granteePubKey32, t.TssParticipantList) { @@ -477,6 +489,7 @@ func (tss *TSS) VerifyKeysharesForPubkeys(tssList []observertypes.TSS, granteePu return nil } +// LoadTssFilesFromDirectory loads the TSS files at the directory specified by the `tssPath` func (tss *TSS) LoadTssFilesFromDirectory(tssPath string) error { files, err := os.ReadDir(tssPath) if err != nil { @@ -528,6 +541,7 @@ func (tss *TSS) LoadTssFilesFromDirectory(tssPath string) error { return nil } +// GetTssAddrBTC generates a bech32 p2wpkh address from pubkey func GetTssAddrBTC(tssPubkey string, bitcoinChainID int64) (string, error) { addrWPKH, err := getKeyAddrBTCWitnessPubkeyHash(tssPubkey, bitcoinChainID) if err != nil { @@ -538,6 +552,7 @@ func GetTssAddrBTC(tssPubkey string, bitcoinChainID int64) (string, error) { return addrWPKH.EncodeAddress(), nil } +// GetTssAddrEVM generates an EVM address from pubkey func GetTssAddrEVM(tssPubkey string) (ethcommon.Address, error) { var keyAddr ethcommon.Address pubk, err := cosmos.GetPubKeyFromBech32(cosmos.Bech32PubKeyTypeAccPub, tssPubkey) @@ -558,6 +573,9 @@ func GetTssAddrEVM(tssPubkey string) (ethcommon.Address, error) { return keyAddr, nil } +// TestKeysign tests the keysign +// it is called when a new TSS is generated to ensure the network works as expected +// TODO(revamp): move to a test package func TestKeysign(tssPubkey string, tssServer *tss.TssServer) error { log.Info().Msg("trying keysign...") data := []byte("hello meta") @@ -594,11 +612,14 @@ func TestKeysign(tssPubkey string, tssServer *tss.TssServer) error { return fmt.Errorf("verify signature fail") } +// IsEnvFlagEnabled checks if the environment flag is enabled func IsEnvFlagEnabled(flag string) bool { value := os.Getenv(flag) return value == "true" || value == "1" } +// verifySignature verifies the signature +// TODO(revamp): move to a test package func verifySignature(tssPubkey string, signature []keysign.Signature, H []byte) bool { if len(signature) == 0 { log.Warn().Msg("verify_signature: empty signature array") @@ -640,12 +661,15 @@ func verifySignature(tssPubkey string, signature []keysign.Signature, H []byte) return bytes.Equal(pubkey.Bytes(), compressedPubkey) } +// combineDigests combines the digests func combineDigests(digestList []string) []byte { digestConcat := strings.Join(digestList[:], "") digestBytes := chainhash.DoubleHashH([]byte(digestConcat)) return digestBytes.CloneBytes() } +// wasNodePartOfTss checks if the node was part of the TSS +// it checks whether a pubkey is part of the list used to generate the TSS , Every TSS generated on the network has its own list of associated public keys func wasNodePartOfTss(granteePubKey32 string, granteeList []string) bool { for _, grantee := range granteeList { if granteePubKey32 == grantee { @@ -655,6 +679,7 @@ func wasNodePartOfTss(granteePubKey32 string, granteeList []string) bool { return false } +// getKeyAddrBTCWitnessPubkeyHash generates a bech32 p2wpkh address from pubkey func getKeyAddrBTCWitnessPubkeyHash(tssPubkey string, chainID int64) (*btcutil.AddressWitnessPubKeyHash, error) { pubk, err := cosmos.GetPubKeyFromBech32(cosmos.Bech32PubKeyTypeAccPub, tssPubkey) if err != nil { diff --git a/zetaclient/types/dynamic_ticker.go b/zetaclient/types/dynamic_ticker.go index 49434e03ea..103bfffb94 100644 --- a/zetaclient/types/dynamic_ticker.go +++ b/zetaclient/types/dynamic_ticker.go @@ -7,12 +7,14 @@ import ( "github.com/rs/zerolog" ) +// DynamicTicker is a ticker that can have its interval updated type DynamicTicker struct { name string interval uint64 impl *time.Ticker } +// NewDynamicTicker creates a new DynamicTicker func NewDynamicTicker(name string, interval uint64) (*DynamicTicker, error) { if interval <= 0 { return nil, fmt.Errorf("non-positive ticker interval %d for %s", interval, name) @@ -25,10 +27,12 @@ func NewDynamicTicker(name string, interval uint64) (*DynamicTicker, error) { }, nil } +// C returns the channel of the ticker func (t *DynamicTicker) C() <-chan time.Time { return t.impl.C } +// UpdateInterval updates the interval of the ticker func (t *DynamicTicker) UpdateInterval(newInterval uint64, logger zerolog.Logger) { if newInterval > 0 && t.interval != newInterval { t.impl.Stop() @@ -39,6 +43,7 @@ func (t *DynamicTicker) UpdateInterval(newInterval uint64, logger zerolog.Logger } } +// Stop stops the ticker func (t *DynamicTicker) Stop() { t.impl.Stop() } diff --git a/zetaclient/types/ethish.go b/zetaclient/types/ethish.go index fd3a40af6d..6935a22141 100644 --- a/zetaclient/types/ethish.go +++ b/zetaclient/types/ethish.go @@ -4,6 +4,7 @@ import ( "encoding/hex" ) +// EthHexToBytes converts an Ethereum hex string to bytes func BytesToEthHex(b []byte) string { return "0x" + hex.EncodeToString(b) } diff --git a/zetaclient/types/sql_evm.go b/zetaclient/types/sql_evm.go index c551fda503..398a968a60 100644 --- a/zetaclient/types/sql_evm.go +++ b/zetaclient/types/sql_evm.go @@ -71,6 +71,7 @@ type LastBlockSQLType struct { // Type translation functions: +// ToReceiptDBType : Converts an Ethereum receipt to a ReceiptDB type func ToReceiptDBType(receipt *ethtypes.Receipt) (ReceiptDB, error) { logs, err := json.Marshal(receipt.Logs) if err != nil { @@ -92,6 +93,7 @@ func ToReceiptDBType(receipt *ethtypes.Receipt) (ReceiptDB, error) { }, nil } +// FromReceiptDBType : Converts a ReceiptDB type to an Ethereum receipt func FromReceiptDBType(receipt ReceiptDB) (*ethtypes.Receipt, error) { res := ðtypes.Receipt{ Type: receipt.Type, @@ -111,6 +113,7 @@ func FromReceiptDBType(receipt ReceiptDB) (*ethtypes.Receipt, error) { return res, err } +// ToReceiptSQLType : Converts an Ethereum receipt to a ReceiptSQLType func ToReceiptSQLType(receipt *ethtypes.Receipt, index string) (*ReceiptSQLType, error) { r, err := ToReceiptDBType(receipt) if err != nil { @@ -122,6 +125,7 @@ func ToReceiptSQLType(receipt *ethtypes.Receipt, index string) (*ReceiptSQLType, }, nil } +// ToTransactionDBType : Converts an Ethereum transaction to a TransactionDB type func ToTransactionDBType(transaction *ethtypes.Transaction) (TransactionDB, error) { data, err := transaction.MarshalBinary() if err != nil { @@ -137,12 +141,14 @@ func ToTransactionDBType(transaction *ethtypes.Transaction) (TransactionDB, erro }, nil } +// FromTransactionDBType : Converts a TransactionDB type to an Ethereum transaction func FromTransactionDBType(transaction TransactionDB) (*ethtypes.Transaction, error) { res := ðtypes.Transaction{} err := res.UnmarshalBinary(transaction.TransactionData) return res, err } +// ToTransactionSQLType : Converts an Ethereum transaction to a TransactionSQLType func ToTransactionSQLType(transaction *ethtypes.Transaction, index string) (*TransactionSQLType, error) { trans, err := ToTransactionDBType(transaction) if err != nil { @@ -154,6 +160,7 @@ func ToTransactionSQLType(transaction *ethtypes.Transaction, index string) (*Tra }, nil } +// ToLastBlockSQLType : Converts a last block number to a LastBlockSQLType func ToLastBlockSQLType(lastBlock uint64) *LastBlockSQLType { return &LastBlockSQLType{ Model: gorm.Model{ID: LastBlockNumID}, diff --git a/zetaclient/zetacore/broadcast.go b/zetaclient/zetacore/broadcast.go index 82a011c6ba..6c1b475476 100644 --- a/zetaclient/zetacore/broadcast.go +++ b/zetaclient/zetacore/broadcast.go @@ -50,7 +50,7 @@ func BroadcastToZetaCore( return client.Broadcast(gasLimit, authzWrappedMsg, authzSigner) } -// Broadcast Broadcasts tx to metachain. Returns txHash and error +// Broadcast Broadcasts tx to ZetaChain. Returns txHash and error func (c *Client) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg, authzSigner authz.Signer) (string, error) { c.broadcastLock.Lock() defer c.broadcastLock.Unlock() @@ -204,6 +204,7 @@ func (c *Client) GetContext() (client.Context, error) { return ctx, nil } +// SignTx signs a tx with the given name func (c *Client) SignTx( txf clienttx.Factory, name string, diff --git a/zetaclient/zetacore/client.go b/zetaclient/zetacore/client.go index 3b85296fe1..4443316a4a 100644 --- a/zetaclient/zetacore/client.go +++ b/zetaclient/zetacore/client.go @@ -1,3 +1,4 @@ +// Package zetacore provides functionalities for interacting with ZetaChain package zetacore import ( @@ -283,14 +284,18 @@ func (c *Client) UpdateZetacoreContext( return nil } +// Pause pauses the client func (c *Client) Pause() { <-c.pause } +// Unpause unpauses the client func (c *Client) Unpause() { c.pause <- struct{}{} } +// EnableMockSDKClient enables the mock cosmos sdk client +// TODO(revamp): move this to a test package func (c *Client) EnableMockSDKClient(client rpcclient.Client) { c.mockSDKClient = client c.enableMockSDKClient = true diff --git a/zetaclient/zetacore/query.go b/zetaclient/zetacore/query.go index b68ea37f8b..e90be274ff 100644 --- a/zetaclient/zetacore/query.go +++ b/zetaclient/zetacore/query.go @@ -25,6 +25,7 @@ import ( "github.com/zeta-chain/zetacore/zetaclient/chains/interfaces" ) +// GetCrosschainFlags returns the crosschain flags func (c *Client) GetCrosschainFlags() (observertypes.CrosschainFlags, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.CrosschainFlags(context.Background(), &observertypes.QueryGetCrosschainFlagsRequest{}) @@ -34,6 +35,7 @@ func (c *Client) GetCrosschainFlags() (observertypes.CrosschainFlags, error) { return resp.CrosschainFlags, nil } +// GetBlockHeaderEnabledChains returns the enabled chains for block headers func (c *Client) GetBlockHeaderEnabledChains() ([]lightclienttypes.HeaderSupportedChain, error) { client := lightclienttypes.NewQueryClient(c.grpcConn) resp, err := client.HeaderEnabledChains(context.Background(), &lightclienttypes.QueryHeaderEnabledChainsRequest{}) @@ -43,6 +45,7 @@ func (c *Client) GetBlockHeaderEnabledChains() ([]lightclienttypes.HeaderSupport return resp.HeaderEnabledChains, nil } +// GetRateLimiterFlags returns the rate limiter flags func (c *Client) GetRateLimiterFlags() (crosschaintypes.RateLimiterFlags, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.RateLimiterFlags(context.Background(), &crosschaintypes.QueryRateLimiterFlagsRequest{}) @@ -52,6 +55,7 @@ func (c *Client) GetRateLimiterFlags() (crosschaintypes.RateLimiterFlags, error) return resp.RateLimiterFlags, nil } +// GetChainParamsForChainID returns the chain params for a given chain ID func (c *Client) GetChainParamsForChainID(externalChainID int64) (*observertypes.ChainParams, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.GetChainParamsForChain( @@ -64,6 +68,7 @@ func (c *Client) GetChainParamsForChainID(externalChainID int64) (*observertypes return resp.ChainParams, nil } +// GetChainParams returns all the chain params func (c *Client) GetChainParams() ([]*observertypes.ChainParams, error) { client := observertypes.NewQueryClient(c.grpcConn) var err error @@ -79,6 +84,7 @@ func (c *Client) GetChainParams() ([]*observertypes.ChainParams, error) { return nil, fmt.Errorf("failed to get chain params | err %s", err.Error()) } +// GetUpgradePlan returns the current upgrade plan func (c *Client) GetUpgradePlan() (*upgradetypes.Plan, error) { client := upgradetypes.NewQueryClient(c.grpcConn) @@ -89,6 +95,7 @@ func (c *Client) GetUpgradePlan() (*upgradetypes.Plan, error) { return resp.Plan, nil } +// GetAllCctx returns all cross chain transactions func (c *Client) GetAllCctx() ([]*crosschaintypes.CrossChainTx, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.CctxAll(context.Background(), &crosschaintypes.QueryAllCctxRequest{}) @@ -98,6 +105,7 @@ func (c *Client) GetAllCctx() ([]*crosschaintypes.CrossChainTx, error) { return resp.CrossChainTx, nil } +// GetCctxByHash returns a cross chain transaction by hash func (c *Client) GetCctxByHash(sendHash string) (*crosschaintypes.CrossChainTx, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.Cctx(context.Background(), &crosschaintypes.QueryGetCctxRequest{Index: sendHash}) @@ -107,6 +115,7 @@ func (c *Client) GetCctxByHash(sendHash string) (*crosschaintypes.CrossChainTx, return resp.CrossChainTx, nil } +// GetCctxByNonce returns a cross chain transaction by nonce func (c *Client) GetCctxByNonce(chainID int64, nonce uint64) (*crosschaintypes.CrossChainTx, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.CctxByNonce(context.Background(), &crosschaintypes.QueryGetCctxByNonceRequest{ @@ -119,6 +128,7 @@ func (c *Client) GetCctxByNonce(chainID int64, nonce uint64) (*crosschaintypes.C return resp.CrossChainTx, nil } +// GetObserverList returns the list of observers func (c *Client) GetObserverList() ([]string, error) { var err error client := observertypes.NewQueryClient(c.grpcConn) @@ -185,6 +195,7 @@ func (c *Client) ListPendingCctxWithinRatelimit() ([]*crosschaintypes.CrossChain return resp.CrossChainTx, resp.TotalPending, resp.CurrentWithdrawWindow, resp.CurrentWithdrawRate, resp.RateLimitExceeded, nil } +// GetAbortedZetaAmount returns the amount of zeta that has been aborted func (c *Client) GetAbortedZetaAmount() (string, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.ZetaAccounting(context.Background(), &crosschaintypes.QueryZetaAccountingRequest{}) @@ -194,6 +205,7 @@ func (c *Client) GetAbortedZetaAmount() (string, error) { return resp.AbortedZetaAmount, nil } +// GetGenesisSupply returns the genesis supply func (c *Client) GetGenesisSupply() (sdkmath.Int, error) { tmURL := fmt.Sprintf("http://%s", c.cfg.ChainRPC) s, err := tmhttp.New(tmURL, "/websocket") @@ -212,6 +224,7 @@ func (c *Client) GetGenesisSupply() (sdkmath.Int, error) { return bankstate.Supply.AmountOf(config.BaseDenom), nil } +// GetZetaTokenSupplyOnNode returns the zeta token supply on the node func (c *Client) GetZetaTokenSupplyOnNode() (sdkmath.Int, error) { client := banktypes.NewQueryClient(c.grpcConn) resp, err := client.SupplyOf(context.Background(), &banktypes.QuerySupplyOfRequest{Denom: config.BaseDenom}) @@ -221,6 +234,7 @@ func (c *Client) GetZetaTokenSupplyOnNode() (sdkmath.Int, error) { return resp.GetAmount().Amount, nil } +// GetLastBlockHeight returns the last block height func (c *Client) GetLastBlockHeight() ([]*crosschaintypes.LastBlockHeight, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.LastBlockHeightAll(context.Background(), &crosschaintypes.QueryAllLastBlockHeightRequest{}) @@ -231,6 +245,7 @@ func (c *Client) GetLastBlockHeight() ([]*crosschaintypes.LastBlockHeight, error return resp.LastBlockHeight, nil } +// GetLatestZetaBlock returns the latest zeta block func (c *Client) GetLatestZetaBlock() (*tmservice.Block, error) { client := tmservice.NewServiceClient(c.grpcConn) res, err := client.GetLatestBlock(context.Background(), &tmservice.GetLatestBlockRequest{}) @@ -240,6 +255,7 @@ func (c *Client) GetLatestZetaBlock() (*tmservice.Block, error) { return res.SdkBlock, nil } +// GetNodeInfo returns the node info func (c *Client) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { var err error @@ -254,18 +270,7 @@ func (c *Client) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { return nil, err } -func (c *Client) GetLastBlockHeightByChain(chain chains.Chain) (*crosschaintypes.LastBlockHeight, error) { - client := crosschaintypes.NewQueryClient(c.grpcConn) - resp, err := client.LastBlockHeight( - context.Background(), - &crosschaintypes.QueryGetLastBlockHeightRequest{Index: chain.ChainName.String()}, - ) - if err != nil { - return nil, err - } - return resp.LastBlockHeight, nil -} - +// GetBlockHeight returns the zetachain block height func (c *Client) GetBlockHeight() (int64, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.LastZetaHeight(context.Background(), &crosschaintypes.QueryLastZetaHeightRequest{}) @@ -275,6 +280,7 @@ func (c *Client) GetBlockHeight() (int64, error) { return resp.Height, nil } +// GetBaseGasPrice returns the base gas price func (c *Client) GetBaseGasPrice() (int64, error) { client := feemarkettypes.NewQueryClient(c.grpcConn) resp, err := client.Params(context.Background(), &feemarkettypes.QueryParamsRequest{}) @@ -287,6 +293,7 @@ func (c *Client) GetBaseGasPrice() (int64, error) { return resp.Params.BaseFee.Int64(), nil } +// GetBallotByID returns a ballot by ID func (c *Client) GetBallotByID(id string) (*observertypes.QueryBallotByIdentifierResponse, error) { client := observertypes.NewQueryClient(c.grpcConn) return client.BallotByIdentifier(context.Background(), &observertypes.QueryBallotByIdentifierRequest{ @@ -294,6 +301,7 @@ func (c *Client) GetBallotByID(id string) (*observertypes.QueryBallotByIdentifie }) } +// GetNonceByChain returns the nonce by chain func (c *Client) GetNonceByChain(chain chains.Chain) (observertypes.ChainNonces, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.ChainNonces( @@ -306,6 +314,7 @@ func (c *Client) GetNonceByChain(chain chains.Chain) (observertypes.ChainNonces, return resp.ChainNonces, nil } +// GetAllNodeAccounts returns all node accounts func (c *Client) GetAllNodeAccounts() ([]*observertypes.NodeAccount, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.NodeAccountAll(context.Background(), &observertypes.QueryAllNodeAccountRequest{}) @@ -316,6 +325,7 @@ func (c *Client) GetAllNodeAccounts() ([]*observertypes.NodeAccount, error) { return resp.NodeAccount, nil } +// GetKeyGen returns the keygen func (c *Client) GetKeyGen() (*observertypes.Keygen, error) { var err error client := observertypes.NewQueryClient(c.grpcConn) @@ -330,6 +340,7 @@ func (c *Client) GetKeyGen() (*observertypes.Keygen, error) { return nil, fmt.Errorf("failed to get keygen | err %s", err.Error()) } +// GetBallot returns a ballot by ID func (c *Client) GetBallot(ballotIdentifier string) (*observertypes.QueryBallotByIdentifierResponse, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.BallotByIdentifier(context.Background(), &observertypes.QueryBallotByIdentifierRequest{ @@ -341,6 +352,7 @@ func (c *Client) GetBallot(ballotIdentifier string) (*observertypes.QueryBallotB return resp, nil } +// GetInboundTrackersForChain returns the inbound trackers for a chain func (c *Client) GetInboundTrackersForChain(chainID int64) ([]crosschaintypes.InboundTracker, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.InboundTrackerAllByChain( @@ -353,6 +365,7 @@ func (c *Client) GetInboundTrackersForChain(chainID int64) ([]crosschaintypes.In return resp.InboundTracker, nil } +// GetCurrentTss returns the current TSS func (c *Client) GetCurrentTss() (observertypes.TSS, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.TSS(context.Background(), &observertypes.QueryGetTSSRequest{}) @@ -362,6 +375,8 @@ func (c *Client) GetCurrentTss() (observertypes.TSS, error) { return resp.TSS, nil } +// GetEthTssAddress returns the ETH TSS address +// TODO(revamp): rename to EVM func (c *Client) GetEthTssAddress() (string, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.GetTssAddress(context.Background(), &observertypes.QueryGetTssAddressRequest{}) @@ -371,6 +386,7 @@ func (c *Client) GetEthTssAddress() (string, error) { return resp.Eth, nil } +// GetBtcTssAddress returns the BTC TSS address func (c *Client) GetBtcTssAddress(chainID int64) (string, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.GetTssAddress(context.Background(), &observertypes.QueryGetTssAddressRequest{ @@ -382,6 +398,7 @@ func (c *Client) GetBtcTssAddress(chainID int64) (string, error) { return resp.Btc, nil } +// GetTssHistory returns the TSS history func (c *Client) GetTssHistory() ([]observertypes.TSS, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.TssHistory(context.Background(), &observertypes.QueryTssHistoryRequest{}) @@ -391,6 +408,7 @@ func (c *Client) GetTssHistory() ([]observertypes.TSS, error) { return resp.TssList, nil } +// GetOutboundTracker returns the outbound tracker for a chain and nonce func (c *Client) GetOutboundTracker(chain chains.Chain, nonce uint64) (*crosschaintypes.OutboundTracker, error) { client := crosschaintypes.NewQueryClient(c.grpcConn) resp, err := client.OutboundTracker(context.Background(), &crosschaintypes.QueryGetOutboundTrackerRequest{ @@ -403,6 +421,7 @@ func (c *Client) GetOutboundTracker(chain chains.Chain, nonce uint64) (*crosscha return &resp.OutboundTracker, nil } +// GetAllOutboundTrackerByChain returns all outbound trackers for a chain func (c *Client) GetAllOutboundTrackerByChain( chainID int64, order interfaces.Order, @@ -437,6 +456,7 @@ func (c *Client) GetAllOutboundTrackerByChain( return resp.OutboundTracker, nil } +// GetPendingNoncesByChain returns the pending nonces for a chain and current tss address func (c *Client) GetPendingNoncesByChain(chainID int64) (observertypes.PendingNonces, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.PendingNoncesByChain( @@ -449,6 +469,7 @@ func (c *Client) GetPendingNoncesByChain(chainID int64) (observertypes.PendingNo return resp.PendingNonces, nil } +// GetBlockHeaderChainState returns the block header chain state func (c *Client) GetBlockHeaderChainState(chainID int64) (lightclienttypes.QueryGetChainStateResponse, error) { client := lightclienttypes.NewQueryClient(c.grpcConn) resp, err := client.ChainState(context.Background(), &lightclienttypes.QueryGetChainStateRequest{ChainId: chainID}) @@ -458,6 +479,7 @@ func (c *Client) GetBlockHeaderChainState(chainID int64) (lightclienttypes.Query return *resp, nil } +// GetSupportedChains returns the supported chains func (c *Client) GetSupportedChains() ([]*chains.Chain, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.SupportedChains(context.Background(), &observertypes.QuerySupportedChains{}) @@ -467,6 +489,7 @@ func (c *Client) GetSupportedChains() ([]*chains.Chain, error) { return resp.GetChains(), nil } +// GetPendingNonces returns the pending nonces func (c *Client) GetPendingNonces() (*observertypes.QueryAllPendingNoncesResponse, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.PendingNoncesAll(context.Background(), &observertypes.QueryAllPendingNoncesRequest{}) @@ -476,6 +499,7 @@ func (c *Client) GetPendingNonces() (*observertypes.QueryAllPendingNoncesRespons return resp, nil } +// Prove returns whether a proof is valid func (c *Client) Prove( blockHash string, txHash string, @@ -497,6 +521,7 @@ func (c *Client) Prove( return resp.Valid, nil } +// HasVoted returns whether an observer has voted func (c *Client) HasVoted(ballotIndex string, voterAddress string) (bool, error) { client := observertypes.NewQueryClient(c.grpcConn) resp, err := client.HasVoted(context.Background(), &observertypes.QueryHasVotedRequest{ @@ -509,6 +534,7 @@ func (c *Client) HasVoted(ballotIndex string, voterAddress string) (bool, error) return resp.HasVoted, nil } +// GetZetaHotKeyBalance returns the zeta hot key balance func (c *Client) GetZetaHotKeyBalance() (sdkmath.Int, error) { client := banktypes.NewQueryClient(c.grpcConn) address, err := c.keys.GetAddress() diff --git a/zetaclient/zetacore/query_test.go b/zetaclient/zetacore/query_test.go index 05d52fc088..70898b8e11 100644 --- a/zetaclient/zetacore/query_test.go +++ b/zetaclient/zetacore/query_test.go @@ -461,30 +461,6 @@ func TestZetacore_GetNodeInfo(t *testing.T) { require.Equal(t, expectedOutput, *resp) } -func TestZetacore_GetLastBlockHeightByChain(t *testing.T) { - index := chains.BscMainnet - expectedOutput := crosschainTypes.QueryGetLastBlockHeightResponse{ - LastBlockHeight: &crosschainTypes.LastBlockHeight{ - Index: index.ChainName.String(), - Chain: "7000", - LastOutboundHeight: 2134123, - LastInboundHeight: 1234333, - }, - } - input := crosschainTypes.QueryGetLastBlockHeightRequest{Index: index.ChainName.String()} - method := "/zetachain.zetacore.crosschain.Query/LastBlockHeight" - server := setupMockServer(t, crosschainTypes.RegisterQueryServer, method, input, expectedOutput) - server.Serve() - defer closeMockServer(t, server) - - client, err := setupZetacoreClient() - require.NoError(t, err) - - resp, err := client.GetLastBlockHeightByChain(index) - require.NoError(t, err) - require.Equal(t, expectedOutput.LastBlockHeight, resp) -} - func TestZetacore_GetZetaBlockHeight(t *testing.T) { expectedOutput := crosschainTypes.QueryLastZetaHeightResponse{Height: 12345} input := crosschainTypes.QueryLastZetaHeightRequest{} diff --git a/zetaclient/zetacore/tx.go b/zetaclient/zetacore/tx.go index 798654856f..0a28336b04 100644 --- a/zetaclient/zetacore/tx.go +++ b/zetaclient/zetacore/tx.go @@ -24,6 +24,7 @@ import ( ) // GetInboundVoteMessage returns a new MsgVoteInbound +// TODO(revamp): move to a different file func GetInboundVoteMessage( sender string, senderChain int64, @@ -69,6 +70,8 @@ func GasPriceMultiplier(chainID int64) (float64, error) { return 0, fmt.Errorf("cannot get gas price multiplier for unknown chain %d", chainID) } +// WrapMessageWithAuthz wraps a message with an authz message +// used since a hotkey is used to broadcast the transactions, instead of the operator func (c *Client) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, clientauthz.Signer, error) { msgURL := sdk.MsgTypeURL(msg) @@ -82,6 +85,8 @@ func (c *Client) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, clientauthz.Signer, return &authzMessage, authzSigner, nil } +// PostGasPrice posts a gas price vote +// TODO(revamp): rename to PostVoteGasPrice func (c *Client) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string, blockNum uint64) (string, error) { // apply gas price multiplier for the chain multiplier, err := GasPriceMultiplier(chain.ChainId) @@ -110,6 +115,8 @@ func (c *Client) PostGasPrice(chain chains.Chain, gasPrice uint64, supply string return "", fmt.Errorf("post gasprice failed after %d retries", DefaultRetryInterval) } +// AddOutboundTracker adds an outbound tracker +// TODO(revamp): rename to PostAddOutboundTracker func (c *Client) AddOutboundTracker( chainID int64, nonce uint64, @@ -143,6 +150,8 @@ func (c *Client) AddOutboundTracker( return zetaTxHash, nil } +// SetTSS sends message to vote tss +// TODO(revamp): rename to PostVoteTSS func (c *Client) SetTSS(tssPubkey string, keyGenZetaHeight int64, status chains.ReceiveStatus) (string, error) { signerAddress := c.keys.GetOperatorAddress().String() msg := observertypes.NewMsgVoteTSS(signerAddress, tssPubkey, keyGenZetaHeight, status) @@ -166,6 +175,8 @@ func (c *Client) SetTSS(tssPubkey string, keyGenZetaHeight int64, status chains. } // ZetacoreContextUpdater is a polling goroutine that checks and updates zetacore context at every height +// TODO(revamp): move to a different file +// TODO(revamp): rename to UpdateZetacoreContext func (c *Client) ZetacoreContextUpdater(appContext *appcontext.AppContext) { c.logger.Info().Msg("ZetacoreContextUpdater started") ticker := time.NewTicker(time.Duration(appContext.Config().ConfigUpdateTicker) * time.Second) @@ -185,6 +196,8 @@ func (c *Client) ZetacoreContextUpdater(appContext *appcontext.AppContext) { } } +// PostBlameData posts blame data message to zetacore +// TODO(revamp): rename to PostVoteBlame func (c *Client) PostBlameData(blame *blame.Blame, chainID int64, index string) (string, error) { signerAddress := c.keys.GetOperatorAddress().String() zetaBlame := observertypes.Blame{ @@ -212,6 +225,7 @@ func (c *Client) PostBlameData(blame *blame.Blame, chainID int64, index string) return "", fmt.Errorf("post blame data failed after %d retries", DefaultRetryCount) } +// PostVoteBlockHeader posts a vote on an observed block header func (c *Client) PostVoteBlockHeader( chainID int64, blockHash []byte, @@ -280,6 +294,7 @@ func (c *Client) PostVoteInbound(gasLimit, retryGasLimit uint64, msg *types.MsgV // MonitorVoteInboundResult monitors the result of a vote inbound tx // retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas // if retryGasLimit is 0, the tx is not resent +// TODO(revamp): move to a monitor file func (c *Client) MonitorVoteInboundResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteInbound) { var lastErr error @@ -330,6 +345,7 @@ func (c *Client) MonitorVoteInboundResult(zetaTxHash string, retryGasLimit uint6 } // PostVoteOutbound posts a vote on an observed outbound tx +// TODO(revamp): rename and move to a different file func (c *Client) PostVoteOutbound( cctxIndex string, outboundHash string, @@ -372,6 +388,7 @@ func (c *Client) PostVoteOutbound( } // PostVoteOutboundFromMsg posts a vote on an observed outbound tx from a MsgVoteOutbound +// TODO(revamp): rename to PostVoteOutbound func (c *Client) PostVoteOutboundFromMsg( gasLimit, retryGasLimit uint64, msg *types.MsgVoteOutbound, @@ -412,6 +429,7 @@ func (c *Client) PostVoteOutboundFromMsg( // MonitorVoteOutboundResult monitors the result of a vote outbound tx // retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas // if retryGasLimit is 0, the tx is not resent +// TODO(revamp): move to a monitor file func (c *Client) MonitorVoteOutboundResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOutbound) { var lastErr error