Skip to content

Commit 4704c44

Browse files
author
Abdul Rabbani
committed
Starting point for Foundry
I still need to finish it up, but geth runs properly.
1 parent f4b7bd4 commit 4704c44

File tree

6 files changed

+298
-0
lines changed

6 files changed

+298
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ profile.cov
4747
/dashboard/assets/package-lock.json
4848

4949
**/yarn-error.log
50+
foundry/deployments/local-private-network/geth-linux-amd64
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM frolvlad/alpine-bash
2+
3+
RUN apk update ; apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ --allow-untrusted ca-certificates curl bash git jshon jq
4+
5+
#USER guest
6+
WORKDIR /root
7+
8+
# copy all files
9+
ADD ./deploy-local-network.sh .
10+
ADD ./geth-linux-amd64 /bin/geth
11+
ADD ./start-private-network.sh .
12+
13+
RUN curl -L https://foundry.paradigm.xyz | bash; \
14+
/bin/bash -c 'source $HOME/.bashrc'; \
15+
/root/.foundry/bin/foundryup
16+
17+
RUN chmod +x /bin/geth
18+
19+
EXPOSE 8545
20+
EXPOSE 8546
21+
ENTRYPOINT ["./start-private-network.sh"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
GREEN='\033[0;32m'
5+
RED='\033[0;31m'
6+
NC='\033[0m'
7+
8+
start_path=$(pwd)
9+
cd ../../../
10+
echo -e "${GREEN}Building geth!${NC}"
11+
docker build -t vulcanize/go-ethereum -f Dockerfile .
12+
docker run --rm --entrypoint cat vulcanize/go-ethereum /usr/local/bin/geth > foundry/deployments/local-private-network/geth-linux-amd64
13+
chmod +x foundry/deployments/local-private-network/geth-linux-amd64
14+
15+
echo -e "${GREEN}geth build complete!${NC}"
16+
cd $start_path
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#!/bin/bash
2+
set -e
3+
4+
OPTS="dapp testnet [<options>] <args>...
5+
dapp testnet --help
6+
--
7+
db-user=name database user
8+
db-password=password database password
9+
db-name=name database name
10+
db-host=address database host
11+
db-port=port database port
12+
db-write=bool turn on database write mode
13+
db-type=name the type of database
14+
db-driver=name the driver used for the database
15+
db-waitforsync=bool Should the statediff service start once geth has synced to head (default: false)
16+
rpc-port=port change RPC port (default: 8545)
17+
rpc-addr=address change RPC address (default: 127.0.0.1)
18+
chain-id=number change chain ID (default: 99)
19+
period=seconds use a block time instead of instamine
20+
accounts=number create multiple accounts (default: 1)
21+
address=address eth address to add to genesis
22+
save=name after finishing, save snapshot
23+
load=name start from a previously saved snapshot
24+
dir=directory testnet directory
25+
"
26+
27+
eval "$(
28+
git rev-parse --parseopt -- "$@" <<<"$OPTS" || echo exit $?
29+
)"
30+
31+
DB_USER=vdbm
32+
DB_PASSWORD=password
33+
DB_NAME=vulcanize_public
34+
DB_HOST=127.0.0.1
35+
DB_PORT=5432
36+
DB_TYPE=postgres
37+
DB_DRIVER=sqlx
38+
DB_WAIT_FOR_SYNC=false
39+
RPC_PORT=8545
40+
RPC_ADDRESS=127.0.0.1
41+
PERIOD=0
42+
CHAINID=99
43+
ACCOUNTS=0
44+
ADDRESS=
45+
gethdir=$HOME/testnet
46+
47+
while [[ $1 ]]; do
48+
case $1 in
49+
--) shift; break;;
50+
--db-user) shift; DB_USER=$1;;
51+
--db-password) shift; DB_PASSWORD=$1;;
52+
--db-name) shift; DB_NAME=$1;;
53+
--db-host) shift; DB_HOST=$1;;
54+
--db-port) shift; DB_PORT=$1;;
55+
--db-write) shift; DB_WRITE=$1;;
56+
--db-type) shift; DB_TYPE=$1;;
57+
--db-driver) shift; DB_DRIVER=$1;;
58+
--db-waitforsync) shift; DB_WAIT_FOR_SYNC=$1;;
59+
--rpc-port) shift; RPC_PORT=$1;;
60+
--rpc-addr) shift; RPC_ADDRESS=$1;;
61+
--chain-id) shift; CHAINID=$1;;
62+
--period) shift; PERIOD=$1;;
63+
--accounts) shift; ACCOUNTS=$1;;
64+
--save) shift; SAVE=$1;;
65+
--address) shift; ADDRESS=$1;;
66+
--load) shift; LOAD=$1;;
67+
--dir) shift; gethdir=$1;;
68+
*) printf "${0##*/}: internal error: %q\\n" "$1"; exit 1
69+
esac; shift
70+
done
71+
72+
chaindir=$gethdir/$RPC_PORT
73+
#while true; do
74+
# if [[ ! -d "$gethdir/$CHAINID" ]]; then break; fi
75+
# CHAINID=$((CHAINID + 1))
76+
#done
77+
78+
mkdir -p "$chaindir/config"
79+
#if [ -n "$ADDRESS" ]; then
80+
# balance+=(-n {} -s "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" -i balance \
81+
# -i "$ADDRESS")
82+
#fi
83+
for i in $(seq 0 "$ACCOUNTS"); do
84+
address+=( "$(
85+
geth 2>/dev/null account new --datadir "$chaindir" --password=<(exit) 2>/dev/null \
86+
| grep -o -E "0x[A-Fa-f0-9]*" )" )
87+
# balance+=(-n {} -s "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" -i balance \
88+
# -i "${address[i]}")
89+
balance+=(' "'"${address[i]}"'": { "balance": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}')
90+
done
91+
92+
#ALLOC_CLEAN=$(echo ${ALLOC} | jq .)
93+
EXTRA_DATA="0x3132333400000000000000000000000000000000000000000000000000000000${address[0]#0x}0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
94+
JSON_VAL='{
95+
"config": {
96+
"chainId": '"$CHAINID"',
97+
"homesteadBlock": 0,
98+
"eip150Block": 0,
99+
"eip155Block": 0,
100+
"eip158Block": 0,
101+
"byzantiumBlock": 0,
102+
"constantinopleBlock": 0,
103+
"petersburgBlock": 0,
104+
"istanbulBlock": 0,
105+
"clique": {
106+
"period": '"$PERIOD"',
107+
"epoch": 3000
108+
}
109+
},
110+
"difficulty": "0x1",
111+
"gaslimit": "0xffffffffffff",
112+
"extraData": "'"$EXTRA_DATA"'",
113+
"alloc": {'"$balance"'}
114+
}'
115+
echo $JSON_VAL | jq . > $chaindir/config/genesis.json
116+
117+
geth 2>/dev/null --datadir "$chaindir" init "$chaindir/config/genesis.json"
118+
119+
export ETH_RPC_URL=http://$RPC_ADDRESS:$RPC_PORT
120+
121+
port=$((RPC_PORT + 30000))
122+
123+
geth version
124+
echo >&2 "dapp-testnet: RPC URL: $ETH_RPC_URL"
125+
echo >&2 "dapp-testnet: TCP port: $port"
126+
echo >&2 "dapp-testnet: Chain ID: $CHAINID"
127+
echo >&2 "dapp-testnet: Database: $chaindir"
128+
echo >&2 "dapp-testnet: Geth log: $chaindir/geth.log"
129+
130+
printf "%s\n" "${address[@]}" > "$chaindir/config/account"
131+
echo "$ETH_RPC_URL" > "$chaindir/config/rpc-url"
132+
echo "$port" > "$chaindir/config/node-port"
133+
134+
set +m
135+
# Uncomment below once waitforsync has been merged
136+
# geth \
137+
# 2> >(tee "$chaindir/geth.log" | grep --line-buffered Success | sed 's/^/geth: /' >&2) \
138+
# --datadir "$chaindir" --networkid "$CHAINID" --port="$port" \
139+
# --mine --miner.threads=1 --allow-insecure-unlock \
140+
# --http --http.api "web3,eth,net,debug,personal,statediff" --http.corsdomain '*' --http.vhosts '*' --nodiscover \
141+
# --http.addr="$RPC_ADDRESS" --http.port="$RPC_PORT" --syncmode=full --gcmode=archive \
142+
# --statediff --statediff.db.host="$DB_HOST" --statediff.db.port="$DB_PORT" --statediff.db.user="$DB_USER" \
143+
# --statediff.db.password="$DB_PASSWORD" --statediff.db.name="$DB_NAME" \
144+
# --statediff.db.nodeid 1 --statediff.db.clientname test1 --statediff.writing="$DB_WRITE" \
145+
# --statediff.db.type="$DB_TYPE" --statediff.db.driver="$DB_DRIVER" --statediff.waitforsync="$DB_WAIT_FOR_SYNC" \
146+
# --ws --ws.addr="0.0.0.0" --unlock="$(IFS=,; echo "${address[*]}")" --password=<(exit) &
147+
148+
geth \
149+
2> >(tee "$chaindir/geth.log" | grep --line-buffered Success | sed 's/^/geth: /' >&2) \
150+
--datadir "$chaindir" --networkid "$CHAINID" --port="$port" \
151+
--mine --miner.threads=1 --allow-insecure-unlock \
152+
--http --http.api "web3,eth,net,debug,personal,statediff" --http.corsdomain '*' --http.vhosts '*' --nodiscover \
153+
--http.addr="$RPC_ADDRESS" --http.port="$RPC_PORT" --syncmode=full --gcmode=archive \
154+
--statediff --statediff.db.host="$DB_HOST" --statediff.db.port="$DB_PORT" --statediff.db.user="$DB_USER" \
155+
--statediff.db.password="$DB_PASSWORD" --statediff.db.name="$DB_NAME" \
156+
--statediff.db.nodeid 1 --statediff.db.clientname test1 --statediff.writing="$DB_WRITE" \
157+
--statediff.db.type="$DB_TYPE" --statediff.db.driver="$DB_DRIVER" \
158+
--ws --ws.addr="0.0.0.0" --unlock="$(IFS=,; echo "${address[*]}")" --password=<(exit) &
159+
160+
gethpid=$!
161+
162+
clean() {
163+
( set -x; kill -INT $gethpid; wait )
164+
if [[ $SAVE ]]; then
165+
echo >&2 "dapp-testnet: saving $gethdir/snapshots/$SAVE"
166+
mkdir -p "$gethdir/snapshots/$SAVE"
167+
cp -r "$chaindir/keystore" "$gethdir/snapshots/$SAVE"
168+
cp -r "$chaindir/config" "$gethdir/snapshots/$SAVE"
169+
geth >/dev/null 2>&1 --datadir "$chaindir" \
170+
export "$gethdir/snapshots/$SAVE/backup"
171+
fi
172+
( set -x; rm -rf "$chaindir" )
173+
}
174+
trap clean EXIT
175+
176+
until curl -s "$ETH_RPC_URL"; do sleep 1; done
177+
178+
# UPDATE
179+
#ETH_FROM=$(seth --rpc-url="$ETH_RPC_URL" rpc eth_coinbase)
180+
#export ETH_FROM
181+
export ETH_KEYSTORE=$chaindir/keystore
182+
export ETH_PASSWORD=/dev/null
183+
printf 'dapp-testnet: Account: %s (default)\n' "${address[0]}" >&2
184+
185+
[[ "${#address[@]}" -gt 1 ]] && printf 'dapp-testnet: Account: %s\n' "${address[@]:1}" >&2
186+
187+
while true; do sleep 3600; done
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: "3.2"
2+
3+
services:
4+
foundry:
5+
restart: unless-stopped
6+
depends_on:
7+
- ipld-eth-db
8+
build: ./
9+
environment:
10+
DB_USER: vdbm
11+
DB_NAME: vulcanize_testing
12+
DB_HOST: ipld-eth-db
13+
DB_PORT: 5432
14+
DB_PASSWORD: password
15+
DB_WRITE: "true"
16+
DB_TYPE: postgres
17+
DB_DRIVER: sqlx
18+
DB_WAIT_FOR_SYNC: "true"
19+
ports:
20+
- "127.0.0.1:8545:8545"
21+
- "127.0.0.1:8546:8546"
22+
23+
ipld-eth-db:
24+
restart: always
25+
image: vulcanize/ipld-eth-db:v3.0.6
26+
environment:
27+
POSTGRES_USER: "vdbm"
28+
POSTGRES_DB: "vulcanize_testing"
29+
POSTGRES_PASSWORD: "password"
30+
volumes:
31+
- vdb_db_eth_server:/var/lib/postgresql/data
32+
ports:
33+
- "127.0.0.1:8077:5432"
34+
command: ["postgres", "-c", "log_statement=all"]
35+
36+
volumes:
37+
vdb_db_eth_server:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# clean up
6+
trap 'killall geth && rm -rf "$TMPDIR"' EXIT
7+
trap "exit 1" SIGINT SIGTERM
8+
9+
TMPDIR=$(mktemp -d)
10+
/bin/bash deploy-local-network.sh --rpc-addr 0.0.0.0 --chain-id 4 --db-user $DB_USER --db-password $DB_PASSWORD --db-name $DB_NAME \
11+
--db-host $DB_HOST --db-port $DB_PORT --db-write $DB_WRITE --dir "$TMPDIR" --address $ADDRESS \
12+
--db-type $DB_TYPE --db-driver $DB_DRIVER --db-waitforsync $DB_WAIT_FOR_SYNC &
13+
echo "sleeping 90 sec"
14+
# give it a few secs to start up
15+
sleep 90
16+
17+
#read -r ACC BAL <<< "$(seth ls --keystore "$TMPDIR/8545/keystore")"
18+
#echo $ACC
19+
#echo $BAL
20+
#
21+
#
22+
## Deploy a contract:
23+
#solc --bin --bin-runtime docker/stateful.sol -o "$TMPDIR"
24+
#A_ADDR=$(seth send --create "$(<"$TMPDIR"/A.bin)" "constructor(uint y)" 1 --from "$ACC" --keystore "$TMPDIR"/8545/keystore --password /dev/null --gas 0xfffffff)
25+
#
26+
#echo $A_ADDR
27+
#
28+
## Call transaction
29+
#
30+
#TX=$(seth send "$A_ADDR" "off()" --gas 0xffff --password /dev/null --from "$ACC" --keystore "$TMPDIR"/8545/keystore --async)
31+
#echo $TX
32+
#RESULT=$(seth run-tx "$TX")
33+
#echo $RESULT
34+
35+
# Run forever
36+
tail -f /dev/null

0 commit comments

Comments
 (0)