Skip to content

Commit 79425e5

Browse files
committed
merge master branch
2 parents f56c8ce + bdaeedb commit 79425e5

File tree

186 files changed

+4048
-2046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+4048
-2046
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
6666

6767
# Fluffy debugging tools + testing tools
6868
FLUFFY_TOOLS := \
69-
beacon_chain_bridge \
69+
beacon_lc_bridge \
7070
eth_data_exporter \
7171
content_verifier \
7272
blockwalk \
7373
portalcli
7474
FLUFFY_TOOLS_DIRS := \
75-
fluffy/tools/bridge \
75+
fluffy/tools/beacon_lc_bridge \
7676
fluffy/tools
7777
# comma-separated values for the "clean" target
7878
FLUFFY_TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(FLUFFY_TOOLS))

fluffy/conf.nim

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import
1111
std/os,
1212
uri, confutils, confutils/std/net, chronicles,
13-
eth/keys, eth/net/nat, eth/p2p/discoveryv5/[enr, node, routing_table],
13+
eth/keys, eth/p2p/discoveryv5/[enr, node, routing_table],
1414
json_rpc/rpcproxy,
1515
nimcrypto/hash,
1616
stew/byteutils,
17+
eth/net/nat, # must be late (compilation annoyance)
1718
./logging,
1819
./network/wire/portal_protocol_config
1920

@@ -239,51 +240,51 @@ func completeCmdArg*(T: type TrustedDigest, input: string): seq[string] =
239240
return @[]
240241

241242
proc parseCmdArg*(T: type enr.Record, p: string): T
242-
{.raises: [ConfigurationError].} =
243+
{.raises: [ValueError].} =
243244
if not fromURI(result, p):
244-
raise newException(ConfigurationError, "Invalid ENR")
245+
raise newException(ValueError, "Invalid ENR")
245246

246247
proc completeCmdArg*(T: type enr.Record, val: string): seq[string] =
247248
return @[]
248249

249250
proc parseCmdArg*(T: type Node, p: string): T
250-
{.raises: [ConfigurationError].} =
251+
{.raises: [ValueError].} =
251252
var record: enr.Record
252253
if not fromURI(record, p):
253-
raise newException(ConfigurationError, "Invalid ENR")
254+
raise newException(ValueError, "Invalid ENR")
254255

255256
let n = newNode(record)
256257
if n.isErr:
257-
raise newException(ConfigurationError, $n.error)
258+
raise newException(ValueError, $n.error)
258259

259260
if n[].address.isNone():
260-
raise newException(ConfigurationError, "ENR without address")
261+
raise newException(ValueError, "ENR without address")
261262

262263
n[]
263264

264265
proc completeCmdArg*(T: type Node, val: string): seq[string] =
265266
return @[]
266267

267268
proc parseCmdArg*(T: type PrivateKey, p: string): T
268-
{.raises: [ConfigurationError].} =
269+
{.raises: [ValueError].} =
269270
try:
270271
result = PrivateKey.fromHex(p).tryGet()
271272
except CatchableError:
272-
raise newException(ConfigurationError, "Invalid private key")
273+
raise newException(ValueError, "Invalid private key")
273274

274275
proc completeCmdArg*(T: type PrivateKey, val: string): seq[string] =
275276
return @[]
276277

277278
proc parseCmdArg*(T: type ClientConfig, p: string): T
278-
{.raises: [ConfigurationError].} =
279+
{.raises: [ValueError].} =
279280
let uri = parseUri(p)
280281
if (uri.scheme == "http" or uri.scheme == "https"):
281282
getHttpClientConfig(p)
282283
elif (uri.scheme == "ws" or uri.scheme == "wss"):
283284
getWebSocketClientConfig(p)
284285
else:
285286
raise newException(
286-
ConfigurationError, "Proxy uri should have defined scheme (http/https/ws/wss)"
287+
ValueError, "Proxy uri should have defined scheme (http/https/ws/wss)"
287288
)
288289

289290
proc completeCmdArg*(T: type ClientConfig, val: string): seq[string] =

fluffy/docs/content_seeding.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ Run a Fluffy node with the JSON-RPC API enabled.
8989
./build/fluffy --rpc --table-ip-limit:1024 --bucket-ip-limit:24
9090
```
9191

92-
Build & run the `beacon_chain_bridge`:
92+
Build & run the `beacon_lc_bridge`:
9393
```bash
94-
make fluffy-tools
94+
make beacon_lc_bridge
9595

9696
TRUSTED_BLOCK_ROOT=0x1234567890123456789012345678901234567890123456789012345678901234 # Replace this
97-
./build/beacon_chain_bridge --trusted-block-root=${TRUSTED_BLOCK_ROOT}
97+
./build/beacon_lc_bridge --trusted-block-root=${TRUSTED_BLOCK_ROOT}
9898
```
9999

100-
The `beacon_chain_bridge` will start with the consensus light client sync follow
100+
The `beacon_lc_bridge` will start with the consensus light client sync follow
101101
beacon block gossip. Once it is synced, the execution payload of new beacon
102102
blocks will be extracted and injected in the Portal network as execution headers
103103
and blocks.

fluffy/network/history/history_network.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
import
1111
stew/results, chronos, chronicles,
12-
eth/[common/eth_types_rlp, rlp, trie, trie/db],
12+
eth/[common/eth_types_rlp, rlp],
1313
eth/p2p/discoveryv5/[protocol, enr],
1414
../../common/common_types,
1515
../../content_db,
1616
../../network_metadata,
17-
../../../nimbus/constants,
17+
../../../nimbus/[constants, db/core_db],
1818
../wire/[portal_protocol, portal_stream, portal_protocol_config],
1919
"."/[history_content, accumulator]
2020

@@ -184,7 +184,7 @@ func encode*(receipts: seq[Receipt]): seq[byte] =
184184
# for if/when peer scoring/banning is added.
185185

186186
proc calcRootHash(items: Transactions | PortalReceipts | Withdrawals): Hash256 =
187-
var tr = initHexaryTrie(newMemoryDB())
187+
var tr = newCoreDbRef(LegacyDbMemory).mptPrune
188188
for i, item in items:
189189
try:
190190
tr.put(rlp.encode(i), item.asSeq())
@@ -209,7 +209,7 @@ func validateBlockHeaderBytes*(
209209

210210
let header = ? decodeRlp(bytes, BlockHeader)
211211

212-
if header.excessDataGas.isSome:
212+
if header.excessBlobGas.isSome:
213213
return err("EIP-4844 not yet implemented")
214214

215215
# TODO: Verify timestamp with Shanghai timestamp to if isSome()

fluffy/network/wire/portal_protocol_config.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ proc init*(
5454
)
5555

5656
proc parseCmdArg*(T: type RadiusConfig, p: string): T
57-
{.raises: [ConfigurationError].} =
57+
{.raises: [ValueError].} =
5858
if p.startsWith("dynamic") and len(p) == 7:
5959
RadiusConfig(kind: Dynamic)
6060
elif p.startsWith("static:"):
@@ -64,11 +64,11 @@ proc parseCmdArg*(T: type RadiusConfig, p: string): T
6464
uint16.parseCmdArg(num)
6565
except ValueError:
6666
let msg = "Provided logRadius: " & num & " is not a valid number"
67-
raise newException(ConfigurationError, msg)
67+
raise newException(ValueError, msg)
6868

6969
if parsed > 256:
7070
raise newException(
71-
ConfigurationError, "Provided logRadius should be <= 256"
71+
ValueError, "Provided logRadius should be <= 256"
7272
)
7373

7474
RadiusConfig(kind: Static, logRadius: parsed)
@@ -80,11 +80,11 @@ proc parseCmdArg*(T: type RadiusConfig, p: string): T
8080
let msg =
8181
"Not supported radius config option: " & p & " . " &
8282
"Supported options: dynamic and static:logRadius"
83-
raise newException(ConfigurationError, msg)
83+
raise newException(ValueError, msg)
8484

8585
if parsed > 256:
8686
raise newException(
87-
ConfigurationError, "Provided logRadius should be <= 256")
87+
ValueError, "Provided logRadius should be <= 256")
8888

8989
RadiusConfig(kind: Static, logRadius: parsed)
9090

fluffy/scripts/launch_local_testnet.sh

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if [ ${PIPESTATUS[0]} != 4 ]; then
3434
fi
3535

3636
OPTS="h:n:d"
37-
LONGOPTS="help,nodes:,data-dir:,enable-htop,log-level:,base-port:,base-rpc-port:,base-metrics-port:,reuse-existing-data-dir,timeout:,kill-old-processes"
37+
LONGOPTS="help,nodes:,data-dir:,enable-htop,log-level:,base-port:,base-rpc-port:,lc-bridge,trusted-block-root:,base-metrics-port:,reuse-existing-data-dir,timeout:,kill-old-processes"
3838

3939
# default values
4040
NUM_NODES="64"
@@ -48,6 +48,8 @@ REUSE_EXISTING_DATA_DIR="0"
4848
TIMEOUT_DURATION="0"
4949
KILL_OLD_PROCESSES="0"
5050
SCRIPTS_DIR="fluffy/scripts/"
51+
LC_BRIDGE="0"
52+
TRUSTED_BLOCK_ROOT=""
5153

5254
print_help() {
5355
cat <<EOF
@@ -61,6 +63,8 @@ E.g.: $(basename "$0") --nodes ${NUM_NODES} --data-dir "${DATA_DIR}" # defaults
6163
--base-port bootstrap node's discv5 port (default: ${BASE_PORT})
6264
--base-rpc-port bootstrap node's RPC port (default: ${BASE_RPC_PORT})
6365
--base-metrics-port bootstrap node's metrics server port (default: ${BASE_METRICS_PORT})
66+
--lc-bridge run an beacon lc bridge attached to the bootstrap node
67+
--trusted-block-root recent trusted finalized block root to initialize the consensus light client from
6468
--enable-htop use "htop" to see the fluffy processes without doing any tests
6569
--log-level set the log level (default: ${LOG_LEVEL})
6670
--reuse-existing-data-dir instead of deleting and recreating the data dir, keep it and reuse everything we can from it
@@ -107,6 +111,14 @@ while true; do
107111
BASE_RPC_PORT="$2"
108112
shift 2
109113
;;
114+
--lc-bridge)
115+
LC_BRIDGE="1"
116+
shift
117+
;;
118+
--trusted-block-root)
119+
TRUSTED_BLOCK_ROOT="$2"
120+
shift 2
121+
;;
110122
--base-metrics-port)
111123
BASE_METRICS_PORT="$2"
112124
shift 2
@@ -183,6 +195,9 @@ fi
183195

184196
# Build the binaries
185197
BINARIES="fluffy"
198+
if [[ "${LC_BRIDGE}" == "1" ]]; then
199+
BINARIES="${BINARIES} beacon_lc_bridge"
200+
fi
186201
TEST_BINARIES="test_portal_testnet"
187202
$MAKE -j ${NPROC} LOG_LEVEL=TRACE ${BINARIES}
188203
$MAKE -j ${NPROC} LOG_LEVEL=INFO ${TEST_BINARIES}
@@ -191,9 +206,13 @@ $MAKE -j ${NPROC} LOG_LEVEL=INFO ${TEST_BINARIES}
191206
# instance as the parent and the target process name as a pattern to the
192207
# "pkill" command.
193208
cleanup() {
194-
pkill -f -P $$ fluffy &>/dev/null || true
209+
for BINARY in ${BINARIES}; do
210+
pkill -f -P $$ ${BINARY} &>/dev/null || true
211+
done
195212
sleep 2
196-
pkill -f -9 -P $$ fluffy &>/dev/null || true
213+
for BINARY in ${BINARIES}; do
214+
pkill -f -9 -P $$ ${BINARY} &>/dev/null || true
215+
done
197216

198217
# Delete the binaries we just built, because these are with none default logs.
199218
# TODO: When fluffy gets run time log options a la nimbus-eth2 we can keep
@@ -219,7 +238,7 @@ if [[ "${TIMEOUT_DURATION}" != "0" ]]; then
219238
fi
220239

221240
PIDS=""
222-
NUM_JOBS=${NUM_NODES}
241+
NUM_JOBS=$(( NUM_NODES + LC_BRIDGE ))
223242

224243
dump_logs() {
225244
LOG_LINES=20
@@ -234,6 +253,11 @@ BOOTSTRAP_NODE=0
234253
BOOTSTRAP_TIMEOUT=5 # in seconds
235254
BOOTSTRAP_ENR_FILE="${DATA_DIR}/node${BOOTSTRAP_NODE}/fluffy_node.enr"
236255

256+
TRUSTED_BLOCK_ROOT_ARG=""
257+
if [[ -z ${TRUSTED_BLOCK_ROOT} ]]; then
258+
TRUSTED_BLOCK_ROOT_ARG="--trusted-block-root=${TRUSTED_BLOCK_ROOT}"
259+
fi
260+
237261
for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
238262
NODE_DATA_DIR="${DATA_DIR}/node${NUM_NODE}"
239263
rm -rf "${NODE_DATA_DIR}"
@@ -275,6 +299,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
275299
--log-level="${LOG_LEVEL}" \
276300
--udp-port=$(( BASE_PORT + NUM_NODE )) \
277301
--data-dir="${NODE_DATA_DIR}" \
302+
--network="none" \
278303
${BOOTSTRAP_ARG} \
279304
--rpc \
280305
--rpc-address="127.0.0.1" \
@@ -285,6 +310,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
285310
--table-ip-limit=1024 \
286311
--bucket-ip-limit=24 \
287312
--bits-per-hop=1 \
313+
${TRUSTED_BLOCK_ROOT_ARG} \
288314
${RADIUS_ARG} \
289315
${EXTRA_ARGS} \
290316
> "${DATA_DIR}/log${NUM_NODE}.txt" 2>&1 &
@@ -296,6 +322,21 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do
296322
fi
297323
done
298324

325+
if [[ "$LC_BRIDGE" == "1" ]]; then
326+
echo "Starting bridge node."
327+
LC_BRIDGE_DATA_DIR="${DATA_DIR}/lc_bridge"
328+
./build/beacon_lc_bridge \
329+
--data-dir="${LC_BRIDGE_DATA_DIR}" \
330+
--udp-port=$(( BASE_PORT + NUM_NODES )) \
331+
--rpc-address="127.0.0.1" \
332+
--rpc-port="${BASE_RPC_PORT}" \
333+
--beacon-light-client \
334+
${TRUSTED_BLOCK_ROOT_ARG} \
335+
> "${DATA_DIR}/log_lc_bridge.txt" 2>&1 &
336+
337+
PIDS="${PIDS},$!"
338+
fi
339+
299340
# give the regular nodes time to crash
300341
sleep 5
301342
BG_JOBS="$(jobs | wc -l | tr -d ' ')"

fluffy/tests/test_state_network.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
import
99
std/os,
1010
testutils/unittests, chronos,
11-
eth/[common/eth_hash, keys, trie/db, trie/hexary],
11+
eth/[common/eth_hash, keys],
1212
eth/p2p/discoveryv5/protocol as discv5_protocol, eth/p2p/discoveryv5/routing_table,
13-
../../nimbus/[config, db/db_chain, db/state_db],
13+
../../nimbus/[config, db/core_db, db/state_db],
1414
../../nimbus/common/[chain_config, genesis],
1515
../network/wire/[portal_protocol, portal_stream],
1616
../network/state/[state_content, state_network],
1717
../content_db,
1818
./test_helpers
1919

20-
proc genesisToTrie(filePath: string): HexaryTrie =
20+
proc genesisToTrie(filePath: string): CoreDbMptRef =
2121
# TODO: Doing our best here with API that exists, to be improved.
2222
var cn: NetworkParams
2323
if not loadNetworkParams(filePath, cn):
2424
quit(1)
2525

26-
let sdb = newStateDB(newMemoryDB(), false)
26+
let sdb = newStateDB(newCoreDbRef LegacyDbMemory, false)
2727
let map = toForkTransitionTable(cn.config)
2828
let fork = map.toHardFork(forkDeterminationInfo(0.toBlockNumber, cn.genesis.timestamp))
2929
discard toGenesisHeader(cn.genesis, sdb, fork)

0 commit comments

Comments
 (0)