diff --git a/Dockerfile b/Dockerfile index d5b38e2..e25d6ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,23 +11,14 @@ FROM ethereum/cpp-build-env USER root -# Make sure bash, bc and jq is available for easier wrapper implementation -RUN URL=https://github.com/ethereum/cpp-ethereum/releases/download/v1.4.0.dev1/cpp-ethereum-1.4.0.dev1-linux.tar.gz && curl -L $URL | tar xz -C /usr/local \ - && curl https://raw.githubusercontent.com/ethereum/cpp-ethereum/develop/scripts/jsonrpcproxy.py > /jsonrpcproxy.py +ADD setup.sh setup.sh +RUN ./setup.sh -RUN git clone https://github.com/ewasm/hera && \ - cd hera && \ - git submodule update --init --recursive && \ - cmake -DBUILD_SHARED_LIBS=ON . && \ - make -j8 && \ - cp src/libhera.so / +RUN mkdir -p /opt/ewasm-testnet +WORKDIR /opt/ewasm-testnet -ADD ewasm-testnet-cpp-config.json /ewasm-testnet-cpp-config.json +ADD cpp-eth.sh cpp-eth.sh -ADD cpp-eth.sh /cpp-eth.sh -ADD enodes /enodes - -# Export the usual networking ports to allow outside access to the node EXPOSE 8545 30303 -ENTRYPOINT ["/cpp-eth.sh"] +ENTRYPOINT ["./cpp-eth.sh"] diff --git a/README.md b/README.md index 2996450..2fd6cae 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,5 @@ # ewasm testnet coordination / documentation repo -## cpp-ethereum - -To build cpp-ethereum with the recent eWASM changes use [ewasm](https://github.com/ethereum/cpp-ethereum/tree/ewasm). - -The `eth`, `ethvm` and `testeth` contain options to run them with [Hera eWASM VM](https://github.com/ewasm/hera): - -- `--vm hera` enables Hera only, -- `--evmc fallback=true` enables fallback to EVM 1.0 Interpreter when EVM bytecode is detected. - ### Test net differences from main net Supports executing EVM 1.0 (Byzantium) **and** eWASM bytecode. The chain id is set to 0x42 (66). @@ -17,6 +8,51 @@ There are two differences: - code size limit introduced by Spurious Dragon has been lifted and there is no upper limit - zero bytes in contract bytecode are not subsidised anymore during deployment (they cost the same as non-zero bytes) + +### Docker + +To get up and running quickly using Docker, simply `docker build -t ethereum/ewasm-testnet .`. + +The `docker run` command should be parameterized (i.e., using the `-e` flag to set environment variables in the running container). The following parameters are currently exposed: + +| Environment Variable | Description | Default | +|--- |--- |--- | +| `BASE_PATH` | prefix where blockchain lives on disk | the directory containing the running instance of `cpp-eth.sh` +| `CHAIN` | name of the chain; useful when this matches a ref in git | master +| `CHAIN_SPEC` | path to the chain spec JSON | `${BASE_PATH}/ewasm-spec.json` +| `CHAIN_SPEC_URL` | arbitrary URL from which the chain spec JSON will be read | https://raw.githubusercontent.com/ewasm/testnet/${CHAIN}/ewasm-testnet-cpp-config.json +| `PEER_SET` | list of enodes for p2p discovery | the contents of `./enodes.txt`, if it exists +| `DB_PATH` | path to the chain-specific database | `${BASE_PATH}/${CHAIN}` +| `EVMC_FALLBACK` | EVM-C `fallback` option | true +| `ASK` | tx ask price, in wei | 0 +| `BID` | tx bid price, in wei | 20000000000 +| `COINBASE` | address to which block rewards will be sent | 0x0000000000000000000000000000000000000000 +| `IPC_PATH` | path to the domain socket | `${BASE_PATH}/geth.ipc` +| `JSON_RPC_PORT` | port on which the JSON-RPC proxy will listen | 8545 +| `JSON_RPC_PROXY_PY` | path to the JSON-RPC proxy python file | /usr/local/bin/jsonrpcproxy.py +| `JSON_RPC_PROXY_URL` | endpoint where the JSON-RPC proxy will be listening | http://0.0.0.0:8545 +| `LISTEN_IP` | local ip on which node accepts inbound p2p connections | 0.0.0.0 +| `LISTEN_PORT` | local port where node accepts inbound p2p connections | 30303 +| `LOG_VERBOSITY` | log level | 2 +| `LOG_PATH` | path to logfile | `${BASE_PATH}/cpp-ethereum.log` +| `MINING` | whether or not the node is mining | on +| `MINING_THREADS` | number of threads to allocate to mining | 1 +| `NETWORK_ID` | network id | 66 +| `MODE` | full or peer | full +| `PORT` | remote p2p port | 30303 +| `PUBLIC_IP` | IP address to advertise for disco | public IP address resolved using ipify.org +| `VM` | path to the VM lib | /usr/local/lib/libhera.so + + +### cpp-ethereum + +To build cpp-ethereum with the recent eWASM changes use [ewasm](https://github.com/ethereum/cpp-ethereum/tree/ewasm). + +The `eth`, `ethvm` and `testeth` contain options to run them with [Hera eWASM VM](https://github.com/ewasm/hera): + +- `--vm hera` enables Hera only, +- `--evmc fallback=true` enables fallback to EVM 1.0 Interpreter when EVM bytecode is detected. + ### Run eth node The config is in [ewasm-testnet-cpp-config.json](ewasm-testnet-cpp-config.json). diff --git a/cpp-eth.sh b/cpp-eth.sh index 6c98ff6..2c0c612 100755 --- a/cpp-eth.sh +++ b/cpp-eth.sh @@ -1,59 +1,146 @@ -#! /bin/bash +#!/usr/bin/env bash +PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PEER_1="enode://a604159cad54b3136812fd19c1656a035f6070e27fc3ab433bc04b61fb2c1a27f6563a53b80c88e2453b6b059bd7658e59ebbbb60de8d09ae9b78fce8e84887b@miner1:30303" -PEER_2="enode://eb085e5795760a7aa83026b56c433ba3b027738eed2cbf4ebad6ccf0ca3ccd78369f4ffa77b59f763e31a41245980d246c2e0acb6362785a9ec21824385cf87b@miner2:30303" -PEER_3="enode://37ffd11745b7243a0e835cae086be8e20b4ace08d5ce38d4d65ac9149e4fbe96a1a00c2df3090a9a858d6a1bf389cb5f7d012f3435ff4b8253ad22414c9da153@miner3:30303" +if [[ -z "${BASE_PATH}" ]]; then + BASE_PATH=$PWD +fi + +if [[ -z "${CHAIN}" ]]; then + CHAIN=master +fi + +if [[ -z "${CHAIN_SPEC}" ]]; then + CHAIN_SPEC=${BASE_PATH}/ewasm-spec.json + + if [ ! -f "${CHAIN_SPEC}" ] || [ ! -s "${CHAIN_SPEC}" ]; then + if [[ -z "${CHAIN_SPEC_URL}" ]]; then + CHAIN_SPEC_URL="https://raw.githubusercontent.com/ewasm/testnet/${CHAIN}/ewasm-testnet-cpp-config.json" + fi + curl "${CHAIN_SPEC_URL}" > "${CHAIN_SPEC}" 2> /dev/null + fi +fi + +if [[ -z "${PEER_SET}" ]]; then + if [ ! -f enodes.txt ] || [ ! -s enodes.txt ]; then + if [[ ! -z "${BOOTNODES_URL}" ]]; then + curl "${BOOTNODES_URL}" > enodes.txt 2> /dev/null + PEER_SET=$(cat enodes.txt | sed 's/,/ /g') + fi + fi +fi + +if [[ -z "${DB_PATH}" ]]; then + DB_PATH=${BASE_PATH}/${CHAIN} +fi + +if [[ -z "${EVMC_FALLBACK}" ]]; then + EVMC_FALLBACK=true +fi + +if [[ -z "${ASK}" ]]; then + ASK=0 +fi + +if [[ -z "${BID}" ]]; then + BID=20000000000 +fi + +if [[ -z "${COINBASE}" ]]; then + COINBASE=0x0000000000000000000000000000000000000000 +fi -PEER_SET="" +if [[ -z "${IPC_PATH}" ]]; then + IPC_PATH=${DB_PATH}/geth.ipc +fi -if [ "$NODE_NUM" == "1" ] -then - PEER_SET="$PEER_2 $PEER_3" - cp /enodes/a604159cad54b3136812fd19c1656a035f6070e27fc3ab433bc04b61fb2c1a27f6563a53b80c88e2453b6b059bd7658e59ebbbb60de8d09ae9b78fce8e84887b/* /tmp/ewasm-node/4201/ - echo "foobar1" +if [[ -z "${JSON_RPC_PORT}" ]]; then + JSON_RPC_PORT=8545 fi -if [ "$NODE_NUM" == "2" ] -then - PEER_SET="$PEER_1 $PEER_3" - cp /enodes/eb085e5795760a7aa83026b56c433ba3b027738eed2cbf4ebad6ccf0ca3ccd78369f4ffa77b59f763e31a41245980d246c2e0acb6362785a9ec21824385cf87b/* /tmp/ewasm-node/4201/ - echo "foobar2" +if [[ -z "${JSON_RPC_PROXY_PY}" ]]; then + JSON_RPC_PROXY_PY=/usr/local/bin/jsonrpcproxy.py fi -if [ "$NODE_NUM" == "3" ] -then - PEER_SET="$PEER_1 $PEER_2" - cp /enodes/37ffd11745b7243a0e835cae086be8e20b4ace08d5ce38d4d65ac9149e4fbe96a1a00c2df3090a9a858d6a1bf389cb5f7d012f3435ff4b8253ad22414c9da153/* /tmp/ewasm-node/4201/ - echo "foobar3" +if [[ -z "${JSON_RPC_PROXY_URL}" ]]; then + JSON_RPC_PROXY_URL=http://0.0.0.0:${JSON_RPC_PORT} fi -echo $PEER_SET +if [[ -z "${LISTEN_IP}" ]]; then + LISTEN_IP=0.0.0.0 +fi -echo "running eth..." +if [[ -z "${LISTEN_PORT}" ]]; then + LISTEN_PORT=30303 +fi +if [[ -z "${LOG_VERBOSITY}" ]]; then + LOG_VERBOSITY=2 +fi -ethCmd=(aleth) +if [[ -z "${LOG_PATH}" ]]; then + LOG_PATH="${BASE_PATH}/cpp-ethereum.log" +fi -ethCmd+=(--vm /libhera.so) -ethCmd+=(--evmc fallback=true) -ethCmd+=(--db-path /tmp/ewasm-node/4201) -ethCmd+=(--no-bootstrap) -ethCmd+=(--mining on) -ethCmd+=(--mining-threads 1) -ethCmd+=(--ask 1) -ethCmd+=(--address 0x031159dF845ADe415202e6DA299223cb640B9DB0) -ethCmd+=(--config /ewasm-testnet-cpp-config.json) -ethCmd+=(--listen 1234) -ethCmd+=(${PEER_SET:+ --peerset "${PEER_SET}"}) # only use --peerset when $PEER_SET not empty +if [[ -z "${MINING}" ]]; then + MINING=on +fi -echo ${ethCmd[@]} +if [[ -z "${MINING_THREADS}" ]]; then + MINING_THREADS=1 +fi -"${ethCmd[@]}" & - +if [[ -z "${NETWORK_ID}" ]]; then + NETWORK_ID=66 +fi -# --peerset "required:61e5475e6870260af84bcf61c02b2127a5c84560401452ae9c99b9ff4f0f343d65c9e26209ec32d42028b365addba27824669eb70c73f69568964f77433afbbe@127.0.0.1:1234" \ +if [[ -z "${MODE}" ]]; then + MODE=full +fi + +if [[ -z "${PORT}" ]]; then + PORT=30303 +fi + +if [[ -z "${PUBLIC_IP}" ]]; then + PUBLIC_IP=$(curl -s https://api.ipify.org 2> /dev/null) +fi + +if [[ -z "${VM}" ]]; then + VM=/usr/local/lib/libhera.so +fi +CPP_ETH_BIN=$(which aleth) +if [ $? -eq 0 ]; then + echo "ewasm testnet node starting in ${BASE_PATH}; cpp-ethereum bin: ${CPP_ETH_BIN}" +fi -echo "running jsonrpcproxy..." -python3 /jsonrpcproxy.py /tmp/ewasm-node/4201/geth.ipc http://0.0.0.0:8545 +$CPP_ETH_BIN --address ${COINBASE} \ + --ask ${ASK} \ + --bid ${BID} \ + --config ${CHAIN_SPEC} \ + --db-path ${DB_PATH} \ + --evmc fallback=${EVMC_FALLBACK} \ + --listen-ip ${LISTEN_IP} \ + --listen ${LISTEN_PORT} \ + --log-verbosity ${LOG_VERBOSITY} \ + --mining ${MINING} \ + --mining-threads ${MINING_THREADS} \ + --mode ${MODE} \ + --network-id ${NETWORK_ID} \ + --no-bootstrap \ + ${PEER_SET:+ --peerset "${PEER_SET}"} \ + --port ${PORT} \ + --public-ip ${PUBLIC_IP} \ + --vm ${VM} & + +while [[ -z "${nodeInfo}" ]]; do + resp=$(echo '{"jsonrpc": "2.0", "method": "admin_nodeInfo", "params": [], "id": null}' | nc -U "${IPC_PATH}" 2> /dev/null) + if [ $? -eq 0 ]; then + nodeInfo=$(echo "${resp}" | sed s/\:0\"/\:${LISTEN_PORT}\"/g) + fi +done +echo "${nodeInfo}" + +echo "Running ${JSON_RPC_PROXY_PY}; IPC path: ${IPC_PATH}; JSON-RPC proxy: ${JSON_RPC_PROXY_URL}" +python3 "${JSON_RPC_PROXY_PY}" "${IPC_PATH}" "${JSON_RPC_PROXY_URL}" diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 7ec5d03..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: '2' - -services: - miner1: - image: ewasm/cpp-ethereum - networks: - ewasm: - ipv4_address: 172.18.0.2 - environment: - - NODE_ID=1 - - miner2: - image: ewasm/cpp-ethereum - networks: - ewasm: - ipv4_address: 172.18.0.3 - environment: - - NODE_ID=2 - -networks: - ewasm: - driver: bridge - # enable_ipv6: true - ipam: - driver: default - config: - - subnet: 172.18.0.0/24 - gateway: 172.18.0.1 -# faucet: - -# explorer diff --git a/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/keys.info b/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/keys.info deleted file mode 100644 index 211ad34..0000000 --- a/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/keys.info +++ /dev/null @@ -1 +0,0 @@ -,yY]KԌ8s&s5Z" \ No newline at end of file diff --git a/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/keys.info.salt b/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/keys.info.salt deleted file mode 100644 index a3c176c..0000000 Binary files a/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/keys.info.salt and /dev/null differ diff --git a/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/network.rlp b/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/network.rlp deleted file mode 100644 index c509c94..0000000 --- a/enodes/1137327feeda2680b43d64d465a90898d50744d065a9e85402a7f0f7d9f6e5c6ac4b5c491303152f8f862cb8018d2d91b72e1ba3d96c0f45af307eb23d05fc22/network.rlp +++ /dev/null @@ -1 +0,0 @@ -ML%nq2V8TEW Z5:J \ No newline at end of file diff --git a/enodes/37ffd11745b7243a0e835cae086be8e20b4ace08d5ce38d4d65ac9149e4fbe96a1a00c2df3090a9a858d6a1bf389cb5f7d012f3435ff4b8253ad22414c9da153/keys.info b/enodes/37ffd11745b7243a0e835cae086be8e20b4ace08d5ce38d4d65ac9149e4fbe96a1a00c2df3090a9a858d6a1bf389cb5f7d012f3435ff4b8253ad22414c9da153/keys.info deleted file mode 100644 index 84c062f..0000000 --- a/enodes/37ffd11745b7243a0e835cae086be8e20b4ace08d5ce38d4d65ac9149e4fbe96a1a00c2df3090a9a858d6a1bf389cb5f7d012f3435ff4b8253ad22414c9da153/keys.info +++ /dev/null @@ -1 +0,0 @@ -NRH pTw/Ss̛@ /usr/local/bin/jq +chmod +x /usr/local/bin/jq + +if [[ -z "${CPP_ETHEREUM_PREFIX}" ]]; then + CPP_ETHEREUM_PREFIX=/usr/local +fi + +if [[ -z "${CPP_ETHEREUM_RELEASE_TGZ_URL}" ]]; then + CPP_ETHEREUM_RELEASE_TGZ_URL=$(curl -L https://api.github.com/repos/ethereum/cpp-ethereum/releases | jq 'first.assets|first.browser_download_url' | tr -d '"') +fi + +if [[ -z "${CPP_ETHEREUM_JSON_RPC_PROXY_PY_URL}" ]]; then + CPP_ETHEREUM_JSON_RPC_PROXY_PY_URL=https://raw.githubusercontent.com/ethereum/cpp-ethereum/develop/scripts/jsonrpcproxy.py +fi + +if [[ -z "${HERA_EVMC_REF}" ]]; then + HERA_EVMC_REF=master +fi + +if [[ -z "${NETCAT_PACKAGE_URL}" ]]; then + NETCAT_PACKAGE_URL=http://ftp.us.debian.org/debian/pool/main/n/netcat-openbsd/netcat-openbsd_1.105-7_amd64.deb +fi + +echo "Prefix for cpp-ethereum install: ${CPP_ETHEREUM_PREFIX}" + +echo "Installing cpp-ethereum release: ${CPP_ETHEREUM_RELEASE_TGZ_URL}" +curl -L "${CPP_ETHEREUM_RELEASE_TGZ_URL}" | tar xz -C "${CPP_ETHEREUM_PREFIX}" + +echo "Installing jsonrpcproxy.py from: ${CPP_ETHEREUM_JSON_RPC_PROXY_PY_URL}" +mkdir -p "${CPP_ETHEREUM_PREFIX}/bin" +curl "${CPP_ETHEREUM_JSON_RPC_PROXY_PY_URL}" > "${CPP_ETHEREUM_PREFIX}/bin/jsonrpcproxy.py" + +git clone --single-branch -b ${HERA_EVMC_REF} https://github.com/ewasm/hera.git +pushd hera +git submodule update --init --recursive +cmake -DBUILD_SHARED_LIBS=ON . && make -j8 +cp src/libhera.so "${CPP_ETHEREUM_PREFIX}/lib/libhera.so" +popd + +echo "Installing netcat from: ${NETCAT_PACKAGE_URL}" +curl ${NETCAT_PACKAGE_URL} > netcat.deb +dpkg -i netcat.deb