From 346c305352ca6e0b53193452d9c777698125f0ec Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Tue, 10 Sep 2024 08:37:52 -0700 Subject: [PATCH 1/7] refactor(observer): disable Bitcoin witness support for mainnet (release/v20) (#2855) * tests * update changelogs --- changelog.md | 1 + zetaclient/chains/bitcoin/observer/inbound.go | 31 +++-- .../chains/bitcoin/observer/inbound_test.go | 107 +++++++++++++++--- .../chains/bitcoin/observer/witness_test.go | 2 +- 4 files changed, 116 insertions(+), 25 deletions(-) diff --git a/changelog.md b/changelog.md index 7ebb3e1c6e..27056bd157 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,7 @@ ### Refactor * [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers +* [2855](https://github.com/zeta-chain/node/pull/2855) - disable Bitcoin witness support for mainnet ### Tests diff --git a/zetaclient/chains/bitcoin/observer/inbound.go b/zetaclient/chains/bitcoin/observer/inbound.go index 546d23277f..efc7d58a5e 100644 --- a/zetaclient/chains/bitcoin/observer/inbound.go +++ b/zetaclient/chains/bitcoin/observer/inbound.go @@ -266,7 +266,7 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string, } // #nosec G115 always positive - event, err := GetBtcEventWithWitness( + event, err := GetBtcEvent( ob.btcClient, *tx, tss, @@ -328,7 +328,7 @@ func FilterAndParseIncomingTx( continue // the first tx is coinbase; we do not process coinbase tx } - inbound, err := GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee) + inbound, err := GetBtcEvent(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee) if err != nil { // unable to parse the tx, the caller should retry return nil, errors.Wrapf(err, "error getting btc event for tx %s in block %d", tx.Txid, blockNumber) @@ -390,10 +390,27 @@ func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent) return false } -// GetBtcEvent either returns a valid BTCInboundEvent or nil +// GetBtcEvent returns a valid BTCInboundEvent or nil +// it uses witness data to extract the sender address, except for mainnet +func GetBtcEvent( + rpcClient interfaces.BTCRPCClient, + tx btcjson.TxRawResult, + tssAddress string, + blockNumber uint64, + logger zerolog.Logger, + netParams *chaincfg.Params, + depositorFee float64, +) (*BTCInboundEvent, error) { + if netParams.Name == chaincfg.MainNetParams.Name { + return GetBtcEventWithoutWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee) + } + return GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee) +} + +// GetBtcEventWithoutWitness 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( +func GetBtcEventWithoutWitness( rpcClient interfaces.BTCRPCClient, tx btcjson.TxRawResult, tssAddress string, @@ -437,7 +454,7 @@ func GetBtcEvent( // deposit amount has to be no less than the minimum depositor fee if vout0.Value < depositorFee { logger.Info(). - Msgf("GetBtcEvent: btc deposit amount %v in txid %s is less than depositor fee %v", vout0.Value, tx.Txid, depositorFee) + Msgf("GetBtcEventWithoutWitness: btc deposit amount %v in txid %s is less than depositor fee %v", vout0.Value, tx.Txid, depositorFee) return nil, nil } value = vout0.Value - depositorFee @@ -446,7 +463,7 @@ func GetBtcEvent( vout1 := tx.Vout[1] memo, found, err = bitcoin.DecodeOpReturnMemo(vout1.ScriptPubKey.Hex, tx.Txid) if err != nil { - logger.Error().Err(err).Msgf("GetBtcEvent: error decoding OP_RETURN memo: %s", vout1.ScriptPubKey.Hex) + logger.Error().Err(err).Msgf("GetBtcEventWithoutWitness: error decoding OP_RETURN memo: %s", vout1.ScriptPubKey.Hex) return nil, nil } } @@ -454,7 +471,7 @@ func GetBtcEvent( // event found, get sender address if found { if len(tx.Vin) == 0 { // should never happen - return nil, fmt.Errorf("GetBtcEvent: no input found for inbound: %s", tx.Txid) + return nil, fmt.Errorf("GetBtcEventWithoutWitness: no input found for inbound: %s", tx.Txid) } fromAddress, err := GetSenderAddressByVin(rpcClient, tx.Vin[0], netParams) diff --git a/zetaclient/chains/bitcoin/observer/inbound_test.go b/zetaclient/chains/bitcoin/observer/inbound_test.go index ec121bd9af..981d0315c7 100644 --- a/zetaclient/chains/bitcoin/observer/inbound_test.go +++ b/zetaclient/chains/bitcoin/observer/inbound_test.go @@ -312,13 +312,13 @@ func TestGetSenderAddressByVinErrors(t *testing.T) { }) } -func TestGetBtcEvent(t *testing.T) { +func TestGetBtcEventWithoutWitness(t *testing.T) { // load archived inbound P2WPKH raw result // https://mempool.space/tx/847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa txHash := "847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa" chain := chains.BitcoinMainnet - // GetBtcEvent arguments + // GetBtcEventWithoutWitness arguments tx := testutils.LoadBTCInboundRawResult(t, TestDataDir, chain.ChainId, txHash, false) tssAddress := testutils.TSSAddressBTCMainnet blockNumber := uint64(835640) @@ -348,7 +348,7 @@ func TestGetBtcEvent(t *testing.T) { rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Equal(t, eventExpected, event) }) @@ -363,7 +363,7 @@ func TestGetBtcEvent(t *testing.T) { rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Equal(t, eventExpected, event) }) @@ -378,7 +378,7 @@ func TestGetBtcEvent(t *testing.T) { rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Equal(t, eventExpected, event) }) @@ -393,7 +393,7 @@ func TestGetBtcEvent(t *testing.T) { rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Equal(t, eventExpected, event) }) @@ -408,7 +408,7 @@ func TestGetBtcEvent(t *testing.T) { rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Equal(t, eventExpected, event) }) @@ -419,7 +419,7 @@ func TestGetBtcEvent(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) }) @@ -430,13 +430,13 @@ func TestGetBtcEvent(t *testing.T) { // modify the tx to have Vout[0] a P2SH output tx.Vout[0].ScriptPubKey.Hex = strings.Replace(tx.Vout[0].ScriptPubKey.Hex, "0014", "a914", 1) - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) // append 1 byte to script to make it longer than 22 bytes tx.Vout[0].ScriptPubKey.Hex = tx.Vout[0].ScriptPubKey.Hex + "00" - event, err = observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err = observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) }) @@ -447,7 +447,7 @@ func TestGetBtcEvent(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) }) @@ -458,7 +458,7 @@ func TestGetBtcEvent(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) }) @@ -469,7 +469,7 @@ func TestGetBtcEvent(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) }) @@ -480,7 +480,7 @@ func TestGetBtcEvent(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.NoError(t, err) require.Nil(t, event) }) @@ -503,7 +503,7 @@ func TestGetBtcEventErrors(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.Error(t, err) require.Nil(t, event) }) @@ -514,7 +514,7 @@ func TestGetBtcEventErrors(t *testing.T) { // get BTC event rpcClient := mocks.NewMockBTCRPCClient() - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.Error(t, err) require.Nil(t, event) }) @@ -524,8 +524,81 @@ func TestGetBtcEventErrors(t *testing.T) { rpcClient := mocks.NewMockBTCRPCClient() // get BTC event - event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + event, err := observer.GetBtcEventWithoutWitness(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) require.Error(t, err) require.Nil(t, event) }) } + +func TestGetBtcEvent(t *testing.T) { + t.Run("should not decode inbound event with witness with mainnet chain", func(t *testing.T) { + // load archived inbound P2WPKH raw result + // https://mempool.space/tx/847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa + chain := chains.BitcoinMainnet + + tssAddress := testutils.TSSAddressBTCMainnet + blockNumber := uint64(835640) + net := &chaincfg.MainNetParams + // 2.992e-05, see avgFeeRate https://mempool.space/api/v1/blocks/835640 + depositorFee := bitcoin.DepositorFee(22 * clientcommon.BTCOutboundGasPriceMultiplier) + + txHash2 := "37777defed8717c581b4c0509329550e344bdc14ac38f71fc050096887e535c8" + tx := testutils.LoadBTCInboundRawResult(t, TestDataDir, chain.ChainId, txHash2, false) + + preHash := "c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697" + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) + + // get BTC event + event, err := observer.GetBtcEvent( + rpcClient, + *tx, + tssAddress, + blockNumber, + log.Logger, + net, + depositorFee, + ) + require.NoError(t, err) + require.Equal(t, (*observer.BTCInboundEvent)(nil), event) + }) + + t.Run("should support legacy BTC inbound event parsing for mainnet", func(t *testing.T) { + // load archived inbound P2WPKH raw result + // https://mempool.space/tx/847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa + txHash := "847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa" + chain := chains.BitcoinMainnet + + // GetBtcEventWithoutWitness arguments + tx := testutils.LoadBTCInboundRawResult(t, TestDataDir, chain.ChainId, txHash, false) + tssAddress := testutils.TSSAddressBTCMainnet + blockNumber := uint64(835640) + net := &chaincfg.MainNetParams + // 2.992e-05, see avgFeeRate https://mempool.space/api/v1/blocks/835640 + depositorFee := bitcoin.DepositorFee(22 * clientcommon.BTCOutboundGasPriceMultiplier) + + // expected result + memo, err := hex.DecodeString(tx.Vout[1].ScriptPubKey.Hex[4:]) + require.NoError(t, err) + eventExpected := &observer.BTCInboundEvent{ + FromAddress: "bc1q68kxnq52ahz5vd6c8czevsawu0ux9nfrzzrh6e", + ToAddress: tssAddress, + Value: tx.Vout[0].Value - depositorFee, // 7008 sataoshis + MemoBytes: memo, + BlockNumber: blockNumber, + TxHash: tx.Txid, + } + + // https://mempool.space/tx/c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697 + preHash := "c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697" + tx.Vin[0].Txid = preHash + tx.Vin[0].Vout = 2 + eventExpected.FromAddress = "bc1q68kxnq52ahz5vd6c8czevsawu0ux9nfrzzrh6e" + // load previous raw tx so so mock rpc client can return it + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) + + // get BTC event + event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) + require.NoError(t, err) + require.Equal(t, eventExpected, event) + }) +} diff --git a/zetaclient/chains/bitcoin/observer/witness_test.go b/zetaclient/chains/bitcoin/observer/witness_test.go index 4e93fb5cf1..3dbcb330e8 100644 --- a/zetaclient/chains/bitcoin/observer/witness_test.go +++ b/zetaclient/chains/bitcoin/observer/witness_test.go @@ -45,7 +45,7 @@ func TestParseScriptFromWitness(t *testing.T) { }) } -func TestGetBtcEventFromInscription(t *testing.T) { +func TestGetBtcEventWithWitness(t *testing.T) { // load archived inbound P2WPKH raw result // https://mempool.space/tx/847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa txHash := "847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa" From 5c8c4a36156ea5611fa36f48b0ab88e03ca7a231 Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Tue, 10 Sep 2024 10:20:10 -0700 Subject: [PATCH 2/7] fix: update go-tss with known fixes (v20) (#2857) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index fa4a5c0e95..607634cad4 100644 --- a/go.mod +++ b/go.mod @@ -366,4 +366,4 @@ replace github.com/evmos/ethermint => github.com/zeta-chain/ethermint v0.0.0-202 replace github.com/libp2p/go-libp2p => github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4 -replace gitlab.com/thorchain/tss/go-tss => github.com/zeta-chain/go-tss v0.0.0-20240729195411-9f5ae8189449 +replace gitlab.com/thorchain/tss/go-tss => github.com/zeta-chain/go-tss v0.0.0-20240907163312-b576693642e0 diff --git a/go.sum b/go.sum index 46c12bf27e..25906fc815 100644 --- a/go.sum +++ b/go.sum @@ -1669,8 +1669,8 @@ github.com/zeta-chain/ethermint v0.0.0-20240531172701-61d040058c94 h1:M54ljayJvy github.com/zeta-chain/ethermint v0.0.0-20240531172701-61d040058c94/go.mod h1:s1zA6OpXv3Tb5I0M6M6j5fo/AssaZL/pgkc7G0W2kN8= github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4 h1:FmO3HfVdZ7LzxBUfg6sVzV7ilKElQU2DZm8PxJ7KcYI= github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4/go.mod h1:TBv5NY/CqWYIfUstXO1fDWrt4bDoqgCw79yihqBspg8= -github.com/zeta-chain/go-tss v0.0.0-20240729195411-9f5ae8189449 h1:4U+4g2QQjbrmeLU1ZdCDU6CYsE5kbwMOKZ/PACR/vN8= -github.com/zeta-chain/go-tss v0.0.0-20240729195411-9f5ae8189449/go.mod h1:LN1IBRN8xQkKgdgLhl5BDGZyPm70QOTbVLejdS2FVpo= +github.com/zeta-chain/go-tss v0.0.0-20240907163312-b576693642e0 h1:OMuw0XgFcX0RQ8+B3gtreV4H/JPglCSfG2PfVi7bONM= +github.com/zeta-chain/go-tss v0.0.0-20240907163312-b576693642e0/go.mod h1:LN1IBRN8xQkKgdgLhl5BDGZyPm70QOTbVLejdS2FVpo= github.com/zeta-chain/keystone/keys v0.0.0-20231105174229-903bc9405da2 h1:gd2uE0X+ZbdFJ8DubxNqLbOVlCB12EgWdzSNRAR82tM= github.com/zeta-chain/keystone/keys v0.0.0-20231105174229-903bc9405da2/go.mod h1:x7Bkwbzt2W2lQfjOirnff0Dj+tykdbTG1FMJPVPZsvE= github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240819143729-b8229cd7b410 h1:sBeVX63s/qmfT1KnIKj1Y2SK3PsFpAM/P49ODcD1CN8= From 8bef3f4413caa6dab354257e5f4f90786d05d6c3 Mon Sep 17 00:00:00 2001 From: Julian Rubino Date: Thu, 5 Sep 2024 00:27:06 +0900 Subject: [PATCH 3/7] chore: change snapshots API on contrib/localnet/scripts to consume state exports (#2819) * Refactor contrib/rpc and contrib/docker-scripts to use snapshots API * Replace Snapshot API on localnet scripts for consuming state exports --------- Co-authored-by: Julian Rubino --- contrib/localnet/scripts/import-data.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/scripts/import-data.sh b/contrib/localnet/scripts/import-data.sh index 52b18945fd..955d42e62a 100755 --- a/contrib/localnet/scripts/import-data.sh +++ b/contrib/localnet/scripts/import-data.sh @@ -10,6 +10,6 @@ echo "NETWORK: ${NETWORK}" rm -rf ~/.zetacored/genesis_data mkdir -p ~/.zetacored/genesis_data echo "Download Latest State Export" -LATEST_EXPORT_URL=$(curl https://snapshots.zetachain.com/latest-state-export | jq -r ."${NETWORK}") +LATEST_EXPORT_URL=$(curl https://snapshots.rpc.zetachain.com/${NETWORK}/state/latest.json | jq -r '.snapshots[0].link') echo "LATEST EXPORT URL: ${LATEST_EXPORT_URL}" wget -q ${LATEST_EXPORT_URL} -O ~/.zetacored/genesis_data/exported-genesis.json From 8bbba311ad3a66364ddc5926b494c890f55e4326 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Mon, 9 Sep 2024 03:03:18 -0700 Subject: [PATCH 4/7] chore: use v19 binaries in upgrade tests (#2689) --- Makefile | 4 +- app/setup_handlers.go | 88 +------------------------------------------ 2 files changed, 4 insertions(+), 88 deletions(-) diff --git a/Makefile b/Makefile index 94fdd9917a..70ee7fa767 100644 --- a/Makefile +++ b/Makefile @@ -293,12 +293,12 @@ start-v2-test: zetanode ifdef UPGRADE_TEST_FROM_SOURCE zetanode-upgrade: zetanode @echo "Building zetanode-upgrade from source" - $(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source --build-arg OLD_VERSION='release/v18' . + $(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source --build-arg OLD_VERSION='release/v19' . .PHONY: zetanode-upgrade else zetanode-upgrade: zetanode @echo "Building zetanode-upgrade from binaries" - $(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v18.0.0' . + $(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v19.1.1' . .PHONY: zetanode-upgrade endif diff --git a/app/setup_handlers.go b/app/setup_handlers.go index b34b147069..dc17069535 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -3,106 +3,22 @@ package app import ( "os" - "github.com/cosmos/cosmos-sdk/baseapp" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "golang.org/x/exp/slices" "github.com/zeta-chain/zetacore/pkg/constant" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" - emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) func SetupHandlers(app *App) { - // Set param key table for params module migration - for _, subspace := range app.ParamsKeeper.GetSubspaces() { - var keyTable paramstypes.KeyTable - switch subspace.Name() { - case authtypes.ModuleName: - keyTable = authtypes.ParamKeyTable() //nolint:staticcheck - case banktypes.ModuleName: - keyTable = banktypes.ParamKeyTable() //nolint:staticcheck - case stakingtypes.ModuleName: - keyTable = stakingtypes.ParamKeyTable() - case distrtypes.ModuleName: - keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck - case slashingtypes.ModuleName: - keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck - case govtypes.ModuleName: - keyTable = govv1.ParamKeyTable() //nolint:staticcheck - case crisistypes.ModuleName: - keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck - case emissionstypes.ModuleName: - keyTable = emissionstypes.ParamKeyTable() - default: - continue - } - if !subspace.HasKeyTable() { - subspace.WithKeyTable(keyTable) - } - } - baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) - needsForcedMigration := []string{ - authtypes.ModuleName, - banktypes.ModuleName, - stakingtypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - govtypes.ModuleName, - crisistypes.ModuleName, - emissionstypes.ModuleName, - authoritytypes.ModuleName, - observertypes.ModuleName, - } allUpgrades := upgradeTracker{ upgrades: []upgradeTrackerItem{ - { - index: 1714664193, - storeUpgrade: &storetypes.StoreUpgrades{ - Added: []string{consensustypes.ModuleName, crisistypes.ModuleName}, - }, - upgradeHandler: func(ctx sdk.Context, vm module.VersionMap) (module.VersionMap, error) { - // Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module - // https://docs.cosmos.network/main/build/migrations/upgrading#xconsensus - baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper) - - // empty version map happens when upgrading from old versions which did not correctly call - // app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) in InitChainer. - // we must populate the version map if we detect this scenario - // - // this will only happen on the first upgrade. mainnet and testnet will not require this condition. - if len(vm) == 0 { - for m, mb := range app.mm.Modules { - if module, ok := mb.(module.HasConsensusVersion); ok { - if slices.Contains(needsForcedMigration, m) { - vm[m] = module.ConsensusVersion() - 1 - } else { - vm[m] = module.ConsensusVersion() - } - } - } - } - return vm, nil - }, - }, // TODO: enable back IBC // these commented lines allow for the IBC modules to be added to the upgrade tracker // https://github.com/zeta-chain/node/issues/2573 //{ - // index: 1715624665, + // index: , // storeUpgrade: &storetypes.StoreUpgrades{ // Added: []string{ // capabilitytypes.ModuleName, @@ -112,7 +28,7 @@ func SetupHandlers(app *App) { // }, //}, //{ - // index: 1715707436, + // index: , // storeUpgrade: &storetypes.StoreUpgrades{ // Added: []string{ibccrosschaintypes.ModuleName}, // }, From 82d3279e648430c44d48f12d4513ebf0398aada0 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Mon, 9 Sep 2024 10:15:59 -0700 Subject: [PATCH 5/7] ci: cleanup release workflow (#2845) * ci: cleanup release workflow * inputs are now booleans not strings 'true'/'false' --- .github/workflows/publish-release.yml | 61 ++++++++++++--------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index f37a74c1b1..e6de47d1a5 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -11,20 +11,32 @@ on: type: boolean required: false default: false - description: 'Use this to skip: check-changelog and check-upgrade-handler-updated go straight to approval step.' + description: 'Skip pre-release checks and skip straight to the actual release' skip_release: type: boolean required: false default: false - description: 'If this is true it will simply execute all the steps for a release prior to actually cutting the release, then stop' + description: 'Only run pre-release checks' concurrency: group: publish-release cancel-in-progress: false jobs: + log: + runs-on: ubuntu-22.04 + steps: + - name: "Log inputs" + env: + INPUTS: ${{ toJson(inputs) }} + run: echo "${INPUTS}" | jq -r + - name: "Log event" + env: + EVENT: ${{ toJson(github.event) }} + run: echo "${EVENT}" | jq -r + check-branch: - if: ${{ (startsWith(github.ref, 'refs/heads/release/v') || startsWith(github.ref, 'refs/heads/hotfix/v')) }} + if: (startsWith(github.ref, 'refs/heads/release/v') || startsWith(github.ref, 'refs/heads/hotfix/v')) runs-on: ubuntu-22.04 steps: - name: Branch @@ -32,7 +44,7 @@ jobs: echo "${{ github.ref }}" check-goreleaser: - if: ${{ github.event.inputs.skip_checks != 'true' }} + if: inputs.skip_checks != true runs-on: ${{ vars.RELEASE_RUNNER }} steps: - uses: actions/checkout@v4 @@ -47,13 +59,13 @@ jobs: steps: - name: Checkout code - if: ${{ github.event.inputs.skip_checks != 'true' }} + if: inputs.skip_checks != true uses: actions/checkout@v4 with: fetch-depth: 0 - name: Get latest commit SHA of Develop & Current Branch - if: ${{ github.event.inputs.skip_checks != 'true' }} + if: inputs.skip_checks != true id: get-develop-sha run: | SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ @@ -62,7 +74,7 @@ jobs: echo "CURRENT_BRANCH_SHA=${{ github.sha }}" >> ${GITHUB_ENV} - name: Check for CHANGELOG.md changes - if: ${{ github.event.inputs.skip_checks != 'true' }} + if: inputs.skip_checks != true run: | echo "Check the changelog has actually been updated from whats in develop" echo "DEVELOP BRANCH SHA: ${DEVELOP_SHA}" @@ -77,7 +89,7 @@ jobs: fi - name: Mark Job Complete Skipped - if: ${{ github.event.inputs.skip_checks == 'true' }} + if: inputs.skip_checks == true shell: bash run: | echo "continue" @@ -90,15 +102,15 @@ jobs: steps: - uses: actions/checkout@v4 - if: ${{ github.event.inputs.skip_checks != 'true' }} + if: inputs.skip_checks != true with: fetch-depth: 0 - name: Major Version in Upgrade Handler Must Match Tag - if: ${{ github.event.inputs.skip_checks != 'true' }} + 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 "${{ github.event.inputs.version }}" | 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 @@ -109,7 +121,7 @@ jobs: echo "The major version found in 'releaseVersion' in app/setup_handlers.go matches this tagged release - Moving Forward!" - name: Mark Job Complete Skipped - if: ${{ github.event.inputs.skip_checks == 'true' }} + if: inputs.skip_checks == true shell: bash run: | echo "continue" @@ -119,7 +131,7 @@ jobs: id-token: write contents: write attestations: write - if: ${{ github.event.inputs.skip_release == 'false' }} + if: inputs.skip_release != true needs: - check-changelog - check-upgrade-handler-updated @@ -131,15 +143,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install Pipeline Dependencies - uses: ./.github/actions/install-dependencies - timeout-minutes: 8 - with: - cpu_architecture: ${{ env.CPU_ARCH }} - skip_python: "true" - skip_aws_cli: "true" - skip_docker_compose: "true" - - name: Change Log Release Notes. id: release_notes run: | @@ -148,19 +151,7 @@ jobs: - name: Set Version run: | - echo "GITHUB_TAG_MAJOR_VERSION=${{ github.event.inputs.version }}" >> ${GITHUB_ENV} - - - name: Set CPU Architecture - shell: bash - run: | - if [ "$(uname -m)" == "aarch64" ]; then - echo "CPU_ARCH=arm64" >> $GITHUB_ENV - elif [ "$(uname -m)" == "x86_64" ]; then - echo "CPU_ARCH=amd64" >> $GITHUB_ENV - else - echo "Unsupported architecture" >&2 - exit 1 - fi + echo "GITHUB_TAG_MAJOR_VERSION=${{ inputs.version }}" >> ${GITHUB_ENV} - name: Create Release Tag shell: bash From 513c65659264c8eec3ff1e25c9566006b2ecc366 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 10 Sep 2024 10:46:08 -0700 Subject: [PATCH 6/7] chore: set release version --- app/setup_handlers.go | 10 +++++----- contrib/localnet/scripts/start-upgrade-orchestrator.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index dc17069535..90a1f10565 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -7,10 +7,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - "github.com/zeta-chain/zetacore/pkg/constant" ) +const releaseVersion = "v20" + func SetupHandlers(app *App) { allUpgrades := upgradeTracker{ upgrades: []upgradeTrackerItem{ @@ -51,9 +51,9 @@ func SetupHandlers(app *App) { } app.UpgradeKeeper.SetUpgradeHandler( - constant.Version, + releaseVersion, 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 " + releaseVersion) var err error for _, upgradeHandler := range upgradeHandlerFns { @@ -71,7 +71,7 @@ func SetupHandlers(app *App) { if err != nil { panic(err) } - if upgradeInfo.Name == constant.Version && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + if upgradeInfo.Name == releaseVersion && !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), diff --git a/contrib/localnet/scripts/start-upgrade-orchestrator.sh b/contrib/localnet/scripts/start-upgrade-orchestrator.sh index 1f8089bc3d..0a3382eb66 100755 --- a/contrib/localnet/scripts/start-upgrade-orchestrator.sh +++ b/contrib/localnet/scripts/start-upgrade-orchestrator.sh @@ -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="v20" # if explicit upgrade height not provided, use dumb estimator if [[ -z $UPGRADE_HEIGHT ]]; then From d5dee31ce5dd3825f685ed87d0a31a0c062e187f Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Tue, 10 Sep 2024 13:40:54 -0700 Subject: [PATCH 7/7] fix: schedule interval out of loop (#2856) --- zetaclient/orchestrator/orchestrator.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zetaclient/orchestrator/orchestrator.go b/zetaclient/orchestrator/orchestrator.go index 9b2ced55bb..43864f514f 100644 --- a/zetaclient/orchestrator/orchestrator.go +++ b/zetaclient/orchestrator/orchestrator.go @@ -453,6 +453,9 @@ func (oc *Orchestrator) ScheduleCctxEVM( // #nosec G115 positive outboundScheduleInterval := uint64(observer.GetChainParams().OutboundScheduleInterval) + criticalInterval := uint64(10) // for critical pending outbound we reduce re-try interval + nonCriticalInterval := outboundScheduleInterval * 2 // for non-critical pending outbound we increase re-try interval + for idx, cctx := range cctxList { params := cctx.GetCurrentOutboundParam() nonce := params.TssNonce @@ -486,8 +489,6 @@ func (oc *Orchestrator) ScheduleCctxEVM( // determining critical outbound; if it satisfies following criteria // 1. it's the first pending outbound for this chain // 2. the following 5 nonces have been in tracker - criticalInterval := uint64(10) // for critical pending outbound we reduce re-try interval - nonCriticalInterval := outboundScheduleInterval * 2 // for non-critical pending outbound we increase re-try interval if nonce%criticalInterval == zetaHeight%criticalInterval { count := 0 for i := nonce + 1; i <= nonce+10; i++ {