@@ -1193,17 +1193,17 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error {
1193
1193
}
1194
1194
1195
1195
// WriteBlockWithState writes the block and all associated state to the database.
1196
- func (bc * BlockChain ) WriteBlockWithState (block * types.Block , receipts []* types.Receipt , logs []* types.Log , evmTraces []* types.ExecutionResult , state * state.StateDB , emitHeadEvent bool ) (status WriteStatus , err error ) {
1196
+ func (bc * BlockChain ) WriteBlockWithState (block * types.Block , receipts []* types.Receipt , logs []* types.Log , evmTraces []* types.ExecutionResult , storageTrace * types. StorageTrace , state * state.StateDB , emitHeadEvent bool ) (status WriteStatus , err error ) {
1197
1197
if ! bc .chainmu .TryLock () {
1198
1198
return NonStatTy , errInsertionInterrupted
1199
1199
}
1200
1200
defer bc .chainmu .Unlock ()
1201
- return bc .writeBlockWithState (block , receipts , logs , evmTraces , state , emitHeadEvent )
1201
+ return bc .writeBlockWithState (block , receipts , logs , evmTraces , storageTrace , state , emitHeadEvent )
1202
1202
}
1203
1203
1204
1204
// writeBlockWithState writes the block and all associated state to the database,
1205
1205
// but is expects the chain mutex to be held.
1206
- func (bc * BlockChain ) writeBlockWithState (block * types.Block , receipts []* types.Receipt , logs []* types.Log , evmTraces []* types.ExecutionResult , state * state.StateDB , emitHeadEvent bool ) (status WriteStatus , err error ) {
1206
+ func (bc * BlockChain ) writeBlockWithState (block * types.Block , receipts []* types.Receipt , logs []* types.Log , evmTraces []* types.ExecutionResult , storageTrace * types. StorageTrace , state * state.StateDB , emitHeadEvent bool ) (status WriteStatus , err error ) {
1207
1207
if bc .insertStopped () {
1208
1208
return NonStatTy , errInsertionInterrupted
1209
1209
}
@@ -1327,7 +1327,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
1327
1327
// Fill blockResult content
1328
1328
var blockResult * types.BlockResult
1329
1329
if evmTraces != nil {
1330
- blockResult = bc .writeBlockResult (state , block , evmTraces )
1330
+ blockResult = bc .writeBlockResult (state , block , evmTraces , storageTrace )
1331
1331
bc .blockResultCache .Add (block .Hash (), blockResult )
1332
1332
}
1333
1333
@@ -1351,57 +1351,22 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
1351
1351
}
1352
1352
1353
1353
// Fill blockResult content
1354
- func (bc * BlockChain ) writeBlockResult (state * state.StateDB , block * types.Block , evmTraces []* types.ExecutionResult ) * types.BlockResult {
1354
+ func (bc * BlockChain ) writeBlockResult (state * state.StateDB , block * types.Block , evmTraces []* types.ExecutionResult , storageTrace * types. StorageTrace ) * types.BlockResult {
1355
1355
blockResult := & types.BlockResult {
1356
1356
ExecutionResults : evmTraces ,
1357
+ StorageTrace : storageTrace ,
1357
1358
}
1358
- coinbase := types.AccountProofWrapper {
1359
+ coinbase := types.AccountWrapper {
1359
1360
Address : block .Coinbase (),
1360
1361
Nonce : state .GetNonce (block .Coinbase ()),
1361
1362
Balance : (* hexutil .Big )(state .GetBalance (block .Coinbase ())),
1362
1363
CodeHash : state .GetCodeHash (block .Coinbase ()),
1363
1364
}
1364
- // Get coinbase address's account proof.
1365
- proof , err := state .GetProof (block .Coinbase ())
1366
- if err != nil {
1367
- log .Error ("Failed to get proof" , "blockNumber" , block .NumberU64 (), "address" , block .Coinbase ().String (), "err" , err )
1368
- } else {
1369
- coinbase .Proof = make ([]string , len (proof ))
1370
- for i := range proof {
1371
- coinbase .Proof [i ] = hexutil .Encode (proof [i ])
1372
- }
1373
- }
1374
1365
1375
1366
blockResult .BlockTrace = types .NewTraceBlock (bc .chainConfig , block , & coinbase )
1367
+ blockResult .StorageTrace .RootAfter = state .GetRootHash ()
1376
1368
for i , tx := range block .Transactions () {
1377
1369
evmTrace := blockResult .ExecutionResults [i ]
1378
-
1379
- from := evmTrace .From .Address
1380
- // Get proof
1381
- proof , err := state .GetProof (from )
1382
- if err != nil {
1383
- log .Error ("Failed to get proof" , "blockNumber" , block .NumberU64 (), "address" , from .String (), "err" , err )
1384
- } else {
1385
- evmTrace .From .Proof = make ([]string , len (proof ))
1386
- for i := range proof {
1387
- evmTrace .From .Proof [i ] = hexutil .Encode (proof [i ])
1388
- }
1389
- }
1390
-
1391
- if evmTrace .To != nil {
1392
- to := evmTrace .To .Address
1393
- // Get proof
1394
- proof , err = state .GetProof (to )
1395
- if err != nil {
1396
- log .Error ("Failed to get proof" , "blockNumber" , block .NumberU64 (), "address" , to .String (), "err" , err )
1397
- } else {
1398
- evmTrace .To .Proof = make ([]string , len (proof ))
1399
- for i := range proof {
1400
- evmTrace .To .Proof [i ] = hexutil .Encode (proof [i ])
1401
- }
1402
- }
1403
- }
1404
-
1405
1370
// Contract is called
1406
1371
if len (tx .Data ()) != 0 && tx .To () != nil {
1407
1372
evmTrace .ByteCode = hexutil .Encode (state .GetCode (* tx .To ()))
@@ -1727,8 +1692,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
1727
1692
1728
1693
// Write the block to the chain and get the status.
1729
1694
substart = time .Now ()
1730
- // EvmTraces is nil is safe because l2geth's p2p server is stoped and the code will not execute there.
1731
- status , err := bc .writeBlockWithState (block , receipts , logs , nil , statedb , false )
1695
+ // EvmTraces & StorageTrace being nil is safe because l2geth's p2p server is stoped and the code will not execute there.
1696
+ status , err := bc .writeBlockWithState (block , receipts , logs , nil , nil , statedb , false )
1732
1697
atomic .StoreUint32 (& followupInterrupt , 1 )
1733
1698
if err != nil {
1734
1699
return it .index , err
0 commit comments