Skip to content

Commit 695f262

Browse files
authored
Merge branch 'master' into faster-hashes
2 parents fa5825f + 008e488 commit 695f262

File tree

103 files changed

+2778
-1844
lines changed

Some content is hidden

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

103 files changed

+2778
-1844
lines changed

.github/workflows/nimbus_verified_proxy.yml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ on:
3434
- 'Makefile'
3535
- 'nimbus.nimble'
3636

37+
workflow_dispatch:
38+
3739
concurrency: # Cancel stale PR builds (but not push builds)
3840
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
3941
cancel-in-progress: true
@@ -67,28 +69,9 @@ jobs:
6769
rocksdb-cache: true
6870
eest-cache: false
6971

70-
- name: Run verified proxy tests (Windows)
71-
if: runner.os == 'Windows'
72+
- name: Run verified proxy tests
7273
run: |
7374
gcc --version
74-
DEFAULT_MAKE_FLAGS="-j${ncpu}"
75-
mingw32-make ${DEFAULT_MAKE_FLAGS} nimbus_verified_proxy libverifproxy
76-
build/nimbus_verified_proxy.exe --help
77-
mingw32-make ${DEFAULT_MAKE_FLAGS} nimbus-verified-proxy-test
78-
79-
- name: Run verified proxy tests (Linux)
80-
if: runner.os == 'Linux'
81-
run: |
82-
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib"
83-
DEFAULT_MAKE_FLAGS="-j${ncpu}"
84-
env CC=gcc make ${DEFAULT_MAKE_FLAGS} nimbus_verified_proxy libverifproxy
85-
build/nimbus_verified_proxy --help
86-
# CC is needed to select correct compiler 32/64 bit
87-
env CC=gcc CXX=g++ make ${DEFAULT_MAKE_FLAGS} nimbus-verified-proxy-test
88-
89-
- name: Run verified proxy tests (Macos)
90-
if: runner.os == 'Macos'
91-
run: |
9275
DEFAULT_MAKE_FLAGS="-j${ncpu}"
9376
make ${DEFAULT_MAKE_FLAGS} nimbus_verified_proxy libverifproxy
9477
build/nimbus_verified_proxy --help

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,7 @@
229229
[submodule "vendor/constantine"]
230230
path = vendor/constantine
231231
url = https://github.com/mratsim/constantine
232+
[submodule "vendor/nim-mcl"]
233+
path = vendor/nim-mcl
234+
url = https://github.com/status-im/nim-mcl
235+
branch = main

Makefile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,13 @@ portal-test-reproducibility:
290290
[ "$$MD5SUM1" = "$$MD5SUM2" ] && echo -e "\e[92mSuccess: identical binaries.\e[39m" || \
291291
{ echo -e "\e[91mFailure: the binary changed between builds.\e[39m"; exit 1; }
292292

293-
# Portal tests
294-
all_eth_history_custom_chain_tests: | build deps
295-
echo -e $(BUILD_MSG) "build/$@" && \
296-
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) -d:chronicles_log_level=ERROR -d:mergeBlockNumber:38130 -o:build/$@ "portal/tests/eth_history_tests/$@.nim"
297-
293+
# builds and runs the Portal test suite
298294
all_portal_tests: | build deps
299295
echo -e $(BUILD_MSG) "build/$@" && \
300296
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) -d:chronicles_log_level=ERROR -o:build/$@ "portal/tests/$@.nim"
301297

302-
# builds and runs the Portal test suite
303-
portal-test: | all_portal_tests all_eth_history_custom_chain_tests
298+
# alias for all_portal_tests
299+
portal-test: | all_portal_tests
304300

305301
# builds the Portal tools, wherever they are
306302
$(PORTAL_TOOLS): | build deps rocksdb

config.nims

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ elif defined(riscv64):
9494
# and seems to be the minimum extensions needed to build.
9595
switch("passC", "-march=rv64gc")
9696
switch("passL", "-march=rv64gc")
97+
elif defined(linux) and defined(arm64):
98+
# clang can't handle "-march=native"
99+
switch("passC", "-march=armv8-a")
100+
switch("passL", "-march=armv8-a")
97101
else:
98102
switch("passC", "-march=native")
99103
switch("passL", "-march=native")

execution_chain/compile_info.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
const chronicles_line_numbers {.strdefine.} = "0"
1515
when chronicles_line_numbers notin ["0", "off"]:
1616
{.hint: "*** Compiling with logger line numbers enabled".}
17+
18+
const enable_mcl_lib* {.booldefine.} = true
19+
when enable_mcl_lib:
20+
{.hint: "*** Compiling with mcl library".}

execution_chain/config.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ type
301301
defaultValue: 4'u64
302302
name: "debug-persist-batch-size" .}: uint64
303303

304+
dynamicBatchSize* {.
305+
hidden
306+
defaultValue: false
307+
name: "debug-dynamic-batch-size" .}: bool
308+
304309
rocksdbMaxOpenFiles {.
305310
hidden
306311
defaultValue: defaultMaxOpenFiles
@@ -358,6 +363,11 @@ type
358363
desc: "Eagerly check state roots when syncing finalized blocks"
359364
name: "debug-eager-state-root".}: bool
360365

366+
deserializeFcState* {.
367+
hidden
368+
defaultValue: true
369+
name: "debug-deserialize-fc-state" .}: bool
370+
361371
statelessProviderEnabled* {.
362372
separator: "\pSTATELESS PROVIDER OPTIONS:"
363373
hidden

execution_chain/constants.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
# at your option. This file may not be copied, modified, or distributed except
99
# according to those terms.
1010

11+
{.push raises: [], gcsafe.}
1112
{.used.}
1213

1314
import
1415
stint,
1516
eth/common/[addresses, hashes, base]
1617

17-
# proc default(t: typedesc): t = discard -- notused
18-
19-
# constants
2018
const
2119
UINT_256_MAX*: UInt256 = high(UInt256)
2220
INT_256_MAX_AS_UINT256* = high(UInt256) shr 1
@@ -43,7 +41,7 @@ const
4341

4442
GAS_LIMIT_MINIMUM* = 5000
4543
GAS_LIMIT_MAXIMUM* = int64.high.GasInt # Maximum the gas limit (2^63-1).
46-
DEFAULT_GAS_LIMIT* = 45_000_000
44+
DEFAULT_GAS_LIMIT* = 60_000_000
4745

4846
# https://eips.ethereum.org/EIPS/eip-7825
4947
TX_GAS_LIMIT* = 1 shl 24 # 2^24

execution_chain/core/block_import.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ proc importRlpBlocks*(importFile: string,
8383
proc importRlpBlocks*(conf: NimbusConf, com: CommonRef): Future[void] {.async: (raises: [CancelledError]).} =
8484
# Both baseDistance and persistBatchSize are 0,
8585
# we want changes persisted immediately
86-
let chain = ForkedChainRef.init(com, baseDistance = 0, persistBatchSize = 0)
86+
let chain = ForkedChainRef.init(com, baseDistance = 0, persistBatchSize = 1)
8787

8888
# success or not, we quit after importing blocks
8989
for i, blocksFile in conf.blocksFile:

execution_chain/core/chain/forked_chain.nim

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ proc updateBase(c: ForkedChainRef, base: BlockRef): uint =
314314
# No update, return
315315
return
316316

317+
let startTime = Moment.now()
318+
317319
# State root sanity check is performed to verify, before writing to disk,
318320
# that optimistically checked blocks indeed end up being stored with a
319321
# consistent state root.
@@ -338,8 +340,7 @@ with --debug-eager-state-root."""
338340

339341
# Cleanup in-memory blocks starting from base backward
340342
# e.g. B2 backward.
341-
var
342-
count = 0'u
343+
var count = 0'u
343344

344345
for it in ancestors(base.parent):
345346
c.removeBlockFromCache(it)
@@ -352,6 +353,33 @@ with --debug-eager-state-root."""
352353
# Base block always have finalized marker
353354
c.base.finalize()
354355

356+
if c.dynamicBatchSize:
357+
# Dynamicly adjust the persistBatchSize based on the recorded run time.
358+
# The goal here is use the maximum batch size possible without blocking the
359+
# event loop for too long which could negatively impact the p2p networking.
360+
# Increasing the batch size can improve performance because the stateroot
361+
# computation and persist calls are performed less frequently.
362+
const
363+
targetTime = 500.milliseconds
364+
targetTimeDelta = 200.milliseconds
365+
targetTimeLowerBound = (targetTime - targetTimeDelta).milliseconds
366+
targetTimeUpperBound = (targetTime + targetTimeDelta).milliseconds
367+
batchSizeLowerBound = 4
368+
batchSizeUpperBound = 512
369+
370+
let
371+
finishTime = Moment.now()
372+
runTime = (finishTime - startTime).milliseconds
373+
374+
if runTime < targetTimeLowerBound and c.persistBatchSize <= batchSizeUpperBound:
375+
c.persistBatchSize *= 2
376+
info "Increased persistBatchSize", runTime, targetTime,
377+
persistBatchSize = c.persistBatchSize
378+
elif runTime > targetTimeUpperBound and c.persistBatchSize >= batchSizeLowerBound:
379+
c.persistBatchSize = c.persistBatchSize div 2
380+
info "Decreased persistBatchSize", runTime, targetTime,
381+
persistBatchSize = c.persistBatchSize
382+
355383
count
356384

357385
proc processUpdateBase(c: ForkedChainRef): Future[Result[void, string]] {.async: (raises: [CancelledError]).} =
@@ -407,20 +435,20 @@ proc queueUpdateBase(c: ForkedChainRef, base: BlockRef)
407435
else:
408436
c.base
409437

410-
if prevQueuedBase.number == base.number:
438+
if prevQueuedBase.number >= base.number:
411439
return
412440

413441
var
414-
number = base.number - min(base.number, PersistBatchSize)
415-
steps = newSeqOfCap[BlockRef]((base.number-prevQueuedBase.number) div PersistBatchSize + 1)
442+
number = base.number - min(base.number, c.persistBatchSize)
443+
steps = newSeqOfCap[BlockRef]((base.number - prevQueuedBase.number) div c.persistBatchSize + 1)
416444
it = base
417445

418446
steps.add base
419447

420448
while it.number > prevQueuedBase.number:
421449
if it.number == number:
422450
steps.add it
423-
number -= min(number, PersistBatchSize)
451+
number -= min(number, c.persistBatchSize)
424452
it = it.parent
425453

426454
for i in countdown(steps.len-1, 0):
@@ -501,8 +529,15 @@ proc validateBlock(c: ForkedChainRef,
501529
# Entering base auto forward mode while avoiding forkChoice
502530
# handled region(head - baseDistance)
503531
# e.g. live syncing with the tip very far from from our latest head
532+
let
533+
offset = c.baseDistance + c.persistBatchSize
534+
number =
535+
if offset >= c.latestFinalizedBlockNumber:
536+
0.uint64
537+
else:
538+
c.latestFinalizedBlockNumber - offset
504539
if c.pendingFCU != zeroHash32 and
505-
c.base.number < c.latestFinalizedBlockNumber - c.baseDistance - c.persistBatchSize:
540+
c.base.number < number:
506541
let
507542
base = c.calculateNewBase(c.latestFinalizedBlockNumber, c.latest)
508543
prevBase = c.base.number
@@ -579,6 +614,7 @@ proc init*(
579614
com: CommonRef;
580615
baseDistance = BaseDistance;
581616
persistBatchSize = PersistBatchSize;
617+
dynamicBatchSize = false;
582618
eagerStateRoot = false;
583619
enableQueue = false;
584620
): T =
@@ -594,6 +630,8 @@ proc init*(
594630
## This constructor also works well when resuming import after running
595631
## `persistentBlocks()` used for `Era1` or `Era` import.
596632
##
633+
doAssert(persistBatchSize > 0)
634+
597635
let
598636
baseTxFrame = com.db.baseTxFrame()
599637
base = baseTxFrame.getSavedStateBlockNumber
@@ -610,19 +648,20 @@ proc init*(
610648
fcuSafe = baseTxFrame.fcuSafe().valueOr:
611649
FcuHashAndNumber(hash: baseHash, number: base)
612650
fc = T(
613-
com: com,
614-
base: baseBlock,
615-
latest: baseBlock,
616-
heads: @[baseBlock],
617-
hashToBlock: {baseHash: baseBlock}.toTable,
618-
baseTxFrame: baseTxFrame,
619-
baseDistance: baseDistance,
620-
persistBatchSize:persistBatchSize,
621-
quarantine: Quarantine.init(),
622-
fcuHead: fcuHead,
623-
fcuSafe: fcuSafe,
624-
baseQueue: initDeque[BlockRef](),
625-
lastBaseLogTime: EthTime.now(),
651+
com: com,
652+
base: baseBlock,
653+
latest: baseBlock,
654+
heads: @[baseBlock],
655+
hashToBlock: {baseHash: baseBlock}.toTable,
656+
baseTxFrame: baseTxFrame,
657+
baseDistance: baseDistance,
658+
persistBatchSize: persistBatchSize,
659+
dynamicBatchSize: dynamicBatchSize,
660+
quarantine: Quarantine.init(),
661+
fcuHead: fcuHead,
662+
fcuSafe: fcuSafe,
663+
baseQueue: initDeque[BlockRef](),
664+
lastBaseLogTime: EthTime.now(),
626665
)
627666

628667
# updateFinalized will stop ancestor lineage
@@ -712,10 +751,8 @@ proc forkChoice*(c: ForkedChainRef,
712751
c.updateHead(head)
713752
c.updateFinalized(finalized, head)
714753

715-
let
716-
base = c.calculateNewBase(finalized.number, head)
717-
718-
if base.number == c.base.number:
754+
let base = c.calculateNewBase(finalized.number, head)
755+
if base.number <= c.base.number:
719756
# The base is not updated, return.
720757
return ok()
721758

execution_chain/core/chain/forked_chain/chain_desc.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ type
8888
# to move the base. And the bulk writing can works
8989
# efficiently.
9090

91+
dynamicBatchSize*: bool
92+
# Enable adjusting the persistBatchSize dynamically based on the
93+
# time it takes to update base.
94+
9195
portal*: HistoryExpiryRef
9296
# History Expiry tracker and portal access entry point
9397

0 commit comments

Comments
 (0)