Skip to content

Commit

Permalink
resolve comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Jul 15, 2024
1 parent be5054d commit 43073d4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
26 changes: 16 additions & 10 deletions x/crosschain/keeper/cctx_orchestrator_validate_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -68,24 +68,29 @@ 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())
}
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())
Expand All @@ -95,5 +100,6 @@ func (k Keeper) CheckIfMigrationDeposit(ctx sdk.Context, msg *types.MsgVoteInbou
}
}
}

return nil
}
30 changes: 15 additions & 15 deletions x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
})

Expand All @@ -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)
})

Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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")
})

Expand All @@ -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)
})
}
4 changes: 2 additions & 2 deletions zetaclient/chains/bitcoin/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion zetaclient/chains/evm/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 43073d4

Please sign in to comment.