Skip to content

Commit

Permalink
txTx tracker bug fix and some necessary code refactor for banned address
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Jan 19, 2024
2 parents b408e56 + 6de5bc8 commit 07f6090
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 230 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

* [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt
* [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic
* [1592](https://github.com/zeta-chain/node/issues/1592) - Check inbound tracker tx hash against Tss address and some refactor on inTx observation
* [1591](https://github.com/zeta-chain/node/pull/1591) - support lower gas limit for voting on inbound and outbound transactions
* [1602](https://github.com/zeta-chain/node/issues/1602) - Check inbound tracker tx hash against Tss address and some refactor on inTx observation

## Version: v12.0.0

Expand Down Expand Up @@ -43,7 +44,10 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c

### Fixes

<<<<<<< HEAD
* [1576](https://github.com/zeta-chain/node/pull/1576) - Fix zetaclient crash due to out of bound integer conversion and log prints.
=======
>>>>>>> 6de5bc85c8b7c298e285602b57a4d2f8ff2d21cd
* [1575](https://github.com/zeta-chain/node/issues/1575) - Skip unsupported chain parameters by IsSupported flag
* [1554](https://github.com/zeta-chain/node/pull/1554) - Screen out unconfirmed UTXOs that are not created by TSS itself
* [1560](https://github.com/zeta-chain/node/issues/1560) - Zetaclient post evm-chain outtx hashes only when receipt is available
Expand Down
2 changes: 1 addition & 1 deletion contrib/localnet/scripts/start-zetaclientd-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ else
SEED=$(curl --retry 10 --retry-delay 5 --retry-connrefused -s zetaclient0:8123/p2p)
done
rm ~/.tss/*
zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 0 --keyring-backend "$BACKEND"
zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 1 --keyring-backend "$BACKEND"
zetaclientd start
fi
2 changes: 1 addition & 1 deletion contrib/localnet/scripts/start-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ else
zetaclientd init \
--peer /ip4/172.20.0.21/tcp/6668/p2p/$SEED \
--pre-params ~/preParams.json --zetacore-url $node \
--chain-id athens_101-1 --operator zeta1lz2fqwzjnk6qy48fgj753h48444fxtt7hekp52 --log-level 0 --hotkey=val_grantee_observer
--chain-id athens_101-1 --operator zeta1lz2fqwzjnk6qy48fgj753h48444fxtt7hekp52 --log-level 1 --hotkey=val_grantee_observer
zetaclientd start
fi
6 changes: 3 additions & 3 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,12 @@ func (ob *BitcoinChainClient) observeInTx() error {
// post inbound vote message to zetacore
for _, inTx := range inTxs {
msg := ob.GetInboundVoteMessageFromBtcEvent(inTx)
zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.WatchInTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zeta core for tx %s", inTx.TxHash)
return err // we have to re-scan this block next time
} else if zetaHash != "" {
ob.logger.WatchInTx.Info().Msgf("observeInTxBTC: BTC deposit detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot)
ob.logger.WatchInTx.Info().Msgf("observeInTxBTC: BTC deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot)
}
}

Expand Down Expand Up @@ -470,7 +470,7 @@ func (ob *BitcoinChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64
}

logger.Debug().Msgf("Bitcoin outTx confirmed: txid %s, amount %s\n", res.TxID, amountInSat.String())
zetaHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
res.TxID,
// #nosec G701 always positive
Expand Down
8 changes: 3 additions & 5 deletions zetaclient/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg
b.seqNumber[authzSigner.KeyType] = seqNumber
}
}
//b.logger.Info().Uint64("account_number", b.accountNumber).Uint64("sequence_number", b.seqNumber).Msg("account info")

flags := flag.NewFlagSet("zetacore", 0)

Expand All @@ -69,12 +68,13 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg
if err != nil {
return "", err
}

builder.SetGasLimit(gaslimit)

// #nosec G701 always in range
fee := sdktypes.NewCoins(sdktypes.NewCoin(config.BaseDenom,
cosmos.NewInt(int64(gaslimit)).Mul(cosmos.NewInt(baseGasPrice))))
builder.SetFeeAmount(fee)
//fmt.Printf("signing from name: %s\n", ctx.GetFromName())
err = b.SignTx(factory, ctx.GetFromName(), builder, true, ctx.TxConfig)
if err != nil {
return "", err
Expand All @@ -90,6 +90,7 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg
b.logger.Error().Err(err).Msgf("fail to broadcast tx %s", err.Error())
return "", err
}

// Code will be the tendermint ABICode , it start at 1 , so if it is an error , code will not be zero
if commit.Code > 0 {
if commit.Code == 32 {
Expand All @@ -114,11 +115,8 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg
}
return commit.TxHash, fmt.Errorf("fail to broadcast to zetachain,code:%d, log:%s", commit.Code, commit.RawLog)
}
//b.logger.Debug().Msgf("Received a TxHash of %v from the metachain, Code %d, log %s", commit.TxHash, commit.Code, commit.Logs)

// increment seqNum
//seq := b.seqNumber[authzSigner.KeyType]
//atomic.AddUint64(&seq, 1)
b.seqNumber[authzSigner.KeyType] = b.seqNumber[authzSigner.KeyType] + 1

return commit.TxHash, nil
Expand Down
32 changes: 16 additions & 16 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
if receipt.Status == 1 {
recvStatus = common.ReceiveStatus_Success
}
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
receipt.TxHash.Hex(),
receipt.BlockNumber.Uint64(),
Expand All @@ -339,7 +339,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co

} else if cointype == common.CoinType_Gas { // the outbound is a regular Ether/BNB/Matic transfer; no need to check events
if receipt.Status == 1 {
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
receipt.TxHash.Hex(),
receipt.BlockNumber.Uint64(),
Expand All @@ -360,7 +360,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
return true, true, nil
} else if receipt.Status == 0 { // the same as below events flow
logger.Info().Msgf("Found (failed tx) sendHash %s on chain %s txhash %s", sendHash, ob.chain.String(), receipt.TxHash.Hex())
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
receipt.TxHash.Hex(),
receipt.BlockNumber.Uint64(),
Expand All @@ -374,7 +374,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
common.CoinType_Gas,
)
if err != nil {
logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s cctx %s nonce %d", zetaTxHash, sendHash, nonce)
logger.Error().Err(err).Msgf("PostVoteOutbound error in WatchTxHashWithTimeout; zeta tx hash %s cctx %s nonce %d", zetaTxHash, sendHash, nonce)
} else if zetaTxHash != "" {
logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d ballot %s", zetaTxHash, sendHash, nonce, ballot)
}
Expand Down Expand Up @@ -404,7 +404,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
sendhash := vLog.Topics[3].Hex()
//var rxAddress string = ethcommon.HexToAddress(vLog.Topics[1].Hex()).Hex()
mMint := receivedLog.ZetaValue
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendhash,
vLog.TxHash.Hex(),
vLog.BlockNumber,
Expand Down Expand Up @@ -441,7 +441,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
}
sendhash := vLog.Topics[2].Hex()
mMint := revertedLog.RemainingZetaValue
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendhash,
vLog.TxHash.Hex(),
vLog.BlockNumber,
Expand Down Expand Up @@ -469,7 +469,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
} else if receipt.Status == 0 {
//FIXME: check nonce here by getTransaction RPC
logger.Info().Msgf("Found (failed tx) sendHash %s on chain %s txhash %s", sendHash, ob.chain.String(), receipt.TxHash.Hex())
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
receipt.TxHash.Hex(),
receipt.BlockNumber.Uint64(),
Expand Down Expand Up @@ -509,7 +509,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
}
if confHeight <= ob.GetLastBlockHeight() {
logger.Info().Msg("Confirmed! Sending PostConfirmation to zetacore...")
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
vLog.TxHash.Hex(),
vLog.BlockNumber,
Expand All @@ -536,7 +536,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
}
} else {
logger.Info().Msgf("Found (failed tx) sendHash %s on chain %s txhash %s", sendHash, ob.chain.String(), receipt.TxHash.Hex())
zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation(
zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound(
sendHash,
receipt.TxHash.Hex(),
receipt.BlockNumber.Uint64(),
Expand All @@ -550,7 +550,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co
common.CoinType_ERC20,
)
if err != nil {
logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s", zetaTxHash)
logger.Error().Err(err).Msgf("PostVoteOutbound error in WatchTxHashWithTimeout; zeta tx hash %s", zetaTxHash)
} else if zetaTxHash != "" {
logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d ballot %s", zetaTxHash, sendHash, nonce, ballot)
}
Expand Down Expand Up @@ -983,15 +983,15 @@ func (ob *EVMChainClient) observeZetaSent(startBlock, toBlock uint64) uint64 {
if msg == nil {
continue
}
zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendNonEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundMessagePassingExecutionGasLimit, msg)
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msgf(
"observeZetaSent: error posting event to zeta core for tx %s at height %d for chain %d",
event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId)
return beingScanned - 1 // we have to re-scan from this block next time
} else if zetaHash != "" {
ob.logger.ExternalChainWatcher.Info().Msgf(
"observeZetaSent: event detected in tx %s at height %d for chain %d, PostSend zeta tx: %s ballot %s",
"observeZetaSent: event detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s",
event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId, zetaHash, ballot)
}
}
Expand Down Expand Up @@ -1073,15 +1073,15 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint
if msg == nil {
continue
}
zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msgf(
"observeERC20Deposited: error posting event to zeta core for tx %s at height %d for chain %d",
event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId)
return beingScanned - 1 // we have to re-scan from this block next time
} else if zetaHash != "" {
ob.logger.ExternalChainWatcher.Info().Msgf(
"observeERC20Deposited: event detected in tx %s at height %d for chain %d, PostSend zeta tx: %s ballot %s",
"observeERC20Deposited: event detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s",
event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId, zetaHash, ballot)
}
}
Expand Down Expand Up @@ -1145,14 +1145,14 @@ func (ob *EVMChainClient) observeTssRecvd(startBlock, toBlock uint64, flags obse
if msg == nil {
continue
}
zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msgf(
"observeTssRecvd: error posting to zeta core for tx %s at height %d for chain %d", tx.Hash().Hex(), bn, ob.chain.ChainId)
return bn - 1 // we have to re-scan this block next time
} else if zetaHash != "" {
ob.logger.ExternalChainWatcher.Info().Msgf(
"observeTssRecvd: gas asset deposit detected in tx %s at height %d for chain %d, PostSend zeta tx: %s ballot %s",
"observeTssRecvd: gas asset deposit detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s",
tx.Hash().Hex(), bn, ob.chain.ChainId, zetaHash, ballot)
}
}
Expand Down
16 changes: 8 additions & 8 deletions zetaclient/inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func (ob *BitcoinChainClient) CheckReceiptForBtcTxHash(txHash string, vote bool)
if !vote {
return msg.Digest(), nil
}
zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.WatchInTx.Error().Err(err).Msg("error posting to zeta core")
return "", err
} else if ballot == "" {
ob.logger.WatchInTx.Info().Msgf("BTC deposit detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot)
ob.logger.WatchInTx.Info().Msgf("BTC deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot)
}
return msg.Digest(), nil
}
Expand Down Expand Up @@ -193,12 +193,12 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeZeta(txHash string, vote bool)
return msg.Digest(), nil
}

zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendNonEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundMessagePassingExecutionGasLimit, msg)
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msg("error posting to zeta core")
return "", err
} else if zetaHash != "" {
ob.logger.ExternalChainWatcher.Info().Msgf("ZetaSent event detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot)
ob.logger.ExternalChainWatcher.Info().Msgf("ZetaSent event detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot)
}

return msg.Digest(), nil
Expand Down Expand Up @@ -253,12 +253,12 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeERC20(txHash string, vote bool)
return msg.Digest(), nil
}

zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msg("error posting to zeta core")
return "", err
} else if zetaHash != "" {
ob.logger.ExternalChainWatcher.Info().Msgf("ERC20 Deposit event detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot)
ob.logger.ExternalChainWatcher.Info().Msgf("ERC20 Deposit event detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot)
}

return msg.Digest(), nil
Expand Down Expand Up @@ -313,12 +313,12 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeGas(txHash string, vote bool) (
return msg.Digest(), nil
}

zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg)
zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg)
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msg("error posting to zeta core")
return "", err
} else if zetaHash != "" {
ob.logger.ExternalChainWatcher.Info().Msgf("Gas deposit detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot)
ob.logger.ExternalChainWatcher.Info().Msgf("Gas deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot)
}

return msg.Digest(), nil
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ type ChainSigner interface {

// ZetaCoreBridger is the interface to interact with ZetaCore
type ZetaCoreBridger interface {
PostSend(zetaGasLimit uint64, msg *crosschaintypes.MsgVoteOnObservedInboundTx) (string, string, error)
PostReceiveConfirmation(
PostVoteInbound(gasLimit, retryGasLimit uint64, msg *crosschaintypes.MsgVoteOnObservedInboundTx) (string, string, error)
PostVoteOutbound(
sendHash string,
outTxHash string,
outBlockHeight uint64,
Expand Down
Loading

0 comments on commit 07f6090

Please sign in to comment.