Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/zeta-chain/node into sup…
Browse files Browse the repository at this point in the history
…port-multiple-btc-chains
  • Loading branch information
ws4charlie committed Sep 13, 2024
2 parents b1ee2eb + 75a4189 commit 31eaed1
Show file tree
Hide file tree
Showing 19 changed files with 953 additions and 229 deletions.
48 changes: 36 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@

### Features

* [2633](https://github.com/zeta-chain/node/pull/2633) - support for stateful precompiled contracts
* [2788](https://github.com/zeta-chain/node/pull/2788) - add common importable zetacored rpc package
* [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

### Refactor

* [2749](https://github.com/zeta-chain/node/pull/2749) - fix all lint errors from govet
* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx to receive tsspubkey as an argument
* [2802](https://github.com/zeta-chain/node/pull/2802) - set default liquidity cap for new ZRC20s
* [2826](https://github.com/zeta-chain/node/pull/2826) - remove unused code from emissions module and add new parameter for fixed block reward amount

### Tests

* [2661](https://github.com/zeta-chain/node/pull/2661) - update connector and erc20Custody addresses in tss migration e2e tests
* [2703](https://github.com/zeta-chain/node/pull/2703) - add e2e tests for stateful precompiled contracts
* [2830](https://github.com/zeta-chain/node/pull/2830) - extend staking precompile tests
* [2867](https://github.com/zeta-chain/node/pull/2867) - skip precompiles test for tss migration

### 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
* [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

## v20.0.0

### Features

* [2578](https://github.com/zeta-chain/node/pull/2578) - add Gateway address in protocol contract list
* [2630](https://github.com/zeta-chain/node/pull/2630) - implement `MsgMigrateERC20CustodyFunds` to migrate the funds from the ERC20Custody to a new contracts (to be used for the new ERC20Custody contract for smart contract V2)
* [2578](https://github.com/zeta-chain/node/pull/2578) - Add Gateway address in protocol contract list
Expand All @@ -20,31 +52,23 @@
* [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
* [2825](https://github.com/zeta-chain/node/pull/2825) - add Bitcoin inscriptions support

### Refactor

* [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers
* [2749](https://github.com/zeta-chain/node/pull/2749) - fix all lint errors from govet
* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx to receive tsspubkey as an argument
* [2802](https://github.com/zeta-chain/node/pull/2802) - set default liquidity cap for new ZRC20s
* [2826](https://github.com/zeta-chain/node/pull/2826) - remove unused code from emissions module and add new parameter for fixed block reward amount
* [2855](https://github.com/zeta-chain/node/pull/2855) - disable Bitcoin witness support for mainnet

### Tests

* [2661](https://github.com/zeta-chain/node/pull/2661) - update connector and erc20Custody addresses in tss migration e2e tests
* [2726](https://github.com/zeta-chain/node/pull/2726) - add e2e tests for deposit and call, deposit and revert
* [2703](https://github.com/zeta-chain/node/pull/2703) - add e2e tests for stateful precompiled contracts
* [2763](https://github.com/zeta-chain/node/pull/2763) - add V2 contracts migration test
* [2830] (https://github.com/zeta-chain/node/pull/2830) - extend staking precompile tests
* [2821](https://github.com/zeta-chain/node/pull/2821) - V2 protocol contracts migration e2e tests

### Fixes

* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module
* [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
* [2787](https://github.com/zeta-chain/node/pull/2787) - ask for 3 accounts (signer, pda, system_program) on solana gateway deposit
* [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
* [2824](https://github.com/zeta-chain/node/pull/2824) - fix Solana deposit number

## v19.0.0

Expand Down
2 changes: 1 addition & 1 deletion contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if [ "$LOCALNET_MODE" == "tss-migrate" ]; then
echo "waiting 10 seconds for node to restart"
sleep 10

zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof
zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof --skip-precompiles
ZETAE2E_EXIT_CODE=$?
if [ $ZETAE2E_EXIT_CODE -eq 0 ]; then
echo "E2E passed after migration"
Expand Down
9 changes: 9 additions & 0 deletions x/crosschain/keeper/grpc_query_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (

// MaxLookbackNonce is the maximum number of nonces to look back to find missed pending cctxs
MaxLookbackNonce = 1000

DefaultPageSize = 100
)

func (k Keeper) ZetaAccounting(
Expand All @@ -46,6 +48,13 @@ func (k Keeper) CctxAll(c context.Context, req *types.QueryAllCctxRequest) (*typ
store := ctx.KVStore(k.storeKey)
sendStore := prefix.NewStore(store, types.KeyPrefix(types.CCTXKey))

if req.Pagination == nil {
req.Pagination = &query.PageRequest{}
}
if req.Pagination.Limit == 0 {
req.Pagination.Limit = DefaultPageSize
}

pageRes, err := query.Paginate(sendStore, req.Pagination, func(_ []byte, value []byte) error {
var send types.CrossChainTx
if err := k.cdc.Unmarshal(value, &send); err != nil {
Expand Down
38 changes: 38 additions & 0 deletions x/crosschain/keeper/grpc_query_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"

keepertest "github.com/zeta-chain/node/testutil/keeper"
Expand Down Expand Up @@ -288,3 +289,40 @@ func TestKeeper_CctxByNonce(t *testing.T) {
require.Equal(t, res.CrossChainTx.CctxStatus.LastUpdateTimestamp, ctx.BlockTime().Unix())
})
}

func TestKeeper_CctxAll(t *testing.T) {
t.Run("empty request", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
_, err := k.CctxAll(ctx, &types.QueryAllCctxRequest{})
require.NoError(t, err)
})

t.Run("default page size", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
chainID := getValidEthChainID()
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
_ = createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk)

res, err := k.CctxAll(ctx, &types.QueryAllCctxRequest{})
require.NoError(t, err)
require.Len(t, res.CrossChainTx, keeper.DefaultPageSize)
})

t.Run("page size provided", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
chainID := getValidEthChainID()
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
_ = createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk)
testPageSize := 200

res, err := k.CctxAll(ctx, &types.QueryAllCctxRequest{
Pagination: &query.PageRequest{
Limit: uint64(testPageSize),
},
})
require.NoError(t, err)
require.Len(t, res.CrossChainTx, testPageSize)
})
}
5 changes: 5 additions & 0 deletions zetaclient/chains/evm/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ func (ob *Observer) ObserveInbound(ctx context.Context, sampledLogger zerolog.Lo
return errors.Wrap(err, "unable to observe TSSReceive")
}

// task 4: filter the outbounds from TSS address to supplement outbound trackers
// TODO: make this a separate go routine in outbound.go after switching to smart contract V2
//
ob.FilterTSSOutbound(ctx, startBlock, toBlock)

// query the gateway logs
// TODO: refactor in a more declarative design. Example: storing the list of contract and events to listen in an array
// https://github.com/zeta-chain/node/issues/2493
Expand Down
85 changes: 58 additions & 27 deletions zetaclient/chains/evm/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package observer_test
import (
"context"
"encoding/hex"
"errors"
"testing"

ethcommon "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/onrik/ethrpc"
"github.com/rs/zerolog"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
zctx "github.com/zeta-chain/node/zetaclient/context"
"github.com/zeta-chain/node/zetaclient/keys"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/zeta-chain/node/pkg/coin"
"github.com/zeta-chain/node/pkg/constant"
"github.com/zeta-chain/node/zetaclient/chains/evm"
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
"github.com/zeta-chain/node/zetaclient/config"
"github.com/zeta-chain/node/zetaclient/testutils"
"github.com/zeta-chain/node/zetaclient/testutils/mocks"
Expand Down Expand Up @@ -461,42 +464,70 @@ func Test_ObserveTSSReceiveInBlock(t *testing.T) {
blockNumber := receipt.BlockNumber.Uint64()
block := testutils.LoadEVMBlock(t, TestDataDir, chainID, blockNumber, true)

// create mock client
evmClient := mocks.NewMockEvmClient()
evmJSONRPC := mocks.NewMockJSONRPCClient()
// create mock zetacore client
tss := mocks.NewTSSMainnet()
lastBlock := receipt.BlockNumber.Uint64() + confirmation

zetacoreClient := mocks.NewZetacoreClient(t).
WithKeys(&keys.Keys{}).
WithZetaChain().
WithPostVoteInbound("", "").
WithPostVoteInbound("", "")

ctx := context.Background()

t.Run("should observe TSS receive in block", func(t *testing.T) {
ob, _ := MockEVMObserver(t, chain, evmClient, evmJSONRPC, zetacoreClient, tss, lastBlock, chainParam)
// test cases
tests := []struct {
name string
evmClient interfaces.EVMRPCClient
jsonClient interfaces.EVMJSONRPCClient
errMsg string
}{
{
name: "should observe TSS receive in block",
evmClient: func() interfaces.EVMRPCClient {
// feed block number and receipt to mock client
evmClient := mocks.NewEVMRPCClient(t)
evmClient.On("BlockNumber", mock.Anything).Return(uint64(1000), nil)
evmClient.On("TransactionReceipt", mock.Anything, mock.Anything).Return(receipt, nil)
return evmClient
}(),
jsonClient: mocks.NewMockJSONRPCClient().WithBlock(block),
errMsg: "",
},
{
name: "should not observe on error getting block",
evmClient: func() interfaces.EVMRPCClient {
// feed block number to allow construction of observer
evmClient := mocks.NewEVMRPCClient(t)
evmClient.On("BlockNumber", mock.Anything).Return(uint64(1000), nil)
return evmClient
}(),
jsonClient: mocks.NewMockJSONRPCClient(), // no block
errMsg: "error getting block",
},
{
name: "should not observe on error getting receipt",
evmClient: func() interfaces.EVMRPCClient {
// feed block number but RPC error on getting receipt
evmClient := mocks.NewEVMRPCClient(t)
evmClient.On("BlockNumber", mock.Anything).Return(uint64(1000), nil)
evmClient.On("TransactionReceipt", mock.Anything, mock.Anything).Return(nil, errors.New("RPC error"))
return evmClient
}(),
jsonClient: mocks.NewMockJSONRPCClient().WithBlock(block),
errMsg: "error getting receipt",
},
}

// feed archived block and receipt
evmJSONRPC.WithBlock(block)
evmClient.WithReceipt(receipt)
err := ob.ObserveTSSReceiveInBlock(ctx, blockNumber)
require.NoError(t, err)
})
t.Run("should not observe on error getting block", func(t *testing.T) {
ob, _ := MockEVMObserver(t, chain, evmClient, evmJSONRPC, zetacoreClient, tss, lastBlock, chainParam)
err := ob.ObserveTSSReceiveInBlock(ctx, blockNumber)
// error getting block is expected because the mock JSONRPC contains no block
require.ErrorContains(t, err, "error getting block")
})
t.Run("should not observe on error getting receipt", func(t *testing.T) {
ob, _ := MockEVMObserver(t, chain, evmClient, evmJSONRPC, zetacoreClient, tss, lastBlock, chainParam)
evmJSONRPC.WithBlock(block)
err := ob.ObserveTSSReceiveInBlock(ctx, blockNumber)
// error getting block is expected because the mock evmClient contains no receipt
require.ErrorContains(t, err, "error getting receipt")
})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ob, _ := MockEVMObserver(t, chain, tt.evmClient, tt.jsonClient, zetacoreClient, tss, lastBlock, chainParam)
err := ob.ObserveTSSReceiveInBlock(context.Background(), blockNumber)
if tt.errMsg != "" {
require.ErrorContains(t, err, tt.errMsg)
} else {
require.NoError(t, err)
}
})
}
}

func makeAppContext(t *testing.T) (context.Context, *zctx.AppContext) {
Expand Down
20 changes: 11 additions & 9 deletions zetaclient/chains/evm/observer/observer_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func TestPostGasPrice(t *testing.T) {
t.Run("Pre EIP-1559 doesn't support priorityFee", func(t *testing.T) {
// ARRANGE
// Given ETH rpc mock
ethRPC := mocks.NewMockEvmClient().WithBlockNumber(blockNumber)
ethRPC := mocks.NewEVMRPCClient(t)
ethRPC.On("BlockNumber", mock.Anything).Return(uint64(blockNumber), nil)

// Given zetacore client mock
zetacoreClient := mocks.NewZetacoreClient(t).WithZetaChain()
Expand All @@ -37,10 +38,11 @@ func TestPostGasPrice(t *testing.T) {
observer, _ := MockEVMObserver(t, chain, ethRPC, nil, zetacoreClient, nil, blockNumber, chainParam)

// Given empty baseFee from RPC
ethRPC.WithHeader(&ethtypes.Header{BaseFee: nil})
ethRPC.On("HeaderByNumber", anything, anything).Return(&ethtypes.Header{BaseFee: nil}, nil)

// Given gas price from RPC
ethRPC.WithSuggestGasPrice(big.NewInt(3 * gwei))
// Given gasPrice and priorityFee from RPC
ethRPC.On("SuggestGasPrice", anything).Return(big.NewInt(3*gwei), nil)
ethRPC.On("SuggestGasTipCap", anything).Return(big.NewInt(0), nil)

// Given mock collector for zetacore call
// PostVoteGasPrice(ctx, chain, gasPrice, priorityFee, blockNum)
Expand Down Expand Up @@ -69,7 +71,8 @@ func TestPostGasPrice(t *testing.T) {
t.Run("Post EIP-1559 supports priorityFee", func(t *testing.T) {
// ARRANGE
// Given ETH rpc mock
ethRPC := mocks.NewMockEvmClient().WithBlockNumber(blockNumber)
ethRPC := mocks.NewEVMRPCClient(t)
ethRPC.On("BlockNumber", mock.Anything).Return(uint64(blockNumber), nil)

// Given zetacore client mock
zetacoreClient := mocks.NewZetacoreClient(t).WithZetaChain()
Expand All @@ -82,12 +85,11 @@ func TestPostGasPrice(t *testing.T) {
observer, _ := MockEVMObserver(t, chain, ethRPC, nil, zetacoreClient, nil, blockNumber, chainParam)

// Given 1 gwei baseFee from RPC
ethRPC.WithHeader(&ethtypes.Header{BaseFee: big.NewInt(gwei)})
ethRPC.On("HeaderByNumber", anything, anything).Return(&ethtypes.Header{BaseFee: big.NewInt(gwei)}, nil)

// Given gasPrice and priorityFee from RPC
ethRPC.
WithSuggestGasPrice(big.NewInt(3 * gwei)).
WithSuggestGasTipCap(big.NewInt(2 * gwei))
ethRPC.On("SuggestGasPrice", anything).Return(big.NewInt(3*gwei), nil)
ethRPC.On("SuggestGasTipCap", anything).Return(big.NewInt(2*gwei), nil)

// Given mock collector for zetacore call
// PostVoteGasPrice(ctx, chain, gasPrice, priorityFee, blockNum)
Expand Down
Loading

0 comments on commit 31eaed1

Please sign in to comment.