Skip to content

Commit a046d00

Browse files
committed
Merge branch 'master' into faster-hashes
2 parents d66a000 + 2af7ab2 commit a046d00

Some content is hidden

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

59 files changed

+310
-769
lines changed

config.nims

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ switch("hintAsError", "DuplicateModuleImport:on")
165165
# `switch("warning[CaseTransition]", "off")` fails with "Error: invalid command line option: '--warning[CaseTransition]'"
166166
switch("warning", "CaseTransition:off")
167167

168-
# Transitional for Nim v2.2, due to newSeqUninit replacing newSeqUninitialized.
169-
switch("warning", "Deprecated:off")
170-
171168
# nim-kzg shipping their own blst, nimbus-eth1 too.
172169
# disable nim-kzg's blst
173170
switch("define", "kzgExternalBlst")

execution_chain/beacon/api_handler/api_newpayload.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ proc newPayload*(ben: BeaconEngineRef,
233233
trace "Importing block without sethead",
234234
hash = blockHash, number = header.number
235235

236-
let vres = await chain.queueImportBlock(blk, finalized = false)
236+
let vres = await chain.queueImportBlock(blk)
237237
if vres.isErr:
238238
warn "Error importing block",
239239
number = header.number,

execution_chain/config.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import
3232
],
3333
toml_serialization,
3434
eth/[common, net/nat, net/nat_toml],
35-
./networking/[bootnodes, eth1_enr as enr],
35+
./networking/bootnodes,
3636
./[constants, compile_info, version_info],
3737
./common/chain_config,
3838
./db/opts

execution_chain/core/block_import.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This file may not be copied, modified, or distributed except according to
88
# those terms.
99

10-
{.push raises: [].}
10+
{.push raises: [], gcsafe.}
1111

1212
import
1313
chronicles,
@@ -54,14 +54,14 @@ proc importRlpBlocks*(blocksRlp:seq[byte],
5454

5555
if not printBanner:
5656
info "Start importing block",
57-
hash=blk.header.blockHash.short,
57+
hash=blk.header.computeBlockHash.short,
5858
number=blk.header.number
5959
printBanner = true
6060

61-
let res = await chain.importBlock(blk, finalized = false)
61+
let res = await chain.importBlock(blk)
6262
if res.isErr:
6363
error "Error occured when importing block",
64-
hash=blk.header.blockHash.short,
64+
hash=blk.header.computeBlockHash.short,
6565
number=blk.header.number,
6666
msg=res.error
6767
if finalize:

execution_chain/core/chain/forked_chain.nim

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ Either the consensus client gave invalid information about finalized blocks or
329329
something else needs attention! Shutting down to preserve the database - restart
330330
with --debug-eager-state-root."""
331331

332+
base.txFrame.checkpoint(base.number, skipSnapshot = true)
332333
c.com.db.persist(base.txFrame)
333334

334335
# Update baseTxFrame when we about to yield to the event loop
@@ -484,7 +485,7 @@ proc validateBlock(c: ForkedChainRef,
484485
# Update the snapshot before processing the block so that any vertexes in snapshots
485486
# from lower levels than the baseTxFrame are removed from the snapshot before running
486487
# the stateroot computation.
487-
c.updateSnapshot(blk, txFrame)
488+
c.updateSnapshot(parent.blk, parentFrame)
488489

489490
var receipts = c.processBlock(parent, txFrame, blk, blkHash, finalized).valueOr:
490491
txFrame.dispose()
@@ -634,7 +635,7 @@ proc init*(
634635

635636
fc
636637

637-
proc importBlock*(c: ForkedChainRef, blk: Block, finalized = false):
638+
proc importBlock*(c: ForkedChainRef, blk: Block):
638639
Future[Result[void, string]] {.async: (raises: [CancelledError]).} =
639640
## Try to import block to canonical or side chain.
640641
## return error if the block is invalid
@@ -655,9 +656,13 @@ proc importBlock*(c: ForkedChainRef, blk: Block, finalized = false):
655656
# to a "staging area" or disk-backed memory but it must not afect `base`.
656657
# `base` is the point of no return, we only update it on finality.
657658

658-
let parent = ?(await c.validateBlock(parent, blk, finalized))
659+
# Setting the finalized flag to true here has the effect of skipping the
660+
# stateroot check for performance reasons.
661+
let
662+
isFinalized = blk.header.number <= c.latestFinalizedBlockNumber
663+
parent = ?(await c.validateBlock(parent, blk, isFinalized))
659664
if c.quarantine.hasOrphans():
660-
c.queueOrphan(parent, finalized)
665+
c.queueOrphan(parent, isFinalized)
661666

662667
else:
663668
# If its parent is an invalid block
@@ -730,9 +735,9 @@ proc stopProcessingQueue*(c: ForkedChainRef) {.async: (raises: []).} =
730735
# at the same time FC.serialize modify the state, crash can happen.
731736
await noCancel c.processingQueueLoop.cancelAndWait()
732737

733-
template queueImportBlock*(c: ForkedChainRef, blk: Block, finalized = false): auto =
738+
template queueImportBlock*(c: ForkedChainRef, blk: Block): auto =
734739
proc asyncHandler(): Future[Result[void, string]] {.async: (raises: [CancelledError], raw: true).} =
735-
c.importBlock(blk, finalized)
740+
c.importBlock(blk)
736741

737742
let item = QueueItem(
738743
responseFut: Future[Result[void, string]].Raising([CancelledError]).init(),

execution_chain/core/chain/forked_chain/chain_serialize.nim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,17 @@ proc replayBlock(fc: ForkedChainRef;
124124
blk: BlockRef): Result[void, string] =
125125
let
126126
parentFrame = parent.txFrame
127-
txFrame = parentFrame.txFrameBegin
127+
txFrame = parentFrame.txFrameBegin()
128128

129129
# Update the snapshot before processing the block so that any vertexes in snapshots
130130
# from lower levels than the baseTxFrame are removed from the snapshot before running
131131
# the stateroot computation.
132-
fc.updateSnapshot(blk.blk, txFrame)
132+
fc.updateSnapshot(parent.blk, parentFrame)
133133

134-
var receipts = fc.processBlock(parent, txFrame, blk.blk, blk.hash, false).valueOr:
134+
# Set finalized to true in order to skip the stateroot check when replaying the
135+
# block because the blocks should have already been checked previously during
136+
# the initial block execution.
137+
var receipts = fc.processBlock(parent, txFrame, blk.blk, blk.hash, finalized = true).valueOr:
135138
txFrame.dispose()
136139
return err(error)
137140

@@ -315,6 +318,9 @@ proc deserialize*(fc: ForkedChainRef): Result[void, string] =
315318
?txFrame.fcuSafe(fc.fcuSafe.hash, fc.fcuSafe.number)
316319

317320
fc.hashToBlock.withValue(fc.pendingFCU, val) do:
321+
# Restore finalized marker
322+
for it in loopNotFinalized(val[]):
323+
it.finalize()
318324
let txFrame = val[].txFrame
319325
?txFrame.fcuFinalized(fc.pendingFCU, fc.latestFinalizedBlockNumber)
320326

execution_chain/core/chain/persist_blocks.nim

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

11-
{.push raises: [].}
11+
{.push raises: [], gcsafe.}
1212

1313
import
1414
stew/assign2,
@@ -79,11 +79,11 @@ proc getVmState(
7979

8080
ok(p.vmState)
8181

82-
proc dispose*(p: var Persister) =
82+
func dispose*(p: var Persister) =
8383
p.vmState.ledger.txFrame.dispose()
8484
p.vmState = nil
8585

86-
proc init*(T: type Persister, com: CommonRef, flags: PersistBlockFlags): T =
86+
func init*(T: type Persister, com: CommonRef, flags: PersistBlockFlags): T =
8787
T(com: com, flags: flags)
8888

8989
proc checkpoint*(p: var Persister): Result[void, string] =
@@ -95,7 +95,7 @@ proc checkpoint*(p: var Persister): Result[void, string] =
9595
# TODO replace logging with better error
9696
debug "wrong state root in block",
9797
blockNumber = p.parent.number,
98-
blockHash = p.parent.blockHash,
98+
blockHash = p.parent.computeBlockHash,
9999
parentHash = p.parent.parentHash,
100100
expected = p.parent.stateRoot,
101101
actual = stateRoot

execution_chain/core/eip4844.nim

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

11+
{.push raises: [], gcsafe.}
12+
1113
import
1214
stew/arrayops,
1315
nimcrypto/sha2,
1416
results,
1517
stint,
18+
kzg4844/kzg,
1619
./eip7691,
1720
./pooled_txs,
18-
./lazy_kzg as kzg,
1921
../constants,
2022
../common/common
2123

2224
from std/sequtils import mapIt
2325

24-
{.push raises: [].}
26+
export
27+
kzg
2528

2629
type
2730
Bytes64 = array[64, byte]
@@ -201,7 +204,7 @@ proc validateBlobTransactionWrapper4844*(tx: PooledTransaction):
201204

202205
# Verify that commitments match the blobs by checking the KZG proof
203206
let res = kzg.verifyBlobKzgProofBatch(
204-
tx.blobsBundle.blobs.mapIt(kzg.KzgBlob(bytes: it.bytes)),
207+
tx.blobsBundle.blobs.mapIt(kzg.KzgBlob(bytes: it.data)),
205208
commitments,
206209
tx.blobsBundle.proofs.mapIt(kzg.KzgProof(bytes: it.data)))
207210

execution_chain/core/eip7594.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import
1313
../constants,
1414
./eip4844,
15-
./pooled_txs,
16-
/lazy_kzg as kzg
15+
./pooled_txs
1716

1817
from std/sequtils import mapIt
1918

execution_chain/core/executor/process_block.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ proc procBlkEpilogue(
220220
# TODO replace logging with better error
221221
debug "wrong state root in block",
222222
blockNumber = header.number,
223-
blockHash = header.blockHash,
223+
blockHash = header.computeBlockHash,
224224
parentHash = header.parentHash,
225225
expected = header.stateRoot,
226226
actual = stateRoot,
@@ -242,7 +242,7 @@ proc procBlkEpilogue(
242242
debug "wrong receiptRoot in block",
243243
blockNumber = header.number,
244244
parentHash = header.parentHash.short,
245-
blockHash = header.blockHash.short,
245+
blockHash = header.computeBlockHash.short,
246246
actual = receiptsRoot,
247247
expected = header.receiptsRoot
248248
return err("receiptRoot mismatch")
@@ -263,7 +263,7 @@ proc procBlkEpilogue(
263263
debug "wrong requestsHash in block",
264264
blockNumber = header.number,
265265
parentHash = header.parentHash.short,
266-
blockHash = header.blockHash.short,
266+
blockHash = header.computeBlockHash.short,
267267
actual = requestsHash,
268268
expected = header.requestsHash.get
269269
return err("requestsHash mismatch")

0 commit comments

Comments
 (0)