16
16
../../../ common,
17
17
../../../ db/ core_db,
18
18
../../../ evm/ types,
19
- ../../../ evm/ state
19
+ ../../../ evm/ state,
20
+ ../../../ stateless/ witness_generation,
21
+ ./ chain_branch
20
22
21
23
proc writeBaggage* (c: ForkedChainRef,
22
24
blk: Block, blkHash: Hash32,
@@ -54,7 +56,7 @@ template updateSnapshot*(c: ForkedChainRef,
54
56
c.lastSnapshots[pos] = txFrame
55
57
56
58
proc processBlock* (c: ForkedChainRef,
57
- parent: Header ,
59
+ parentBlk: BlockRef ,
58
60
txFrame: CoreDbTxRef,
59
61
blk: Block,
60
62
blkHash: Hash32,
@@ -63,21 +65,39 @@ proc processBlock*(c: ForkedChainRef,
63
65
blk.header
64
66
65
67
let vmState = BaseVMState()
66
- vmState.init(parent , header, c.com, txFrame)
68
+ vmState.init(parentBlk.header , header, c.com, txFrame)
67
69
68
70
? c.com.validateHeaderAndKinship(blk, vmState.parent, txFrame)
69
71
70
- # When processing a finalized block, we optimistically assume that the state
71
- # root will check out and delay such validation for when it's time to persist
72
- # changes to disk
73
- ? vmState.processBlock(
74
- blk,
75
- skipValidation = false ,
76
- skipReceipts = false ,
77
- skipUncles = true ,
78
- skipStateRootCheck = finalized and not c.eagerStateRoot,
79
- taskpool = c.com.taskpool,
80
- )
72
+ template processBlock(): auto =
73
+ # When processing a finalized block, we optimistically assume that the state
74
+ # root will check out and delay such validation for when it's time to persist
75
+ # changes to disk
76
+ ? vmState.processBlock(
77
+ blk,
78
+ skipValidation = false ,
79
+ skipReceipts = false ,
80
+ skipUncles = true ,
81
+ skipStateRootCheck = finalized and not c.eagerStateRoot,
82
+ taskpool = c.com.taskpool,
83
+ )
84
+
85
+ if not vmState.com.statelessProviderEnabled:
86
+ processBlock()
87
+ else :
88
+ # Clear the caches before executing the block to ensure we collect the correct
89
+ # witness keys and block hashes when processing the block as these will be used
90
+ # when building the witness.
91
+ vmState.ledger.clearWitnessKeys()
92
+ vmState.ledger.clearBlockHashesCache()
93
+
94
+ processBlock()
95
+
96
+ let
97
+ preStateLedger = LedgerRef.init(parentBlk.txFrame)
98
+ witness = Witness.build(preStateLedger, vmState.ledger, parentBlk.header, header)
99
+
100
+ ? vmState.ledger.txFrame.persistWitness(blkHash, witness)
81
101
82
102
# We still need to write header to database
83
103
# because validateUncles still need it
0 commit comments