Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera authored Nov 5, 2024
2 parents a9a3f09 + ad73744 commit 8ffdac0
Show file tree
Hide file tree
Showing 50 changed files with 854 additions and 358 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
timeout-minutes: 15
# do not run this on forks as they are not installable
# it will still be check in the merge queue in this case
if: github.repository == 'zeta-chain/node'
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'zeta-chain/node'
steps:
- uses: actions/checkout@v4
- name: Set up Go
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ jobs:
runs-on: ${{ vars.RELEASE_RUNNER }}
steps:
- uses: actions/checkout@v4
- name: Release build dry-run
- name: Build release snapshot
run: |
make release-dry-run
make release-snapshot
check-changelog:
needs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Login to Docker Hub registry
uses: docker/login-action@v3
if: (github.event_name == 'push' && github.repository == 'zeta-chain/node') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'zeta-chain/node')
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'zeta-chain/node'
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_READ_ONLY }}
Expand Down
9 changes: 7 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ builds:
- -X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd
- -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }}
- -X github.com/cosmos/cosmos-sdk/version.Commit={{ .FullCommit }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb
- -X github.com/zeta-chain/node/pkg/constant.Name=zetacored
- -X github.com/zeta-chain/node/pkg/constant.Version={{ .Version }}
- -X github.com/zeta-chain/node/pkg/constant.CommitHash={{ .FullCommit }}
- -X github.com/zeta-chain/node/pkg/constant.BuildTime={{ .Env.BUILDTIME }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb
- -X github.com/zeta-chain/node/pkg/constant.BuildTime={{ .CommitDate }}
- -X main.version={{ .Version }}
- -X main.commit={{ .Commit }}
- -X main.date={{ .CommitDate }}
- -buildid=
- -s -w

- id: "zetaclientd"
main: ./cmd/zetaclientd
Expand Down
46 changes: 21 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@
PACKAGE_NAME := github.com/zeta-chain/node
NODE_VERSION := $(shell ./version.sh)
NODE_COMMIT := $(shell [ -z "${NODE_COMMIT}" ] && git log -1 --format='%H' || echo ${NODE_COMMIT} )
BUILDTIME := $(shell date -u +"%Y%m%d.%H%M%S" )
DOCKER ?= docker
# allow setting of NODE_COMPOSE_ARGS to pass additional args to docker compose
# useful for setting profiles and/ort optional overlays
# example: NODE_COMPOSE_ARGS="--profile monitoring -f docker-compose-persistent.yml"
DOCKER_COMPOSE ?= $(DOCKER) compose -f docker-compose.yml $(NODE_COMPOSE_ARGS)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
GOFLAGS := ""
GOLANG_CROSS_VERSION ?= v1.22.7
GOPATH ?= '$(HOME)/go'

# common goreaser command definition
GOLANG_CROSS_VERSION ?= v1.22.7@sha256:24b2d75007f0ec8e35d01f3a8efa40c197235b200a1a91422d78b851f67ecce4
GORELEASER := $(DOCKER) run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
-e "GITHUB_TOKEN=${GITHUB_TOKEN}" \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION}

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \
-X github.com/cosmos/cosmos-sdk/version.ServerName=zetacored \
-X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(NODE_VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(NODE_COMMIT) \
-X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb \
-X github.com/zeta-chain/node/pkg/constant.Name=zetacored \
-X github.com/zeta-chain/node/pkg/constant.Version=$(NODE_VERSION) \
-X github.com/zeta-chain/node/pkg/constant.CommitHash=$(NODE_COMMIT) \
-X github.com/zeta-chain/node/pkg/constant.BuildTime=$(BUILDTIME) \
-X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb
-buildid= \
-s -w

BUILD_FLAGS := -ldflags '$(ldflags)' -tags pebbledb,ledger

Expand Down Expand Up @@ -429,33 +440,18 @@ test-sim-after-import-long
### GoReleaser ###
###############################################################################

release-dry-run:
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v ${GOPATH}/pkg:/go/pkg \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish --snapshot
release-snapshot:
$(GORELEASER) --clean --skip=validate --skip=publish --snapshot

release-build-only:
$(GORELEASER) --clean --skip=validate --skip=publish

release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-e "GITHUB_TOKEN=${GITHUB_TOKEN}" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --skip=validate
$(GORELEASER) --clean --skip=validate

###############################################################################
### Local Mainnet Development ###
Expand Down
2 changes: 1 addition & 1 deletion app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type EVMKeeper interface {
statedb.Keeper
DynamicFeeEVMKeeper

NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
NewEVM(ctx sdk.Context, msg *core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
ResetTransientGasUsed(ctx sdk.Context)
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
### Features

* [2984](https://github.com/zeta-chain/node/pull/2984) - add Whitelist message ability to whitelist SPL tokens on Solana
* [3091](https://github.com/zeta-chain/node/pull/3091) - improve build reproducability. `make release{,-build-only}` checksums should now be stable.

### Tests
* [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert.

## v21.0.0

Expand Down
2 changes: 2 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
tonTests := []string{
e2etests.TestTONDepositName,
e2etests.TestTONDepositAndCallName,
e2etests.TestTONDepositAndCallRefundName,
e2etests.TestTONWithdrawName,
e2etests.TestTONWithdrawConcurrentName,
}

eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...))
Expand Down
5 changes: 5 additions & 0 deletions contrib/rpcimportable/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ replace (
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
)

// go-ethereum fork must be used as it removes incompatible pebbledb version
replace (
github.com/ethereum/go-ethereum => github.com/zeta-chain/go-ethereum v1.13.16-0.20241022183758-422c6ef93ccc
)

// uncomment this for local development/testing/debugging
// replace github.com/zeta-chain/node => ../..
22 changes: 19 additions & 3 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ const (
/**
* TON tests
*/
TestTONDepositName = "ton_deposit"
TestTONDepositAndCallName = "ton_deposit_and_call"
TestTONWithdrawName = "ton_withdraw"
TestTONDepositName = "ton_deposit"
TestTONDepositAndCallName = "ton_deposit_and_call"
TestTONDepositAndCallRefundName = "ton_deposit_refund"
TestTONWithdrawName = "ton_withdraw"
TestTONWithdrawConcurrentName = "ton_withdraw_concurrent"

/*
Bitcoin tests
Expand Down Expand Up @@ -479,6 +481,14 @@ var AllE2ETests = []runner.E2ETest{
},
TestTONDepositAndCall,
),
runner.NewE2ETest(
TestTONDepositAndCallRefundName,
"deposit TON into ZEVM and call a smart contract that reverts; expect refund",
[]runner.ArgDefinition{
{Description: "amount in nano tons", DefaultValue: "1000000000"}, // 1.0 TON
},
TestTONDepositAndCallRefund,
),
runner.NewE2ETest(
TestTONWithdrawName,
"withdraw TON from ZEVM",
Expand All @@ -487,6 +497,12 @@ var AllE2ETests = []runner.E2ETest{
},
TestTONWithdraw,
),
runner.NewE2ETest(
TestTONWithdrawConcurrentName,
"withdraw TON from ZEVM for several recipients simultaneously",
[]runner.ArgDefinition{},
TestTONWithdrawConcurrent,
),
/*
Bitcoin tests
*/
Expand Down
50 changes: 50 additions & 0 deletions e2e/e2etests/test_ton_deposit_refund.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package e2etests

import (
"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"
cctypes "github.com/zeta-chain/node/x/crosschain/types"
)

func TestTONDepositAndCallRefund(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

// Given amount and arbitrary call data
var (
amount = parseUint(r, args[0])
data = []byte("hello reverter")
)

// Given deployer mock revert contract
// deploy a reverter contract in ZEVM
reverterAddr, _, _, err := testcontract.DeployReverter(r.ZEVMAuth, r.ZEVMClient)
require.NoError(r, err)
r.Logger.Info("Reverter contract deployed at: %s", reverterAddr.String())

// ACT
// Send a deposit and call transaction from the deployer (faucet)
// to the reverter contract
cctx, err := r.TONDepositAndCall(
&r.TONDeployer.Wallet,
amount,
reverterAddr,
data,
runner.TONExpectStatus(cctypes.CctxStatus_Reverted),
)

// ASSERT
require.NoError(r, err)
r.Logger.CCTX(*cctx, "ton_deposit_and_refund")

// Check the error carries the revert executed.
// tolerate the error in both the ErrorMessage field and the StatusMessage field
if cctx.CctxStatus.ErrorMessage != "" {
require.Contains(r, cctx.CctxStatus.ErrorMessage, "revert executed")
return
}

require.Contains(r, cctx.CctxStatus.StatusMessage, utils.ErrHashRevertFoo)
}
7 changes: 2 additions & 5 deletions e2e/e2etests/test_ton_withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
"github.com/zeta-chain/node/zetaclient/chains/ton/liteapi"
)

// TODO: Add "withdraw_many_concurrent" test
// https://github.com/zeta-chain/node/issues/3044

func TestTONWithdraw(r *runner.E2ERunner, args []string) {
// ARRANGE
require.Len(r, args, 1)
Expand All @@ -34,7 +31,7 @@ func TestTONWithdraw(r *runner.E2ERunner, args []string) {
tonRecipient, err := deployer.CreateWallet(r.Ctx, toncontracts.Coins(1))
require.NoError(r, err)

tonRecipientBalanceBefore, err := deployer.GetBalanceOf(r.Ctx, tonRecipient.GetAddress())
tonRecipientBalanceBefore, err := deployer.GetBalanceOf(r.Ctx, tonRecipient.GetAddress(), true)
require.NoError(r, err)

r.Logger.Info("Recipient's TON balance before withdrawal: %s", toncontracts.FormatCoins(tonRecipientBalanceBefore))
Expand All @@ -61,7 +58,7 @@ func TestTONWithdraw(r *runner.E2ERunner, args []string) {
)

// Make sure that recipient's TON balance has increased
tonRecipientBalanceAfter, err := deployer.GetBalanceOf(r.Ctx, tonRecipient.GetAddress())
tonRecipientBalanceAfter, err := deployer.GetBalanceOf(r.Ctx, tonRecipient.GetAddress(), true)
require.NoError(r, err)

r.Logger.Info("Recipient's balance after withdrawal: %s", toncontracts.FormatCoins(tonRecipientBalanceAfter))
Expand Down
74 changes: 74 additions & 0 deletions e2e/e2etests/test_ton_withdrawal_concurrent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package e2etests

import (
"math/rand"
"sync"

"cosmossdk.io/math"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/tonkeeper/tongo/ton"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
toncontracts "github.com/zeta-chain/node/pkg/contracts/ton"
"github.com/zeta-chain/node/testutil/sample"
cc "github.com/zeta-chain/node/x/crosschain/types"
)

// TestTONWithdrawConcurrent makes sure that multiple concurrent
// withdrawals will be eventually processed by sequentially increasing Gateway nonce
// and that zetaclient tolerates "invalid nonce" error from RPC.
func TestTONWithdrawConcurrent(r *runner.E2ERunner, _ []string) {
// ARRANGE
// Given a deployer
_, deployer := r.Ctx, r.TONDeployer

const recipientsCount = 10

// Fire withdrawals. Note that zevm sender is r.ZEVMAuth
var wg sync.WaitGroup
for i := 0; i < recipientsCount; i++ {
// ARRANGE
// Given multiple recipients WITHOUT deployed wallet-contracts
// and withdrawal amounts between 1 and 5 TON
var (
// #nosec G404: it's a test
amountCoins = 1 + rand.Intn(5)
// #nosec G115 test - always in range
amount = toncontracts.Coins(uint64(amountCoins))
recipient = sample.GenerateTONAccountID()
)

// ACT
r.Logger.Info(
"Withdrawal #%d: sending %s to %s",
i+1,
toncontracts.FormatCoins(amount),
recipient.ToRaw(),
)

approvedAmount := amount.Add(toncontracts.Coins(1))
tx := r.SendWithdrawTONZRC20(recipient, amount.BigInt(), approvedAmount.BigInt())

wg.Add(1)

go func(number int, recipient ton.AccountID, amount math.Uint, tx *ethtypes.Transaction) {
defer wg.Done()

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)

// ASSERT
utils.RequireCCTXStatus(r, cctx, cc.CctxStatus_OutboundMined)
r.Logger.Info("Withdrawal #%d complete! cctx index: %s", number, cctx.Index)

// Check recipient's balance ON TON
balance, err := deployer.GetBalanceOf(r.Ctx, recipient, false)
require.NoError(r, err, "failed to get balance of %s", recipient.ToRaw())
require.Equal(r, amount.Uint64(), balance.Uint64())
}(i+1, recipient, amount, tx)
}

wg.Wait()
}
2 changes: 1 addition & 1 deletion e2e/runner/setup_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) {
r.ZetaEth = ZetaEth
r.ZetaEthAddr = zetaEthAddr
conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(zetaEthAddr.String())
r.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), zetaEthAddr.Hash().Hex())
r.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), txZetaEth.Hash())

r.Logger.Info("Deploying ZetaConnectorEth contract")
connectorEthAddr, txConnector, ConnectorEth, err := zetaconnectoreth.DeployZetaConnectorEth(
Expand Down
Loading

0 comments on commit 8ffdac0

Please sign in to comment.