diff --git a/.github/actions/upgrade-testing/create_genesis.py b/.github/actions/upgrade-testing/create_genesis.py index b0c95a8d81..75ef7f9f66 100644 --- a/.github/actions/upgrade-testing/create_genesis.py +++ b/.github/actions/upgrade-testing/create_genesis.py @@ -4,6 +4,15 @@ genesis = open(os.environ["NEW_GENESIS"], "r").read() genesis_json_object = json.loads(genesis) +#cut this out for now because it fails to start when done in python with the exact same keys being replaced with same value. Will fix later. +# genesis_json_object["staking"]["params"]["bond_denom"] = "azeta" +# genesis_json_object["crisis"]["constant_fee"]["denom"] = "azeta" +# genesis_json_object["gov"]["deposit_params"]["min_deposit"][0]["denom"] = "azeta" +# genesis_json_object["mint"]["params"]["mint_denom"] = "azeta" +# genesis_json_object["evm"]["params"]["evm_denom"] = "azeta" +# genesis_json_object["block"]["max_gas"] = "10000000" +# genesis_json_object["gov"]["voting_params"]["voting_period"] = '60s' + exported_genesis = open(os.environ["OLD_GENESIS"], "r").read() exported_genesis_json_object = json.loads(exported_genesis) diff --git a/.github/actions/upgrade-testing/scripts/create_genesis.py b/.github/actions/upgrade-testing/scripts/create_genesis.py new file mode 100644 index 0000000000..ce5e3627dd --- /dev/null +++ b/.github/actions/upgrade-testing/scripts/create_genesis.py @@ -0,0 +1,49 @@ +import json +import os + +print("OPEN NEW GENESIS") +genesis = open(os.environ["NEW_GENESIS"], "r").read() +genesis_json_object = json.loads(genesis) + +print("OPEN OLD GENESIS") +exported_genesis = open(os.environ["OLD_GENESIS"], "r").read() +exported_genesis_json_object = json.loads(exported_genesis) + +print("PULL STATE OUT OF OLD GENESIS") +crosschain = exported_genesis_json_object["app_state"]["crosschain"] +observer = exported_genesis_json_object["app_state"]["observer"] +emissions = exported_genesis_json_object["app_state"]["emissions"] +fungible = exported_genesis_json_object["app_state"]["fungible"] +evm = exported_genesis_json_object["app_state"]["evm"] +auth_accounts = exported_genesis_json_object["app_state"]["auth"]["accounts"] + +print("MANIPULATE NEW GENESIS") +genesis_json_object["app_state"]["auth"]["accounts"] = genesis_json_object["app_state"]["auth"]["accounts"] + auth_accounts +genesis_json_object["app_state"]["crosschain"] = crosschain +genesis_json_object["app_state"]["observer"] = observer +genesis_json_object["app_state"]["emissions"] = emissions +genesis_json_object["app_state"]["fungible"] = fungible + +evm_accounts = [] +for index, account in enumerate(evm["accounts"]): + if account["address"] == "0x0000000000000000000000000000000000000001": + print("pop account", account["address"]) + elif account["address"] == "0x0000000000000000000000000000000000000006": + print("pop account", account["address"]) + elif account["address"] == "0x0000000000000000000000000000000000000002": + print("pop account", account["address"]) + elif account["address"] == "0x0000000000000000000000000000000000000002": + print("pop account", account["address"]) + elif account["address"] == "0x0000000000000000000000000000000000000008": + print("pop account", account["address"]) + else: + evm_accounts.append(account) +evm["accounts"] = evm_accounts +genesis_json_object["app_state"]["evm"] = evm + +print("WRITE GENESIS-EDITED") +genesis = open("genesis-edited.json", "w") +genesis_string = json.dumps(genesis_json_object, indent=2) +dumped_genesis_object = genesis_string.replace("0x0000000000000000000000000000000000000001","0x387A12B28fe02DcAa467c6a1070D19B82F718Bb5") +genesis.write(genesis_string) +genesis.close() diff --git a/.github/actions/upgrade-testing/scripts/get_proposal_id.py b/.github/actions/upgrade-testing/scripts/get_proposal_id.py new file mode 100644 index 0000000000..39105228de --- /dev/null +++ b/.github/actions/upgrade-testing/scripts/get_proposal_id.py @@ -0,0 +1,23 @@ +import json +import subprocess +import os + +os.environ['NODE'] = "http://127.0.0.1:26657" +def run_command(self, cmd): + COMMAND_PREFIX = "export PATH=" + self.go_path + ":${PATH} && " + cmd = COMMAND_PREFIX + cmd + result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True) + result_output = result.stdout.decode('utf-8') + return result_output + +try: + QUERY_GOV_PROPOSAL = f"""zetacored query gov proposals --output json --node {os.environ['NODE']}""" + GOV_PROPOSALS = json.loads(run_command(QUERY_GOV_PROPOSAL)) + for proposal in GOV_PROPOSALS["proposals"]: + try: + PROPOSAL_ID = proposal["id"] + except Exception as e: + print(1) + print(PROPOSAL_ID) +except Exception as e: + print(1) \ No newline at end of file diff --git a/.github/actions/upgrade-testing/scripts/raise_gov_proposal.py b/.github/actions/upgrade-testing/scripts/raise_gov_proposal.py new file mode 100644 index 0000000000..8cb876e71f --- /dev/null +++ b/.github/actions/upgrade-testing/scripts/raise_gov_proposal.py @@ -0,0 +1,63 @@ +import os +import requests +import json + +os.environ['NODE'] = "http://127.0.0.1:26657" +CURRENT_HEIGHT = requests.get(f"{os.environ['NODE']}/status").json()["result"]["sync_info"]["latest_block_height"] +UPGRADE_HEIGHT = int(CURRENT_HEIGHT) + ( + int(os.environ['PROPOSAL_TIME_SECONDS']) / int(os.environ['BLOCK_TIME_SECONDS'])) + 20 +github_file = open(os.environ["GITHUB_ENV"], "a+") +github_file.write(f"UPGRADE_HEIGHT={UPGRADE_HEIGHT}") +github_file.close() + +proposal_json = { + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": os.environ["GOV_ADDRESS"], + "plan": { + "name": os.environ['VERSION'], + "time": "0001-01-01T00:00:00Z", + "height": str(UPGRADE_HEIGHT).split('.')[0], + "info": os.environ["UPGRADE_INFO"], + "upgraded_client_state": None + } + } + ], + "metadata": os.environ["METADATA"], + "deposit": os.environ["DEPOSIT"] +} + +proposal_json = json.dumps(proposal_json) +write_gov_json = open("gov.json", "w") +write_gov_json.write(proposal_json) +write_gov_json.close() + +GOV_PROPOSAL = f"""zetacored tx gov submit-proposal gov.json \ +--from {os.environ['MONIKER']} \ +--chain-id "{os.environ['CHAINID']}" \ +--keyring-backend test \ +--node "{os.environ['NODE']}" \ +--gas=auto \ +--gas-adjustment=2 \ +--gas-prices={os.environ['GAS_PRICES']} \ +-y +""" + +# GOV_PROPOSAL = f"""zetacored tx gov submit-legacy-proposal software-upgrade "{os.environ['VERSION']}" \ +# --from "{os.environ['MONIKER']}" \ +# --deposit {os.environ["DEPOSIT"]} \ +# --upgrade-height "{str(UPGRADE_HEIGHT).split('.')[0]}" \ +# --upgrade-info '{os.environ["UPGRADE_INFO"]}' \ +# --title "{os.environ['VERSION']}" \ +# --description "Zeta Release {os.environ['VERSION']}" \ +# --chain-id "{os.environ['CHAINID']}" \ +# --node "{os.environ['NODE']}" \ +# --keyring-backend test \ +# --gas=auto \ +# --gas-adjustment=2 \ +# --gas-prices={os.environ['GAS_PRICES']} \ +# -y \ +# --no-validate""" + +print(GOV_PROPOSAL) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce4ba4a4dc..f6012ce610 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -245,7 +245,6 @@ jobs: shell: alpine.sh --root {0} run: | git config --global --add safe.directory '*' - go mod tidy make install-testnet cp "$HOME"/go/bin/* ./ diff --git a/.github/workflows/upgrade_path_testing.yaml b/.github/workflows/upgrade_path_testing.yaml index c6864da9ba..418fe3b84b 100644 --- a/.github/workflows/upgrade_path_testing.yaml +++ b/.github/workflows/upgrade_path_testing.yaml @@ -3,28 +3,54 @@ name: "UPGRADE_PATH_TESTING" on: workflow_dispatch: inputs: - runner: - description: 'Select an Runner Set' - type: choice - required: true - default: 'zeta-runners-athens3' - options: [ 'zeta-runners', 'zeta-runners-athens3'] version: description: 'The new version to upgrade to from latest state.' required: true - default: 'v10.0.0' + default: 'v9.0.6' jobs: upgrade_path_test_state_export: name: "UPGRADE_PATH_TEST_STATE_EXPORT" - runs-on: ["${{ github.event.inputs.runner }}"] + runs-on: ["buildjet-8vcpu-ubuntu-2204"] env: latest_state_export: "https://zetachain-external-files.s3.amazonaws.com/state-export/athens3/latest.json" github_binary_version_link: "https://github.com/zeta-chain/node/releases/download/${{ github.event.inputs.version }}/zetacored-ubuntu-22-amd64" downloaded_binary_name: "zetacored-ubuntu-22-amd64" + VERSION: "${{ github.event.inputs.version }}" aws_region: "us-east-1" + GAS_PRICES: "1.0azeta" + DEPOSIT: "10000000000000000000azeta" + METADATA: "ipfs://QmeABfwZ2nAxDzYyqZ1LEypPgQFMjEyrx8FfnoPLkF8R3f" + LOG_LEVEL: "INFO" + CHAINID: "localnet_101-1" + DAEMON_HOME: "/home/runner/.zetacored" + DAEMON_NAME: "zetacored" + DENOM: "azeta" + DAEMON_ALLOW_DOWNLOAD_BINARIES: "false" + DAEMON_RESTART_AFTER_UPGRADE: "true" + MONIKER: "zeta" + BLOCK_TIME_SECONDS: "6" + PROPOSAL_TIME_SECONDS: "60" + UNSAFE_SKIP_BACKUP: "true" + CLIENT_DAEMON_NAME: "zetaclientd" + CLIENT_DAEMON_ARGS: "-enable-chains,GOERLI,-val,zeta" + CLIENT_SKIP_UPGRADE: "true" + CLIENT_START_PROCESS: "false" + BINARY_NAME_SUFFIX: "ubuntu-22-amd64" + UPGRADES_SLEEP_TIME: "300" + KEYRING: "test" + STATUS_ENDPOINT: "http://127.0.0.1:26657/status" + ABCI_ENDPOINT: "http://127.0.0.1:26657/abci_info" + ENDPOINT: "http://127.0.0.1:26657" + SLEEP_DURATION: "5" + GOV_ADDRESS: "zeta10d07y265gmmuvt4z0w9aw880jnsr700jvxasvr" + previous_height: "-1" + stalled_count: "0" + first: "true" + MAX_TRIES: "100" + count: "0" steps: - uses: actions/checkout@v1 @@ -33,33 +59,66 @@ jobs: with: version: 2 - - name: "DOWNLOAD_STATE_EXPORT_AND_BINARY" - shell: python + - uses: actions/setup-go@v4 + with: + check-latest: false + go-version: '^1.20' + + - name: "CLONE:ZETAVISOR:REPOSITORY" + uses: actions/checkout@v2 + with: + repository: zeta-chain/cosmos-sdk + path: zetavisor/ + ref: zetavisor-v0.1.5 + + - name: "INSTALL_APT_PACKAGES" + working-directory: "zetavisor/cosmovisor" run: | - wget ${latest_state_export} - wget github_binary_version_link - current_version=$(curl https://rpc-archive.athens.zetachain.com:26657/abci_info -s | jq .result.response.version -r | tr -d '\n') - wget https://github.com/zeta-chain/node/releases/download/${current_version}/zetacored-ubuntu-22-amd64 -O ./zetacored - echo "PATH=$(pwd):$PATH" >> ${GITHUB_ENV} + echo "*********INSTALL SOME APT PACKAGES*********" + sudo apt update + sudo apt install unzip psmisc -y - - name: "START_TESTING_NETWORK" - shell: shell + - name: "INSTALL_ZETAVISOR" + working-directory: "zetavisor/cosmovisor" run: | - export DAEMON_HOME=~/.zetacored + echo "*********INSTALL ZETAVISOR*********" + go get github.com/zeta-chain/cosmos-sdk/cosmovisor/cmd/zetavisor + go install github.com/zeta-chain/cosmos-sdk/cosmovisor/cmd/zetavisor + zetavisor version || echo "zetavisor failed to install." - export DAEMON_NAME=zetacored - - export CHAINID="localnet_101-1" - - export KEYRING="test" - - rm -rf ~/.zetacored - - kill -9 $(lsof -ti:26657) + echo "*********SETUP ZETAVISOR DIRECTORIES*********" + rm -rf /home/runner/.zetacored + mkdir -p /home/runner/.zetacored/zetavisor + mkdir -p /home/runner/.zetacored/zetavisor/genesis/bin + mkdir -p /home/runner/.zetacored/zetavisor/upgrades/${{ github.event.inputs.version }}/bin + + - name: "DOWNLOAD_STATE_EXPORT_AND_BINARIES" + run: | + echo "*********DOWNLOAD STATE EXPORT*********" + wget -q ${latest_state_export} - zetacored config keyring-backend $KEYRING --home ~/.zetacored + echo "*********DOWNLOAD UPGRADE BINARY AND PUT IN ZETAVISOR UPGRADES FOLDER*********" + wget -q ${github_binary_version_link} -O /home/runner/.zetacored/zetavisor/upgrades/${{ github.event.inputs.version }}/bin/zetacored + ZETACORED_CHECKSUM=$(shasum -b -a 256 /home/runner/.zetacored/zetavisor/upgrades/${{ github.event.inputs.version }}/bin/zetacored | cut -d ' ' -f 1) + echo "ZETACORED_CHECKSUM=${ZETACORED_CHECKSUM}" >> ${GITHUB_ENV} + UPGRADE_INFO='{"binaries": {"zetacored-linux/amd64": "https://github.com/zeta-chain/node/releases/download/${{ github.event.inputs.version }}/zetacored-ubuntu-22-amd64?checksum=sha256:'${ZETACORED_CHECKSUM}'"}}' + echo ${UPGRADE_INFO} + echo "UPGRADE_INFO=${UPGRADE_INFO}" >> ${GITHUB_ENV} + sudo chmod a+x /home/runner/.zetacored/zetavisor/upgrades/${{ github.event.inputs.version }}/bin/zetacored + + echo "*********DOWNLOAD CURRENT BINARY AND PUT IN ZETAVISOR GENESIS & CURRENT FOLDER*********" + current_version=$(curl https://rpc-archive.athens.zetachain.com:26657/abci_info -s | jq .result.response.version -r | tr -d '\n') + echo "STARTING_VERSION=${current_version}" >> ${GITHUB_ENV} + echo "STARTING_VERSION=${current_version}" + wget -q https://github.com/zeta-chain/node/releases/download/${current_version}/zetacored-ubuntu-22-amd64 -O /home/runner/.zetacored/zetavisor/genesis/bin/zetacored + sudo chmod a+x /home/runner/.zetacored/zetavisor/genesis/bin/zetacored + echo "PATH=/home/runner/.zetacored/zetavisor/genesis/bin:$PATH" >> ${GITHUB_ENV} + + - name: "START_TESTING_NETWORK" + run: | + zetacored config keyring-backend $KEYRING --home ${DAEMON_HOME} - zetacored config chain-id $CHAINID --home ~/.zetacored + zetacored config chain-id $CHAINID --home ${DAEMON_HOME} zetacored keys delete zetaa --keyring-backend $KEYRING -y > /dev/null 2>&1 || echo "doesn't exist" zetacored keys delete executer_zeta --keyring-backend $KEYRING -y > /dev/null 2>&1 || echo "doesn't exist" @@ -97,10 +156,8 @@ jobs: cat $DAEMON_HOME/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $DAEMON_HOME/config/tmp_genesis.json && mv $DAEMON_HOME/config/tmp_genesis.json $DAEMON_HOME/config/genesis.json cat $DAEMON_HOME/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $DAEMON_HOME/config/tmp_genesis.json && mv $DAEMON_HOME/config/tmp_genesis.json $DAEMON_HOME/config/genesis.json cat $DAEMON_HOME/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $DAEMON_HOME/config/tmp_genesis.json && mv $DAEMON_HOME/config/tmp_genesis.json $DAEMON_HOME/config/genesis.json - - contents="$(jq '.app_state.gov.voting_params.voting_period = "10s"' $DAEMON_HOME/config/genesis.json)" && \ - echo "${contents}" > $DAEMON_HOME/config/genesis.json - + cat $DAEMON_HOME/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="60s"' > $DAEMON_HOME/config/tmp_genesis.json && mv $DAEMON_HOME/config/tmp_genesis.json $DAEMON_HOME/config/genesis.json + sed -i '/\[api\]/,+3 s/enable = false/enable = true/' $DAEMON_HOME/config/app.toml zetacored add-observer-list observers.json --keygen-block=5 @@ -112,32 +169,39 @@ jobs: echo "Validating genesis file..." zetacored validate-genesis - - rm -rf ./genesis.json - rm -rf ./genesis-edited.json - + cp $DAEMON_HOME/config/genesis.json ./genesis.json - + echo "Do Genesis Manipulation" export OLD_GENESIS=./latest.json export NEW_GENESIS=./genesis.json - - python .github/actions/upgrade-testing/create_genesis.py + + python .github/actions/upgrade-testing/scripts/create_genesis.py echo "Move Manipulated Genesis" cp ./genesis-edited.json $DAEMON_HOME/config/genesis.json echo "Start Network" - zetacored start + nohup zetavisor start --rpc.laddr tcp://0.0.0.0:26657 --minimum-gas-prices ${GAS_PRICES} "--grpc.enable=true" > cosmovisor.log 2>&1 & + + sleep ${UPGRADES_SLEEP_TIME} + cat cosmovisor.log - name: "DETERMINE_UPGRADE_TYPE" shell: python run: | import os + + first_version=os.environ["STARTING_VERSION"] + first_major_version = first_version.split(".")[0] + first_minor_version = first_version.split(".")[1] + first_sub_version = first_version.split(".")[2] + version="${{ github.event.inputs.version }}" major_version = version.split(".")[0] minor_version = version.split(".")[1] sub_version = version.split(".")[2] + git_env_file = open(os.environ["GITHUB_ENV"], "a+") if major_version == first_major_version and minor_version != first_minor_version: git_env_file.write("UPGRADE_TYPE=NONCON") @@ -146,8 +210,205 @@ jobs: else: git_env_file.write("UPGRADE_TYPE=GOV") git_env_file.close() - - - name: "CHECK_UPGRADE_TYPE" - shell: shell + + - name: "NON_CONSENSUS_BREAKING_UPGRADE" + if: env.UPGRADE_TYPE == 'NONCON' run: | - echo ${UPGRADE_TYPE} \ No newline at end of file + echo ${UPGRADE_TYPE} + echo "*********CHECK VERSION BEFORE BINARY SWITCH*********" + zetavisor version + + echo "*********KILLALL ZETAVISOR*********" + killall zetavisor + + echo "*********COPY UPGRADE BINARY TO NEW LOCATION*********" + rm -rf /home/runner/.zetacored/zetavisor/genesis/bin/zetacored + rm -rf /home/runner/.zetacored/zetavisor/current/bin/zetacored + + cp /home/runner/.zetacored/zetavisor/upgrades/${{ github.event.inputs.version }}/bin/zetacored /home/runner/.zetacored/zetavisor/genesis/bin/zetacored + cp /home/runner/.zetacored/zetavisor/upgrades/${{ github.event.inputs.version }}/bin/zetacored /home/runner/.zetacored/zetavisor/current/bin/zetacored + nohup zetavisor start --rpc.laddr tcp://0.0.0.0:26657 --minimum-gas-prices ${GAS_PRICES} "--grpc.enable=true" > cosmovisor.log 2>&1 & + + sleep ${UPGRADES_SLEEP_TIME} + cat cosmovisor.log + echo "*********CHECK VERSION AFTER BINARY SWITCH*********" + check_version=$(zetavisor version | tr -d '\n') + http_version=$(curl http://127.0.0.1:26657/abci_info | jq .result.response.version -r | tr -d '\n') + + echo "END_VERSION=${{ github.event.inputs.version }}" + echo "CURRENT_VERSION_BINARY=${check_version}" + echo "CURRENT_VERSION_HTTP=${http_version}" + + if [ "${{ github.event.inputs.version }}" == "${check_version}" ]; then + if [ "${{ github.event.inputs.version }}" == "${http_version}" ]; then + echo "*********VERSION MATCHES UPGRADE SUCCESS*********" + exit 0 + else + echo "*********VERSION DOESN'T MATCH UPGRADE FAILED*********" + exit 2 + fi + else + echo "*********VERSION DOESN'T MATCH UPGRADE FAILED*********" + exit 2 + fi + + - name: "CONSENSUS_BREAKING_UPGRADE" + if: env.UPGRADE_TYPE == 'GOV' #GOV + run: | + echo "*****UPGRADE TYPE*****" + echo ${UPGRADE_TYPE} + + echo "*****BUILD GOV PROPOSAL*****" + GOV_PROPOSAL=$(python .github/actions/upgrade-testing/scripts/raise_gov_proposal.py) + + echo "${GOV_PROPOSAL}" + cat gov.json + + GOV_PROPOSAL_OUTPUT=$(eval ${GOV_PROPOSAL}) + + echo "*****GOV PROPOSAL OUTPUT*****" + echo ${GOV_PROPOSAL_OUTPUT} + + echo "*****GET TX HASH*****" + TX_HASH=$(echo ${GOV_PROPOSAL_OUTPUT} | awk -F'txhash: ' '{print $2}' | tr -d '\n' | tr -d ' ') + echo "****TXHASH: ${TX_HASH}****" + + echo "*****SLEEP FOR 1 MIN TO ALLOW TX TO MAKE IT ON NETWORK*****" + sleep 15 + + zetacored query tx --type=hash ${TX_HASH} + + proposal_id=$(python .github/actions/upgrade-testing/scripts/get_proposal_id.py) + echo "****PROPOSAL_ID: ${proposal_id}****" + + source ${GITHUB_ENV} + + zetacored tx gov vote "${proposal_id}" yes \ + --from ${MONIKER} \ + --keyring-backend test \ + --chain-id ${CHAINID} \ + --node http://127.0.0.1:26657 \ + --gas=auto \ + --gas-adjustment=2 \ + --gas-prices=${{ env.GAS_PRICES }} \ + -y + + sleep 5 + zetacored query gov proposal ${proposal_id} --node http://127.0.0.1:26657 + + TARGET_HEIGHT=$(echo ${UPGRADE_HEIGHT} | cut -d '.' -f 1) + + echo "**** CHECK FOR HEIGHT ${TARGET_HEIGHT} ****" + while [[ $count -lt $MAX_TRIES ]] + do + echo "CURL FOR CURRENT HEIGHT" + response=$(curl -s "$ENDPOINT/status" || echo "failed curl") + if [ $? -ne 0 ]; then + echo "CURL failed with exit code $?" + else + echo "curl success" + fi + echo "curl success" + echo "${response}" + current_height=$(echo $response | jq '.result.sync_info.latest_block_height' | tr -d '"') + echo "Current Height: $current_height" + echo "Target Height: $TARGET_HEIGHT" + + if [[ $current_height -ge $TARGET_HEIGHT ]]; then + echo "Reached target height: $current_height. Sleep and wait for upgrade to take place." + sleep 120 + break + fi + + echo "attempt number ${count} of ${MAX_TRIES}" + ((count=count+1)) + echo "sleep and ty again." + sleep 10 + done + + if [[ $count -eq $MAX_TRIES ]]; then + cat cosmovisor.log + echo "Max tries reached without achieving target height." + exit 2 + fi + + for (( i=1; i<=MAX_TRIES; i++ )) + do + pgrep zetavisor > /dev/null + if [[ $? -ne 0 ]]; then + cat cosmovisor.log + echo "zetavisor process not found." + exit 2 + fi + + response=$(curl -s "$STATUS_ENDPOINT") + + # If curl fails + if [[ $? -ne 0 ]]; then + cat cosmovisor.log + echo "Failed to get a response from the status endpoint on try $i." + exit 2 + fi + + # Extracting the current height from the response + current_height=$(echo $response | jq '.result.sync_info.latest_block_height' | tr -d '"') + + # If jq fails or height is empty + if [[ $? -ne 0 || -z "$current_height" ]]; then + cat cosmovisor.log + echo "Failed to extract block height from the response on try $i." + exit 2 + fi + + # If the block height has changed since last check + if [[ $current_height -ne $previous_height ]]; then + if [ "${first}" == "true" ]; then + stalled_count=0 + first="false" + else + echo "Network appears to be processing blocks" + stalled_count=0 + + # Query the ABCI endpoint for version info + abci_response=$(curl -s "$ABCI_ENDPOINT") + + # Extracting the version from the response + app_version=$(echo $abci_response | jq '.result.response.version' | tr -d '"') + + # If jq fails or version is empty + if [[ $? -ne 0 || -z "$app_version" ]]; then + cat cosmovisor.log + echo "Failed to extract version from the ABCI response on try $i." + exit 2 + fi + + # Compare the extracted version with the expected version + if [[ "$app_version" == "$VERSION" ]]; then + echo "Version matches the expected version. Exiting..." + echo "ABCI RESPONSE \n ${abci_response}" + echo "Versions: $VERSION, Found: $app_version" + exit 0 + else + cat cosmovisor.log + echo "Version mismatch. Expected: $VERSION, Found: $app_version" + echo "ABCI RESPONSE \n ${abci_response}" + exit 2 + fi + fi + else + ((stalled_count=stalled_count+1)) + fi + + # Update the previous height + previous_height=$current_height + + # If we're on the last iteration and the block height hasn't changed for all tries + if [[ $i -eq $MAX_TRIES && $stalled_count -eq $MAX_TRIES ]]; then + cat cosmovisor.log + echo "Block height hasn't changed for $MAX_TRIES consecutive checks. Network might be stalled." + exit 2 + fi + + # Sleep for the specified duration + sleep $SLEEP_DURATION + done \ No newline at end of file diff --git a/Makefile b/Makefile index 1e17d79e5b..996fb0c914 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \ BUILD_FLAGS := -ldflags '$(ldflags)' -tags PRIVNET,pebbledb,ledger TESTNET_BUILD_FLAGS := -ldflags '$(ldflags)' -tags TESTNET,pebbledb,ledger +MOCK_MAINNET_BUILD_FLAGS := -ldflags '$(ldflags)' -tags MOCK_MAINNET,pebbledb,ledger +MAINNET_BUILD_FLAGS := -ldflags '$(ldflags)' -tags pebbledb,ledger TEST_DIR?="./..." TEST_BUILD_FLAGS := -tags TESTNET,pebbledb,ledger @@ -85,6 +87,17 @@ install: go.sum @go install -race -mod=readonly $(BUILD_FLAGS) ./cmd/zetacored @go install -race -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd +install-mainnet: go.sum + @echo "--> Installing zetacored & zetaclientd" + @go install -mod=readonly $(MAINNET_BUILD_FLAGS) ./cmd/zetacored + @go install -mod=readonly $(MAINNET_BUILD_FLAGS) ./cmd/zetaclientd + +install-mock-mainnet: go.sum + @echo "--> Installing zetacored & zetaclientd" + @go install -mod=readonly $(MOCK_MAINNET_BUILD_FLAGS) ./cmd/zetacored + @go install -mod=readonly $(MOCK_MAINNET_BUILD_FLAGS) ./cmd/zetaclientd + + install-zetaclient: go.sum @echo "--> Installing zetaclientd" @go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd @@ -129,6 +142,9 @@ chain-stop: chain-init-testnet: clean install-zetacore-testnet init chain-run-testnet: clean install-zetacore-testnet init run +chain-init-mock-mainnet: clean install-mock-mainnet init +chain-run-mock-mainnet: clean install-mock-mainnet init run + lint-pre: @test -z $(gofmt -l .) @GOFLAGS=$(GOFLAGS) go mod verify diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 66e168f7ee..47d63564ad 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -5,23 +5,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" - crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -const releaseVersion = "v9.0.0" +const releaseVersion = "v10.0.0" func SetupHandlers(app *App) { app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { app.Logger().Info("Running upgrade handler for " + releaseVersion) - // Updated version map to the latest consensus versions from each module for m, mb := range app.mm.Modules { vm[m] = mb.ConsensusVersion() } - vm[observertypes.ModuleName] = vm[observertypes.ModuleName] - 1 - vm[crosschaintypes.ModuleName] = vm[crosschaintypes.ModuleName] - 1 - SetParams(app, ctx) + return app.mm.RunMigrations(ctx, app.configurator, vm) }) @@ -40,11 +35,3 @@ func SetupHandlers(app *App) { app.SetStoreLoader(types.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } } - -// SetParams sets the default params for the observer module -// A new policy has been added for add_observer. -func SetParams(app *App, ctx sdk.Context) { - params := app.ZetaObserverKeeper.GetParamsIsExists(ctx) - params.AdminPolicy = observertypes.DefaultAdminPolicy() - app.ZetaObserverKeeper.SetParams(ctx, params) -} diff --git a/cmd/config_mainnet.go b/cmd/config_mainnet.go index bb50270c19..dcc8c4f9e2 100644 --- a/cmd/config_mainnet.go +++ b/cmd/config_mainnet.go @@ -1,5 +1,5 @@ -//go:build !PRIVNET && !TESTNET -// +build !PRIVNET,!TESTNET +//go:build !PRIVNET && !TESTNET && !MOCK_MAINNET +// +build !PRIVNET,!TESTNET,!MOCK_MAINNET package cmd @@ -13,9 +13,4 @@ const ( DenomRegex = `[a-zA-Z][a-zA-Z0-9:\\/\\\-\\_\\.]{2,127}` ZetaChainCoinType uint32 = 60 ZetaChainHDPath string = `m/44'/60'/0'/0/0` - NET = "TESTNET" -) - -var ( - CHAINID = "zeta_7001-1" ) diff --git a/cmd/config_mock_mainnet.go b/cmd/config_mock_mainnet.go new file mode 100644 index 0000000000..c8f775c61c --- /dev/null +++ b/cmd/config_mock_mainnet.go @@ -0,0 +1,16 @@ +//go:build MOCK_MAINNET +// +build MOCK_MAINNET + +package cmd + +const ( + Bech32PrefixAccAddr = "zeta" + Bech32PrefixAccPub = "zetapub" + Bech32PrefixValAddr = "zetav" + Bech32PrefixValPub = "zetavpub" + Bech32PrefixConsAddr = "zetac" + Bech32PrefixConsPub = "zetacpub" + DenomRegex = `[a-zA-Z][a-zA-Z0-9:\\/\\\-\\_\\.]{2,127}` + ZetaChainCoinType uint32 = 60 + ZetaChainHDPath string = `m/44'/60'/0'/0/0` +) diff --git a/cmd/zetaclientd/init.go b/cmd/zetaclientd/init.go index 303ce02e90..79ef1833cb 100644 --- a/cmd/zetaclientd/init.go +++ b/cmd/zetaclientd/init.go @@ -1,10 +1,8 @@ package main import ( - etherminttypes "github.com/evmos/ethermint/types" "github.com/rs/zerolog" "github.com/spf13/cobra" - "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/zetaclient/config" ) @@ -86,16 +84,7 @@ func Initialize(_ *cobra.Command, _ []string) error { configData.TssPath = initArgs.TssPath configData.P2PDiagnosticTicker = initArgs.p2pDiagnosticTicker configData.ConfigUpdateTicker = initArgs.configUpdateTicker - initChainID(&configData) //Save config file return config.Save(&configData, rootArgs.zetaCoreHome) } - -func initChainID(configData *config.Config) { - ZEVMChainID, err := etherminttypes.ParseChainID(configData.ChainID) - if err != nil { - panic(err) - } - configData.EVMChainConfigs[common.ZetaChain().ChainId].Chain.ChainId = ZEVMChainID.Int64() -} diff --git a/cmd/zetaclientd/keygen_tss.go b/cmd/zetaclientd/keygen_tss.go index d06848e071..3b303450c3 100644 --- a/cmd/zetaclientd/keygen_tss.go +++ b/cmd/zetaclientd/keygen_tss.go @@ -15,14 +15,15 @@ import ( observerTypes "github.com/zeta-chain/zetacore/x/observer/types" mc "github.com/zeta-chain/zetacore/zetaclient" "github.com/zeta-chain/zetacore/zetaclient/config" + "github.com/zeta-chain/zetacore/zetaclient/metrics" tsscommon "gitlab.com/thorchain/tss/go-tss/common" "gitlab.com/thorchain/tss/go-tss/keygen" "gitlab.com/thorchain/tss/go-tss/p2p" ) -func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaCoreBridge, peers p2p.AddrList, priKey secp256k1.PrivKey, ts *mc.TelemetryServer, tssHistoricalList []types.TSS) (*mc.TSS, error) { +func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaCoreBridge, peers p2p.AddrList, priKey secp256k1.PrivKey, ts *mc.TelemetryServer, tssHistoricalList []types.TSS, metrics *metrics.Metrics) (*mc.TSS, error) { keygenLogger := logger.With().Str("module", "keygen").Logger() - tss, err := mc.NewTSS(peers, priKey, preParams, cfg, zetaBridge, tssHistoricalList) + tss, err := mc.NewTSS(peers, priKey, preParams, cfg, zetaBridge, tssHistoricalList, metrics) if err != nil { keygenLogger.Error().Err(err).Msg("NewTSS error") return nil, err @@ -69,7 +70,7 @@ func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaC if currentBlock != keyGen.BlockNumber { if currentBlock > lastBlock { lastBlock = currentBlock - keygenLogger.Info().Msgf("Waiting For Keygen Block to arrive or new keygen block to be set. Keygen Block : %d Current Block : %d", keyGen.BlockNumber, currentBlock) + keygenLogger.Info().Msgf("Waiting For Keygen Block to arrive or new keygen block to be set. Keygen Block : %d Current Block : %d ChainID %s ", keyGen.BlockNumber, currentBlock, cfg.ChainID) } continue } diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 2cfb8d4a0a..211dbe8d8c 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -81,6 +81,7 @@ func start(_ *cobra.Command, _ []string) error { if strings.Compare(res.GetDefaultNodeInfo().Network, cfg.ChainID) != 0 { startLogger.Warn().Msgf("chain id mismatch, zeta-core chain id %s, zeta client chain id %s; reset zeta client chain id", res.GetDefaultNodeInfo().Network, cfg.ChainID) cfg.ChainID = res.GetDefaultNodeInfo().Network + zetaBridge.UpdateChainID(cfg.ChainID) } // CreateAuthzSigner : which is used to sign all authz messages . All votes broadcast to zetacore are wrapped in authz exec . @@ -135,6 +136,14 @@ func start(_ *cobra.Command, _ []string) error { startLogger.Error().Err(err).Msg("telemetryServer error") } }() + + metrics, err := metrics2.NewMetrics() + if err != nil { + log.Error().Err(err).Msg("NewMetrics") + return err + } + metrics.Start() + var tssHistoricalList []types.TSS tssHistoricalList, err = zetaBridge.GetTssHistory() if err != nil { @@ -142,7 +151,7 @@ func start(_ *cobra.Command, _ []string) error { } telemetryServer.SetIPAddress(cfg.PublicIP) - tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer, tssHistoricalList) + tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer, tssHistoricalList, metrics) if err != nil { return err } @@ -204,23 +213,9 @@ func start(_ *cobra.Command, _ []string) error { return err } - metrics, err := metrics2.NewMetrics() - if err != nil { - log.Error().Err(err).Msg("NewMetrics") - return err - } - metrics.Start() - userDir, _ := os.UserHomeDir() dbpath := filepath.Join(userDir, ".zetaclient/chainobserver") - // Register zetaclient.TSS prometheus metrics - err = tss.RegisterMetrics(metrics) - if err != nil { - startLogger.Err(err).Msg("tss.RegisterMetrics") - return err - } - // CreateChainClientMap : This creates a map of all chain clients . Each chain client is responsible for listening to events on the chain and processing them chainClientMap, err := CreateChainClientMap(zetaBridge, tss, dbpath, metrics, masterLogger, cfg, telemetryServer) if err != nil { @@ -243,7 +238,11 @@ func start(_ *cobra.Command, _ []string) error { // stop zetacore observer for _, chain := range cfg.GetEnabledChains() { - (chainClientMap)[chain].Stop() + // zeta chain does not have a chain client + if chain.IsExternalChain() { + (chainClientMap)[chain].Stop() + } + } zetaBridge.Stop() diff --git a/cmd/zetacored/observer_accounts.go b/cmd/zetacored/observer_accounts.go index 5efc118277..397146a688 100644 --- a/cmd/zetacored/observer_accounts.go +++ b/cmd/zetacored/observer_accounts.go @@ -28,6 +28,10 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) +// Token distribution +// Validators Only = ValidatorTokens sent to their operator address +// Observer = ObserverTokens sent to their operator address + HotkeyTokens sent to their hotkey address +// HotkeyTokens are for operational expenses such as paying for gas fees const ( ValidatorTokens = "100000000000000000000000" ObserverTokens = "4100000000000000000000000" diff --git a/common/default_chains_mainnet.go b/common/default_chains_mainnet.go index c57cd2f1be..18868b5a13 100644 --- a/common/default_chains_mainnet.go +++ b/common/default_chains_mainnet.go @@ -1,5 +1,5 @@ -//go:build !PRIVNET && !TESTNET -// +build !PRIVNET,!TESTNET +//go:build !PRIVNET && !TESTNET && !MOCK_MAINNET +// +build !PRIVNET,!TESTNET,!MOCK_MAINNET package common @@ -20,7 +20,7 @@ func BscMainnetChain() Chain { func ZetaChain() Chain { return Chain{ ChainName: ChainName_zeta_mainnet, - ChainId: 101, + ChainId: 7000, } } @@ -41,7 +41,6 @@ func PolygonChain() Chain { func DefaultChainsList() []*Chain { chains := []Chain{ BtcMainnetChain(), - PolygonChain(), BscMainnetChain(), EthChain(), ZetaChain(), @@ -52,3 +51,16 @@ func DefaultChainsList() []*Chain { } return c } + +func ExternalChainList() []*Chain { + chains := []Chain{ + BtcMainnetChain(), + BscMainnetChain(), + EthChain(), + } + var c []*Chain + for i := 0; i < len(chains); i++ { + c = append(c, &chains[i]) + } + return c +} diff --git a/common/default_chains_mock_mainnet.go b/common/default_chains_mock_mainnet.go new file mode 100644 index 0000000000..6498ed087e --- /dev/null +++ b/common/default_chains_mock_mainnet.go @@ -0,0 +1,66 @@ +//go:build MOCK_MAINNET +// +build MOCK_MAINNET + +package common + +func EthChain() Chain { + return Chain{ + ChainName: ChainName_eth_mainnet, + ChainId: 1, + } +} + +func BscMainnetChain() Chain { + return Chain{ + ChainName: ChainName_bsc_mainnet, + ChainId: 56, + } +} + +func ZetaChain() Chain { + return Chain{ + ChainName: ChainName_zeta_mainnet, + ChainId: 70000, + } +} + +func BtcMainnetChain() Chain { + return Chain{ + ChainName: ChainName_btc_mainnet, + ChainId: 8332, + } +} + +func PolygonChain() Chain { + return Chain{ + ChainName: ChainName_polygon_mainnet, + ChainId: 137, + } +} + +func DefaultChainsList() []*Chain { + chains := []Chain{ + BtcMainnetChain(), + BscMainnetChain(), + EthChain(), + ZetaChain(), + } + var c []*Chain + for i := 0; i < len(chains); i++ { + c = append(c, &chains[i]) + } + return c +} + +func ExternalChainList() []*Chain { + chains := []Chain{ + BtcMainnetChain(), + BscMainnetChain(), + EthChain(), + } + var c []*Chain + for i := 0; i < len(chains); i++ { + c = append(c, &chains[i]) + } + return c +} diff --git a/common/default_chains_privnet.go b/common/default_chains_privnet.go index 328799d7c8..f415cc0af7 100644 --- a/common/default_chains_privnet.go +++ b/common/default_chains_privnet.go @@ -36,3 +36,15 @@ func DefaultChainsList() []*Chain { } return c } + +func ExternalChainList() []*Chain { + chains := []Chain{ + BtcRegtestChain(), + GoerliChain(), + } + var c []*Chain + for i := 0; i < len(chains); i++ { + c = append(c, &chains[i]) + } + return c +} diff --git a/common/default_chains_testnet.go b/common/default_chains_testnet.go index 23942c1e22..74473464ca 100644 --- a/common/default_chains_testnet.go +++ b/common/default_chains_testnet.go @@ -52,3 +52,17 @@ func DefaultChainsList() []*Chain { } return c } + +func ExternalChainList() []*Chain { + chains := []Chain{ + BtcTestNetChain(), + MumbaiChain(), + BscTestnetChain(), + GoerliChain(), + } + var c []*Chain + for i := 0; i < len(chains); i++ { + c = append(c, &chains[i]) + } + return c +} diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index b6e222894a..e1cf35b007 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -50785,6 +50785,9 @@ definitions: type: boolean fungibleMsgDeployFungibleCoinZRC20Response: type: object + properties: + address: + type: string fungibleMsgRemoveForeignCoinResponse: type: object fungibleMsgUpdateContractBytecodeResponse: diff --git a/proto/fungible/tx.proto b/proto/fungible/tx.proto index 5e2b7d5299..bd7a67794a 100644 --- a/proto/fungible/tx.proto +++ b/proto/fungible/tx.proto @@ -45,7 +45,9 @@ message MsgDeployFungibleCoinZRC20 { int64 gas_limit = 8; } -message MsgDeployFungibleCoinZRC20Response {} +message MsgDeployFungibleCoinZRC20Response { + string address = 1; +} message MsgRemoveForeignCoin { string creator = 1; diff --git a/standalone-network/run-zetaclient.sh b/standalone-network/run-zetaclient.sh index 8c8a27b71e..5ad3375ea9 100644 --- a/standalone-network/run-zetaclient.sh +++ b/standalone-network/run-zetaclient.sh @@ -1,2 +1,2 @@ -zetaclientd init --chain-id localnet_101-1 --operator zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk --hotkey=zeta --public-ip=0.0.0.0 +zetaclientd init --chain-id localnet_101-1 --operator zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax --hotkey=zeta --public-ip=0.0.0.0 zetaclientd start \ No newline at end of file diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index 22b57c6cde..2eef2b61b0 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -7,6 +7,8 @@ import ( "strconv" "testing" + "github.com/zeta-chain/zetacore/cmd/zetacored/config" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -113,3 +115,8 @@ func StringRandom(r *rand.Rand, length int) string { } return string(result) } + +// Coins returns a sample sdk.Coins +func Coins() sdk.Coins { + return sdk.NewCoins(sdk.NewCoin(config.BaseDenom, sdk.NewInt(42))) +} diff --git a/x/crosschain/keeper/keeper_cross_chain_tx_vote_inbound_tx.go b/x/crosschain/keeper/keeper_cross_chain_tx_vote_inbound_tx.go index fba173c240..01c8e5d822 100644 --- a/x/crosschain/keeper/keeper_cross_chain_tx_vote_inbound_tx.go +++ b/x/crosschain/keeper/keeper_cross_chain_tx_vote_inbound_tx.go @@ -105,12 +105,14 @@ func (k msgServer) VoteOnObservedInboundTx(goCtx context.Context, msg *types.Msg } // Validation if we want to send ZETA to external chain, but there is no ZETA token. - coreParams, found := k.zetaObserverKeeper.GetCoreParamsByChainID(ctx, receiverChain.ChainId) - if !found { - return nil, types.ErrNotFoundCoreParams - } - if receiverChain.IsExternalChain() && coreParams.ZetaTokenContractAddress == "" && msg.CoinType == common.CoinType_Zeta { - return nil, types.ErrUnableToSendCoinType + if receiverChain.IsExternalChain() { + coreParams, found := k.zetaObserverKeeper.GetCoreParamsByChainID(ctx, receiverChain.ChainId) + if !found { + return nil, types.ErrNotFoundCoreParams + } + if coreParams.ZetaTokenContractAddress == "" && msg.CoinType == common.CoinType_Zeta { + return nil, types.ErrUnableToSendCoinType + } } // ****************************************************************************** diff --git a/x/fungible/keeper/begin_blocker_deploy_system_contracts.go b/x/fungible/keeper/begin_blocker_deploy_system_contracts.go index 495a51563d..8425f4e9a0 100644 --- a/x/fungible/keeper/begin_blocker_deploy_system_contracts.go +++ b/x/fungible/keeper/begin_blocker_deploy_system_contracts.go @@ -1,5 +1,5 @@ -//go:build !PRIVNET && !TESTNET -// +build !PRIVNET,!TESTNET +//go:build !PRIVNET && !TESTNET && !MOCK_MAINNET +// +build !PRIVNET,!TESTNET,!MOCK_MAINNET package keeper diff --git a/x/fungible/keeper/begin_blocker_deploy_system_contracts_mock_mainnet.go b/x/fungible/keeper/begin_blocker_deploy_system_contracts_mock_mainnet.go new file mode 100644 index 0000000000..44a45dacc9 --- /dev/null +++ b/x/fungible/keeper/begin_blocker_deploy_system_contracts_mock_mainnet.go @@ -0,0 +1,18 @@ +//go:build MOCK_MAINNET +// +build MOCK_MAINNET + +package keeper + +import ( + "context" +) + +func (k Keeper) BlockOneDeploySystemContracts(_ context.Context) error { + return nil +} +func (k Keeper) TestUpdateSystemContractAddress(_ context.Context) error { + return nil +} +func (k Keeper) TestUpdateZRC20WithdrawFee(_ context.Context) error { + return nil +} diff --git a/x/fungible/keeper/begin_blocker_deploy_system_contracts_privnet.go b/x/fungible/keeper/begin_blocker_deploy_system_contracts_privnet.go index 0c155cfa7a..579767fe35 100644 --- a/x/fungible/keeper/begin_blocker_deploy_system_contracts_privnet.go +++ b/x/fungible/keeper/begin_blocker_deploy_system_contracts_privnet.go @@ -133,7 +133,7 @@ func (k Keeper) TestUpdateSystemContractAddress(goCtx context.Context) error { return sdkerrors.Wrapf(err, "failed to DeploySystemContract") } creator := k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_deploy_fungible_coin) - msg := types.NewMessageUpdateSystemContract(creator, SystemContractAddress.Hex()) + msg := types.NewMsgUpdateSystemContract(creator, SystemContractAddress.Hex()) _, err = k.UpdateSystemContract(ctx, msg) k.Logger(ctx).Info("System contract updated", "new address", SystemContractAddress.String()) return err diff --git a/x/fungible/keeper/evm.go b/x/fungible/keeper/evm.go index c86df4d92a..df739a5157 100644 --- a/x/fungible/keeper/evm.go +++ b/x/fungible/keeper/evm.go @@ -38,7 +38,8 @@ var ( ZEVMGasLimitDepositAndCall = big.NewInt(1_000_000) ) -func (k Keeper) deployContract(ctx sdk.Context, metadata *bind.MetaData, ctorArguments ...interface{}) (common.Address, error) { +// DeployContract deploys a new contract in the ZEVM +func (k Keeper) DeployContract(ctx sdk.Context, metadata *bind.MetaData, ctorArguments ...interface{}) (common.Address, error) { contractABI, err := metadata.GetAbi() if err != nil { return common.Address{}, cosmoserrors.Wrapf(types.ErrABIGet, "failed to get ABI: %s", err.Error()) @@ -104,7 +105,7 @@ func (k Keeper) DeployZRC20Contract( if !found { return common.Address{}, cosmoserrors.Wrapf(types.ErrSystemContractNotFound, "system contract not found") } - contractAddr, err := k.deployContract(ctx, zrc20.ZRC20MetaData, + contractAddr, err := k.DeployContract(ctx, zrc20.ZRC20MetaData, name, // name symbol, // symbol decimals, // decimals @@ -134,7 +135,7 @@ func (k Keeper) DeployZRC20Contract( func (k Keeper) DeploySystemContract(ctx sdk.Context, wzeta common.Address, v2factory common.Address, router02 common.Address) (common.Address, error) { system, _ := k.GetSystemContract(ctx) - contractAddr, err := k.deployContract(ctx, systemcontract.SystemContractMetaData, wzeta, v2factory, router02) + contractAddr, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, v2factory, router02) if err != nil { return common.Address{}, cosmoserrors.Wrapf(err, "failed to deploy SystemContract") } @@ -150,7 +151,7 @@ func (k Keeper) DeployUniswapV2Factory(ctx sdk.Context) (common.Address, error) // https://etherscan.io/address/0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f#code refFactoryBytecode := "0x608060405234801561001057600080fd5b506040516136863803806136868339818101604052602081101561003357600080fd5b5051600180546001600160a01b0319166001600160a01b03909216919091179055613623806100636000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063a2e74af61161005b578063a2e74af6146100fd578063c9c6539614610132578063e6a439051461016d578063f46901ed146101a857610088565b8063017e7e581461008d578063094b7415146100be5780631e3dd18b146100c6578063574f2ba3146100e3575b600080fd5b6100956101db565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6100956101f7565b610095600480360360208110156100dc57600080fd5b5035610213565b6100eb610247565b60408051918252519081900360200190f35b6101306004803603602081101561011357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661024d565b005b6100956004803603604081101561014857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602001351661031a565b6100956004803603604081101561018357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602001351661076d565b610130600480360360208110156101be57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166107a0565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b6003818154811061022057fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60035490565b60015473ffffffffffffffffffffffffffffffffffffffff1633146102d357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60008173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156103b757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f556e697377617056323a204944454e544943414c5f4144445245535345530000604482015290519081900360640190fd5b6000808373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16106103f45783856103f7565b84845b909250905073ffffffffffffffffffffffffffffffffffffffff821661047e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f556e697377617056323a205a45524f5f41444452455353000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff82811660009081526002602090815260408083208585168452909152902054161561051f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f556e697377617056323a20504149525f45584953545300000000000000000000604482015290519081900360640190fd5b6060604051806020016105319061086d565b6020820181038252601f19601f82011660405250905060008383604051602001808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b81526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b815260140192505050604051602081830303815290604052805190602001209050808251602084016000f5604080517f485cc95500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8781166004830152868116602483015291519297509087169163485cc9559160448082019260009290919082900301818387803b15801561065e57600080fd5b505af1158015610672573d6000803e3d6000fd5b5050505073ffffffffffffffffffffffffffffffffffffffff84811660008181526002602081815260408084208987168086529083528185208054978d167fffffffffffffffffffffffff000000000000000000000000000000000000000098891681179091559383528185208686528352818520805488168517905560038054600181018255958190527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b90950180549097168417909655925483519283529082015281517f0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9929181900390910190a35050505092915050565b600260209081526000928352604080842090915290825290205473ffffffffffffffffffffffffffffffffffffffff1681565b60015473ffffffffffffffffffffffffffffffffffffffff16331461082657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b612d748061087b8339019056fe60806040526001600c5534801561001557600080fd5b506040514690806052612d228239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612c1d806101056000396000f3fe608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429a265627a7a723158202760f92d7fa1db6f5aa16307bad65df4ebcc8550c4b1f03755ab8dfd830c178f64736f6c63430005100032" uniswapv2factory.UniswapV2FactoryMetaData.Bin = refFactoryBytecode - contractAddr, err := k.deployContract(ctx, uniswapv2factory.UniswapV2FactoryMetaData, types.ModuleAddressEVM) + contractAddr, err := k.DeployContract(ctx, uniswapv2factory.UniswapV2FactoryMetaData, types.ModuleAddressEVM) if err != nil { return common.Address{}, cosmoserrors.Wrapf(err, "UniswapV2FactoryContract") } @@ -159,7 +160,7 @@ func (k Keeper) DeployUniswapV2Factory(ctx sdk.Context) (common.Address, error) } func (k Keeper) DeployUniswapV2Router02(ctx sdk.Context, factory common.Address, wzeta common.Address) (common.Address, error) { - contractAddr, err := k.deployContract(ctx, uniswapv2router02.UniswapV2Router02MetaData, factory, wzeta) + contractAddr, err := k.DeployContract(ctx, uniswapv2router02.UniswapV2Router02MetaData, factory, wzeta) if err != nil { return common.Address{}, cosmoserrors.Wrapf(err, "UniswapV2Router02") } @@ -167,7 +168,7 @@ func (k Keeper) DeployUniswapV2Router02(ctx sdk.Context, factory common.Address, } func (k Keeper) DeployWZETA(ctx sdk.Context) (common.Address, error) { - contractAddr, err := k.deployContract(ctx, wzeta.WETH9MetaData) + contractAddr, err := k.DeployContract(ctx, wzeta.WETH9MetaData) if err != nil { return common.Address{}, cosmoserrors.Wrapf(err, "WZETA") } @@ -175,7 +176,7 @@ func (k Keeper) DeployWZETA(ctx sdk.Context) (common.Address, error) { } func (k Keeper) DeployConnectorZEVM(ctx sdk.Context, wzeta common.Address) (common.Address, error) { - contractAddr, err := k.deployContract(ctx, connectorzevm.ZetaConnectorZEVMMetaData, wzeta) + contractAddr, err := k.DeployContract(ctx, connectorzevm.ZetaConnectorZEVMMetaData, wzeta) if err != nil { return common.Address{}, cosmoserrors.Wrapf(err, "ZetaConnectorZEVM") } diff --git a/x/fungible/keeper/gas_price.go b/x/fungible/keeper/gas_price.go index cca8c03597..f492ddb2ec 100644 --- a/x/fungible/keeper/gas_price.go +++ b/x/fungible/keeper/gas_price.go @@ -10,7 +10,7 @@ import ( "github.com/zeta-chain/zetacore/x/fungible/types" ) -// sets gas price on the system contract in zEVM; return the gasUsed and error code +// SetGasPrice sets gas price on the system contract in zEVM; return the gasUsed and error code func (k Keeper) SetGasPrice(ctx sdk.Context, chainid *big.Int, gasPrice *big.Int) (uint64, error) { system, found := k.GetSystemContract(ctx) if !found { @@ -66,9 +66,9 @@ func (k Keeper) SetGasZetaPool(ctx sdk.Context, chainid *big.Int, pool common.Ad if err != nil { return sdkerrors.Wrapf(types.ErrABIGet, "SystemContractMetaData") } - res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, oracle, BigIntZero, nil, true, false, "SetGasZetaPool", chainid, pool) + res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, oracle, BigIntZero, nil, true, false, "setGasZetaPool", chainid, pool) if err != nil || res.Failed() { - return sdkerrors.Wrapf(types.ErrContractCall, "SetGasZetaPool") + return sdkerrors.Wrapf(types.ErrContractCall, "setGasZetaPool") } return nil diff --git a/x/fungible/keeper/gas_price_test.go b/x/fungible/keeper/gas_price_test.go new file mode 100644 index 0000000000..ec1bf267d8 --- /dev/null +++ b/x/fungible/keeper/gas_price_test.go @@ -0,0 +1,75 @@ +package keeper_test + +import ( + "math/big" + "testing" + + ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/fungible/keeper" + "github.com/zeta-chain/zetacore/x/fungible/types" +) + +func TestKeeper_SetGasPrice(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + _, _, _, _, system := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + queryGasPrice := func(chainID *big.Int) *big.Int { + abi, err := systemcontract.SystemContractMetaData.GetAbi() + require.NoError(t, err) + res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, system, keeper.BigIntZero, nil, false, false, "gasPriceByChainId", chainID) + require.NoError(t, err) + unpacked, err := abi.Unpack("gasPriceByChainId", res.Ret) + require.NoError(t, err) + gasPrice, ok := unpacked[0].(*big.Int) + require.True(t, ok) + return gasPrice + } + + _, err := k.SetGasPrice(ctx, big.NewInt(1), big.NewInt(42)) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), queryGasPrice(big.NewInt(1))) +} + +func TestKeeper_SetGasCoin(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + gas := sample.EthAddress() + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + err := k.SetGasCoin(ctx, big.NewInt(1), gas) + require.NoError(t, err) + + found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(1)) + require.NoError(t, err) + require.Equal(t, gas.Hex(), found.Hex()) +} + +func TestKeeper_SetGasZetaPool(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + zrc20 := sample.EthAddress() + + _, _, _, _, system := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + queryZetaPool := func(chainID *big.Int) ethcommon.Address { + abi, err := systemcontract.SystemContractMetaData.GetAbi() + require.NoError(t, err) + res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, system, keeper.BigIntZero, nil, false, false, "gasZetaPoolByChainId", chainID) + require.NoError(t, err) + unpacked, err := abi.Unpack("gasZetaPoolByChainId", res.Ret) + require.NoError(t, err) + pool, ok := unpacked[0].(ethcommon.Address) + require.True(t, ok) + return pool + } + + err := k.SetGasZetaPool(ctx, big.NewInt(1), zrc20) + require.NoError(t, err) + require.NotEqual(t, ethcommon.Address{}, queryZetaPool(big.NewInt(1))) +} diff --git a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20.go b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20.go index 41b678e349..db782a6491 100644 --- a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20.go +++ b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20.go @@ -4,6 +4,8 @@ import ( "context" "math/big" + "github.com/ethereum/go-ethereum/common" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" zetacommon "github.com/zeta-chain/zetacore/common" @@ -31,6 +33,10 @@ import ( // Only the admin policy account is authorized to broadcast this message. func (k msgServer) DeployFungibleCoinZRC20(goCtx context.Context, msg *types.MsgDeployFungibleCoinZRC20) (*types.MsgDeployFungibleCoinZRC20Response, error) { ctx := sdk.UnwrapSDKContext(goCtx) + + var address common.Address + var err error + if msg.Creator != k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(zetaObserverTypes.Policy_Type_deploy_fungible_coin) { return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Deploy can only be executed by the correct policy account") } @@ -38,34 +44,35 @@ func (k msgServer) DeployFungibleCoinZRC20(goCtx context.Context, msg *types.Msg return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "decimals must be less than 256") } if msg.CoinType == zetacommon.CoinType_Gas { - _, err := k.SetupChainGasCoinAndPool(ctx, msg.ForeignChainId, msg.Name, msg.Symbol, uint8(msg.Decimals)) + address, err = k.SetupChainGasCoinAndPool(ctx, msg.ForeignChainId, msg.Name, msg.Symbol, uint8(msg.Decimals)) if err != nil { return nil, sdkerrors.Wrapf(err, "failed to setupChainGasCoinAndPool") } } else { - addr, err := k.DeployZRC20Contract(ctx, msg.Name, msg.Symbol, uint8(msg.Decimals), msg.ForeignChainId, msg.CoinType, msg.ERC20, big.NewInt(msg.GasLimit)) + address, err = k.DeployZRC20Contract(ctx, msg.Name, msg.Symbol, uint8(msg.Decimals), msg.ForeignChainId, msg.CoinType, msg.ERC20, big.NewInt(msg.GasLimit)) if err != nil { return nil, err } + } - err = ctx.EventManager().EmitTypedEvent( - &types.EventZRC20Deployed{ - MsgTypeUrl: sdk.MsgTypeURL(&types.MsgDeployFungibleCoinZRC20{}), - ChainId: msg.ForeignChainId, - Contract: addr.String(), - Name: msg.Name, - Symbol: msg.Symbol, - Decimals: int64(msg.Decimals), - CoinType: msg.CoinType, - Erc20: msg.ERC20, - GasLimit: msg.GasLimit, - }, - ) - if err != nil { - return nil, sdkerrors.Wrapf(err, "failed to emit event") - } - + err = ctx.EventManager().EmitTypedEvent( + &types.EventZRC20Deployed{ + MsgTypeUrl: sdk.MsgTypeURL(&types.MsgDeployFungibleCoinZRC20{}), + ChainId: msg.ForeignChainId, + Contract: address.String(), + Name: msg.Name, + Symbol: msg.Symbol, + Decimals: int64(msg.Decimals), + CoinType: msg.CoinType, + Erc20: msg.ERC20, + GasLimit: msg.GasLimit, + }, + ) + if err != nil { + return nil, sdkerrors.Wrapf(err, "failed to emit event") } - return &types.MsgDeployFungibleCoinZRC20Response{}, nil + return &types.MsgDeployFungibleCoinZRC20Response{ + Address: address.Hex(), + }, nil } diff --git a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go new file mode 100644 index 0000000000..5eef132e3f --- /dev/null +++ b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go @@ -0,0 +1,147 @@ +package keeper_test + +import ( + "math/big" + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/common" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/fungible/keeper" + "github.com/zeta-chain/zetacore/x/fungible/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" +) + +func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { + t.Run("can deploy a new zrc20", func(t *testing.T) { + k, ctx, sdkk, zk := keepertest.FungibleKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + chainID := getValidChainID(t) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + res, err := msgServer.DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( + admin, + sample.EthAddress().Hex(), + chainID, + 8, + "foo", + "foo", + common.CoinType_Gas, + 1000000, + )) + require.NoError(t, err) + gasAddress := res.Address + assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(gasAddress)) + + // can retrieve the gas coin + foreignCoin, found := k.GetForeignCoins(ctx, gasAddress) + require.True(t, found) + require.Equal(t, foreignCoin.CoinType, common.CoinType_Gas) + require.Contains(t, foreignCoin.Name, "foo") + + gas, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) + require.NoError(t, err) + require.Equal(t, gasAddress, gas.Hex()) + + // can deploy non-gas zrc20 + res, err = msgServer.DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( + admin, + sample.EthAddress().Hex(), + chainID, + 8, + "bar", + "bar", + common.CoinType_ERC20, + 1000000, + )) + require.NoError(t, err) + assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.Address)) + + foreignCoin, found = k.GetForeignCoins(ctx, res.Address) + require.True(t, found) + require.Equal(t, foreignCoin.CoinType, common.CoinType_ERC20) + require.Contains(t, foreignCoin.Name, "bar") + + // gas should remain the same + gas, err = k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) + require.NoError(t, err) + require.NotEqual(t, res.Address, gas.Hex()) + require.Equal(t, gasAddress, gas.Hex()) + }) + + t.Run("should not deploy a new zrc20 if not admin", func(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + chainID := getValidChainID(t) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + // should not deploy a new zrc20 if not admin + _, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( + sample.AccAddress(), + sample.EthAddress().Hex(), + chainID, + 8, + "foo", + "foo", + common.CoinType_Gas, + 1000000, + )) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + }) + + t.Run("should not deploy a new zrc20 with wrong decimal", func(t *testing.T) { + k, ctx, sdkk, zk := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + chainID := getValidChainID(t) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + // should not deploy a new zrc20 if not admin + _, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( + admin, + sample.EthAddress().Hex(), + chainID, + 256, + "foo", + "foo", + common.CoinType_Gas, + 1000000, + )) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + }) + + t.Run("should not deploy a new zrc20 with invalid chain ID", func(t *testing.T) { + k, ctx, sdkk, zk := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + // should not deploy a new zrc20 if not admin + _, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( + admin, + sample.EthAddress().Hex(), + 9999999, + 8, + "foo", + "foo", + common.CoinType_Gas, + 1000000, + )) + require.Error(t, err) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) + }) +} diff --git a/x/fungible/keeper/msg_server_remove_foreign_coin_test.go b/x/fungible/keeper/msg_server_remove_foreign_coin_test.go new file mode 100644 index 0000000000..c866d81f21 --- /dev/null +++ b/x/fungible/keeper/msg_server_remove_foreign_coin_test.go @@ -0,0 +1,60 @@ +package keeper_test + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/fungible/keeper" + "github.com/zeta-chain/zetacore/x/fungible/types" +) + +func TestMsgServer_RemoveForeignCoin(t *testing.T) { + t.Run("can remove a foreign coin", func(t *testing.T) { + k, ctx, sdkk, zk := keepertest.FungibleKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + chainID := getValidChainID(t) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo") + + _, found := k.GetForeignCoins(ctx, zrc20.Hex()) + require.True(t, found) + + _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, zrc20.Hex())) + require.NoError(t, err) + _, found = k.GetForeignCoins(ctx, zrc20.Hex()) + require.False(t, found) + }) + + t.Run("should fail if not admin", func(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + chainID := getValidChainID(t) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo") + + _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(sample.AccAddress(), zrc20.Hex())) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + }) + + t.Run("should fail if not found", func(t *testing.T) { + k, ctx, _, zk := keepertest.FungibleKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + + _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, sample.EthAddress().Hex())) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + }) +} diff --git a/x/fungible/keeper/msg_server_test.go b/x/fungible/keeper/msg_server_test.go deleted file mode 100644 index b4b4427f8e..0000000000 --- a/x/fungible/keeper/msg_server_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package keeper_test - -import ( - "context" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - keepertest "github.com/zeta-chain/zetacore/testutil/keeper" - "github.com/zeta-chain/zetacore/x/fungible/keeper" - "github.com/zeta-chain/zetacore/x/fungible/types" -) - -func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { - k, ctx, _, _ := keepertest.FungibleKeeper(t) - return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx) -} diff --git a/x/fungible/keeper/msg_server_update_system_contract_test.go b/x/fungible/keeper/msg_server_update_system_contract_test.go new file mode 100644 index 0000000000..1d38265022 --- /dev/null +++ b/x/fungible/keeper/msg_server_update_system_contract_test.go @@ -0,0 +1,108 @@ +package keeper_test + +import ( + "math/big" + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" + "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" + zetacommon "github.com/zeta-chain/zetacore/common" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/fungible/keeper" + "github.com/zeta-chain/zetacore/x/fungible/types" +) + +func TestKeeper_UpdateSystemContract(t *testing.T) { + t.Run("can update the system contract", func(t *testing.T) { + k, ctx, sdkk, zk := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + + queryZRC20SystemContract := func(contract common.Address) string { + abi, err := zrc20.ZRC20MetaData.GetAbi() + require.NoError(t, err) + res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, keeper.BigIntZero, nil, false, false, "SYSTEM_CONTRACT_ADDRESS") + require.NoError(t, err) + unpacked, err := abi.Unpack("SYSTEM_CONTRACT_ADDRESS", res.Ret) + require.NoError(t, err) + address, ok := unpacked[0].(common.Address) + require.True(t, ok) + return address.Hex() + } + + chains := zetacommon.DefaultChainsList() + require.True(t, len(chains) > 1) + require.NotNil(t, chains[0]) + require.NotNil(t, chains[1]) + chainID1 := chains[0].ChainId + chainID2 := chains[1].ChainId + + wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + gas1 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID1, "foo", "foo") + gas2 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID2, "bar", "bar") + + // deploy a new system contracts + newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) + require.NoError(t, err) + require.NotEqual(t, oldSystemContract, newSystemContract) + + // can update the system contract + _, err = k.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())) + require.NoError(t, err) + + // can retrieve the system contract + sc, found := k.GetSystemContract(ctx) + require.True(t, found) + require.Equal(t, newSystemContract.Hex(), sc.SystemContract) + + // check gas updated + foundGas1, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID1)) + require.NoError(t, err) + require.Equal(t, gas1, foundGas1) + foundGas2, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID2)) + require.NoError(t, err) + require.Equal(t, gas2, foundGas2) + + require.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas1)) + require.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas2)) + }) + + t.Run("should not update the system contract if not admin", func(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + // deploy a new system contracts + wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) + require.NoError(t, err) + require.NotEqual(t, oldSystemContract, newSystemContract) + + // should not update the system contract if not admin + _, err = k.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(sample.AccAddress(), newSystemContract.Hex())) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + }) + + t.Run("should not update the system contract if invalid address", func(t *testing.T) { + k, ctx, sdkk, zk := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + admin := sample.AccAddress() + setAdminDeployFungibleCoin(ctx, zk, admin) + + // deploy a new system contracts + wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) + require.NoError(t, err) + require.NotEqual(t, oldSystemContract, newSystemContract) + + // should not update the system contract if invalid address + _, err = k.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(admin, "invalid")) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + }) +} diff --git a/x/fungible/keeper/system_contract.go b/x/fungible/keeper/system_contract.go index 2688e2914a..b49141b031 100644 --- a/x/fungible/keeper/system_contract.go +++ b/x/fungible/keeper/system_contract.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/connectorzevm.sol" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/wzeta.sol" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" @@ -188,9 +187,10 @@ func (k *Keeper) QueryWZetaBalanceOf(ctx sdk.Context, addr ethcommon.Address) (* if err != nil { return nil, cosmoserrors.Wrapf(err, "failed to get wzeta contract address") } - wzetaABI, err := connectorzevm.WZETAMetaData.GetAbi() + + wzetaABI, err := wzeta.WETH9MetaData.GetAbi() if err != nil { - return nil, cosmoserrors.Wrapf(err, "failed to get wzeta abi") + return nil, cosmoserrors.Wrapf(err, "failed to get ABI") } res, err := k.CallEVM( diff --git a/x/fungible/keeper/system_contract_test.go b/x/fungible/keeper/system_contract_test.go index ff60389a13..3874f52435 100644 --- a/x/fungible/keeper/system_contract_test.go +++ b/x/fungible/keeper/system_contract_test.go @@ -1,16 +1,126 @@ package keeper_test import ( - "fmt" + "math/big" "testing" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) func TestKeeper_GetSystemContract(t *testing.T) { - keeper, ctx, _, _ := keepertest.FungibleKeeper(t) - keeper.SetSystemContract(ctx, types.SystemContract{SystemContract: "test"}) - val, b := keeper.GetSystemContract(ctx) - fmt.Println(val, b) + k, ctx, _, _ := keepertest.FungibleKeeper(t) + k.SetSystemContract(ctx, types.SystemContract{SystemContract: "test"}) + val, found := k.GetSystemContract(ctx) + require.True(t, found) + require.Equal(t, types.SystemContract{SystemContract: "test"}, val) + + // can remove contract + k.RemoveSystemContract(ctx) + _, found = k.GetSystemContract(ctx) + require.False(t, found) +} + +func TestKeeper_GetSystemContractAddress(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + _, err := k.GetSystemContractAddress(ctx) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) + + _, _, _, _, systemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + found, err := k.GetSystemContractAddress(ctx) + require.NoError(t, err) + require.Equal(t, systemContract, found) +} + +func TestKeeper_GetWZetaContractAddress(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + _, err := k.GetWZetaContractAddress(ctx) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) + + wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + found, err := k.GetWZetaContractAddress(ctx) + require.NoError(t, err) + require.Equal(t, wzeta, found) +} + +func TestKeeper_GetUniswapV2FactoryAddress(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + _, err := k.GetUniswapV2FactoryAddress(ctx) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) + + _, factory, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + found, err := k.GetUniswapV2FactoryAddress(ctx) + require.NoError(t, err) + require.Equal(t, factory, found) +} + +func TestKeeper_GetUniswapV2Router02Address(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + _, err := k.GetUniswapV2Router02Address(ctx) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) + + _, _, router, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + found, err := k.GetUniswapV2Router02Address(ctx) + require.NoError(t, err) + require.Equal(t, router, found) +} + +func TestKeeper_CallWZetaDeposit(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + + // mint tokens + addr := sample.Bech32AccAddress() + ethAddr := common.BytesToAddress(addr.Bytes()) + coins := sample.Coins() + err := sdkk.BankKeeper.MintCoins(ctx, types.ModuleName, sample.Coins()) + require.NoError(t, err) + err = sdkk.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, coins) + require.NoError(t, err) + + // fail if no system contract + err = k.CallWZetaDeposit(ctx, ethAddr, big.NewInt(42)) + require.Error(t, err) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + + // deposit + err = k.CallWZetaDeposit(ctx, ethAddr, big.NewInt(42)) + require.NoError(t, err) + + balance, err := k.QueryWZetaBalanceOf(ctx, ethAddr) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), balance) +} + +func TestKeeper_QuerySystemContractGasCoinZRC20(t *testing.T) { + k, ctx, sdkk, _ := keepertest.FungibleKeeper(t) + k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) + chainID := getValidChainID(t) + + _, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) + + deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) + zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foobar", "foobar") + + found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) + require.NoError(t, err) + require.Equal(t, zrc20, found) } diff --git a/x/fungible/types/message_update_system_contract.go b/x/fungible/types/message_update_system_contract.go index 201aad573f..b6879f2ff6 100644 --- a/x/fungible/types/message_update_system_contract.go +++ b/x/fungible/types/message_update_system_contract.go @@ -10,7 +10,7 @@ const TypeMsgUpdateSystemContract = "update_system_contract" var _ sdk.Msg = &MsgUpdateSystemContract{} -func NewMessageUpdateSystemContract(creator string, systemContractAddr string) *MsgUpdateSystemContract { +func NewMsgUpdateSystemContract(creator string, systemContractAddr string) *MsgUpdateSystemContract { return &MsgUpdateSystemContract{ Creator: creator, NewSystemContractAddress: systemContractAddr, diff --git a/x/fungible/types/tx.pb.go b/x/fungible/types/tx.pb.go index eafc374a03..62cb8d4ac8 100644 --- a/x/fungible/types/tx.pb.go +++ b/x/fungible/types/tx.pb.go @@ -334,6 +334,7 @@ func (m *MsgDeployFungibleCoinZRC20) GetGasLimit() int64 { } type MsgDeployFungibleCoinZRC20Response struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` } func (m *MsgDeployFungibleCoinZRC20Response) Reset() { *m = MsgDeployFungibleCoinZRC20Response{} } @@ -369,6 +370,13 @@ func (m *MsgDeployFungibleCoinZRC20Response) XXX_DiscardUnknown() { var xxx_messageInfo_MsgDeployFungibleCoinZRC20Response proto.InternalMessageInfo +func (m *MsgDeployFungibleCoinZRC20Response) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + type MsgRemoveForeignCoin struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` @@ -676,59 +684,60 @@ func init() { func init() { proto.RegisterFile("fungible/tx.proto", fileDescriptor_197fdedece277fa0) } var fileDescriptor_197fdedece277fa0 = []byte{ - // 831 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4d, 0x6f, 0xdb, 0x36, - 0x18, 0xb6, 0xe2, 0xc6, 0x89, 0xdf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- 0x33, 0x17, 0x35, 0xf7, 0xfd, 0x77, 0x90, 0x9b, 0x2f, 0x5c, 0x6d, 0xe6, 0x15, 0xed, 0x79, 0xf4, - 0xe8, 0xe5, 0x59, 0x53, 0x79, 0x75, 0xd6, 0x54, 0xfe, 0x3b, 0x6b, 0x2a, 0x2f, 0xce, 0x9b, 0xa5, - 0x57, 0xe7, 0xcd, 0xd2, 0x3f, 0xe7, 0xcd, 0xd2, 0x13, 0x33, 0xf7, 0x06, 0x88, 0xa0, 0xf7, 0xe5, - 0x2a, 0x66, 0xba, 0x8a, 0xf9, 0xd4, 0x7c, 0xfb, 0xfc, 0x89, 0x1e, 0x04, 0xfd, 0x8a, 0x7c, 0xba, - 0x7c, 0xfa, 0x26, 0x00, 0x00, 0xff, 0xff, 0x05, 0x67, 0x8a, 0xaa, 0x17, 0x09, 0x00, 0x00, + // 843 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xcd, 0x6e, 0xdb, 0x46, + 0x10, 0x16, 0xad, 0x58, 0xb6, 0xa6, 0x89, 0x2c, 0x6f, 0x85, 0x84, 0xa5, 0x0b, 0xd9, 0x61, 0x0a, + 0x44, 0x0d, 0x60, 0xd2, 0x55, 0x7f, 0x82, 0x02, 0x6d, 0x0a, 0x5b, 0x89, 0xd1, 0x00, 0x55, 0x1b, + 0xd0, 0x15, 0x8a, 0xe6, 0x42, 0xac, 0xc8, 0x35, 0x45, 0x54, 0xdc, 0x15, 0xb8, 0xab, 0x2a, 0xca, + 0xad, 0xd7, 0x9c, 0x82, 0xf6, 0x3d, 0x7a, 0xeb, 0x3b, 0xe4, 0x98, 0x63, 0xd1, 0x43, 0x50, 0xd8, + 0x97, 0x3e, 0x46, 0xc1, 0xe5, 0x4f, 0x28, 0x59, 0x94, 0x1c, 0x9f, 0xb8, 0xb3, 0x9a, 0xf9, 0xf6, + 0x9b, 0x99, 0x6f, 0x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0xf9, 0xa8, 0xf9, 0xf4, 0xff, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x16, 0xf6, 0xee, 0xe7, 0x31, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1212,6 +1221,13 @@ func (m *MsgDeployFungibleCoinZRC20Response) MarshalToSizedBuffer(dAtA []byte) ( _ = i var l int _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTx(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -1524,6 +1540,10 @@ func (m *MsgDeployFungibleCoinZRC20Response) Size() (n int) { } var l int _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -2269,6 +2289,38 @@ func (m *MsgDeployFungibleCoinZRC20Response) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgDeployFungibleCoinZRC20Response: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/observer/types/core_params_mainnet.go b/x/observer/types/core_params_mainnet.go index bc56eb388f..38ab439aab 100644 --- a/x/observer/types/core_params_mainnet.go +++ b/x/observer/types/core_params_mainnet.go @@ -1,11 +1,72 @@ -//go:build !PRIVNET && !TESTNET -// +build !PRIVNET,!TESTNET +//go:build !PRIVNET && !TESTNET && !MOCK_MAINNET +// +build !PRIVNET,!TESTNET,!MOCK_MAINNET package types +import ( + "fmt" + + "github.com/coinbase/rosetta-sdk-go/types" + "github.com/zeta-chain/zetacore/common" +) + func GetCoreParams() CoreParamsList { params := CoreParamsList{ - CoreParams: []*CoreParams{}, + CoreParams: []*CoreParams{ + { + ChainId: common.EthChain().ChainId, + ConfirmationCount: 14, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + InTxTicker: 12, + OutTxTicker: 15, + WatchUtxoTicker: 0, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + { + ChainId: common.BscMainnetChain().ChainId, + ConfirmationCount: 14, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + InTxTicker: 5, + OutTxTicker: 15, + WatchUtxoTicker: 0, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + { + ChainId: common.BtcMainnetChain().ChainId, + ConfirmationCount: 2, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + WatchUtxoTicker: 30, + InTxTicker: 120, + OutTxTicker: 60, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + }, + } + chainList := common.ExternalChainList() + requiredParams := len(chainList) + availableParams := 0 + for _, chain := range chainList { + for _, param := range params.CoreParams { + if chain.ChainId == param.ChainId { + availableParams++ + } + } + } + if availableParams != requiredParams { + panic(fmt.Sprintf("Core params are not available for all chains , DefaultChains : %s , CoreParams : %s", + types.PrettyPrintStruct(chainList), params.String())) } return params } diff --git a/x/observer/types/core_params_mock_mainnet.go b/x/observer/types/core_params_mock_mainnet.go new file mode 100644 index 0000000000..549edc5bf7 --- /dev/null +++ b/x/observer/types/core_params_mock_mainnet.go @@ -0,0 +1,72 @@ +//go:build MOCK_MAINNET +// +build MOCK_MAINNET + +package types + +import ( + "fmt" + + "github.com/coinbase/rosetta-sdk-go/types" + "github.com/zeta-chain/zetacore/common" +) + +func GetCoreParams() CoreParamsList { + params := CoreParamsList{ + CoreParams: []*CoreParams{ + { + ChainId: common.EthChain().ChainId, + ConfirmationCount: 6, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + InTxTicker: 12, + OutTxTicker: 15, + WatchUtxoTicker: 0, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + { + ChainId: common.BscMainnetChain().ChainId, + ConfirmationCount: 6, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + InTxTicker: 5, + OutTxTicker: 15, + WatchUtxoTicker: 0, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + { + ChainId: common.BtcMainnetChain().ChainId, + ConfirmationCount: 2, + ZetaTokenContractAddress: "", + ConnectorContractAddress: "", + Erc20CustodyContractAddress: "", + WatchUtxoTicker: 30, + InTxTicker: 120, + OutTxTicker: 60, + GasPriceTicker: 30, + OutboundTxScheduleInterval: 30, + OutboundTxScheduleLookahead: 60, + }, + }, + } + chainList := common.ExternalChainList() + requiredParams := len(chainList) + availableParams := 0 + for _, chain := range chainList { + for _, param := range params.CoreParams { + if chain.ChainId == param.ChainId { + availableParams++ + } + } + } + if availableParams != requiredParams { + panic(fmt.Sprintf("Core params are not available for all chains , DefaultChains : %s , CoreParams : %s", + types.PrettyPrintStruct(chainList), params.String())) + } + return params +} diff --git a/x/observer/types/core_params_privnet.go b/x/observer/types/core_params_privnet.go index 71e9a0525a..832bf57475 100644 --- a/x/observer/types/core_params_privnet.go +++ b/x/observer/types/core_params_privnet.go @@ -26,15 +26,6 @@ func GetCoreParams() CoreParamsList { OutboundTxScheduleInterval: 2, OutboundTxScheduleLookahead: 5, }, - { - - ChainId: common.ZetaChain().ChainId, - ConfirmationCount: 1, - GasPriceTicker: 5, - ZetaTokenContractAddress: "0x2DD9830f8Ac0E421aFF9B7c8f7E9DF6F65DBF6Ea", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - }, { ChainId: common.BtcRegtestChain().ChainId, ConfirmationCount: 2, @@ -49,7 +40,7 @@ func GetCoreParams() CoreParamsList { OutboundTxScheduleLookahead: 5, }}, } - chainList := common.DefaultChainsList() + chainList := common.ExternalChainList() requiredParams := len(chainList) availableParams := 0 for _, chain := range chainList { diff --git a/x/observer/types/core_params_testnet.go b/x/observer/types/core_params_testnet.go index b7c4cb07bb..cada5613b3 100644 --- a/x/observer/types/core_params_testnet.go +++ b/x/observer/types/core_params_testnet.go @@ -53,17 +53,6 @@ func GetCoreParams() CoreParamsList { OutboundTxScheduleInterval: 30, OutboundTxScheduleLookahead: 60, }, - { - ChainId: common.ZetaChain().ChainId, - ConfirmationCount: 3, - ZetaTokenContractAddress: "", - ConnectorContractAddress: "", - Erc20CustodyContractAddress: "", - InTxTicker: 2, - OutTxTicker: 3, - WatchUtxoTicker: 0, - GasPriceTicker: 5, - }, { ChainId: common.BtcTestNetChain().ChainId, ConfirmationCount: 2, @@ -79,7 +68,7 @@ func GetCoreParams() CoreParamsList { }, }, } - chainList := common.DefaultChainsList() + chainList := common.ExternalChainList() requiredParams := len(chainList) availableParams := 0 for _, chain := range chainList { diff --git a/x/observer/types/params.go b/x/observer/types/params.go index 92ba0d5e0b..660a4e12f9 100644 --- a/x/observer/types/params.go +++ b/x/observer/types/params.go @@ -28,7 +28,7 @@ func DefaultParams() Params { IsSupported: true, Chain: chain, BallotThreshold: sdk.MustNewDecFromStr("0.66"), - MinObserverDelegation: sdk.MustNewDecFromStr("10000000000"), + MinObserverDelegation: sdk.MustNewDecFromStr("1000000000000000000000"), // 1000 ZETA } } return NewParams(observerParams, DefaultAdminPolicy(), 100) diff --git a/zetaclient/config/config_mainnet.go b/zetaclient/config/config_mainnet.go index 1622edf923..646b8b3460 100644 --- a/zetaclient/config/config_mainnet.go +++ b/zetaclient/config/config_mainnet.go @@ -1,10 +1,11 @@ -//go:build !PRIVNET && !TESTNET -// +build !PRIVNET,!TESTNET +//go:build !PRIVNET && !TESTNET && !MOCK_MAINNET +// +build !PRIVNET,!TESTNET,!MOCK_MAINNET package config import ( "github.com/btcsuite/btcd/chaincfg" + "github.com/zeta-chain/zetacore/common" ) const ( @@ -21,9 +22,6 @@ const ( // Constants // #nosec G101 const ( - DevEthBlockTime = 2 - - // to catch up: MaxBlocksPerPeriod = 100 ) @@ -42,13 +40,24 @@ func GetERC20CustodyABI() string { } var ( - BitconNetParams = &chaincfg.RegressionNetParams + BitconNetParams = &chaincfg.MainNetParams ) func New() Config { return Config{ - EVMChainConfigs: nil, - BitcoinConfig: nil, - ChainsEnabled: nil, + EVMChainConfigs: evmChainConfigs, + BitcoinConfig: BitcoinConfig, + ChainsEnabled: []common.Chain{}, } } + +var BitcoinConfig = &BTCConfig{} + +var evmChainConfigs = map[int64]*EVMConfig{ + common.EthChain().ChainId: { + Chain: common.EthChain(), + }, + common.BscMainnetChain().ChainId: { + Chain: common.BscMainnetChain(), + }, +} diff --git a/zetaclient/config/config_mock_mainnet.go b/zetaclient/config/config_mock_mainnet.go new file mode 100644 index 0000000000..fe7195d1cd --- /dev/null +++ b/zetaclient/config/config_mock_mainnet.go @@ -0,0 +1,63 @@ +//go:build MOCK_MAINNET +// +build MOCK_MAINNET + +package config + +import ( + "github.com/btcsuite/btcd/chaincfg" + "github.com/zeta-chain/zetacore/common" +) + +const ( + BtcConfirmationCount = 1 + DevEthConfirmationCount = 2 +) + +const ( + // #nosec G101 + TssTestPrivkey = "2082bc9775d6ee5a05ef221a9d1c00b3cc3ecb274a4317acc0a182bc1e05d1bb" + TssTestAddress = "0xE80B6467863EbF8865092544f441da8fD3cF6074" +) + +// Constants +// #nosec G101 +const ( + MaxBlocksPerPeriod = 100 +) + +const ( + ConnectorAbiString = ` +[{"inputs":[{"internalType":"address","name":"_zetaTokenAddress","type":"address"},{"internalType":"address","name":"_tssAddress","type":"address"},{"internalType":"address","name":"_tssAddressUpdater","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"originSenderAddress","type":"bytes"},{"indexed":true,"internalType":"uint256","name":"originChainId","type":"uint256"},{"indexed":true,"internalType":"address","name":"destinationAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":true,"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"ZetaReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"originSenderAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"originChainId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":true,"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":true,"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"ZetaReverted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"originSenderAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"gasLimit","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"zetaParams","type":"bytes"}],"name":"ZetaSent","type":"event"},{"inputs":[],"name":"getLockedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"originSenderAddress","type":"bytes"},{"internalType":"uint256","name":"originChainId","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"onReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"originSenderAddress","type":"address"},{"internalType":"uint256","name":"originChainId","type":"uint256"},{"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"bytes32","name":"internalSendHash","type":"bytes32"}],"name":"onRevert","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceTssAddressUpdater","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"bytes","name":"destinationAddress","type":"bytes"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"uint256","name":"zetaAmount","type":"uint256"},{"internalType":"bytes","name":"zetaParams","type":"bytes"}],"internalType":"struct ZetaInterfaces.SendInput","name":"input","type":"tuple"}],"name":"send","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tssAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tssAddressUpdater","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tssAddress","type":"address"}],"name":"updateTssAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"zetaToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]` + ERC20CustodyAbiString = ` +[{"inputs":[{"internalType":"address","name":"_TSSAddress","type":"address"},{"internalType":"address","name":"_TSSAddressUpdater","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidSender","type":"error"},{"inputs":[],"name":"InvalidTSSUpdater","type":"error"},{"inputs":[],"name":"IsPaused","type":"error"},{"inputs":[],"name":"NotPaused","type":"error"},{"inputs":[],"name":"NotWhitelisted","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"recipient","type":"bytes"},{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"Unwhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"Whitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[],"name":"TSSAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TSSAddressUpdater","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"recipient","type":"bytes"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceTSSAddressUpdater","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"unwhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateTSSAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"whitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]` +) + +func GetConnectorABI() string { + return ConnectorAbiString +} +func GetERC20CustodyABI() string { + return ERC20CustodyAbiString +} + +var ( + BitconNetParams = &chaincfg.MainNetParams +) + +func New() Config { + return Config{ + EVMChainConfigs: evmChainConfigs, + BitcoinConfig: BitcoinConfig, + ChainsEnabled: []common.Chain{}, + } +} + +var BitcoinConfig = &BTCConfig{} + +var evmChainConfigs = map[int64]*EVMConfig{ + common.EthChain().ChainId: { + Chain: common.EthChain(), + }, + common.BscMainnetChain().ChainId: { + Chain: common.BscMainnetChain(), + }, +} diff --git a/zetaclient/config/config_privnet.go b/zetaclient/config/config_privnet.go index 90776a1561..d801c8dbd7 100644 --- a/zetaclient/config/config_privnet.go +++ b/zetaclient/config/config_privnet.go @@ -59,7 +59,4 @@ var evmChainConfigs = map[int64]*EVMConfig{ Chain: common.GoerliChain(), Endpoint: "http://eth:8545", }, - common.ZetaChain().ChainId: { - Chain: common.ZetaChain(), - }, } diff --git a/zetaclient/config/config_testnet.go b/zetaclient/config/config_testnet.go index 3524049268..5a3bf948e0 100644 --- a/zetaclient/config/config_testnet.go +++ b/zetaclient/config/config_testnet.go @@ -73,7 +73,4 @@ var evmChainsConfig = map[int64]*EVMConfig{ Chain: common.MumbaiChain(), Endpoint: "", }, - common.ZetaChain().ChainId: { - Chain: common.ZetaChain(), - }, } diff --git a/zetaclient/evm_client.go b/zetaclient/evm_client.go index 0a6ce3f698..16b0ae9645 100644 --- a/zetaclient/evm_client.go +++ b/zetaclient/evm_client.go @@ -718,14 +718,16 @@ func (ob *EVMChainClient) observeInTX() error { continue } destAddr := clienttypes.BytesToEthHex(event.DestinationAddress) - cfgDest, found := ob.cfg.GetEVMConfig(destChain.ChainId) - if !found { - ob.logger.ExternalChainWatcher.Warn().Msgf("chain id not present in EVMChainConfigs %d", event.DestinationChainId.Int64()) - continue - } - if strings.EqualFold(destAddr, cfgDest.ZetaTokenContractAddress) { - ob.logger.ExternalChainWatcher.Warn().Msgf("potential attack attempt: %s destination address is ZETA token contract address %s", destChain, destAddr) - continue + if destChain.IsExternalChain() { + cfgDest, found := ob.cfg.GetEVMConfig(destChain.ChainId) + if !found { + ob.logger.ExternalChainWatcher.Warn().Msgf("chain id not present in EVMChainConfigs %d", event.DestinationChainId.Int64()) + continue + } + if strings.EqualFold(destAddr, cfgDest.ZetaTokenContractAddress) { + ob.logger.ExternalChainWatcher.Warn().Msgf("potential attack attempt: %s destination address is ZETA token contract address %s", destChain, destAddr) + continue + } } zetaHash, err := ob.zetaClient.PostSend( event.ZetaTxSenderAddress.Hex(), diff --git a/zetaclient/query.go b/zetaclient/query.go index 9e00acab4c..e83ea5cd87 100644 --- a/zetaclient/query.go +++ b/zetaclient/query.go @@ -123,10 +123,9 @@ func (b *ZetaCoreBridge) GetCctxByNonce(chainID int64, nonce uint64) (*types.Cro func (b *ZetaCoreBridge) GetObserverList(chain common.Chain) ([]string, error) { client := zetaObserverTypes.NewQueryClient(b.grpcConn) - resp, err := client.ObserversByChain(context.Background(), &zetaObserverTypes.QueryObserversByChainRequest{ - ObservationChain: chain.ChainName.String(), - }) + err := error(nil) for i := 0; i <= DefaultRetryCount; i++ { + resp, err := client.ObserversByChain(context.Background(), &zetaObserverTypes.QueryObserversByChainRequest{ObservationChain: chain.ChainName.String()}) if err == nil { return resp.Observers, nil } @@ -166,8 +165,9 @@ func (b *ZetaCoreBridge) GetLatestZetaBlock() (*tmtypes.Block, error) { func (b *ZetaCoreBridge) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { client := tmservice.NewServiceClient(b.grpcConn) - res, err := client.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{}) + err := error(nil) for i := 0; i <= DefaultRetryCount; i++ { + res, err := client.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{}) if err == nil { return res, nil } @@ -215,11 +215,16 @@ func (b *ZetaCoreBridge) GetAllNodeAccounts() ([]*zetaObserverTypes.NodeAccount, func (b *ZetaCoreBridge) GetKeyGen() (*zetaObserverTypes.Keygen, error) { client := zetaObserverTypes.NewQueryClient(b.grpcConn) - resp, err := client.Keygen(context.Background(), &zetaObserverTypes.QueryGetKeygenRequest{}) - if err != nil { - return nil, err + err := error(nil) + for i := 0; i <= ExtendedRetryCount; i++ { + resp, err := client.Keygen(context.Background(), &zetaObserverTypes.QueryGetKeygenRequest{}) + if err == nil { + return resp.Keygen, nil + } + time.Sleep(DefaultRetryInterval * time.Second) } - return resp.Keygen, nil + return nil, fmt.Errorf("failed to get keygen | err %s", err.Error()) + } func (b *ZetaCoreBridge) GetCurrentTss() (*types.TSS, error) { @@ -289,6 +294,15 @@ func (b *ZetaCoreBridge) GetClientParams(chainID int64) (zetaObserverTypes.Query return *resp, nil } +func (b *ZetaCoreBridge) GetSupportedChains() ([]*common.Chain, error) { + client := zetaObserverTypes.NewQueryClient(b.grpcConn) + resp, err := client.SupportedChains(context.Background(), &zetaObserverTypes.QuerySupportedChains{}) + if err != nil { + return nil, err + } + return resp.GetChains(), nil +} + func (b *ZetaCoreBridge) GetPendingNonces() (*types.QueryAllPendingNoncesResponse, error) { client := types.NewQueryClient(b.grpcConn) resp, err := client.PendingNoncesAll(context.Background(), &types.QueryAllPendingNoncesRequest{}) diff --git a/zetaclient/tss_signer.go b/zetaclient/tss_signer.go index d171c74ff9..b3369007c0 100644 --- a/zetaclient/tss_signer.go +++ b/zetaclient/tss_signer.go @@ -365,7 +365,7 @@ func getKeyAddrBTCWitnessPubkeyHash(tssPubkey string) (*btcutil.AddressWitnessPu return addr, nil } -func NewTSS(peer p2p.AddrList, privkey tmcrypto.PrivKey, preParams *keygen.LocalPreParams, cfg *config.Config, bridge *ZetaCoreBridge, tssHistoricalList []types.TSS) (*TSS, error) { +func NewTSS(peer p2p.AddrList, privkey tmcrypto.PrivKey, preParams *keygen.LocalPreParams, cfg *config.Config, bridge *ZetaCoreBridge, tssHistoricalList []types.TSS, metrics *metrics.Metrics) (*TSS, error) { server, err := SetupTSSServer(peer, privkey, preParams, cfg) if err != nil { return nil, fmt.Errorf("SetupTSSServer error: %w", err) @@ -390,6 +390,12 @@ func NewTSS(peer p2p.AddrList, privkey tmcrypto.PrivKey, preParams *keygen.Local if err != nil { bridge.logger.Error().Err(err).Msg("VerifyKeysharesForPubkeys fail") } + err = newTss.RegisterMetrics(metrics) + if err != nil { + bridge.logger.Err(err).Msg("tss.RegisterMetrics") + return nil, err + } + return &newTss, nil } diff --git a/zetaclient/tx.go b/zetaclient/tx.go index e88e469044..467aa868e6 100644 --- a/zetaclient/tx.go +++ b/zetaclient/tx.go @@ -27,6 +27,7 @@ const ( DefaultGasLimit = 200_000 PostProveOutboundTxGasLimit = 400_000 DefaultRetryCount = 5 + ExtendedRetryCount = 15 DefaultRetryInterval = 5 ) diff --git a/zetaclient/zetabridge.go b/zetaclient/zetabridge.go index 6e4c625ec2..8dfd11afa9 100644 --- a/zetaclient/zetabridge.go +++ b/zetaclient/zetabridge.go @@ -116,6 +116,12 @@ func MakeLegacyCodec() *codec.LegacyAmino { return cdc } +func (b *ZetaCoreBridge) UpdateChainID(chainID string) { + if b.zetaChainID != chainID { + b.zetaChainID = chainID + } +} + func (b *ZetaCoreBridge) Stop() { b.logger.Info().Msgf("ZetaBridge is stopping") close(b.stop) // this notifies all configupdater to stop @@ -146,7 +152,7 @@ func (b *ZetaCoreBridge) WaitForCoreToCreateBlocks() { } retryCount++ b.logger.Debug().Msgf("Failed to get latest Block , Retry : %d/%d", retryCount, DefaultRetryCount) - if retryCount > DefaultRetryCount { + if retryCount > ExtendedRetryCount { panic(fmt.Sprintf("ZetaCore is not ready , Waited for %d seconds", DefaultRetryCount*DefaultRetryInterval)) } time.Sleep(DefaultRetryInterval * time.Second) @@ -176,23 +182,31 @@ func (b *ZetaCoreBridge) UpdateConfigFromCore(cfg *config.Config, init bool) err if err != nil { return err } - newChains := make([]common.Chain, len(coreParams)) + newEVMParams := make(map[int64]*observertypes.CoreParams) var newBTCParams *observertypes.CoreParams // check and update core params for each chain - for i, params := range coreParams { + for _, params := range coreParams { err := config.ValidateCoreParams(params) if err != nil { - b.logger.Err(err).Msgf("Invalid core params for chain %s", common.GetChainFromChainID(params.ChainId).ChainName) + b.logger.Debug().Err(err).Msgf("Invalid core params for chain %s", common.GetChainFromChainID(params.ChainId).ChainName) } - newChains[i] = *common.GetChainFromChainID(params.ChainId) if common.IsBitcoinChain(params.ChainId) { newBTCParams = params } else { newEVMParams[params.ChainId] = params } } + + chains, err := b.GetSupportedChains() + if err != nil { + return err + } + newChains := make([]common.Chain, len(chains)) + for i, chain := range chains { + newChains[i] = *chain + } keyGen, err := b.GetKeyGen() if err != nil { b.logger.Info().Msg("Unable to fetch keygen from zetacore") @@ -201,7 +215,7 @@ func (b *ZetaCoreBridge) UpdateConfigFromCore(cfg *config.Config, init bool) err tss, err := b.GetCurrentTss() if err != nil { - b.logger.Error().Err(err).Msg("Unable to fetch TSS from zetacore") + b.logger.Debug().Err(err).Msg("Unable to fetch TSS from zetacore") } else { cfg.CurrentTssPubkey = tss.GetTssPubkey() }