mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
core: address PR review comments and add EIP-7702 tracking
Address review comments from #33655: - Rename bytecodes -> code for cross-client consistency - Use common.Hash instead of string for block hash - Fix StateHashMs calculation to include AccountUpdates + StorageUpdates - Fix CommitMs calculation using max() for parallel commits + BlockWrite - Add code write tracking (CodeUpdated, CodeBytesWritten) - Add EIP-7702 delegation tracking (delegations set/cleared) The EIP-7702 fields will be 0 for pre-Pectra blocks per spec.
This commit is contained in:
parent
bfe7a6c3dc
commit
e9a4577ba9
1 changed files with 71 additions and 0 deletions
|
|
@ -172,6 +172,77 @@ func TestLogSlowBlockJSON(t *testing.T) {
|
||||||
t.Logf("Parsed JSON:\n%+v", logEntry)
|
t.Logf("Parsed JSON:\n%+v", logEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestLogSlowBlockEIP7702 tests that EIP-7702 delegation fields are properly serialized.
|
||||||
|
func TestLogSlowBlockEIP7702(t *testing.T) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
handler := log.NewTerminalHandler(&buf, false)
|
||||||
|
log.SetDefault(log.NewLogger(handler))
|
||||||
|
|
||||||
|
header := &types.Header{
|
||||||
|
Number: common.Big1,
|
||||||
|
GasUsed: 21000000,
|
||||||
|
GasLimit: 30000000,
|
||||||
|
}
|
||||||
|
block := types.NewBlockWithHeader(header)
|
||||||
|
|
||||||
|
// Create test stats with EIP-7702 delegation data
|
||||||
|
stats := &ExecuteStats{
|
||||||
|
Execution: 500 * time.Millisecond,
|
||||||
|
TotalTime: 1200 * time.Millisecond,
|
||||||
|
MgasPerSecond: 17.5,
|
||||||
|
AccountLoaded: 100,
|
||||||
|
StorageLoaded: 500,
|
||||||
|
CodeLoaded: 20,
|
||||||
|
CodeBytesRead: 4096,
|
||||||
|
AccountUpdated: 50,
|
||||||
|
StorageUpdated: 200,
|
||||||
|
CodeUpdated: 5,
|
||||||
|
CodeBytesWrite: 2048,
|
||||||
|
Eip7702DelegationsSet: 3,
|
||||||
|
Eip7702DelegationsCleared: 1,
|
||||||
|
StateReadCacheStats: state.ReaderStats{
|
||||||
|
AccountCacheHit: 4,
|
||||||
|
AccountCacheMiss: 6,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.logSlow(block, 1*time.Second)
|
||||||
|
|
||||||
|
// Find and parse the JSON
|
||||||
|
jsonStart := bytes.Index(buf.Bytes(), []byte(`{"level"`))
|
||||||
|
if jsonStart == -1 {
|
||||||
|
t.Fatal("Could not find JSON in log output")
|
||||||
|
}
|
||||||
|
jsonBytes := buf.Bytes()[jsonStart:]
|
||||||
|
if jsonEnd := bytes.IndexByte(jsonBytes, '\n'); jsonEnd != -1 {
|
||||||
|
jsonBytes = jsonBytes[:jsonEnd]
|
||||||
|
}
|
||||||
|
|
||||||
|
var logEntry slowBlockLog
|
||||||
|
if err := json.Unmarshal(jsonBytes, &logEntry); err != nil {
|
||||||
|
t.Fatalf("Failed to parse JSON: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify EIP-7702 fields
|
||||||
|
if logEntry.StateWrites.Eip7702DelegationsSet != 3 {
|
||||||
|
t.Errorf("Expected eip7702_delegations_set 3, got %d", logEntry.StateWrites.Eip7702DelegationsSet)
|
||||||
|
}
|
||||||
|
if logEntry.StateWrites.Eip7702DelegationsCleared != 1 {
|
||||||
|
t.Errorf("Expected eip7702_delegations_cleared 1, got %d", logEntry.StateWrites.Eip7702DelegationsCleared)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify code bytes fields
|
||||||
|
if logEntry.StateReads.CodeBytes != 4096 {
|
||||||
|
t.Errorf("Expected code_bytes read 4096, got %d", logEntry.StateReads.CodeBytes)
|
||||||
|
}
|
||||||
|
if logEntry.StateWrites.CodeBytes != 2048 {
|
||||||
|
t.Errorf("Expected code_bytes write 2048, got %d", logEntry.StateWrites.CodeBytes)
|
||||||
|
}
|
||||||
|
if logEntry.StateWrites.Code != 5 {
|
||||||
|
t.Errorf("Expected code writes 5, got %d", logEntry.StateWrites.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestLogSlowBlockThreshold tests that logSlow respects the threshold.
|
// TestLogSlowBlockThreshold tests that logSlow respects the threshold.
|
||||||
func TestLogSlowBlockThreshold(t *testing.T) {
|
func TestLogSlowBlockThreshold(t *testing.T) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue