diff --git a/core/blockchain.go b/core/blockchain.go index 81700f0e88..897a05e442 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -324,7 +324,7 @@ type BlockChain struct { flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state triedb *triedb.Database // The database handler for maintaining trie nodes. codedb *state.CodeDB // The database handler for maintaining contract codes. - jumpDest *JumpDestCache // Shared JUMPDEST analysis cache for block processing + jumpDest vm.JumpDestCache // Shared JUMPDEST analysis cache for block processing txIndexer *txIndexer // Transaction indexer, might be nil if not enabled hc *HeaderChain diff --git a/core/jumpdest.go b/core/jumpdest.go index e7f500dbe9..d2c861b70f 100644 --- a/core/jumpdest.go +++ b/core/jumpdest.go @@ -38,19 +38,19 @@ const ( jumpDestBucketSize = 8 * 1024 * 1024 ) -// JumpDestCache is a thread-safe, byte-bounded LRU of JUMPDEST analysis +// shardedJumpDestCache is a thread-safe, byte-bounded LRU of JUMPDEST analysis // bitmaps, sharded into independent buckets to reduce lock contention. It is // owned by BlockChain and shared across block processing and prefetching, // keyed by the immutable contract code hash. -type JumpDestCache struct { +type shardedJumpDestCache struct { buckets [jumpDestBuckets]struct { dest *lru.SizeConstrainedCache[common.Hash, vm.BitVec] } } // NewJumpDestCache constructs the analysis cache. -func NewJumpDestCache() *JumpDestCache { - c := new(JumpDestCache) +func NewJumpDestCache() vm.JumpDestCache { + c := new(shardedJumpDestCache) for i := range c.buckets { c.buckets[i].dest = lru.NewSizeConstrainedCache[common.Hash, vm.BitVec](jumpDestBucketSize) } @@ -58,7 +58,7 @@ func NewJumpDestCache() *JumpDestCache { } // Load retrieves the cached jumpdest analysis for the given code hash. -func (c *JumpDestCache) Load(hash common.Hash) (vm.BitVec, bool) { +func (c *shardedJumpDestCache) Load(hash common.Hash) (vm.BitVec, bool) { bucket := &c.buckets[hash[0]&(jumpDestBuckets-1)] v, ok := bucket.dest.Get(hash) if ok { @@ -70,7 +70,7 @@ func (c *JumpDestCache) Load(hash common.Hash) (vm.BitVec, bool) { } // Store saves the jumpdest analysis for the given code hash. -func (c *JumpDestCache) Store(hash common.Hash, b vm.BitVec) { +func (c *shardedJumpDestCache) Store(hash common.Hash, b vm.BitVec) { bucket := &c.buckets[hash[0]&(jumpDestBuckets-1)] bucket.dest.Add(hash, b) } diff --git a/core/state_prefetcher.go b/core/state_prefetcher.go index b36f8b7bba..a71a7929c3 100644 --- a/core/state_prefetcher.go +++ b/core/state_prefetcher.go @@ -49,7 +49,7 @@ func newStatePrefetcher(config *params.ChainConfig, chain *HeaderChain) *statePr // Prefetch processes the state changes according to the Ethereum rules by running // the transaction messages using the statedb, but any changes are discarded. The // only goal is to warm the state caches. -func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, jumpDests *JumpDestCache, cfg vm.Config, interrupt *atomic.Bool) { +func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, jumpDests vm.JumpDestCache, cfg vm.Config, interrupt *atomic.Bool) { var ( fails atomic.Int64 header = block.Header() diff --git a/core/state_processor.go b/core/state_processor.go index 0994d19226..024d36858a 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -61,7 +61,7 @@ func (p *StateProcessor) chainConfig() *params.ChainConfig { // Process returns the receipts and logs accumulated during the process and // returns the amount of gas that was used in the process. If any of the // transactions failed to execute due to insufficient gas it will return an error. -func (p *StateProcessor) Process(ctx context.Context, block *types.Block, statedb *state.StateDB, jumpDests *JumpDestCache, cfg vm.Config) (*ProcessResult, error) { +func (p *StateProcessor) Process(ctx context.Context, block *types.Block, statedb *state.StateDB, jumpDests vm.JumpDestCache, cfg vm.Config) (*ProcessResult, error) { var ( config = p.chainConfig() receipts = make(types.Receipts, 0, len(block.Transactions())) diff --git a/core/types.go b/core/types.go index 935202a441..0b75b269ba 100644 --- a/core/types.go +++ b/core/types.go @@ -41,7 +41,7 @@ type Prefetcher interface { // Prefetch processes the state changes according to the Ethereum rules by running // the transaction messages using the statedb, but any changes are discarded. The // only goal is to pre-cache transaction signatures and state trie nodes. - Prefetch(block *types.Block, statedb *state.StateDB, jumpDests *JumpDestCache, cfg vm.Config, interrupt *atomic.Bool) + Prefetch(block *types.Block, statedb *state.StateDB, jumpDests vm.JumpDestCache, cfg vm.Config, interrupt *atomic.Bool) } // Processor is an interface for processing blocks using a given initial state. @@ -49,7 +49,7 @@ type Processor interface { // Process processes the state changes according to the Ethereum rules by running // the transaction messages using the statedb and applying any rewards to both // the processor (coinbase) and any included uncles. - Process(ctx context.Context, block *types.Block, statedb *state.StateDB, jumpDests *JumpDestCache, cfg vm.Config) (*ProcessResult, error) + Process(ctx context.Context, block *types.Block, statedb *state.StateDB, jumpDests vm.JumpDestCache, cfg vm.Config) (*ProcessResult, error) } // ProcessResult contains the values computed by Process.