Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/zeta-chain/node into fix…
Browse files Browse the repository at this point in the history
…-btc-inscription-decoding-panic
  • Loading branch information
ws4charlie committed Nov 15, 2024
2 parents 80d275a + 46f3d44 commit 4cfb924
Show file tree
Hide file tree
Showing 33 changed files with 317 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/actions/upgrade-testing/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
with:
python-version: 'pypy3.9'

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4 #v3 reaches deprecation on November 30, 2024
with:
name: binaries-${{ github.sha }}
path: ./
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,6 @@ jobs:
run: |
echo "continue"
check-upgrade-handler-updated:
needs:
- check-branch
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:

- uses: actions/checkout@v4
if: inputs.skip_checks != true
with:
fetch-depth: 0

- name: Major Version in Upgrade Handler Must Match Tag
if: inputs.skip_checks != true
run: |
UPGRADE_HANDLER_MAJOR_VERSION=$(cat app/setup_handlers.go | grep "const releaseVersion" | cut -d ' ' -f4 | tr -d '"' | cut -d '.' -f 1 | tr -d '\n')
USER_INPUT_VERSION=$(echo "${{ inputs.version }}" | cut -d '.' -f 1 | tr -d '\n')
echo "Upgrade Handler Major Version: ${UPGRADE_HANDLER_MAJOR_VERSION}"
echo "User Inputted Release Version: ${USER_INPUT_VERSION}"
if [ ${USER_INPUT_VERSION} != $UPGRADE_HANDLER_MAJOR_VERSION ]; then
echo "ERROR: The input version doesn't match the release handler for the branch selected. Please ensure the upgrade handler of the branch you selected when you ran the pipeline matches the input version."
echo "Did you forget to update the 'releaseVersion' in app/setup_handlers.go?"
exit 1
fi
echo "The major version found in 'releaseVersion' in app/setup_handlers.go matches this tagged release - Moving Forward!"
- name: Mark Job Complete Skipped
if: inputs.skip_checks == true
shell: bash
run: |
echo "continue"
publish-release:
permissions:
id-token: write
Expand All @@ -134,7 +102,6 @@ jobs:
if: inputs.skip_release != true
needs:
- check-changelog
- check-upgrade-handler-updated
- check-branch
- check-goreleaser
runs-on: ${{ vars.RELEASE_RUNNER }}
Expand Down
26 changes: 23 additions & 3 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,28 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
"golang.org/x/mod/semver"

"github.com/zeta-chain/node/pkg/constant"
)

// GetDefaultUpgradeHandlerVersion prints the default upgrade handler version
//
// There may be multiple upgrade handlers configured on some releases if different
// migrations needto be run in different environment
func GetDefaultUpgradeHandlerVersion() string {
// semver must have v prefix, but we store without prefix
vVersion := "v" + constant.Version

// development builds always use the full version in the release handlers
if semver.Build(vVersion) != "" || semver.Prerelease(vVersion) != "" {
return constant.Version
}

// release builds use just the major version (v22.0.0 -> v22)
return semver.Major(vVersion)
}

func SetupHandlers(app *App) {
allUpgrades := upgradeTracker{
upgrades: []upgradeTrackerItem{
Expand Down Expand Up @@ -50,10 +68,12 @@ func SetupHandlers(app *App) {
upgradeHandlerFns, storeUpgrades = allUpgrades.mergeAllUpgrades()
}

upgradeHandlerVersion := GetDefaultUpgradeHandlerVersion()

app.UpgradeKeeper.SetUpgradeHandler(
constant.Version,
upgradeHandlerVersion,
func(ctx sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + constant.Version)
app.Logger().Info("Running upgrade handler for " + upgradeHandlerVersion)

var err error
for _, upgradeHandler := range upgradeHandlerFns {
Expand All @@ -71,7 +91,7 @@ func SetupHandlers(app *App) {
if err != nil {
panic(err)
}
if upgradeInfo.Name == constant.Version && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
if upgradeInfo.Name == upgradeHandlerVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
// so that new stores start with the correct version (the current height of chain),
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert.
* [3105](https://github.com/zeta-chain/node/pull/3105) - split Bitcoin E2E tests into two runners for deposit and withdraw
* [3154](https://github.com/zeta-chain/node/pull/3154) - configure Solana gateway program id for E2E tests

### Refactor
* [3118](https://github.com/zeta-chain/node/pull/3118) - zetaclient: remove hsm signer
Expand All @@ -25,7 +26,9 @@
* [3041](https://github.com/zeta-chain/node/pull/3041) - replace libp2p public DHT with private gossip peer discovery and connection gater for inbound connections
* [3106](https://github.com/zeta-chain/node/pull/3106) - prevent blocked CCTX on out of gas during omnichain calls
* [3139](https://github.com/zeta-chain/node/pull/3139) - fix config resolution in orchestrator
* [3149](https://github.com/zeta-chain/node/pull/3149) - abort the cctx if dust amount is detected in the revert outbound
* [3155](https://github.com/zeta-chain/node/pull/3155) - fix potential panic in the Bitcoin inscription parsing
* [3162](https://github.com/zeta-chain/node/pull/3162) - skip depositor fee calculation if transaction does not involve TSS address

## v21.0.0

Expand Down
1 change: 1 addition & 0 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig types.EncodingConfig) {
GetPubKeyCmd(),
CollectObserverInfoCmd(),
AddrConversionCmd(),
UpgradeHandlerVersionCmd(),
tmcli.NewCompletionCmd(rootCmd, true),
ethermintclient.NewTestnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),

Expand Down
19 changes: 19 additions & 0 deletions cmd/zetacored/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"fmt"

"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
)

func UpgradeHandlerVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "upgrade-handler-version",
Short: "Print the default upgrade handler version",
Run: func(_ *cobra.Command, _ []string) {
fmt.Println(app.GetDefaultUpgradeHandlerVersion())
},
}
}
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func RunnerFromConfig(
// ExportContractsFromRunner export contracts from the runner to config using a source config
func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.Config {
// copy contracts from deployer runner
conf.Contracts.Solana.GatewayProgramID = r.GatewayProgram.String()
conf.Contracts.Solana.GatewayProgramID = config.DoubleQuotedString(r.GatewayProgram.String())
conf.Contracts.Solana.SPLAddr = config.DoubleQuotedString(r.SPLAddr.String())

conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(r.ZetaEthAddr.Hex())
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {

// set Solana contracts
if c := conf.Contracts.Solana.GatewayProgramID; c != "" {
r.GatewayProgram = solana.MustPublicKeyFromBase58(c)
r.GatewayProgram = solana.MustPublicKeyFromBase58(c.String())
}

if c := conf.Contracts.Solana.SPLAddr; c != "" {
Expand Down Expand Up @@ -242,7 +242,6 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {
}

// v2 contracts

if c := conf.Contracts.EVM.Gateway; c != "" {
r.GatewayEVMAddr, err = c.AsEVMAddress()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@ contracts:
custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
test_dapp: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed"
gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826"
gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826"
solana:
gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"
spl: ""
6 changes: 5 additions & 1 deletion cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ rpcs:
ton_sidecar_url: "http://ton:8000"
zetacore_grpc: "zetacore0:9090"
zetacore_rpc: "http://zetacore0:26657"
# contracts will be populated on first run
contracts:
# configure localnet solana gateway program id
solana:
gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"
spl: ""
8 changes: 6 additions & 2 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
deployerRunner.SetupEVMV2()

if testSolana {
deployerRunner.SetupSolana(conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String())
deployerRunner.SetupSolana(
conf.Contracts.Solana.GatewayProgramID.String(),
conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String(),
)
}

deployerRunner.SetZEVMSystemContracts()
Expand Down Expand Up @@ -433,7 +436,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestSolanaDepositName,
e2etests.TestSolanaWithdrawName,
e2etests.TestSolanaDepositAndCallName,
e2etests.TestSolanaDepositAndCallRefundName,
e2etests.TestSolanaDepositAndCallRevertName,
e2etests.TestSolanaDepositAndCallRevertWithDustName,
e2etests.TestSolanaDepositRestrictedName,
e2etests.TestSolanaWithdrawRestrictedName,
// TODO move under admin tests
Expand Down
2 changes: 1 addition & 1 deletion contrib/localnet/scripts/start-upgrade-orchestrator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fi
# get new zetacored version
curl -L -o /tmp/zetacored.new "${ZETACORED_URL}"
chmod +x /tmp/zetacored.new
UPGRADE_NAME=$(/tmp/zetacored.new version)
UPGRADE_NAME=$(/tmp/zetacored.new upgrade-handler-version)

# if explicit upgrade height not provided, use dumb estimator
if [[ -z $UPGRADE_HEIGHT ]]; then
Expand Down
29 changes: 29 additions & 0 deletions docs/cli/zetacored/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Zetacore Daemon (server)
* [zetacored tendermint](#zetacored-tendermint) - Tendermint subcommands
* [zetacored testnet](#zetacored-testnet) - subcommands for starting or configuring local testnets
* [zetacored tx](#zetacored-tx) - Transactions subcommands
* [zetacored upgrade-handler-version](#zetacored-upgrade-handler-version) - Print the default upgrade handler version
* [zetacored validate-genesis](#zetacored-validate-genesis) - validates the genesis file at the default location or at the location passed as an arg
* [zetacored version](#zetacored-version) - Print the application binary version information

Expand Down Expand Up @@ -14346,6 +14347,34 @@ zetacored tx vesting create-vesting-account [to_address] [amount] [end_time] [fl

* [zetacored tx vesting](#zetacored-tx-vesting) - Vesting transaction subcommands

## zetacored upgrade-handler-version

Print the default upgrade handler version

```
zetacored upgrade-handler-version [flags]
```

### Options

```
-h, --help help for upgrade-handler-version
```

### Options inherited from parent commands

```
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--log_no_color Disable colored logs
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored](#zetacored) - Zetacore Daemon (server)

## zetacored validate-genesis

validates the genesis file at the default location or at the location passed as an arg
Expand Down
2 changes: 1 addition & 1 deletion e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Contracts struct {

// Solana contains the addresses of predeployed contracts and accounts on the Solana chain
type Solana struct {
GatewayProgramID string `yaml:"gateway_program_id"`
GatewayProgramID DoubleQuotedString `yaml:"gateway_program_id"`
SPLAddr DoubleQuotedString `yaml:"spl"`
}

Expand Down
33 changes: 20 additions & 13 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ const (
/*
* Solana tests
*/
TestSolanaDepositName = "solana_deposit"
TestSolanaWithdrawName = "solana_withdraw"
TestSolanaDepositAndCallName = "solana_deposit_and_call"
TestSolanaDepositAndCallRefundName = "solana_deposit_and_call_refund"
TestSolanaDepositRestrictedName = "solana_deposit_restricted"
TestSolanaWithdrawRestrictedName = "solana_withdraw_restricted"
TestSPLDepositName = "spl_deposit"
TestSPLDepositAndCallName = "spl_deposit_and_call"
TestSPLWithdrawName = "spl_withdraw"
TestSPLWithdrawAndCreateReceiverAtaName = "spl_withdraw_and_create_receiver_ata"
TestSolanaDepositName = "solana_deposit"
TestSolanaWithdrawName = "solana_withdraw"
TestSolanaDepositAndCallName = "solana_deposit_and_call"
TestSolanaDepositAndCallRevertName = "solana_deposit_and_call_revert"
TestSolanaDepositAndCallRevertWithDustName = "solana_deposit_and_call_revert_with_dust"
TestSolanaDepositRestrictedName = "solana_deposit_restricted"
TestSolanaWithdrawRestrictedName = "solana_withdraw_restricted"
TestSPLDepositName = "spl_deposit"
TestSPLDepositAndCallName = "spl_deposit_and_call"
TestSPLWithdrawName = "spl_withdraw"
TestSPLWithdrawAndCreateReceiverAtaName = "spl_withdraw_and_create_receiver_ata"

/**
* TON tests
Expand Down Expand Up @@ -453,12 +454,18 @@ var AllE2ETests = []runner.E2ETest{
TestSPLWithdrawAndCreateReceiverAta,
),
runner.NewE2ETest(
TestSolanaDepositAndCallRefundName,
"deposit SOL into ZEVM and call a contract that reverts; should refund",
TestSolanaDepositAndCallRevertName,
"deposit SOL into ZEVM and call a contract that reverts",
[]runner.ArgDefinition{
{Description: "amount in lamport", DefaultValue: "1200000"},
},
TestSolanaDepositAndCallRefund,
TestSolanaDepositAndCallRevert,
),
runner.NewE2ETest(
TestSolanaDepositAndCallRevertWithDustName,
"deposit SOL into ZEVM; revert with dust amount that aborts the CCTX",
[]runner.ArgDefinition{},
TestSolanaDepositAndCallRevertWithDust,
),
runner.NewE2ETest(
TestSolanaDepositRestrictedName,
Expand Down
18 changes: 9 additions & 9 deletions e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package e2etests

import (
"strings"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
Expand Down Expand Up @@ -38,16 +40,14 @@ func TestBitcoinDepositAndCallRevertWithDust(r *runner.E2ERunner, args []string)
// Send BTC to TSS address with a dummy memo
// zetacore should revert cctx if call is made on a non-existing address
nonExistReceiver := sample.EthAddress()
badMemo := append(nonExistReceiver.Bytes(), []byte("gibberish-memo")...)
txHash, err := r.SendToTSSFromDeployerWithMemo(amount, utxos, badMemo)
anyMemo := append(nonExistReceiver.Bytes(), []byte("gibberish-memo")...)
txHash, err := r.SendToTSSFromDeployerWithMemo(amount, utxos, anyMemo)
require.NoError(r, err)
require.NotEmpty(r, txHash)

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

// check the test was effective: the revert outbound amount is less than the dust amount
require.Less(r, cctx.GetCurrentOutboundParam().Amount.Uint64(), uint64(constant.BTCWithdrawalDustAmount))
// ASSERT
// Now we want to make sure the cctx is aborted with expected error message
cctx := utils.WaitCctxAbortedByInboundHash(r.Ctx, r, txHash.String(), r.CctxClient)
require.True(r, cctx.GetCurrentOutboundParam().Amount.Uint64() < constant.BTCWithdrawalDustAmount)
require.True(r, strings.Contains(cctx.CctxStatus.ErrorMessage, crosschaintypes.ErrInvalidWithdrawalAmount.Error()))
}
Loading

0 comments on commit 4cfb924

Please sign in to comment.