Skip to content

Commit 8d4e7bf

Browse files
domiweiclaude
andauthored
stagedsync: guard BAL debug file writes and unify serialization format (#20223)
## Summary - Guard `writeBALToFile` behind `dbg.TraceBlockAccessLists` (`TRACE_BLOCK_ACCESS_LISTS` env var) so BAL debug files are **not written by default**, preventing unbounded disk growth - Replace ~65 lines of custom printf-based serialization in `writeBALToFile` with a single call to `bal.DebugPrint(file)`, unifying the output format with the mismatch-dump path (`DebugString`) Related: #20214, #20216 ## Test plan - [x] `make erigon` compiles successfully - [ ] Run with `TRACE_BLOCK_ACCESS_LISTS=true` and verify BAL files are written with the unified format - [ ] Run without the env var and verify no BAL files are created 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 90d065f commit 8d4e7bf

1 file changed

Lines changed: 5 additions & 67 deletions

File tree

execution/stagedsync/bal_create.go

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/erigontech/erigon/common/dbg"
89
"github.com/erigontech/erigon/common/log/v3"
910
"github.com/erigontech/erigon/db/kv"
1011
"github.com/erigontech/erigon/db/rawdb"
@@ -15,7 +16,9 @@ import (
1516

1617
func CreateBAL(blockNum uint64, txIO *state.VersionedIO, dataDir string) types.BlockAccessList {
1718
bal := txIO.AsBlockAccessList()
18-
writeBALToFile(bal, blockNum, dataDir)
19+
if dbg.TraceBlockAccessLists {
20+
writeBALToFile(bal, blockNum, dataDir)
21+
}
1922
return bal
2023
}
2124

@@ -40,73 +43,8 @@ func writeBALToFile(bal types.BlockAccessList, blockNum uint64, dataDir string)
4043
}
4144
defer file.Close()
4245

43-
// Write header information
4446
fmt.Fprintf(file, "Block Access List for Block %d\n", blockNum)
45-
fmt.Fprintf(file, "Total Accounts: %d\n\n", len(bal))
46-
47-
// Write each account's changes
48-
for _, account := range bal {
49-
fmt.Fprintf(file, "Account: %s\n", account.Address.Value().Hex())
50-
51-
// Storage changes
52-
if len(account.StorageChanges) > 0 {
53-
fmt.Fprintf(file, " Storage Changes (%d):\n", len(account.StorageChanges))
54-
for _, slotChange := range account.StorageChanges {
55-
fmt.Fprintf(file, " Slot: %s\n", slotChange.Slot.Value().Hex())
56-
for _, change := range slotChange.Changes {
57-
fmt.Fprintf(file, " [%d] -> %s\n", change.Index, change.Value.Hex())
58-
}
59-
}
60-
}
61-
62-
// Storage reads
63-
if len(account.StorageReads) > 0 {
64-
fmt.Fprintf(file, " Storage Reads (%d):\n", len(account.StorageReads))
65-
for _, read := range account.StorageReads {
66-
fmt.Fprintf(file, " %s\n", read.Value().Hex())
67-
}
68-
}
69-
70-
// Balance changes
71-
if len(account.BalanceChanges) > 0 {
72-
fmt.Fprintf(file, " Balance Changes (%d):\n", len(account.BalanceChanges))
73-
for _, change := range account.BalanceChanges {
74-
fmt.Fprintf(file, " [%d] -> %s\n", change.Index, change.Value.String())
75-
}
76-
}
77-
78-
// Nonce changes
79-
if len(account.NonceChanges) > 0 {
80-
fmt.Fprintf(file, " Nonce Changes (%d):\n", len(account.NonceChanges))
81-
for _, change := range account.NonceChanges {
82-
fmt.Fprintf(file, " [%d] -> %d\n", change.Index, change.Value)
83-
}
84-
}
85-
86-
// Code changes
87-
if len(account.CodeChanges) > 0 {
88-
fmt.Fprintf(file, " Code Changes (%d):\n", len(account.CodeChanges))
89-
for _, change := range account.CodeChanges {
90-
fmt.Fprintf(file, " [%d] -> %d bytes\n", change.Index, len(change.Bytecode))
91-
if len(change.Bytecode) <= 64 {
92-
fmt.Fprintf(file, " Bytecode: %x\n", change.Bytecode)
93-
} else {
94-
fmt.Fprintf(file, " Bytecode: %x... (truncated)\n", change.Bytecode[:64])
95-
}
96-
}
97-
}
98-
99-
// If no changes, indicate that
100-
if len(account.StorageChanges) == 0 && len(account.StorageReads) == 0 &&
101-
len(account.BalanceChanges) == 0 && len(account.NonceChanges) == 0 &&
102-
len(account.CodeChanges) == 0 {
103-
fmt.Fprintf(file, " No changes (accessed only)\n")
104-
}
105-
106-
fmt.Fprintf(file, "\n")
107-
}
108-
109-
//log.Info("BAL written to file", "blockNum", blockNum, "filename", filename, "accounts", len(bal))
47+
bal.DebugPrint(file)
11048
}
11149

11250
func ProcessBAL(tx kv.TemporalRwTx, h *types.Header, vio *state.VersionedIO, amsterdam bool, experimental bool, dataDir string) error {

0 commit comments

Comments
 (0)