diff --git a/cmd/zetae2e/config/localnet.yml b/cmd/zetae2e/config/localnet.yml index 83b32c10f2..59452f723a 100644 --- a/cmd/zetae2e/config/localnet.yml +++ b/cmd/zetae2e/config/localnet.yml @@ -34,8 +34,8 @@ additional_accounts: private_key: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" user_migration: bech32_address: "zeta1pvtxa708yvdmszn687nne6nl8qn704daf420xz" - evm_address: "0x0B166ef9e7231Bb80A7A3FA73CEA7F3827E7D5BD" - private_key: "0BCC2FA28B526F90E1D54648D612DB901E860BF68248555593F91EA801C6B482" + evm_address: "0x0b166ef9e7231bb80a7a3fa73cea7f3827e7d5bd" + private_key: "0bcc2fa28b526f90e1d54648d612db901e860bf68248555593f91ea801c6b482" user_fungible_admin: bech32_address: "zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3" evm_address: "0x8305C114Ea73cAc4A88f39A173803F94741b9055" diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 7417bc0a07..deb1109901 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/rs/zerolog/log" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/signer" "github.com/zeta-chain/zetacore/e2e/utils" "github.com/zeta-chain/zetacore/pkg/chains" @@ -72,8 +73,8 @@ func (r *E2ERunner) GetTop20UTXOsForTssAddress() ([]btcjson.ListUnspentResult, e return utxos[i].Amount < utxos[j].Amount }) - if len(utxos) > 20 { - utxos = utxos[:20] + if len(utxos) > signer.MaxNoOfInputsPerTx { + utxos = utxos[:signer.MaxNoOfInputsPerTx] } return utxos, nil } diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go index f3bda67590..24d139f76f 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go @@ -22,7 +22,7 @@ func (k Keeper) ValidateInbound( return nil, types.ErrCannotFindTSSKeys } - err := k.CheckIfMigrationDeposit(ctx, msg) + err := k.CheckIfMigrationTransfer(ctx, msg) if err != nil { return nil, err } @@ -57,9 +57,9 @@ func (k Keeper) ValidateInbound( return &cctx, nil } -// CheckIfMigrationDeposit checks if the sender is a TSS address and returns an error if it is. +// CheckIfMigrationTransfer checks if the sender is a TSS address and returns an error if it is. // If the sender is an older TSS address, this means that it is a migration transfer, and we do not need to treat this as a deposit and process the CCTX -func (k Keeper) CheckIfMigrationDeposit(ctx sdk.Context, msg *types.MsgVoteInbound) error { +func (k Keeper) CheckIfMigrationTransfer(ctx sdk.Context, msg *types.MsgVoteInbound) error { additionalChains := k.GetAuthorityKeeper().GetAdditionalChainList(ctx) historicalTssList := k.zetaObserverKeeper.GetAllTSS(ctx) @@ -68,12 +68,14 @@ func (k Keeper) CheckIfMigrationDeposit(ctx sdk.Context, msg *types.MsgVoteInbou return observertypes.ErrSupportedChains.Wrapf("chain not found for chainID %d", msg.SenderChainId) } + // the check is only necessary if the inbound is validated from observers from a connected chain if chain.CctxGateway != chains.CCTXGateway_observers { return nil } - for _, tss := range historicalTssList { - if chains.IsEVMChain(chain.ChainId, additionalChains) { + switch { + case chains.IsEVMChain(chain.ChainId, additionalChains): + for _, tss := range historicalTssList { ethTssAddress, err := crypto.GetTssAddrEVM(tss.TssPubkey) if err != nil { return errors.Wrap(types.ErrInvalidAddress, err.Error()) @@ -81,11 +83,14 @@ func (k Keeper) CheckIfMigrationDeposit(ctx sdk.Context, msg *types.MsgVoteInbou if ethTssAddress.Hex() == msg.Sender { return types.ErrMigrationFromOldTss } - } else if chains.IsBitcoinChain(chain.ChainId, additionalChains) { - bitcoinParams, err := chains.BitcoinNetParamsFromChainID(chain.ChainId) - if err != nil { - return err - } + + } + case chains.IsBitcoinChain(chain.ChainId, additionalChains): + bitcoinParams, err := chains.BitcoinNetParamsFromChainID(chain.ChainId) + if err != nil { + return err + } + for _, tss := range historicalTssList { btcTssAddress, err := crypto.GetTssAddrBTC(tss.TssPubkey, bitcoinParams) if err != nil { return errors.Wrap(types.ErrInvalidAddress, err.Error()) @@ -95,5 +100,6 @@ func (k Keeper) CheckIfMigrationDeposit(ctx sdk.Context, msg *types.MsgVoteInbou } } } + return nil } diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go index d0c696dc20..8be95af4c7 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go @@ -43,7 +43,7 @@ func TestKeeper_ValidateInbound(t *testing.T) { sender := sample.EthAddress() tssList := sample.TssList(3) - // Set up mocks for CheckIfMigrationDeposit + // Set up mocks for CheckIfMigrationTransfer observerMock.On("GetAllTSS", ctx).Return(tssList) observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId).Return(senderChain, true) authorityMock.On("GetAdditionalChainList", ctx).Return([]chains.Chain{}) @@ -172,7 +172,7 @@ func TestKeeper_ValidateInbound(t *testing.T) { sender := sample.EthAddress() tssList := sample.TssList(3) - // Set up mocks for CheckIfMigrationDeposit + // Set up mocks for CheckIfMigrationTransfer observerMock.On("GetAllTSS", ctx).Return(tssList) observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId).Return(senderChain, true) authorityMock.On("GetAdditionalChainList", ctx).Return([]chains.Chain{}) @@ -238,7 +238,7 @@ func TestKeeper_ValidateInbound(t *testing.T) { sender := sample.EthAddress() tssList := sample.TssList(3) - // Set up mocks for CheckIfMigrationDeposit + // Set up mocks for CheckIfMigrationTransfer observerMock.On("GetAllTSS", ctx).Return(tssList) observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId).Return(senderChain, true) authorityMock.On("GetAdditionalChainList", ctx).Return([]chains.Chain{}) @@ -310,7 +310,7 @@ func TestKeeper_ValidateInbound(t *testing.T) { sender := sample.EthAddress() tssList := sample.TssList(3) - // Set up mocks for CheckIfMigrationDeposit + // Set up mocks for CheckIfMigrationTransfer observerMock.On("GetAllTSS", ctx).Return(tssList) observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId).Return(senderChain, true) authorityMock.On("GetAdditionalChainList", ctx).Return([]chains.Chain{}) @@ -347,7 +347,7 @@ func TestKeeper_ValidateInbound(t *testing.T) { require.ErrorIs(t, err, observerTypes.ErrInboundDisabled) }) - t.Run("fails when CheckIfMigrationDeposit fails", func(t *testing.T) { + t.Run("fails when CheckIfMigrationTransfer fails", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseObserverMock: true, @@ -376,7 +376,7 @@ func TestKeeper_ValidateInbound(t *testing.T) { // setup Mocks for GetTSS observerMock.On("GetTSS", mock.Anything).Return(tssList[0], true) - // Set up mocks for CheckIfMigrationDeposit + // Set up mocks for CheckIfMigrationTransfer observerMock.On("GetAllTSS", ctx).Return(tssList) observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId).Return(senderChain, false) authorityMock.On("GetAdditionalChainList", ctx).Return([]chains.Chain{}) @@ -433,7 +433,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.NoError(t, err) }) @@ -460,7 +460,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.NoError(t, err) }) @@ -489,7 +489,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.ErrorIs(t, err, observerTypes.ErrSupportedChains) }) @@ -517,7 +517,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.ErrorIs(t, err, types.ErrInvalidAddress) }) @@ -545,7 +545,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.ErrorIs(t, err, types.ErrInvalidAddress) }) @@ -573,7 +573,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender.String(), } - err = k.CheckIfMigrationDeposit(ctx, &msg) + err = k.CheckIfMigrationTransfer(ctx, &msg) require.ErrorIs(t, err, types.ErrMigrationFromOldTss) }) @@ -603,7 +603,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err = k.CheckIfMigrationDeposit(ctx, &msg) + err = k.CheckIfMigrationTransfer(ctx, &msg) require.ErrorIs(t, err, types.ErrMigrationFromOldTss) }) @@ -634,7 +634,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.ErrorContains(t, err, "no Bitcoin net params for chain ID: 999") }) @@ -657,7 +657,7 @@ func TestKeeper_CheckMigration(t *testing.T) { Sender: sender, } - err := k.CheckIfMigrationDeposit(ctx, &msg) + err := k.CheckIfMigrationTransfer(ctx, &msg) require.NoError(t, err) }) } diff --git a/zetaclient/chains/bitcoin/signer/signer.go b/zetaclient/chains/bitcoin/signer/signer.go index 259f55bc53..d8027d1668 100644 --- a/zetaclient/chains/bitcoin/signer/signer.go +++ b/zetaclient/chains/bitcoin/signer/signer.go @@ -33,7 +33,7 @@ import ( const ( // the maximum number of inputs per outbound - maxNoOfInputsPerTx = 20 + MaxNoOfInputsPerTx = 20 // the rank below (or equal to) which we consolidate UTXOs consolidationRank = 10 @@ -196,7 +196,7 @@ func (signer *Signer) SignWithdrawTx( // select N UTXOs to cover the total expense prevOuts, total, consolidatedUtxo, consolidatedValue, err := observer.SelectUTXOs( amount+estimateFee+float64(nonceMark)*1e-8, - maxNoOfInputsPerTx, + MaxNoOfInputsPerTx, nonce, consolidationRank, false, diff --git a/zetaclient/chains/evm/observer/outbound.go b/zetaclient/chains/evm/observer/outbound.go index 5952d1fa4e..86218df8f8 100644 --- a/zetaclient/chains/evm/observer/outbound.go +++ b/zetaclient/chains/evm/observer/outbound.go @@ -366,6 +366,8 @@ func (ob *Observer) checkConfirmedTx(txHash string, nonce uint64) (*ethtypes.Rec } if from != ob.TSS().EVMAddress() { // must be TSS address // If from is not TSS address, check if it is one of the previous TSS addresses We can still try to confirm a tx which was broadcast by an old TSS + // This is to handle situations where the outbound has already been broad-casted by an older TSS address and the zetacore is waiting for the all the required block confirmations + // to go through before marking the cctx into a finalized state log.Info().Msgf("confirmTxByHash: sender %s for outbound %s chain %d is not current TSS address %s", from.Hex(), transaction.Hash().Hex(), ob.Chain().ChainId, ob.TSS().EVMAddress().Hex()) addressList := ob.TSS().EVMAddressList() @@ -404,7 +406,7 @@ func (ob *Observer) checkConfirmedTx(txHash string, nonce uint64) (*ethtypes.Rec log.Error().Msgf("confirmTxByHash: receipt is nil for txHash %s nonce %d", txHash, nonce) return nil, nil, false } - + ob.LastBlock() // check confirmations lastHeight, err := ob.evmClient.BlockNumber(context.Background()) if err != nil {