@@ -24,7 +24,6 @@ import (
2424 "time"
2525
2626 "github.com/c2h5oh/datasize"
27- "github.com/erigontech/erigon/execution/exec3"
2827 "golang.org/x/sync/errgroup"
2928
3029 "github.com/erigontech/erigon-lib/chain"
@@ -38,7 +37,6 @@ import (
3837 "github.com/erigontech/erigon-lib/log/v3"
3938 libstate "github.com/erigontech/erigon-lib/state"
4039 "github.com/erigontech/erigon-lib/wrap"
41-
4240 "github.com/erigontech/erigon/consensus"
4341 "github.com/erigontech/erigon/core/rawdb"
4442 "github.com/erigontech/erigon/core/rawdb/rawdbhelpers"
@@ -48,6 +46,7 @@ import (
4846 "github.com/erigontech/erigon/eth/ethconfig"
4947 "github.com/erigontech/erigon/eth/stagedsync/stages"
5048 "github.com/erigontech/erigon/ethdb/prune"
49+ "github.com/erigontech/erigon/execution/exec3"
5150 "github.com/erigontech/erigon/turbo/services"
5251 "github.com/erigontech/erigon/turbo/shards"
5352 "github.com/erigontech/erigon/turbo/silkworm"
@@ -261,7 +260,7 @@ func SpawnExecuteBlocksStage(s *StageState, u Unwinder, txc wrap.TxContainer, to
261260 return nil
262261}
263262
264- func blocksReadAhead (ctx context.Context , cfg * ExecuteBlockCfg , workers int , histV3 bool ) (chan uint64 , context.CancelFunc ) {
263+ func blocksReadAhead (ctx context.Context , cfg * ExecuteBlockCfg , workers int ) (chan uint64 , context.CancelFunc ) {
265264 const readAheadBlocks = 100
266265 readAhead := make (chan uint64 , readAheadBlocks )
267266 g , gCtx := errgroup .WithContext (ctx )
@@ -274,6 +273,9 @@ func blocksReadAhead(ctx context.Context, cfg *ExecuteBlockCfg, workers int, his
274273 if tx != nil {
275274 tx .Rollback ()
276275 }
276+ if rec := recover (); rec != nil {
277+ err = fmt .Errorf ("%s, %s" , rec , dbg .Stack ())
278+ }
277279 }()
278280
279281 for i := 0 ; ; i ++ {
@@ -296,7 +298,7 @@ func blocksReadAhead(ctx context.Context, cfg *ExecuteBlockCfg, workers int, his
296298 }
297299 }
298300
299- if err := blocksReadAheadFunc (gCtx , tx , cfg , bn + readAheadBlocks , histV3 ); err != nil {
301+ if err := blocksReadAheadFunc (gCtx , tx , cfg , bn + readAheadBlocks ); err != nil {
300302 return err
301303 }
302304 }
@@ -307,7 +309,7 @@ func blocksReadAhead(ctx context.Context, cfg *ExecuteBlockCfg, workers int, his
307309 _ = g .Wait ()
308310 }
309311}
310- func blocksReadAheadFunc (ctx context.Context , tx kv.Tx , cfg * ExecuteBlockCfg , blockNum uint64 , histV3 bool ) error {
312+ func blocksReadAheadFunc (ctx context.Context , tx kv.Tx , cfg * ExecuteBlockCfg , blockNum uint64 ) error {
311313 block , err := cfg .blockReader .BlockByNumber (ctx , tx , blockNum )
312314 if err != nil {
313315 return err
@@ -316,9 +318,55 @@ func blocksReadAheadFunc(ctx context.Context, tx kv.Tx, cfg *ExecuteBlockCfg, bl
316318 return nil
317319 }
318320 _ , _ = cfg .engine .Author (block .HeaderNoCopy ()) // Bor consensus: this calc is heavy and has cache
319- if histV3 {
321+
322+ ttx , ok := tx .(kv.TemporalTx )
323+ if ! ok {
320324 return nil
321325 }
326+
327+ stateReader := state .NewReaderV3 (ttx )
328+ senders := block .Body ().SendersFromTxs ()
329+
330+ for _ , sender := range senders {
331+ a , _ := stateReader .ReadAccountData (sender )
332+ if a == nil {
333+ continue
334+ }
335+
336+ //Code domain using .bt index - means no false-positives
337+ if code , _ := stateReader .ReadAccountCode (sender , 0 ); len (code ) > 0 {
338+ _ , _ = code [0 ], code [len (code )- 1 ]
339+ }
340+ }
341+
342+ for _ , txn := range block .Transactions () {
343+ to := txn .GetTo ()
344+ if to != nil {
345+ a , _ := stateReader .ReadAccountData (* to )
346+ if a == nil {
347+ continue
348+ }
349+ //if account != nil && !bytes.Equal(account.CodeHash, types.EmptyCodeHash.Bytes()) {
350+ // reader.Code(*tx.To(), common.BytesToHash(account.CodeHash))
351+ //}
352+ if code , _ := stateReader .ReadAccountCode (* to , 0 ); len (code ) > 0 {
353+ _ , _ = code [0 ], code [len (code )- 1 ]
354+ }
355+
356+ for _ , list := range txn .GetAccessList () {
357+ stateReader .ReadAccountData (list .Address )
358+ if len (list .StorageKeys ) > 0 {
359+ for _ , slot := range list .StorageKeys {
360+ stateReader .ReadAccountStorage (list .Address , 0 , & slot )
361+ }
362+ }
363+ }
364+ //TODO: exec txn and pre-fetch commitment keys. see also: `func (p *statePrefetcher) Prefetch` in geth
365+ }
366+
367+ }
368+ _ , _ = stateReader .ReadAccountData (block .Coinbase ())
369+
322370 return nil
323371}
324372
0 commit comments