Skip to content

Add an option to start re validation from a specified block and end at a specified block #2893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ func (c *BlockValidatorConfig) Validate() error {
}

type BlockValidatorDangerousConfig struct {
ResetBlockValidation bool `koanf:"reset-block-validation"`
ResetBlockValidation bool `koanf:"reset-block-validation"`
Revalidation RevalidationConfig `koanf:"re-validation"`
}

type RevalidationConfig struct {
Enable bool `koanf:"enable"`
StartBlock uint64 `koanf:"start-block"`
}

type BlockValidatorConfigFetcher func() *BlockValidatorConfig
Expand All @@ -197,6 +203,12 @@ func BlockValidatorConfigAddOptions(prefix string, f *pflag.FlagSet) {

func BlockValidatorDangerousConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".reset-block-validation", DefaultBlockValidatorDangerousConfig.ResetBlockValidation, "resets block-by-block validation, starting again at genesis")
RevalidationConfigAddOptions(prefix+".re-validation", f)
}

func RevalidationConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".enable", DefaultRevalidationConfig.Enable, "enable re-validation")
f.Uint64(prefix+".start-block", DefaultBlockValidatorDangerousConfig.Revalidation.StartBlock, "start re-validation from this block")
}

var DefaultBlockValidatorConfig = BlockValidatorConfig{
Expand Down Expand Up @@ -237,6 +249,12 @@ var TestBlockValidatorConfig = BlockValidatorConfig{

var DefaultBlockValidatorDangerousConfig = BlockValidatorDangerousConfig{
ResetBlockValidation: false,
Revalidation: DefaultRevalidationConfig,
}

var DefaultRevalidationConfig = RevalidationConfig{
Enable: false,
StartBlock: 0,
}

type valStatusField uint32
Expand Down Expand Up @@ -325,6 +343,27 @@ func NewBlockValidator(
PosInBatch: 0,
}
}
if config().Dangerous.Revalidation.Enable && config().Dangerous.Revalidation.StartBlock > 0 {
startBlock := config().Dangerous.Revalidation.StartBlock
messageCount, err := inbox.GetBatchMessageCount(startBlock - 1)
if err != nil {
return nil, err
}
res, err := streamer.ResultAtCount(messageCount)
if err != nil {
return nil, err
}
gs := validator.GoGlobalState{
BlockHash: res.BlockHash,
SendRoot: res.SendRoot,
Batch: startBlock,
PosInBatch: 0,
}
err = ret.writeLastValidated(gs, nil)
if err != nil {
return nil, err
}
}
streamer.SetBlockValidator(ret)
inbox.SetBlockValidator(ret)
if config().MemoryFreeLimit != "" {
Expand Down
Loading