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:
CPerezz 2026-01-23 02:22:30 +01:00
parent e9a4577ba9
commit 6552fed94c
No known key found for this signature in database
GPG key ID: 62045F34B97177DD
2 changed files with 28 additions and 0 deletions

View file

@ -2241,6 +2241,14 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s
stats.CodeLoaded = statedb.CodeLoaded
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.Validation = vtime - (statedb.AccountHashes + statedb.AccountUpdates + statedb.StorageUpdates) // The time spent on block validation
stats.CrossValidation = xvtime // The time spent on stateless cross validation

View file

@ -165,6 +165,14 @@ type StateDB struct {
// 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.
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.
@ -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) {
stateObject := s.getOrNewStateObject(addr)
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 nil