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

Dynamic dockerfile #50

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
54 changes: 45 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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).
Expand Down
167 changes: 127 additions & 40 deletions cpp-eth.sh
Original file line number Diff line number Diff line change
@@ -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}"
31 changes: 0 additions & 31 deletions docker-compose.yml

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

echo "Installing ewasm-testnet prerequisites"
if [[ -z "${JQ_BIN_URL}" ]]; then
JQ_BIN_URL=https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
fi
curl -L "${JQ_BIN_URL}" > /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