mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
core/vm: rename to JumpDestCache
This commit is contained in:
parent
fd6d6d7fb3
commit
2f96b90846
3 changed files with 9 additions and 15 deletions
|
|
@ -31,8 +31,8 @@ type Contract struct {
|
|||
caller common.Address
|
||||
address common.Address
|
||||
|
||||
jumpDests JumpDests // Aggregated result of JUMPDEST analysis.
|
||||
analysis BitVec // Locally cached result of JUMPDEST analysis
|
||||
jumpDests JumpDestCache // Aggregated result of JUMPDEST analysis.
|
||||
analysis BitVec // Locally cached result of JUMPDEST analysis
|
||||
|
||||
Code []byte
|
||||
CodeHash common.Hash
|
||||
|
|
@ -47,7 +47,7 @@ type Contract struct {
|
|||
}
|
||||
|
||||
// NewContract returns a new contract environment for the execution of EVM.
|
||||
func NewContract(caller common.Address, address common.Address, value *uint256.Int, gas uint64, jumpDests JumpDests) *Contract {
|
||||
func NewContract(caller common.Address, address common.Address, value *uint256.Int, gas uint64, jumpDests JumpDestCache) *Contract {
|
||||
// Initialize the jump analysis cache if it's nil, mostly for tests
|
||||
if jumpDests == nil {
|
||||
jumpDests = newMapJumpDests()
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ type EVM struct {
|
|||
precompiles map[common.Address]PrecompiledContract
|
||||
|
||||
// jumpDests stores results of JUMPDEST analysis.
|
||||
jumpDests JumpDests
|
||||
jumpDests JumpDestCache
|
||||
}
|
||||
|
||||
// NewEVM constructs an EVM instance with the supplied block context, state
|
||||
|
|
@ -151,10 +151,8 @@ func (evm *EVM) SetPrecompiles(precompiles PrecompiledContracts) {
|
|||
evm.precompiles = precompiles
|
||||
}
|
||||
|
||||
// SetJumpDests sets a custom JumpDests implementation for the EVM.
|
||||
// This allows for flexible caching strategies, including global caches
|
||||
// that can be shared across multiple EVM instances.
|
||||
func (evm *EVM) SetJumpDests(jumpDests JumpDests) {
|
||||
// SetJumpDestCache configures the analysis cache.
|
||||
func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) {
|
||||
evm.jumpDests = jumpDests
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,8 @@ package vm
|
|||
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
// JumpDests is an interface for managing the jumpdest analysis cache.
|
||||
// It provides methods to store and retrieve the results of JUMPDEST analysis
|
||||
// for contract bytecode, which is used to determine valid jump destinations.
|
||||
type JumpDests interface {
|
||||
// JumpDestCache represents the cache of jumpdest analysis results.
|
||||
type JumpDestCache interface {
|
||||
// Load retrieves the cached jumpdest analysis for the given code hash.
|
||||
// Returns the BitVec and true if found, or nil and false if not cached.
|
||||
Load(codeHash common.Hash) (BitVec, bool)
|
||||
|
|
@ -35,17 +33,15 @@ type JumpDests interface {
|
|||
type mapJumpDests map[common.Hash]BitVec
|
||||
|
||||
// newMapJumpDests creates a new map-based JumpDests implementation.
|
||||
func newMapJumpDests() JumpDests {
|
||||
func newMapJumpDests() JumpDestCache {
|
||||
return make(mapJumpDests)
|
||||
}
|
||||
|
||||
// Load retrieves the cached jumpdest analysis for the given code hash.
|
||||
func (j mapJumpDests) Load(codeHash common.Hash) (BitVec, bool) {
|
||||
vec, ok := j[codeHash]
|
||||
return vec, ok
|
||||
}
|
||||
|
||||
// Store saves the jumpdest analysis for the given code hash.
|
||||
func (j mapJumpDests) Store(codeHash common.Hash, vec BitVec) {
|
||||
j[codeHash] = vec
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue