Skip to content

Commit

Permalink
Merge branch 'develop' into fix-btc-outbound-height
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie authored May 23, 2024
2 parents 78aab02 + 1302dcc commit d1b19df
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 141 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [1484](https://github.com/zeta-chain/node/issues/1484) - replaced hard-coded `MaxLookaheadNonce` with a default lookback factor
* [2125](https://github.com/zeta-chain/node/pull/2125) - fix develop upgrade test
* [2222](https://github.com/zeta-chain/node/pull/2222) - removed `maxHeightDiff` to let observer scan from Bitcoin height where it left off
* [2233](https://github.com/zeta-chain/node/pull/2233) - fix `IsSupported` flag not properly updated in zetaclient's context

### CI

Expand Down
4 changes: 2 additions & 2 deletions contrib/localnet/docker-compose-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ services:
image: zetanode:old

zetaclient0:
entrypoint: ["/root/start-zetaclientd.sh", "background"]
entrypoint: ["/root/start-zetaclientd.sh"]
image: zetanode:old

zetaclient1:
entrypoint: ["/root/start-zetaclientd.sh", "background"]
entrypoint: ["/root/start-zetaclientd.sh"]
image: zetanode:old

orchestrator:
Expand Down
20 changes: 7 additions & 13 deletions contrib/localnet/scripts/start-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ operator=$(cat $HOME/.zetacored/os.json | jq '.ObserverAddress' )
operatorAddress=$(echo "$operator" | tr -d '"')
echo "operatorAddress: $operatorAddress"
echo "Start zetaclientd"
if [ $HOSTNAME == "zetaclient0" ]
# skip initialization if the config file already exists (zetaclientd init has already been run)
if [[ $HOSTNAME == "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]]
then
rm ~/.tss/*
MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --keyring-backend "$BACKEND"

# check if the option is additional-evm
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
# in /root/.zetacored/config/zetaclient_config.json
if [ "$OPTION" == "additional-evm" ]; then
set_sepolia_endpoint
fi

zetaclientd-supervisor start < /root/password.file
else
fi
if [[ $HOSTNAME != "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]]
then
num=$(echo $HOSTNAME | tr -dc '0-9')
node="zetacore$num"
MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
Expand All @@ -71,13 +72,6 @@ else
if [ "$OPTION" == "additional-evm" ]; then
set_sepolia_endpoint
fi

zetaclientd-supervisor start < /root/password.file
fi

# check if the option is background
# in this case, we tail the zetaclientd log file
if [ "$OPTION" == "background" ]; then
sleep 3
tail -f $HOME/zetaclient.log
fi
zetaclientd-supervisor start < /root/password.file
43 changes: 25 additions & 18 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,24 @@ while [ ! -f ~/.ssh/authorized_keys ]; do
sleep 1
done

# Init a new node to generate genesis file .
# Copy config files from existing folders which get copied via Docker Copy when building images
mkdir -p ~/.backup/config
zetacored init Zetanode-Localnet --chain-id=$CHAINID
rm -rf ~/.zetacored/config/app.toml
rm -rf ~/.zetacored/config/client.toml
rm -rf ~/.zetacored/config/config.toml
cp -r ~/zetacored/common/app.toml ~/.zetacored/config/
cp -r ~/zetacored/common/client.toml ~/.zetacored/config/
cp -r ~/zetacored/common/config.toml ~/.zetacored/config/
sed -i -e "/moniker =/s/=.*/= \"$HOSTNAME\"/" "$HOME"/.zetacored/config/config.toml
# Skip init if it has already been completed (marked by presence of ~/.zetacored/init_complete file)
if [[ ! -f ~/.zetacored/init_complete ]]
then
# Init a new node to generate genesis file .
# Copy config files from existing folders which get copied via Docker Copy when building images
mkdir -p ~/.backup/config
zetacored init Zetanode-Localnet --chain-id=$CHAINID
rm -rf ~/.zetacored/config/app.toml
rm -rf ~/.zetacored/config/client.toml
rm -rf ~/.zetacored/config/config.toml
cp -r ~/zetacored/common/app.toml ~/.zetacored/config/
cp -r ~/zetacored/common/client.toml ~/.zetacored/config/
cp -r ~/zetacored/common/config.toml ~/.zetacored/config/
sed -i -e "/moniker =/s/=.*/= \"$HOSTNAME\"/" "$HOME"/.zetacored/config/config.toml

# Add two new keys for operator and hotkey and create the required json structure for os_info
source ~/add-keys.sh
# Add two new keys for operator and hotkey and create the required json structure for os_info
source ~/add-keys.sh
fi

# Pause other nodes so that the primary can node can do the genesis creation
if [ $HOSTNAME != "zetacore0" ]
Expand All @@ -143,8 +147,7 @@ then
echo "Waiting for genesis.json file to exist..."
sleep 1
done
# need to wait for zetacore0 to be up otherwise you get
#
# need to wait for zetacore0 to be up
while ! curl -s -o /dev/null zetacore0:26657/status ; do
echo "Waiting for zetacore0 rpc"
sleep 1
Expand All @@ -160,8 +163,9 @@ fi
# 6. Update Config in zetacore0 so that it has the correct persistent peer list
# 7. Start the nodes

# Start of genesis creation . This is done only on zetacore0
if [ $HOSTNAME == "zetacore0" ]
# Start of genesis creation . This is done only on zetacore0.
# Skip genesis if it has already been completed (marked by presence of ~/.zetacored/init_complete file)
if [[ $HOSTNAME == "zetacore0" && ! -f ~/.zetacored/init_complete ]]
then
# Misc : Copying the keyring to the client nodes so that they can sign the transactions
ssh zetaclient0 mkdir -p ~/.zetacored/keyring-test/
Expand Down Expand Up @@ -266,7 +270,7 @@ fi
# End of genesis creation steps . The steps below are common to all the nodes

# Update persistent peers
if [ $HOSTNAME != "zetacore0" ]
if [[ $HOSTNAME != "zetacore0" && ! -f ~/.zetacored/init_complete ]]
then
# Misc : Copying the keyring to the client nodes so that they can sign the transactions
ssh zetaclient"$INDEX" mkdir -p ~/.zetacored/keyring-test/
Expand All @@ -279,4 +283,7 @@ then
sed -i -e "/persistent_peers =/s/=.*/= \"$pps\"/" "$HOME"/.zetacored/config/config.toml
fi

# mark init completed so we skip it if container is restarted
touch ~/.zetacored/init_complete

cosmovisor run start --pruning=nothing --minimum-gas-prices=0.0001azeta --json-rpc.api eth,txpool,personal,net,debug,web3,miner --api.enable --home /root/.zetacored
17 changes: 0 additions & 17 deletions e2e/e2etests/test_message_passing_zevm_to_evm_revert_fail.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ func TestMessagePassingZEVMtoEVMRevertFail(r *runner.E2ERunner, args []string) {
}

// Get previous balances to check funds are not minted anywhere when aborted
previousBalanceEVM, err := r.ZetaEth.BalanceOf(&bind.CallOpts{}, r.EvmTestDAppAddr)
if err != nil {
panic(err)
}
previousBalanceZEVM, err := r.WZeta.BalanceOf(&bind.CallOpts{}, testDappNoRevertAddr)
if err != nil {
panic(err)
Expand All @@ -102,19 +98,6 @@ func TestMessagePassingZEVMtoEVMRevertFail(r *runner.E2ERunner, args []string) {
panic("expected cctx to be reverted")
}

// Check ZETA balance on EVM TestDApp and check new balance is previous balance
newBalanceEVM, err := r.ZetaEth.BalanceOf(&bind.CallOpts{}, r.EvmTestDAppAddr)
if err != nil {
panic(err)
}
if newBalanceEVM.Cmp(previousBalanceEVM) != 0 {
panic(fmt.Sprintf(
"expected new balance to be %s, got %s",
previousBalanceEVM.String(),
newBalanceEVM.String()),
)
}

// Check the funds are not minted to the contract as the cctx has been aborted
newBalanceZEVM, err := r.WZeta.BalanceOf(&bind.CallOpts{}, testDappNoRevertAddr)
if err != nil {
Expand Down
20 changes: 9 additions & 11 deletions x/crosschain/types/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (m CrossChainTx) Validate() error {
return fmt.Errorf("outbound tx params cannot be more than 2")
}
if m.Index != "" {
err := ValidateZetaIndex(m.Index)
err := ValidateCCTXIndex(m.Index)
if err != nil {
return err
}
Expand All @@ -70,16 +70,10 @@ func (m CrossChainTx) Validate() error {
return nil
}

/*
AddRevertOutbound does the following things in one function:
1. create a new OutboundTxParams for the revert
2. append the new OutboundTxParams to the current OutboundTxParams
3. update the TxFinalizationStatus of the current OutboundTxParams to Executed.
*/

// AddRevertOutbound does the following things in one function:
// 1. create a new OutboundTxParams for the revert
// 2. append the new OutboundTxParams to the current OutboundTxParams
// 3. update the TxFinalizationStatus of the current OutboundTxParams to Executed.
func (m *CrossChainTx) AddRevertOutbound(gasLimit uint64) error {
if m.IsCurrentOutboundRevert() {
return fmt.Errorf("cannot revert a revert tx")
Expand Down Expand Up @@ -223,9 +217,13 @@ func NewCCTX(ctx sdk.Context, msg MsgVoteInbound, tssPubkey string) (CrossChainT
InboundParams: inboundParams,
OutboundParams: []*OutboundParams{outBoundParams},
}

// TODO: remove this validate call
// https://github.com/zeta-chain/node/issues/2236
err := cctx.Validate()
if err != nil {
return CrossChainTx{}, err
}

return cctx, nil
}
4 changes: 2 additions & 2 deletions x/crosschain/types/cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Test_InitializeCCTX(t *testing.T) {
tss := sample.Tss()
msg := types.MsgVoteInbound{
Creator: creator,
Sender: "invalid",
Sender: "",
SenderChainId: senderChain.ChainId,
Receiver: receiver.String(),
ReceiverChain: receiverChain.ChainId,
Expand All @@ -107,7 +107,7 @@ func Test_InitializeCCTX(t *testing.T) {
EventIndex: eventIndex,
}
_, err := types.NewCCTX(ctx, msg, tss.TssPubkey)
require.ErrorContains(t, err, "invalid address")
require.ErrorContains(t, err, "sender cannot be empty")
})
}

Expand Down
45 changes: 23 additions & 22 deletions x/crosschain/types/inbound_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@ package types
import (
"fmt"

"github.com/cosmos/cosmos-sdk/types/errors"

"github.com/zeta-chain/zetacore/pkg/chains"
)

func (m InboundParams) Validate() error {
if m.Sender == "" {
return fmt.Errorf("sender cannot be empty")
}

if chains.GetChainFromChainID(m.SenderChainId) == nil {
return fmt.Errorf("invalid sender chain id %d", m.SenderChainId)
}
err := ValidateAddressForChain(m.Sender, m.SenderChainId)
if err != nil {
return err
}

if m.TxOrigin != "" {
errTxOrigin := ValidateAddressForChain(m.TxOrigin, m.SenderChainId)
if errTxOrigin != nil {
return errTxOrigin
}
}
if m.Amount.IsNil() {
return fmt.Errorf("amount cannot be nil")
}
err = ValidateHashForChain(m.ObservedHash, m.SenderChainId)
if err != nil {
return errors.Wrap(err, "invalid inbound tx observed hash")
}
if m.BallotIndex != "" {
err = ValidateZetaIndex(m.BallotIndex)
if err != nil {
return errors.Wrap(err, "invalid inbound tx ballot index")
}
}

// Disabled checks
// TODO: Improve the checks, move the validation call to a new place and reenable
// https://github.com/zeta-chain/node/issues/2234
// https://github.com/zeta-chain/node/issues/2235
//if err := ValidateAddressForChain(m.Sender, m.SenderChainId) err != nil {
// return err
//}
//if m.TxOrigin != "" {
// errTxOrigin := ValidateAddressForChain(m.TxOrigin, m.SenderChainId)
// if errTxOrigin != nil {
// return errTxOrigin
// }
//}
//if err := ValidateHashForChain(m.ObservedHash, m.SenderChainId); err != nil {
// return errors.Wrap(err, "invalid inbound tx observed hash")
//}
//if m.BallotIndex != "" {
// if err := ValidateCCTXIndex(m.BallotIndex); err != nil {
// return errors.Wrap(err, "invalid inbound tx ballot index")
// }
//}
return nil
}
38 changes: 22 additions & 16 deletions x/crosschain/types/inbound_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,44 @@ import (
sdkmath "cosmossdk.io/math"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/testutil/sample"
)

func TestInboundTxParams_Validate(t *testing.T) {
r := rand.New(rand.NewSource(42))

inboundParams := sample.InboundParamsValidChainID(r)
inboundParams.Sender = ""
require.ErrorContains(t, inboundParams.Validate(), "sender cannot be empty")

inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.SenderChainId = 1000
require.ErrorContains(t, inboundParams.Validate(), "invalid sender chain id 1000")
inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.SenderChainId = chains.GoerliChain.ChainId
inboundParams.Sender = "0x123"
require.ErrorContains(t, inboundParams.Validate(), "invalid address 0x123")
inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.SenderChainId = chains.GoerliChain.ChainId
inboundParams.TxOrigin = "0x123"
require.ErrorContains(t, inboundParams.Validate(), "invalid address 0x123")

inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.Amount = sdkmath.Uint{}
require.ErrorContains(t, inboundParams.Validate(), "amount cannot be nil")
inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.ObservedHash = "12"
require.ErrorContains(t, inboundParams.Validate(), "hash must be a valid ethereum hash 12")
inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.ObservedHash = sample.Hash().String()
inboundParams.BallotIndex = "12"
require.ErrorContains(t, inboundParams.Validate(), "invalid index length 2")

inboundParams = sample.InboundParamsValidChainID(r)
inboundParams.ObservedHash = sample.Hash().String()
inboundParams.BallotIndex = sample.ZetaIndex(t)
require.NoError(t, inboundParams.Validate())

// Disabled checks
// TODO: Improve the checks, move the validation call to a new place and reenable
// https://github.com/zeta-chain/node/issues/2234
// https://github.com/zeta-chain/node/issues/2235
//inboundParams = sample.InboundParamsValidChainID(r)
//inboundParams.SenderChainId = chains.GoerliChain.ChainId
//inboundParams.Sender = "0x123"
//require.ErrorContains(t, inboundParams.Validate(), "invalid address 0x123")
//
//inboundParams = sample.InboundParamsValidChainID(r)
//inboundParams.ObservedHash = "12"
//require.ErrorContains(t, inboundParams.Validate(), "hash must be a valid ethereum hash 12")
//
//inboundParams = sample.InboundParamsValidChainID(r)
//inboundParams.ObservedHash = sample.Hash().String()
//inboundParams.BallotIndex = "12"
//require.ErrorContains(t, inboundParams.Validate(), "invalid index length 2")
}
3 changes: 2 additions & 1 deletion x/crosschain/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const (
//TssMigrationGasMultiplierEVM is multiplied to the median gas price to get the gas price for the tss migration . This is done to avoid the tss migration tx getting stuck in the mempool
TssMigrationGasMultiplierEVM = "2.5"

ZetaIndexLength = 66
// CCTXIndexLength is the length of a crosschain transaction index
CCTXIndexLength = 66
)

func GetProtocolFee() sdk.Uint {
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/message_abort_stuck_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (msg *MsgAbortStuckCCTX) ValidateBasic() error {
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if len(msg.CctxIndex) != ZetaIndexLength {
if len(msg.CctxIndex) != CCTXIndexLength {
return ErrInvalidIndexValue
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/message_refund_aborted.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (msg *MsgRefundAbortedCCTX) ValidateBasic() error {
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if len(msg.CctxIndex) != ZetaIndexLength {
if len(msg.CctxIndex) != CCTXIndexLength {
return ErrInvalidIndexValue
}
if msg.RefundAddress != "" && !ethcommon.IsHexAddress(msg.RefundAddress) {
Expand Down
Loading

0 comments on commit d1b19df

Please sign in to comment.