Skip to content

Commit

Permalink
Merge branch 'develop' into refactor-msgupdatechaininfo
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Sep 19, 2024
2 parents 43359bc + 17f26e6 commit 89db4b8
Show file tree
Hide file tree
Showing 37 changed files with 671 additions and 231 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* [2784](https://github.com/zeta-chain/node/pull/2784) - staking precompiled contract
* [2795](https://github.com/zeta-chain/node/pull/2795) - support restricted address in Solana
* [2861](https://github.com/zeta-chain/node/pull/2861) - emit events from staking precompile
* [2870](https://github.com/zeta-chain/node/pull/2870) - support for multiple Bitcoin chains in the zetaclient
* [2883](https://github.com/zeta-chain/node/pull/2883) - add chain static information for btc signet testnet

### Refactor

Expand All @@ -26,12 +28,15 @@
* [2867](https://github.com/zeta-chain/node/pull/2867) - skip precompiles test for tss migration
* [2833](https://github.com/zeta-chain/node/pull/2833) - add e2e framework for TON blockchain
* [2874](https://github.com/zeta-chain/node/pull/2874) - add support for multiple runs for precompile tests
* [2895](https://github.com/zeta-chain/node/pull/2895) - add e2e test for bitcoin deposit and call
* [2894](https://github.com/zeta-chain/node/pull/2894) - increase gas limit for TSS vote tx

### Fixes

* [2674](https://github.com/zeta-chain/node/pull/2674) - allow operators to vote on ballots associated with discarded keygen without affecting the status of the current keygen.
* [2672](https://github.com/zeta-chain/node/pull/2672) - check observer set for duplicates when adding a new observer or updating an existing one
* [2735](https://github.com/zeta-chain/node/pull/2735) - fix the outbound tracker blocking confirmation and outbound processing on EVM chains by locally index outbound txs in zetaclient
* [2944](https://github.com/zeta-chain/node/pull/2844) - add tsspubkey to index for tss keygen voting
* [2842](https://github.com/zeta-chain/node/pull/2842) - fix: move interval assignment out of cctx loop in EVM outbound tx scheduler
* [2853](https://github.com/zeta-chain/node/pull/2853) - calling precompile through sc with sc state update

Expand Down
14 changes: 9 additions & 5 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,21 @@ func debugCmd(_ *cobra.Command, args []string) error {
fmt.Println("CoinType not detected")
}
fmt.Println("CoinType : ", coinType)
} else if chain.IsUTXO() {
} else if chain.IsBitcoin() {
btcObserver := btcobserver.Observer{}
btcObserver.WithZetacoreClient(client)
btcObserver.WithChain(*chainProto)
btcConfig, found := cfg.GetBTCConfig(chainID)
if !found {
return fmt.Errorf("unable to find config for BTC chain %d", chainID)
}
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Pass: cfg.BitcoinConfig.RPCPassword,
Host: btcConfig.RPCHost,
User: btcConfig.RPCUsername,
Pass: btcConfig.RPCPassword,
HTTPPostMode: true,
DisableTLS: true,
Params: cfg.BitcoinConfig.RPCParams,
Params: btcConfig.RPCParams,
}

btcClient, err := rpcclient.New(connCfg, nil)
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func start(_ *cobra.Command, _ []string) error {
return err
}

startLogger.Info().Msgf("Config is updated from zetacore %s", maskCfg(cfg))
startLogger.Info().Msgf("Config is updated from zetacore\n %s", cfg.StringMasked())

go zetacoreClient.UpdateAppContextWorker(ctx, appContext)

Expand Down Expand Up @@ -230,7 +230,7 @@ func start(_ *cobra.Command, _ []string) error {
return err
}

btcChains := appContext.FilterChains(zctx.Chain.IsUTXO)
btcChains := appContext.FilterChains(zctx.Chain.IsBitcoin)
switch {
case len(btcChains) == 0:
return errors.New("no BTC chains found")
Expand Down
41 changes: 0 additions & 41 deletions cmd/zetaclientd/start_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"net"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -52,43 +51,3 @@ func validatePeer(seedPeer string) error {

return nil
}

// maskCfg sensitive fields are masked, currently only the EVM endpoints and bitcoin credentials,
//
// other fields can be added.
func maskCfg(cfg config.Config) string {
maskedCfg := cfg

maskedCfg.BitcoinConfig = config.BTCConfig{
RPCUsername: cfg.BitcoinConfig.RPCUsername,
RPCPassword: cfg.BitcoinConfig.RPCPassword,
RPCHost: cfg.BitcoinConfig.RPCHost,
RPCParams: cfg.BitcoinConfig.RPCParams,
}
maskedCfg.EVMChainConfigs = map[int64]config.EVMConfig{}
for key, val := range cfg.EVMChainConfigs {
maskedCfg.EVMChainConfigs[key] = config.EVMConfig{
Chain: val.Chain,
Endpoint: val.Endpoint,
}
}

// Mask Sensitive data
for _, chain := range maskedCfg.EVMChainConfigs {
if chain.Endpoint == "" {
continue
}
endpointURL, err := url.Parse(chain.Endpoint)
if err != nil {
continue
}
chain.Endpoint = endpointURL.Hostname()
}

// mask endpoints
maskedCfg.BitcoinConfig.RPCUsername = ""
maskedCfg.BitcoinConfig.RPCPassword = ""
maskedCfg.SolanaConfig.Endpoint = ""

return maskedCfg.String()
}
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {

bitcoinTests := []string{
e2etests.TestBitcoinDepositName,
e2etests.TestBitcoinDepositAndCallName,
e2etests.TestBitcoinDepositRefundName,
e2etests.TestBitcoinWithdrawSegWitName,
e2etests.TestBitcoinWithdrawInvalidAddressName,
Expand Down
1 change: 1 addition & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56986,6 +56986,7 @@ definitions:
- solana_mainnet
- solana_devnet
- solana_localnet
- btc_signet_testnet
default: empty
title: |-
ChainName represents the name of the chain
Expand Down
9 changes: 9 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const (
*/
TestBitcoinDepositName = "bitcoin_deposit"
TestBitcoinDepositRefundName = "bitcoin_deposit_refund"
TestBitcoinDepositAndCallName = "bitcoin_deposit_and_call"
TestBitcoinWithdrawSegWitName = "bitcoin_withdraw_segwit"
TestBitcoinWithdrawTaprootName = "bitcoin_withdraw_taproot"
TestBitcoinWithdrawMultipleName = "bitcoin_withdraw_multiple"
Expand Down Expand Up @@ -451,6 +452,14 @@ var AllE2ETests = []runner.E2ETest{
},
TestBitcoinDeposit,
),
runner.NewE2ETest(
TestBitcoinDepositAndCallName,
"deposit Bitcoin into ZEVM and call a contract",
[]runner.ArgDefinition{
{Description: "amount in btc", DefaultValue: "0.001"},
},
TestBitcoinDepositAndCall,
),
runner.NewE2ETest(
TestBitcoinDepositRefundName,
"deposit Bitcoin into ZEVM; expect refund", []runner.ArgDefinition{
Expand Down
55 changes: 55 additions & 0 deletions e2e/e2etests/test_bitcoin_deposit_call.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package e2etests

import (
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
testcontract "github.com/zeta-chain/node/testutil/contracts"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
zetabitcoin "github.com/zeta-chain/node/zetaclient/chains/bitcoin"
)

func TestBitcoinDepositAndCall(r *runner.E2ERunner, args []string) {
// ARRANGE
// Given BTC address
r.SetBtcAddress(r.Name, false)

// Given "Live" BTC network
stop := r.MineBlocksIfLocalBitcoin()
defer stop()

// Given amount to send
require.Len(r, args, 1)
amount := parseFloat(r, args[0])
amountTotal := amount + zetabitcoin.DefaultDepositorFee

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
require.NotEmpty(r, utxos)

// deploy an example contract in ZEVM
contractAddr, _, contract, err := testcontract.DeployExample(r.ZEVMAuth, r.ZEVMClient)
require.NoError(r, err)
r.Logger.Print("Bitcoin: Example contract deployed at: %s", contractAddr.String())

// ACT
// Send BTC to TSS address with a dummy memo
data := []byte("hello satoshi")
memo := append(contractAddr.Bytes(), data...)
txHash, err := r.SendToTSSFromDeployerWithMemo(amountTotal, utxos, memo)
require.NoError(r, err)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "bitcoin_deposit_and_call")
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined)

// check if example contract has been called, 'bar' value should be set to amount
amoutSats, err := zetabitcoin.GetSatoshis(amount)
require.NoError(r, err)
utils.MustHaveCalledExampleContract(r, contract, big.NewInt(amoutSats))
}
3 changes: 3 additions & 0 deletions e2e/e2etests/test_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func TestWhitelistERC20(r *runner.E2ERunner, _ []string) {
erc20zrc20Addr, err := txserver.FetchAttributeFromTxResponse(res, "zrc20_address")
require.NoError(r, err)

err = r.ZetaTxServer.InitializeLiquidityCap(erc20zrc20Addr)
require.NoError(r, err)

// ensure CCTX created
resCCTX, err := r.CctxClient.Cctx(r.Ctx, &crosschaintypes.QueryGetCctxRequest{Index: whitelistCCTXIndex})
require.NoError(r, err)
Expand Down
5 changes: 4 additions & 1 deletion e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,11 @@ func (r *E2ERunner) SendToTSSFromDeployerWithMemo(
scriptPubkeys[i] = utxo.ScriptPubKey
}

// use static fee 0.0005 BTC to calculate change
feeSats := btcutil.Amount(0.0005 * btcutil.SatoshiPerBitcoin)
amountSats := btcutil.Amount(amount * btcutil.SatoshiPerBitcoin)
amountInt, err := zetabitcoin.GetSatoshis(amount)
require.NoError(r, err)
amountSats := btcutil.Amount(amountInt)
change := inputSats - feeSats - amountSats

if change < 0 {
Expand Down
12 changes: 6 additions & 6 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(zrc20); err != nil {
if err := zts.InitializeLiquidityCap(zrc20); err != nil {
return "", err
}

Expand All @@ -481,7 +481,7 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(zrc20); err != nil {
if err := zts.InitializeLiquidityCap(zrc20); err != nil {
return "", err
}

Expand All @@ -503,7 +503,7 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(zrc20); err != nil {
if err := zts.InitializeLiquidityCap(zrc20); err != nil {
return "", err
}

Expand All @@ -527,7 +527,7 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(erc20zrc20Addr); err != nil {
if err := zts.InitializeLiquidityCap(erc20zrc20Addr); err != nil {
return "", err
}

Expand Down Expand Up @@ -579,8 +579,8 @@ func (zts *ZetaTxServer) SetAuthorityClient(authorityClient authoritytypes.Query
zts.authorityClient = authorityClient
}

// initializeLiquidityCap initializes the liquidity cap for the given coin with a large value
func (zts ZetaTxServer) initializeLiquidityCap(zrc20 string) error {
// InitializeLiquidityCap initializes the liquidity cap for the given coin with a large value
func (zts ZetaTxServer) InitializeLiquidityCap(zrc20 string) error {
liquidityCap := sdktypes.NewUint(1e18).MulUint64(1e12)

msg := fungibletypes.NewMsgUpdateZRC20LiquidityCap(
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ require (

require (
github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae // indirect
github.com/showa-93/go-mask v0.6.2 // indirect
github.com/snksoft/crc v1.1.0 // indirect
github.com/tonkeeper/tongo v1.9.3 // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,8 @@ github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/showa-93/go-mask v0.6.2 h1:sJEUQRpbxUoMTfBKey5K9hCg+eSx5KIAZFT7pa1LXbM=
github.com/showa-93/go-mask v0.6.2/go.mod h1:aswIj007gm0EPAzOGES9ACy1jDm3QT08/LPSClMp410=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down
16 changes: 10 additions & 6 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ func GetChainFromChainID(chainID int64, additionalChains []Chain) (Chain, bool)
// GetBTCChainParams returns the bitcoin chain config params from the chain ID
func GetBTCChainParams(chainID int64) (*chaincfg.Params, error) {
switch chainID {
case 18444:
case BitcoinRegtest.ChainId:
return &chaincfg.RegressionNetParams, nil
case 18332:
case BitcoinTestnet.ChainId:
return &chaincfg.TestNet3Params, nil
case 8332:
case BitcoinMainnet.ChainId:
return &chaincfg.MainNetParams, nil
case BitcoinSignetTestnet.ChainId:
return &chaincfg.SigNetParams, nil
default:
return nil, fmt.Errorf("error chainID %d is not a bitcoin chain", chainID)
}
Expand All @@ -182,11 +184,13 @@ func GetBTCChainParams(chainID int64) (*chaincfg.Params, error) {
func GetBTCChainIDFromChainParams(params *chaincfg.Params) (int64, error) {
switch params.Name {
case chaincfg.RegressionNetParams.Name:
return 18444, nil
return BitcoinRegtest.ChainId, nil
case chaincfg.TestNet3Params.Name:
return 18332, nil
return BitcoinTestnet.ChainId, nil
case chaincfg.MainNetParams.Name:
return 8332, nil
return BitcoinMainnet.ChainId, nil
case chaincfg.SigNetParams.Name:
return BitcoinSignetTestnet.ChainId, nil
default:
return 0, fmt.Errorf("error chain %s is not a bitcoin chain", params.Name)
}
Expand Down
Loading

0 comments on commit 89db4b8

Please sign in to comment.