Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Funding issue when using docker-compose with Mumbai as Rootchain #1717

Open
sahil3Vedi opened this issue Jul 11, 2023 · 2 comments
Open

Funding issue when using docker-compose with Mumbai as Rootchain #1717

sahil3Vedi opened this issue Jul 11, 2023 · 2 comments

Comments

@sahil3Vedi
Copy link

sahil3Vedi commented Jul 11, 2023

Funding issue when using docker-compose with Mumbai as Rootchain

Description

I have modified the docker-compose.yml and the polygon-edge.sh file as follows in order to run Mumbai as Rootchain in place of the local geth instance. I'm pretty sure I have got most of it right except the part where we transfer Rootchain Stake Tokens to the Validators on the rootchain. In the local setup I used to do this manually but there does not seem to be a way to doing this using the rootchain fund command.

The rootchain fund command deducts native rootchain tokens from the deployer's private key and transfers it to the validators. What it does NOT seem to do is transfer Rootchain Stake Tokens to the validators. Kindly suggest solutions or workarounds for this. I believe modifying the command to transfer Rootchain Stake Tokens in the presence of the --stake-token flag and transferring native rootchain tokens otherwise would be ideal.

docker-compose.yml

version: '3.9'

services:
  ## INITIALIZE GENESIS AND SECRETS, ETC.
  init:
    build:
      context: ../../
      dockerfile: docker/local/Dockerfile
    image: local/polygon-edge
    container_name: polygon-edge-bootstrapper
    command: [ "init", "${EDGE_CONSENSUS:-polybft}" ]
    volumes:
      - data:/data
    networks:
      - polygon-edge-docker

  ## RUN NODES
  node-1:
    image: local/polygon-edge
    container_name: polygon-edge-validator-1
    command: [
      "server",
      "--data-dir", "/data/data-1",
      "--chain", "/data/genesis.json",
      "--grpc-address", "0.0.0.0:9632",
      "--libp2p", "0.0.0.0:1478",
      "--jsonrpc", "0.0.0.0:8545",
      "--prometheus", "0.0.0.0:5001",
      "--seal",
      "--relayer"
    ]
    depends_on:
      init:
        condition: service_completed_successfully
    ports:
      - '10000:9632'
      - '10002:8545'
      - '10003:5001'
    volumes:
      - data:/data
    networks:
      - polygon-edge-docker
    restart: on-failure

  node-2:
    image: local/polygon-edge
    container_name: polygon-edge-validator-2
    command: [
      "server",
      "--data-dir",
      "/data/data-2",
      "--chain", "/data/genesis.json",
      "--grpc-address", "0.0.0.0:9632",
      "--libp2p", "0.0.0.0:1478",
      "--jsonrpc", "0.0.0.0:8545",
      "--prometheus", "0.0.0.0:5001",
      "--seal"
    ]
    depends_on:
      init:
        condition: service_completed_successfully
      # rootchain:
      #   condition: service_started
    ports:
      - '20000:9632'
      - '20002:8545'
      - '20003:5001'
    volumes:
      - data:/data
    networks:
      - polygon-edge-docker
    restart: on-failure

  node-3:
    image: local/polygon-edge
    container_name: polygon-edge-validator-3
    command: [
      "server",
      "--data-dir", "/data/data-3",
      "--chain", "/data/genesis.json",
      "--grpc-address", "0.0.0.0:9632",
      "--libp2p", "0.0.0.0:1478",
      "--jsonrpc", "0.0.0.0:8545",
      "--prometheus", "0.0.0.0:5001",
      "--seal"
    ]
    depends_on:
      init:
        condition: service_completed_successfully
    ports:
      - '30000:9632'
      - '30002:8545'
      - '30003:5001'
    volumes:
      - data:/data
    networks:
      - polygon-edge-docker
    restart: on-failure

  node-4:
    image: local/polygon-edge
    container_name: polygon-edge-validator-4
    command: [
      "server",
      "--data-dir",  "/data/data-4",
      "--chain", "/data/genesis.json",
      "--grpc-address", "0.0.0.0:9632",
      "--libp2p", "0.0.0.0:1478",
      "--jsonrpc", "0.0.0.0:8545",
      "--prometheus", "0.0.0.0:5001",
      "--seal"
    ]
    depends_on:
      init:
        condition: service_completed_successfully
    ports:
      - '40000:9632'
      - '40002:8545'
      - '40003:5001'
    volumes:
      - data:/data
    networks:
      - polygon-edge-docker
    restart: on-failure

networks:
  polygon-edge-docker:
    driver: bridge
    name: polygon-edge-docker

volumes:
  data:
  eth1data:
  genesis:

polygon-edge.sh

#!/bin/sh

set -e

POLYGON_EDGE_BIN=./polygon-edge
ROOTCHAIN_STAKE_TOKEN=<rootchain_stake_token_address_here>
ROOTCHAIN_RPC=<rootchain_rpc_here>
DEPLOYER_KEY=<private_key_here>
CHAIN_CUSTOM_OPTIONS=$(tr "\n" " " << EOL
--block-gas-limit 10000000
--epoch-size 10
--chain-id 51001
--name polygon-edge-docker
--premine 0x228466F2C715CbEC05dEAbfAc040ce3619d7CF0B:0xD3C21BCECCEDA1000000
--premine 0xca48694ebcB2548dF5030372BE4dAad694ef174e:0xD3C21BCECCEDA1000000
--premine <personal_wallet_address_here>:0xD3C21BCECCEDA1000000
--premine 0x0:0xD3C21BCECCEDA1000000
EOL
)

case "$1" in
   "init")
      case "$2" in 
          "ibft")
              if [ -f "$GENESIS_PATH" ]; then
                  echo "Secrets have already been generated."
              else
                  echo "Generating IBFT secrets..."
                  secrets=$("$POLYGON_EDGE_BIN" secrets init --insecure --num 4 --data-dir /data/data- --json)
                  echo "Secrets have been successfully generated"

                  rm -f /data/genesis.json

                  echo "Generating IBFT Genesis file..."
                  "$POLYGON_EDGE_BIN" genesis $CHAIN_CUSTOM_OPTIONS \
                    --dir /data/genesis.json \
                    --consensus ibft \
                    --ibft-validators-prefix-path data- \
                    --bootnode "/dns4/node-1/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[0] | .node_id')" \
                    --bootnode "/dns4/node-2/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[1] | .node_id')" \
                    --bootnode "/dns4/node-3/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[2] | .node_id')" \
                    --bootnode "/dns4/node-4/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[3] | .node_id')"
              fi
              ;;
          "polybft")
              echo "Generating PolyBFT secrets..."
              secrets=$("$POLYGON_EDGE_BIN" polybft-secrets init --insecure --num 4 --data-dir /data/data- --json)
              echo "Secrets have been successfully generated"

              rm -f /data/genesis.json

              echo "Generating PolyBFT genesis file..."
              "$POLYGON_EDGE_BIN" genesis $CHAIN_CUSTOM_OPTIONS \
                --dir /data/genesis.json \
                --consensus polybft \
                --validators-path /data \
                --validators-prefix data- \
                --reward-wallet 0xDEADBEEF:1000000 \
                --native-token-config "Polygon:MATIC:18:true:$(echo "$secrets" | jq -r '.[0] | .address')" \
                --bootnode "/dns4/node-1/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[0] | .node_id')" \
                --bootnode "/dns4/node-2/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[1] | .node_id')" \
                --bootnode "/dns4/node-3/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[2] | .node_id')" \
                --bootnode "/dns4/node-4/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[3] | .node_id')"

              echo "Deploying stake manager..."
              "$POLYGON_EDGE_BIN" polybft stake-manager-deploy \
                --private-key ${DEPLOYER_KEY} \
                --jsonrpc ${ROOTCHAIN_RPC} \
                --genesis /data/genesis.json \
                --stake-token ${ROOTCHAIN_STAKE_TOKEN}

              stakeManagerAddr=$(cat /data/genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr')
              stakeToken=$(cat /data/genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr')

              "$POLYGON_EDGE_BIN" rootchain deploy \
                --stake-manager ${stakeManagerAddr} \
                --stake-token ${stakeToken} \
                --json-rpc ${ROOTCHAIN_RPC} \
                --genesis /data/genesis.json \
                --deployer-key ${DEPLOYER_KEY}

              customSupernetManagerAddr=$(cat /data/genesis.json | jq -r '.params.engine.polybft.bridge.customSupernetManagerAddr')
              supernetID=$(cat /data/genesis.json | jq -r '.params.engine.polybft.supernetID')
              addresses="$(echo "$secrets" | jq -r '.[0] | .address'),$(echo "$secrets" | jq -r '.[1] | .address'),$(echo "$secrets" | jq -r '.[2] | .address'),$(echo "$secrets" | jq -r '.[3] | .address')"

              "$POLYGON_EDGE_BIN" rootchain fund \
                --json-rpc ${ROOTCHAIN_RPC} \
                --addresses ${addresses} \
                --amounts 200000000000000000,200000000000000000,200000000000000000,200000000000000000 \
                --private-key ${DEPLOYER_KEY} \
                --stake-token ${stakeToken} \
                --mint 

              "$POLYGON_EDGE_BIN" polybft whitelist-validators \
                --addresses ${addresses} \
                --supernet-manager ${customSupernetManagerAddr} \
                --private-key ${DEPLOYER_KEY} \
                --jsonrpc ${ROOTCHAIN_RPC}

              counter=1
              while [ $counter -le 4 ]; do
                echo "Registering validator: ${counter}"

                "$POLYGON_EDGE_BIN" polybft register-validator \
                  --supernet-manager ${customSupernetManagerAddr} \
                  --data-dir /data/data-${counter} \
                  --jsonrpc ${ROOTCHAIN_RPC}

                "$POLYGON_EDGE_BIN" polybft stake \
                  --data-dir /data/data-${counter} \
                  --amount 100000000000000000 \
                  --supernet-id ${supernetID} \
                  --stake-manager ${stakeManagerAddr} \
                  --stake-token ${stakeToken} \
                  --jsonrpc ${ROOTCHAIN_RPC}

                counter=$((counter + 1))
              done

              "$POLYGON_EDGE_BIN" polybft supernet \
                --private-key ${DEPLOYER_KEY} \
                --supernet-manager ${customSupernetManagerAddr} \
                --stake-manager ${stakeManagerAddr} \
                --finalize-genesis-set \
                --enable-staking \
                --genesis /data/genesis.json \
                --jsonrpc ${ROOTCHAIN_RPC}
              ;;
      esac
      ;;
   *)
      echo "Executing polygon-edge..."
      exec "$POLYGON_EDGE_BIN" "$@"
      ;;
esac

Your environment

  • Ubuntu 22
  • Latest Commit on develop [#f4efe97]
  • Locally hosted using docker-compose

Steps to reproduce

  • Clone the repo, install and compile the core-contracts
  • replace the docker-compose.yml and polygon-edge.sh files inside the /docker/local folder with the above files
  • run the containers using
export EDGE_CONSENSUS=polybft
docker-compose -f ./docker/local/docker-compose.yml up -d --build

Expected behavior

  • I expect this to crash since the validators on the rootchain (Mumbai) have been funded with native tokens but not Rootchain Stake Tokens

Logs from the polygon-edge-bootstrapper container

[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1870312 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1146506 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1767122 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 196429 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1146686 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1442395 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1321573 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 2595019 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 826639 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1458136 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1590998 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 682127 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 1793675 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 2460706 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 2072916 
Gas Price = 1500000017

[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = StateSender
Contract (address)     = 0xAF0950FC118d9Bcea4178c1B52d2EE4F84eccAAD
Transaction (hash)     = 0x01c18816d4b9426c22f67f096478ff585ba9df09225d85d03e363b49a7866057
Transaction (gas used) = 196429


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = CheckpointManager
Contract (address)     = 0xe2B10f089d92B60F1859F7C8F11Db1BF3847804f
Transaction (hash)     = 0x9185d7efd44e778eb9c410d354175806f6f4d10acd0470e306ee6b91ce552295
Transaction (gas used) = 1321573


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = BLS
Contract (address)     = 0xE30973316252496918ee0faF4fE6621f58785999
Transaction (hash)     = 0x36b51ac2162e15527a6a8ffaec97ed90b9a5bb05f31a9d1423e5761537b22fd3
Transaction (gas used) = 2595019


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = BN256G2
Contract (address)     = 0x71d4E02E6A80c0f80dE177f4978d6D52d50743f7
Transaction (hash)     = 0x51645ae25ea7daa3614a711f134c6ece789200e3eb9d24f73c0d133f49c12773
Transaction (gas used) = 826639


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ExitHelper
Contract (address)     = 0xB8F5c9C04d5816604caA480745087F454754Cda4
Transaction (hash)     = 0xb7b77a6012e21b88379493c07bf225fccdc9b9cab12fe3287d4c280dfd726a43
Transaction (gas used) = 682127


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = RootERC20Predicate
Contract (address)     = 0xf120b5f58048583c616644D8fd87D5817b554288
Transaction (hash)     = 0xf6598cf7e0d20feb5b9276a595baed8c6490fe08a7bf9b736fb4da8440e6b121
Transaction (gas used) = 1146506


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ChildERC20MintablePredicate
Contract (address)     = 0x5116b608b3920394d7172799bdAFDbA65F33747A
Transaction (hash)     = 0xe1b8f5614a7990d3b1b15714b5246b580dca7b3bc37100ed390b52d0369a53a6
Transaction (gas used) = 1146686


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ERC20Template
Contract (address)     = 0xcdd5338f80fD21f4135A4fdeABB797cC4e793912
Transaction (hash)     = 0x3ca4a9cfd77ec2efec32bafc1c985663a1aaa426f51c1457619cac5d5d08f420
Transaction (gas used) = 1442395


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = RootERC721Predicate
Contract (address)     = 0x37c6aDaa5F589b3F32C5cCd0551a2e8D5c35543E
Transaction (hash)     = 0x80c74749707386a53274b0560d3469ce0261f58357d8cdd3ca4b977c67a682ec
Transaction (gas used) = 1458136


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ChildERC721MintablePredicate
Contract (address)     = 0x52B8ee5fBB121Ec0b87F1fA2Ed09602fFd2e356C
Transaction (hash)     = 0x142d3a195c7600ab3ce8495040d2e7554e4ac57166c47d0b8655fe4abbed5e03
Transaction (gas used) = 1767122


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ERC721Template
Contract (address)     = 0xC8eDb9FfCc919303ac440eF7e3a472f766e8Af4F
Transaction (hash)     = 0x52da76fe83ce349f2ff66c3af78bea453f786110cbcf3b812f3ee9bd5be77c49
Transaction (gas used) = 2072916


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = RootERC1155Predicate
Contract (address)     = 0xf8Dfe096867559eAdD5057f468c5FC1489422F01
Transaction (hash)     = 0x93b3110daea94d3cf4ddb6f01c47c6a98c3063540429d8414d49987d82c1bdec
Transaction (gas used) = 1590998


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ChildERC1155MintablePredicate
Contract (address)     = 0x030E368A0A5086948ECD1f9aF9A298a5B98FA309
Transaction (hash)     = 0x803cd8fb2f11e2a4472565db4e5e58a1e0fe275cfae994d2b6ee308785d085f7
Transaction (gas used) = 1793675


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = ERC1155Template
Contract (address)     = 0x112F1435933f992025ab38Cc4B41b4f9A1bc47B6
Transaction (hash)     = 0x156fd0c783df2acc59388b26d5a91e192a715b602f4d55b112e5d397f71f0626
Transaction (gas used) = 2460706


[ROOTCHAIN - DEPLOY CONTRACT]
Name                   = CustomSupernetManager
Contract (address)     = 0x2252e4A7f4fCfBc8DFA22513a32b64EcF3FaCF74
Transaction (hash)     = 0x18a19b20530c4c7e946d3560f833e6718682cbec0a88a582316bb7c956fa98fc
Transaction (gas used) = 1870312

[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 115064 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 71735 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 115064 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 114911 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 115020 
Gas Price = 1500000017
[ROOTCHAIN - CONTRACTS DEPLOYMENT] ChildERC721MintablePredicate contract is initialized

[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 114758 
Gas Price = 1500000017
[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 114780 
Gas Price = 1500000017
[ROOTCHAIN - CONTRACTS DEPLOYMENT] ExitHelper contract is initialized

[ROOTCHAIN - CONTRACTS DEPLOYMENT] RootERC20Predicate contract is initialized

[ROOTCHAIN - CONTRACTS DEPLOYMENT] ChildERC1155MintablePredicate contract is initialized

[ROOTCHAIN - CONTRACTS DEPLOYMENT] ChildERC20MintablePredicate contract is initialized

[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 232215 
Gas Price = 1500000017
[ROOTCHAIN - CONTRACTS DEPLOYMENT] RootERC721Predicate contract is initialized

[ROOTCHAIN - CONTRACTS DEPLOYMENT] RootERC1155Predicate contract is initialized

[ROOTCHAIN - CONTRACTS DEPLOYMENT] CustomSupernetManager contract is initialized

[TxRelayer.SendTransaction]
From = 0xAE3ac03497aB6aFfF786bCFF95DD6e9095Dc5d55 
Gas = 117658 
Gas Price = 1500000017
[ROOTCHAIN - CONTRACTS DEPLOYMENT] finished. All contracts are successfully deployed and initialized.


[ROOTCHAIN FUND] Successfully funded following accounts
failed to send mint native tokens transaction to validator '0x74eBB8341F08C3334d60487876dD9B984dfA218A'. err: {"code":-32000,"message":"execution reverted"}

Proposed solution

I believe modifying the rootchain fund command to transfer Rootchain Stake Tokens in the presence of the --stake-token flag and transferring native rootchain tokens otherwise would be ideal.

Thanks for your time!

@sahil3Vedi
Copy link
Author

I will try adding a line in the polygon-edge.sh file that curls the JSON-RPC of the rootchain to transfer Rootchain Stake Tokens to the validators and that should resolve the issue. Will update the result here shortly!

@sahil3Vedi
Copy link
Author

@Stefan-Ethernal turns out the funding issue inside the polygoin-edge.sh file cannot be fixed by editing the shell file itself. Kindly review this, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant