flag to stop before stage (#2194)

This commit is contained in:
Alex Sharov 2021-06-19 16:01:33 +07:00 committed by GitHub
parent bc271f92ce
commit 4533b59724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -118,3 +118,19 @@ func HeadersSeal() bool {
})
return headersSeal
}
var (
stopBeforeStage string
stopBeforeStageFlag sync.Once
)
func StopBeforeStage() string {
f := func() {
v, _ := os.LookupEnv("STOP_BEFORE_STAGE") // see names in eth/stagedsync/stages/stages.go
if v != "" {
stopBeforeStage = v
}
}
stopBeforeStageFlag.Do(f)
return stopBeforeStage
}

View File

@ -3,10 +3,12 @@ package stagedsync
import (
"context"
"fmt"
"os"
"runtime"
"time"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/debug"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/log"
@ -166,6 +168,11 @@ func (s *State) Run(db ethdb.RwKV, tx ethdb.RwTx) error {
_, stage := s.CurrentStage()
if string(stage.ID) == debug.StopBeforeStage() { // stop process for debugging reasons
log.Error("STOP_BEFORE_STAGE env flag forced to stop app")
os.Exit(1)
}
if stage.Disabled {
logPrefix := s.LogPrefix()
message := fmt.Sprintf(