Skip to content

Commit 1dcac1b

Browse files
hexoscottrevitteth
andauthored
quiet logging for witness generation unwinds (0xPolygonHermez#1407)
* quiet logging for witness generation unwinds * fix - integration --------- Co-authored-by: Max Revitt <[email protected]>
1 parent 0715bc5 commit 1dcac1b

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

cmd/integration/commands/stages.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ func stageHashState(db kv.RwDB, ctx context.Context, logger log.Logger) error {
12131213
cfg := stagedsync.StageHashStateCfg(db, dirs, historyV3, agg)
12141214
if unwind > 0 {
12151215
u := sync.NewUnwindState(stages.HashState, s.BlockNumber-unwind, s.BlockNumber)
1216-
err = stagedsync.UnwindHashStateStage(u, s, tx, cfg, ctx, logger)
1216+
err = stagedsync.UnwindHashStateStage(u, s, tx, cfg, ctx, logger, false)
12171217
if err != nil {
12181218
return err
12191219
}

cmd/integration/commands/state_stages.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func loopIh(db kv.RwDB, ctx context.Context, unwind uint64, logger log.Logger) e
473473
to := execStage.BlockNumber - unwind
474474
_ = sync.SetCurrentStage(stages.HashState)
475475
u := &stagedsync.UnwindState{ID: stages.HashState, UnwindPoint: to}
476-
if err = stagedsync.UnwindHashStateStage(u, stage(sync, tx, nil, stages.HashState), tx, stagedsync.StageHashStateCfg(db, dirs, historyV3, agg), ctx, logger); err != nil {
476+
if err = stagedsync.UnwindHashStateStage(u, stage(sync, tx, nil, stages.HashState), tx, stagedsync.StageHashStateCfg(db, dirs, historyV3, agg), ctx, logger, false); err != nil {
477477
return err
478478
}
479479
_ = sync.SetCurrentStage(stages.IntermediateHashes)

eth/stagedsync/default_stages.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func DefaultStages(ctx context.Context,
138138
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
139139
},
140140
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
141-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
141+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
142142
},
143143
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
144144
return PruneHashStateStage(p, tx, hashState, ctx)
@@ -318,7 +318,7 @@ func PipelineStages(ctx context.Context, snapshots SnapshotsCfg, blockHashCfg Bl
318318
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
319319
},
320320
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
321-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
321+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
322322
},
323323
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
324324
return PruneHashStateStage(p, tx, hashState, ctx)
@@ -527,7 +527,7 @@ func UploaderPipelineStages(ctx context.Context, snapshots SnapshotsCfg, headers
527527
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
528528
},
529529
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
530-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
530+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
531531
},
532532
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
533533
return PruneHashStateStage(p, tx, hashState, ctx)
@@ -701,7 +701,7 @@ func StateStages(ctx context.Context, headers HeadersCfg, bodies BodiesCfg, bloc
701701
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
702702
},
703703
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
704-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
704+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
705705
},
706706
},
707707
{

eth/stagedsync/stage_hashstate.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func SpawnHashStateStage(s *StageState, tx kv.RwTx, cfg HashStateCfg, ctx contex
102102
return nil
103103
}
104104

105-
func UnwindHashStateStage(u *UnwindState, s *StageState, tx kv.RwTx, cfg HashStateCfg, ctx context.Context, logger log.Logger) (err error) {
105+
func UnwindHashStateStage(u *UnwindState, s *StageState, tx kv.RwTx, cfg HashStateCfg, ctx context.Context, logger log.Logger, quiet bool) (err error) {
106106
useExternalTx := tx != nil
107107
if !useExternalTx {
108108
tx, err = cfg.db.BeginRw(ctx)
@@ -113,7 +113,7 @@ func UnwindHashStateStage(u *UnwindState, s *StageState, tx kv.RwTx, cfg HashSta
113113
}
114114

115115
logPrefix := u.LogPrefix()
116-
if err = unwindHashStateStageImpl(logPrefix, u, s, tx, cfg, ctx, logger); err != nil {
116+
if err = unwindHashStateStageImpl(logPrefix, u, s, tx, cfg, ctx, logger, quiet); err != nil {
117117
return err
118118
}
119119
if err = u.Done(tx); err != nil {
@@ -127,7 +127,7 @@ func UnwindHashStateStage(u *UnwindState, s *StageState, tx kv.RwTx, cfg HashSta
127127
return nil
128128
}
129129

130-
func unwindHashStateStageImpl(logPrefix string, u *UnwindState, s *StageState, tx kv.RwTx, cfg HashStateCfg, ctx context.Context, logger log.Logger) error {
130+
func unwindHashStateStageImpl(logPrefix string, u *UnwindState, s *StageState, tx kv.RwTx, cfg HashStateCfg, ctx context.Context, logger log.Logger, quiet bool) error {
131131
// Currently it does not require unwinding because it does not create any Intermediate Hash records
132132
// and recomputes the state root from scratch
133133
prom := NewPromoter(tx, cfg.dirs, ctx, logger)
@@ -143,13 +143,13 @@ func unwindHashStateStageImpl(logPrefix string, u *UnwindState, s *StageState, t
143143
}
144144
return nil
145145
}
146-
if err := prom.Unwind(logPrefix, s, u, false /* storage */, true /* codes */); err != nil {
146+
if err := prom.Unwind(logPrefix, s, u, false /* storage */, true /* codes */, quiet); err != nil {
147147
return err
148148
}
149-
if err := prom.Unwind(logPrefix, s, u, false /* storage */, false /* codes */); err != nil {
149+
if err := prom.Unwind(logPrefix, s, u, false /* storage */, false /* codes */, quiet); err != nil {
150150
return err
151151
}
152-
if err := prom.Unwind(logPrefix, s, u, true /* storage */, false /* codes */); err != nil {
152+
if err := prom.Unwind(logPrefix, s, u, true /* storage */, false /* codes */, quiet); err != nil {
153153
return err
154154
}
155155
return nil
@@ -844,7 +844,7 @@ func (p *Promoter) UnwindOnHistoryV3(logPrefix string, agg *state.Aggregator, un
844844
return collector.Load(p.tx, kv.HashedAccounts, etl.IdentityLoadFunc, etl.TransformArgs{Quit: p.ctx.Done()})
845845
}
846846

847-
func (p *Promoter) Unwind(logPrefix string, s *StageState, u *UnwindState, storage bool, codes bool) error {
847+
func (p *Promoter) Unwind(logPrefix string, s *StageState, u *UnwindState, storage bool, codes bool, quiet bool) error {
848848
var changeSetBucket string
849849
if storage {
850850
changeSetBucket = kv.StorageChangeSet
@@ -854,7 +854,9 @@ func (p *Promoter) Unwind(logPrefix string, s *StageState, u *UnwindState, stora
854854
from := s.BlockNumber
855855
to := u.UnwindPoint
856856

857-
p.logger.Info(fmt.Sprintf("[%s] Unwinding started", logPrefix), "from", from, "to", to, "storage", storage, "codes", codes)
857+
if !quiet {
858+
p.logger.Info(fmt.Sprintf("[%s] Unwinding started", logPrefix), "from", from, "to", to, "storage", storage, "codes", codes)
859+
}
858860

859861
startkey := hexutility.EncodeTs(to + 1)
860862

eth/stagedsync/stage_hashstate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestUnwindHashed(t *testing.T) {
106106
}
107107
u := &UnwindState{UnwindPoint: 50}
108108
s := &StageState{BlockNumber: 100}
109-
err = unwindHashStateStageImpl("logPrefix", u, s, tx2, StageHashStateCfg(db2, dirs, historyV3, nil), context.Background(), logger)
109+
err = unwindHashStateStageImpl("logPrefix", u, s, tx2, StageHashStateCfg(db2, dirs, historyV3, nil), context.Background(), logger, false)
110110
if err != nil {
111111
t.Errorf("error while unwind state: %v", err)
112112
}
@@ -227,7 +227,7 @@ func TestUnwindHashStateShutdown(t *testing.T) {
227227

228228
u := &UnwindState{UnwindPoint: 5}
229229
s := &StageState{BlockNumber: 10}
230-
if err = unwindHashStateStageImpl("logPrefix", u, s, tx, cfg, ctx, logger); !errors.Is(err, tc.errExp) {
230+
if err = unwindHashStateStageImpl("logPrefix", u, s, tx, cfg, ctx, logger, false); !errors.Is(err, tc.errExp) {
231231
t.Errorf("error does not match expected error while shutdown unwindHashStateStageImpl, got: %v, expected: %v", err, tc.errExp)
232232
}
233233

turbo/jsonrpc/eth_call.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (api *APIImpl) GetProof(ctx context.Context, address libcommon.Address, sto
362362
stageState := &stagedsync.StageState{BlockNumber: latestBlock}
363363

364364
hashStageCfg := stagedsync.StageHashStateCfg(nil, api.dirs, api.historyV3(batch), api._agg)
365-
if err := stagedsync.UnwindHashStateStage(unwindState, stageState, batch, hashStageCfg, ctx, api.logger); err != nil {
365+
if err := stagedsync.UnwindHashStateStage(unwindState, stageState, batch, hashStageCfg, ctx, api.logger, true); err != nil {
366366
return nil, err
367367
}
368368

zk/stages/stages.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func SequencerZkStages(
125125
return stages.SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
126126
},
127127
Unwind: func(firstCycle bool, u *stages.UnwindState, s *stages.StageState, txc wrap.TxContainer, logger log.Logger) error {
128-
return stages.UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
128+
return stages.UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
129129
},
130130
Prune: func(firstCycle bool, p *stages.PruneState, tx kv.RwTx, logger log.Logger) error {
131131
return stages.PruneHashStateStage(p, tx, hashState, ctx)
@@ -328,7 +328,7 @@ func DefaultZkStages(
328328
return stages.SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
329329
},
330330
Unwind: func(firstCycle bool, u *stages.UnwindState, s *stages.StageState, txc wrap.TxContainer, logger log.Logger) error {
331-
return stages.UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
331+
return stages.UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
332332
},
333333
Prune: func(firstCycle bool, p *stages.PruneState, tx kv.RwTx, logger log.Logger) error {
334334
return stages.PruneHashStateStage(p, tx, hashState, ctx)

zk/witness/witness.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (g *Generator) generateWitness(tx kv.Tx, ctx context.Context, batchNum uint
223223
stageState := &stagedsync.StageState{BlockNumber: latestBlock}
224224

225225
hashStageCfg := stagedsync.StageHashStateCfg(nil, g.dirs, g.historyV3, g.agg)
226-
if err := stagedsync.UnwindHashStateStage(unwindState, stageState, batch, hashStageCfg, ctx, log.New()); err != nil {
226+
if err := stagedsync.UnwindHashStateStage(unwindState, stageState, batch, hashStageCfg, ctx, log.New(), true); err != nil {
227227
return nil, fmt.Errorf("unwind hash state: %w", err)
228228
}
229229

0 commit comments

Comments
 (0)