From 6552fed94cbe9dfe64366d5b52301027a5518715 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Fri, 23 Jan 2026 02:22:30 +0100 Subject: [PATCH] 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 --- core/blockchain.go | 8 ++++++++ core/state/statedb.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index db3f71c44d..240e20aff1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 diff --git a/core/state/statedb.go b/core/state/statedb.go index 610e7173cf..044778ad38 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -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