From 8c76f61a86bdec68853f20878cd13c265424038b Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Dec 2022 11:29:21 +0700 Subject: [PATCH] save --- eth/stagedsync/sync.go | 10 +++++++++- turbo/stages/stageloop.go | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/eth/stagedsync/sync.go b/eth/stagedsync/sync.go index d6dd1d748d8..528618a62ba 100644 --- a/eth/stagedsync/sync.go +++ b/eth/stagedsync/sync.go @@ -264,6 +264,15 @@ func (s *Sync) Run(db kv.RwDB, tx kv.RwTx, firstCycle bool, quiet bool) error { s.NextStage() } + if err := s.SetCurrentStage(s.stages[0].ID); err != nil { + return err + } + + s.currentStage = 0 + return nil +} +func (s *Sync) RunPrune(db kv.RwDB, tx kv.RwTx, firstCycle bool) error { + s.timings = s.timings[:0] for i := 0; i < len(s.pruningOrder); i++ { if s.pruningOrder[i] == nil || s.pruningOrder[i].Disabled || s.pruningOrder[i].Prune == nil { continue @@ -275,7 +284,6 @@ func (s *Sync) Run(db kv.RwDB, tx kv.RwTx, firstCycle bool, quiet bool) error { if err := s.SetCurrentStage(s.stages[0].ID); err != nil { return err } - s.currentStage = 0 return nil } diff --git a/turbo/stages/stageloop.go b/turbo/stages/stageloop.go index 7ba0892b3e5..60f338c35b4 100644 --- a/turbo/stages/stageloop.go +++ b/turbo/stages/stageloop.go @@ -160,7 +160,8 @@ func StageLoopStep( var tx kv.RwTx // on this variable will run sync cycle. if canRunCycleInOneTransaction { - tx, err = db.BeginRw(context.Background()) + // -- Process new blocks + commit(no_sync) + tx, err = db.BeginRwAsync(ctx) if err != nil { return headBlockHash, err } @@ -191,6 +192,9 @@ func StageLoopStep( } commitTime = time.Since(commitStart) } + + // -- send notifications START + var rotx kv.Tx if rotx, err = db.BeginRo(ctx); err != nil { return headBlockHash, err @@ -262,6 +266,12 @@ func StageLoopStep( } } } + // -- send notifications END + + // -- Prune+commit(sync) + if err := db.Update(ctx, func(tx kv.RwTx) error { return sync.RunPrune(db, tx, initialCycle) }); err != nil { + return headBlockHash, err + } return headBlockHash, nil }