Skip to content
This repository was archived by the owner on Jun 9, 2026. It is now read-only.

Commit b728488

Browse files
fix: remove duplicate logs (#261)
There are two fixes to the logging done in `saexec/execution.go`: 1. When encountering a FATAL error, there would be two log entries. One logged by the `execute` function and one by the `processQueue` function. Now only the `processQueue` function reports errors. 2. Inside `execute`, we overwrote `logger` with `logger = logger.With(` for every tx iteration. This causes O(n^2) memory allocations. Related (but non-functional) changes: - `logger` was renamed to `log` to align with the rest of the codebase. - `log := log.With(` was replaced with `blockLog := log.With(` in `sae/block_builder.go` to avoid any potential future O(n^2) memory allocations (and to align with the `txLog` and `opLog` that is performed in the rest of the function).
1 parent 54700ad commit b728488

2 files changed

Lines changed: 30 additions & 40 deletions

File tree

sae/block_builder.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,19 @@ func (b *blockBuilderG[T]) buildWithTxs(
193193

194194
unsettled := blocks.Range(lastSettled, parent)
195195
for _, block := range unsettled {
196-
log := log.With(
196+
blockLog := log.With(
197197
zap.Uint64("block_height", block.Height()),
198198
zap.Stringer("block_hash", block.Hash()),
199199
)
200200
if err := state.StartBlock(block.Header()); err != nil {
201-
log.Warn("Could not start historical worst-case calculation",
201+
blockLog.Warn("Could not start historical worst-case calculation",
202202
zap.Error(err),
203203
)
204204
return nil, fmt.Errorf("starting worst-case state for block %d: %v", block.Height(), err)
205205
}
206206
for i, tx := range block.Transactions() {
207207
if err := state.ApplyTx(tx); err != nil {
208-
log.Warn("Could not apply tx during historical worst-case calculation",
208+
blockLog.Warn("Could not apply tx during historical worst-case calculation",
209209
zap.Int("tx_index", i),
210210
zap.Stringer("tx_hash", tx.Hash()),
211211
zap.Error(err),
@@ -215,14 +215,14 @@ func (b *blockBuilderG[T]) buildWithTxs(
215215
}
216216
ops, err := b.hooks.EndOfBlockOps(block.EthBlock())
217217
if err != nil {
218-
log.Warn("Could not extract ops during historical worst-case calculation",
218+
blockLog.Warn("Could not extract ops during historical worst-case calculation",
219219
zap.Error(err),
220220
)
221221
return nil, fmt.Errorf("extracting ops of block %d to worst-case state: %v", block.Height(), err)
222222
}
223223
for i, op := range ops {
224224
if err := state.Apply(op); err != nil {
225-
log.Warn("Could not apply op during historical worst-case calculation",
225+
blockLog.Warn("Could not apply op during historical worst-case calculation",
226226
zap.Int("op_index", i),
227227
zap.Stringer("op_id", op.ID),
228228
zap.Error(err),
@@ -231,7 +231,7 @@ func (b *blockBuilderG[T]) buildWithTxs(
231231
}
232232
}
233233
if _, err := state.FinishBlock(); err != nil {
234-
log.Warn("Could not finish historical worst-case calculation",
234+
blockLog.Warn("Could not finish historical worst-case calculation",
235235
zap.Error(err),
236236
)
237237
return nil, fmt.Errorf("finishing worst-case state for block %d: %v", block.Height(), err)

saexec/execution.go

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (e *Executor) Enqueue(ctx context.Context, block *blocks.Block) error {
5151
}
5252
}
5353

54-
var emergencyPlaybookLink = zap.String("playbook", "https://github.com/ava-labs/strevm/issues/28")
54+
const emergencyPlaybookLink = "https://github.com/ava-labs/strevm/issues/28"
5555

5656
func (e *Executor) processQueue() {
5757
defer close(e.done)
@@ -62,27 +62,39 @@ func (e *Executor) processQueue() {
6262
return
6363

6464
case block := <-e.queue:
65-
logger := e.log.With(
65+
log := e.log.With(
6666
zap.Uint64("block_height", block.Height()),
6767
zap.Uint64("block_time", block.BuildTime()),
6868
zap.Stringer("block_hash", block.Hash()),
6969
zap.Int("tx_count", len(block.Transactions())),
7070
)
7171

72-
if err := e.execute(block, logger); err != nil {
73-
logger.Fatal(
74-
"Block execution failed; see emergency playbook",
75-
emergencyPlaybookLink,
72+
err := e.execute(block, log)
73+
switch {
74+
case errors.Is(err, errFatal):
75+
log.Fatal( //nolint:gocritic // False positive, will not terminate the process
76+
"Block execution failed",
77+
zap.String("playbook", emergencyPlaybookLink),
7678
zap.Error(err),
7779
)
80+
case err != nil:
81+
log.Error(
82+
"Error of unknown severity in block execution",
83+
zap.String("if_escalation_required", emergencyPlaybookLink),
84+
zap.Error(err),
85+
)
86+
}
87+
if err != nil {
7888
return
7989
}
8090
}
8191
}
8292
}
8393

84-
func (e *Executor) execute(b *blocks.Block, logger logging.Logger) error {
85-
logger.Debug("Executing block")
94+
var errFatal = errors.New("fatal execution error")
95+
96+
func (e *Executor) execute(b *blocks.Block, log logging.Logger) error {
97+
log.Debug("Executing block")
8698

8799
// Since `b` hasn't been executed, it definitely hasn't been settled, so we
88100
// are guaranteed to have a non-nil parent available.
@@ -122,11 +134,6 @@ func (e *Executor) execute(b *blocks.Block, logger logging.Logger) error {
122134
stateDB.SetTxContext(tx.Hash(), ti)
123135
b.CheckSenderBalanceBound(stateDB, signer, tx)
124136

125-
logger = logger.With(
126-
zap.Int("tx_index", ti),
127-
zap.Stringer("tx_hash", tx.Hash()),
128-
)
129-
130137
receipt, err := core.ApplyTransaction(
131138
e.chainConfig,
132139
e.chainContext,
@@ -139,12 +146,7 @@ func (e *Executor) execute(b *blocks.Block, logger logging.Logger) error {
139146
vm.Config{},
140147
)
141148
if err != nil {
142-
logger.Fatal(
143-
"Transaction execution errored (not reverted); see emergency playbook",
144-
emergencyPlaybookLink,
145-
zap.Error(err),
146-
)
147-
return err
149+
return fmt.Errorf("%w: transaction execution errored (not reverted) [%d](%#x): %v", errFatal, ti, tx.Hash(), err)
148150
}
149151

150152
perTxClock.Tick(gas.Gas(receipt.GasUsed))
@@ -180,12 +182,7 @@ func (e *Executor) execute(b *blocks.Block, logger logging.Logger) error {
180182
numTxs := len(b.Transactions())
181183
ops, err := e.hooks.EndOfBlockOps(b.EthBlock())
182184
if err != nil {
183-
logger.Fatal(
184-
"Unable to extract extra block operations; see emergency playbook",
185-
emergencyPlaybookLink,
186-
zap.Error(err),
187-
)
188-
return err
185+
return fmt.Errorf("%w: %T.EndOfBlockOps(%#x): %v", errFatal, e.hooks, b.Hash(), err)
189186
}
190187
for i, o := range ops {
191188
b.CheckOpBurnerBalanceBounds(stateDB, numTxs+i, o)
@@ -194,14 +191,7 @@ func (e *Executor) execute(b *blocks.Block, logger logging.Logger) error {
194191
b.SetInterimExecutionTime(perTxClock)
195192

196193
if err := o.ApplyTo(stateDB); err != nil {
197-
logger.Fatal(
198-
"Extra block operation errored; see emergency playbook",
199-
zap.Int("op_index", i),
200-
zap.Stringer("op_id", o.ID),
201-
emergencyPlaybookLink,
202-
zap.Error(err),
203-
)
204-
return err
194+
return fmt.Errorf("%w: applying end-of-block operation [%d](%v): %v", errFatal, i, o.ID, err)
205195
}
206196
}
207197

@@ -211,7 +201,7 @@ func (e *Executor) execute(b *blocks.Block, logger logging.Logger) error {
211201
return fmt.Errorf("after-block gas time update: %w", err)
212202
}
213203

214-
logger.Debug(
204+
log.Debug(
215205
"Block execution complete",
216206
zap.Uint64("gas_consumed", uint64(blockGasConsumed)),
217207
zap.Time("gas_time", gasClock.AsTime()),

0 commit comments

Comments
 (0)