Skip to content

Commit e958ef4

Browse files
committed
Added ethrex client
1 parent aa46f75 commit e958ef4

File tree

5 files changed

+242
-0
lines changed

5 files changed

+242
-0
lines changed

clients/ethrex/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARG baseimage=ghcr.io/lambdaclass/ethrex
2+
ARG tag=latest
3+
4+
FROM $baseimage:$tag as builder
5+
6+
# Install script tools.
7+
RUN apt-get update -y
8+
RUN apt-get install -y bash curl jq
9+
10+
# Add genesis mapper script.
11+
ADD genesis.json /genesis.json
12+
ADD mapper.jq /mapper.jq
13+
14+
# Add the startup script.
15+
ADD ethrex.sh /ethrex.sh
16+
RUN chmod +x /ethrex.sh
17+
18+
# Add the enode URL retriever script.
19+
ADD enode.sh /hive-bin/enode.sh
20+
RUN chmod +x /hive-bin/enode.sh
21+
22+
# Create version.txt
23+
RUN ethrex --version | sed -e 's/ethrex \(.*\)/\1/' > /version.txt
24+
25+
# Export the usual networking ports to allow outside access to the node.
26+
EXPOSE 8545 8546 30303 30303/udp
27+
28+
ENTRYPOINT ["/ethrex.sh"]

clients/ethrex/enode.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Script to retrieve the enode
4+
#
5+
# This is copied into the validator container by Hive
6+
# and used to provide a client-specific enode id retriever
7+
#
8+
9+
# Immediately abort the script on any error encountered
10+
set -e
11+
data='{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}'
12+
TARGET_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" --data $data "localhost:8545" )
13+
TARGET_ENODE=$(echo ${TARGET_RESPONSE}| jq -r '.result.enode')
14+
echo "$TARGET_ENODE"

clients/ethrex/ethrex.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# Immediately abort the script on any error encountered
4+
set -ex
5+
6+
# no ansi colors
7+
export RUST_LOG_STYLE=never
8+
9+
ethrex=./ethrex
10+
11+
# Create the data directory.
12+
# DATADIR="/ethrex-hive-datadir"
13+
# mkdir $DATADIR
14+
# FLAGS="$FLAGS --datadir $DATADIR"
15+
16+
# TODO If a specific network ID is requested, use that
17+
#if [ "$HIVE_NETWORK_ID" != "" ]; then
18+
# FLAGS="$FLAGS --networkid $HIVE_NETWORK_ID"
19+
#else
20+
# FLAGS="$FLAGS --networkid 1337"
21+
#fi
22+
23+
# Configure the chain.
24+
mv /genesis.json /genesis-input.json
25+
jq -f /mapper.jq /genesis-input.json > /genesis.json
26+
27+
# Configure log level
28+
LOG=info
29+
case "$HIVE_LOGLEVEL" in
30+
0|1) LOG=error ;;
31+
2) LOG=warn ;;
32+
3) LOG=info ;;
33+
4) LOG=debug ;;
34+
5) LOG=trace ;;
35+
esac
36+
FLAGS="$FLAGS --log.level=$LOG"
37+
38+
# Dump genesis.
39+
if [ "$HIVE_LOGLEVEL" -lt 4 ]; then
40+
echo "Supplied genesis state (trimmed, use --sim.loglevel 4 or 5 for full output):"
41+
jq 'del(.alloc[] | select(.balance == "0x123450000000000000000"))' /genesis.json
42+
else
43+
echo "Supplied genesis state:"
44+
cat /genesis.json
45+
fi
46+
47+
echo "Command flags till now:"
48+
echo $FLAGS
49+
50+
# Initialize the local testchain with the genesis state
51+
# echo "Initializing database with genesis state..."
52+
# $ethrex init $FLAGS --chain /genesis.json
53+
FLAGS="$FLAGS --network /genesis.json"
54+
55+
# Don't immediately abort, some imports are meant to fail
56+
set +ex
57+
58+
# Load the test chain if present
59+
echo "Loading initial blockchain..."
60+
if [ -f /chain.rlp ]; then
61+
echo "Importing chain.rlp..."
62+
$ethrex $FLAGS $HIVE_ETHREX_FLAGS import /chain.rlp
63+
else
64+
echo "Warning: chain.rlp not found."
65+
fi
66+
67+
# Load the remainder of the test chain
68+
if [ -d /blocks ]; then
69+
echo "Loading remaining individual blocks..."
70+
$ethrex $FLAGS $HIVE_ETHREX_FLAGS import /blocks
71+
else
72+
echo "Warning: blocks folder not found."
73+
fi
74+
75+
# Only set boot nodes in online steps
76+
# It doesn't make sense to dial out, use only a pre-set bootnode.
77+
if [ "$HIVE_BOOTNODE" != "" ]; then
78+
FLAGS="$FLAGS --bootnodes=$HIVE_BOOTNODE"
79+
fi
80+
81+
# Configure any mining operation
82+
if [ "$HIVE_MINER" != "" ]; then
83+
echo "Warning: miner not supported."
84+
exit 1
85+
fi
86+
if [ "$HIVE_MINER_EXTRA" != "" ]; then
87+
echo "Warning: miner extra data not supported."
88+
exit 1
89+
fi
90+
91+
# Import clique signing key.
92+
if [ "$HIVE_CLIQUE_PRIVATEKEY" != "" ]; then
93+
echo "Warning: clique private key not supported."
94+
exit 1
95+
fi
96+
97+
# Configure RPC.
98+
FLAGS="$FLAGS --http.addr=0.0.0.0 --authrpc.addr=0.0.0.0"
99+
100+
if [ "$HIVE_TERMINAL_TOTAL_DIFFICULTY" != "" ]; then
101+
JWT_SECRET="7365637265747365637265747365637265747365637265747365637265747365"
102+
echo -n $JWT_SECRET > /jwt.secret
103+
FLAGS="$FLAGS --authrpc.jwtsecret=/jwt.secret"
104+
fi
105+
106+
FLAGS="$FLAGS $HIVE_ETHREX_FLAGS"
107+
108+
# Launch the main client.
109+
echo "Running ethrex with flags: $FLAGS"
110+
$ethrex $FLAGS

clients/ethrex/genesis.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
3+
"difficulty" : "0x020000",
4+
"extraData" : "0x42",
5+
"gasLimit" : "0x2fefd8",
6+
"mixHash" : "0x2c85bcbce56429100b2108254bb56906257582aeafcbd682bc9af67a9f5aee46",
7+
"nonce" : "0x78cc16f7b4f65485",
8+
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
9+
"timestamp" : "0x54c98c81",
10+
"alloc" : {
11+
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
12+
"balance" : "0x09184e72a000"
13+
}
14+
}
15+
}

clients/ethrex/mapper.jq

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Removes all empty keys and values in input.
2+
def remove_empty:
3+
. | walk(
4+
if type == "object" then
5+
with_entries(
6+
select(
7+
.value != null and
8+
.value != "" and
9+
.value != [] and
10+
.key != null and
11+
.key != ""
12+
)
13+
)
14+
else .
15+
end
16+
)
17+
;
18+
19+
# Converts decimal string to number.
20+
def to_int:
21+
if . == null then . else .|tonumber end
22+
;
23+
24+
# Converts "1" / "0" to boolean.
25+
def to_bool:
26+
if . == null then . else
27+
if . == "1" then true else false end
28+
end
29+
;
30+
31+
# Replace config in input.
32+
. + {
33+
"config": {
34+
"ethash": (if env.HIVE_CLIQUE_PERIOD then null else {} end),
35+
"clique": (if env.HIVE_CLIQUE_PERIOD == null then null else {
36+
"period": env.HIVE_CLIQUE_PERIOD|to_int,
37+
} end),
38+
"chainId": (if env.HIVE_CHAIN_ID == null then 1 else env.HIVE_CHAIN_ID|to_int end),
39+
"homesteadBlock": env.HIVE_FORK_HOMESTEAD|to_int,
40+
"daoForkBlock": env.HIVE_FORK_DAO_BLOCK|to_int,
41+
"daoForkSupport": env.HIVE_FORK_DAO_VOTE|to_bool,
42+
"eip150Block": env.HIVE_FORK_TANGERINE|to_int,
43+
"eip150Hash": env.HIVE_FORK_TANGERINE_HASH,
44+
"eip155Block": env.HIVE_FORK_SPURIOUS|to_int,
45+
"eip158Block": env.HIVE_FORK_SPURIOUS|to_int,
46+
"byzantiumBlock": env.HIVE_FORK_BYZANTIUM|to_int,
47+
"constantinopleBlock": env.HIVE_FORK_CONSTANTINOPLE|to_int,
48+
"petersburgBlock": env.HIVE_FORK_PETERSBURG|to_int,
49+
"istanbulBlock": env.HIVE_FORK_ISTANBUL|to_int,
50+
"muirGlacierBlock": env.HIVE_FORK_MUIR_GLACIER|to_int,
51+
"berlinBlock": env.HIVE_FORK_BERLIN|to_int,
52+
"londonBlock": env.HIVE_FORK_LONDON|to_int,
53+
"arrowGlacierBlock": env.HIVE_FORK_ARROW_GLACIER|to_int,
54+
"grayGlacierBlock": env.HIVE_FORK_GRAY_GLACIER|to_int,
55+
"mergeNetsplitBlock": env.HIVE_MERGE_BLOCK_ID|to_int,
56+
"terminalTotalDifficulty": env.HIVE_TERMINAL_TOTAL_DIFFICULTY|to_int,
57+
"terminalTotalDifficultyPassed": env.HIVE_TERMINAL_TOTAL_DIFFICULTY_PASSED|to_bool,
58+
"shanghaiTime": env.HIVE_SHANGHAI_TIMESTAMP|to_int,
59+
"cancunTime": env.HIVE_CANCUN_TIMESTAMP|to_int,
60+
"pragueTime": env.HIVE_PRAGUE_TIMESTAMP|to_int,
61+
"blobSchedule": {
62+
"cancun": {
63+
"target": (if env.HIVE_CANCUN_BLOB_TARGET then env.HIVE_CANCUN_BLOB_TARGET|to_int else 3 end),
64+
"max": (if env.HIVE_CANCUN_BLOB_MAX then env.HIVE_CANCUN_BLOB_MAX|to_int else 6 end),
65+
"baseFeeUpdateFraction": (if env.HIVE_CANCUN_BLOB_BASE_FEE_UPDATE_FRACTION then env.HIVE_CANCUN_BLOB_BASE_FEE_UPDATE_FRACTION|to_int else 3338477 end)
66+
},
67+
"prague": {
68+
"target": (if env.HIVE_PRAGUE_BLOB_TARGET then env.HIVE_PRAGUE_BLOB_TARGET|to_int else 6 end),
69+
"max": (if env.HIVE_PRAGUE_BLOB_MAX then env.HIVE_PRAGUE_BLOB_MAX|to_int else 9 end),
70+
"baseFeeUpdateFraction": (if env.HIVE_PRAGUE_BLOB_BASE_FEE_UPDATE_FRACTION then env.HIVE_PRAGUE_BLOB_BASE_FEE_UPDATE_FRACTION|to_int else 5007716 end)
71+
}
72+
},
73+
"depositContractAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa"
74+
}|remove_empty
75+
}

0 commit comments

Comments
 (0)