mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
core: add EIP-7702 delegation and code write metrics tracking
Add cross-client execution metrics for EIP-7702 delegations and code writes: - Track Eip7702DelegationsSet/Cleared in SetCode based on CodeChangeReason - Track CodeUpdated and CodeBytesWrite for contract deployments - Collect metrics in ProcessBlock for slow block logging
This commit is contained in:
parent
e9a4577ba9
commit
6552fed94c
2 changed files with 28 additions and 0 deletions
|
|
@ -2241,6 +2241,14 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s
|
||||||
stats.CodeLoaded = statedb.CodeLoaded
|
stats.CodeLoaded = statedb.CodeLoaded
|
||||||
stats.CodeLoadBytes = statedb.CodeLoadBytes
|
stats.CodeLoadBytes = statedb.CodeLoadBytes
|
||||||
|
|
||||||
|
// EIP-7702 delegation metrics
|
||||||
|
stats.Eip7702DelegationsSet = statedb.Eip7702DelegationsSet
|
||||||
|
stats.Eip7702DelegationsCleared = statedb.Eip7702DelegationsCleared
|
||||||
|
|
||||||
|
// Code write metrics
|
||||||
|
stats.CodeUpdated = statedb.CodeUpdated
|
||||||
|
stats.CodeBytesWrite = statedb.CodeBytesWrite
|
||||||
|
|
||||||
stats.Execution = ptime - (statedb.AccountReads + statedb.StorageReads + statedb.CodeReads) // The time spent on EVM processing
|
stats.Execution = ptime - (statedb.AccountReads + statedb.StorageReads + statedb.CodeReads) // The time spent on EVM processing
|
||||||
stats.Validation = vtime - (statedb.AccountHashes + statedb.AccountUpdates + statedb.StorageUpdates) // The time spent on block validation
|
stats.Validation = vtime - (statedb.AccountHashes + statedb.AccountUpdates + statedb.StorageUpdates) // The time spent on block validation
|
||||||
stats.CrossValidation = xvtime // The time spent on stateless cross validation
|
stats.CrossValidation = xvtime // The time spent on stateless cross validation
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,14 @@ type StateDB struct {
|
||||||
// some APIs (e.g. CodeSize) may load the entire code from either the
|
// some APIs (e.g. CodeSize) may load the entire code from either the
|
||||||
// cache or the database when the size is not available in the cache.
|
// cache or the database when the size is not available in the cache.
|
||||||
CodeLoadBytes int
|
CodeLoadBytes int
|
||||||
|
|
||||||
|
// EIP-7702 delegation tracking for cross-client execution metrics
|
||||||
|
Eip7702DelegationsSet int // Number of EIP-7702 delegations set
|
||||||
|
Eip7702DelegationsCleared int // Number of EIP-7702 delegations cleared
|
||||||
|
|
||||||
|
// Code write tracking for cross-client execution metrics
|
||||||
|
CodeUpdated int // Number of contracts deployed (CREATE/CREATE2)
|
||||||
|
CodeBytesWrite int // Total bytes of code written during deployments
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new state from a given trie.
|
// New creates a new state from a given trie.
|
||||||
|
|
@ -473,6 +481,18 @@ func (s *StateDB) SetNonce(addr common.Address, nonce uint64, reason tracing.Non
|
||||||
func (s *StateDB) SetCode(addr common.Address, code []byte, reason tracing.CodeChangeReason) (prev []byte) {
|
func (s *StateDB) SetCode(addr common.Address, code []byte, reason tracing.CodeChangeReason) (prev []byte) {
|
||||||
stateObject := s.getOrNewStateObject(addr)
|
stateObject := s.getOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
|
// Track code write and EIP-7702 delegation metrics
|
||||||
|
switch reason {
|
||||||
|
case tracing.CodeChangeContractCreation:
|
||||||
|
s.CodeUpdated++
|
||||||
|
s.CodeBytesWrite += len(code)
|
||||||
|
case tracing.CodeChangeAuthorization:
|
||||||
|
s.CodeUpdated++
|
||||||
|
s.CodeBytesWrite += len(code)
|
||||||
|
s.Eip7702DelegationsSet++
|
||||||
|
case tracing.CodeChangeAuthorizationClear:
|
||||||
|
s.Eip7702DelegationsCleared++
|
||||||
|
}
|
||||||
return stateObject.SetCode(crypto.Keccak256Hash(code), code)
|
return stateObject.SetCode(crypto.Keccak256Hash(code), code)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue