Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,28 +785,21 @@ func reportReaderStats(prefetch, process, parallel state.ReaderWithStats) {
accountHitFromPrefetchUniqueMeter.Mark(procPF.AccountHitFromPrefetchUnique + parPF.AccountHitFromPrefetchUnique)
}

// sharedBlockCaches holds VM-level caches that are shared between the
// prefetcher goroutine and the V2 BlockSTM workers for a single block.
type sharedBlockCaches struct {
jumpDests vm.JumpDestCache
keccak *sync.Map
ecrecover *sync.Map
}

func newSharedBlockCaches() *sharedBlockCaches {
return &sharedBlockCaches{
jumpDests: vm.NewSyncJumpDestCache(),
keccak: &sync.Map{},
ecrecover: &sync.Map{},
}
// sharedBlockCaches wraps the exported vm.SharedResultCaches owner so
// existing call sites (startPrefetchGoroutine, ProcessBlock) keep working
// unchanged. The legacy caches it wires are always on; the widened keccak
// store and EnablePrecompileCache flag are gated by bc.cfg.VmConfig.
type sharedBlockCaches struct{ *vm.SharedResultCaches }

// newSharedBlockCaches constructs the owner, reading the extended-cache flag
// from the chain's VM config so the flag can be toggled without touching
// call sites.
func (bc *BlockChain) newSharedBlockCaches() *sharedBlockCaches {
return &sharedBlockCaches{vm.NewSharedResultCaches(bc.cfg.VmConfig.EnablePrecompileCache)}
}

// applyTo populates a vm.Config with the shared caches.
func (c *sharedBlockCaches) applyTo(cfg *vm.Config) {
cfg.SharedJumpDestCache = c.jumpDests
cfg.Keccak256Cache = c.keccak
cfg.EcrecoverCache = c.ecrecover
}
func (c *sharedBlockCaches) applyTo(cfg *vm.Config) { c.SharedResultCaches.ApplyTo(cfg) }

// startPrefetchGoroutine launches the throwaway-statedb prefetcher in
// the background. It runs the block with tracing disabled to warm caches
Expand Down Expand Up @@ -845,7 +838,7 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header, wit
defer reportReaderStats(prefetch, process, parallel)

// Shared caches for this block — used by both prefetcher and V2 workers.
sharedCaches := newSharedBlockCaches()
sharedCaches := bc.newSharedBlockCaches()
bc.startPrefetchGoroutine(block, throwaway, sharedCaches, followupInterrupt)

type Result struct {
Expand Down Expand Up @@ -907,7 +900,11 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header, wit
go func() {
pstart := time.Now()
statedb.StartPrefetcher("chain", witness, nil)
res, err := bc.processor.Process(block, statedb, bc.cfg.VmConfig, nil, ctx)
serialVmCfg := bc.cfg.VmConfig
if serialVmCfg.EnablePrecompileCache {
sharedCaches.applyTo(&serialVmCfg)
}
res, err := bc.processor.Process(block, statedb, serialVmCfg, nil, ctx)
blockExecutionSerialTimer.UpdateSince(pstart)
var localVtime time.Duration
if err == nil {
Expand Down
Loading
Loading