Skip to content
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

Support remote validator #2635

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion arbnode/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type BlockValidatorAPI struct {
}

func (a *BlockValidatorAPI) LatestValidated(ctx context.Context) (*staker.GlobalStateValidatedInfo, error) {
return a.val.ReadLastValidatedInfo()
return a.val.ReadLastValidatedInfo(ctx)
}

type BlockValidatorDebugAPI struct {
Expand Down
2 changes: 2 additions & 0 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,13 @@ func createNodeImpl(
var blockValidator *staker.BlockValidator
if config.ValidatorRequired() {
blockValidator, err = staker.NewBlockValidator(
ctx,
statelessBlockValidator,
inboxTracker,
txStreamer,
func() *staker.BlockValidatorConfig { return &configFetcher.Get().BlockValidator },
fatalErrChan,
stack,
)
if err != nil {
return nil, err
Expand Down
48 changes: 37 additions & 11 deletions staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rlp"
"github.com/offchainlabs/nitro/arbnode/resourcemanager"
"github.com/offchainlabs/nitro/arbutil"
Expand Down Expand Up @@ -102,12 +103,15 @@ type BlockValidator struct {
fatalErr chan<- error

MemoryFreeLimitChecker resourcemanager.LimitChecker

remoteBlockValidatorClient *rpcclient.RpcClient
}

type BlockValidatorConfig struct {
Enable bool `koanf:"enable"`
RedisValidationClientConfig redis.ValidationClientConfig `koanf:"redis-validation-client-config"`
ValidationServer rpcclient.ClientConfig `koanf:"validation-server" reload:"hot"`
RemoteBlockValidatorServer rpcclient.ClientConfig `koanf:"remote-block-validator-server" reload:"hot"`
ValidationServerConfigs []rpcclient.ClientConfig `koanf:"validation-server-configs"`
ValidationPoll time.Duration `koanf:"validation-poll" reload:"hot"`
PrerecordedBlocks uint64 `koanf:"prerecorded-blocks" reload:"hot"`
Expand Down Expand Up @@ -178,6 +182,7 @@ type BlockValidatorConfigFetcher func() *BlockValidatorConfig
func BlockValidatorConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".enable", DefaultBlockValidatorConfig.Enable, "enable block-by-block validation")
rpcclient.RPCClientAddOptions(prefix+".validation-server", f, &DefaultBlockValidatorConfig.ValidationServer)
rpcclient.RPCClientAddOptions(prefix+".remote-block-validator-server", f, &DefaultBlockValidatorConfig.RemoteBlockValidatorServer)
redis.ValidationClientConfigAddOptions(prefix+".redis-validation-client-config", f)
f.String(prefix+".validation-server-configs-list", DefaultBlockValidatorConfig.ValidationServerConfigsList, "array of execution rpc configs given as a json string. time duration should be supplied in number indicating nanoseconds")
f.Duration(prefix+".validation-poll", DefaultBlockValidatorConfig.ValidationPoll, "poll time to check validations")
Expand All @@ -201,6 +206,7 @@ var DefaultBlockValidatorConfig = BlockValidatorConfig{
Enable: false,
ValidationServerConfigsList: "default",
ValidationServer: rpcclient.DefaultClientConfig,
RemoteBlockValidatorServer: rpcclient.DefaultClientConfig,
RedisValidationClientConfig: redis.DefaultValidationClientConfig,
ValidationPoll: time.Second,
ForwardBlocks: 128,
Expand Down Expand Up @@ -273,20 +279,33 @@ func (s *validationStatus) profileStep() int64 {
}

func NewBlockValidator(
ctx context.Context,
statelessBlockValidator *StatelessBlockValidator,
inbox InboxTrackerInterface,
streamer TransactionStreamerInterface,
config BlockValidatorConfigFetcher,
fatalErr chan<- error,
stack *node.Node,
) (*BlockValidator, error) {
remoteBlockValidatorServerUrl := config().RemoteBlockValidatorServer.URL
var remoteBlockValidatorClient *rpcclient.RpcClient
if len(remoteBlockValidatorServerUrl) > 0 && remoteBlockValidatorServerUrl != "self" && remoteBlockValidatorServerUrl != "self-auth" {
confFetcher := func() *rpcclient.ClientConfig { return &config().RemoteBlockValidatorServer }
remoteBlockValidatorClient = rpcclient.NewRpcClient(confFetcher, stack)
err := remoteBlockValidatorClient.Start(ctx)
if err != nil {
return nil, err
}
}
ret := &BlockValidator{
StatelessBlockValidator: statelessBlockValidator,
createNodesChan: make(chan struct{}, 1),
sendRecordChan: make(chan struct{}, 1),
progressValidationsChan: make(chan struct{}, 1),
config: config,
fatalErr: fatalErr,
prevBatchCache: make(map[uint64][]byte),
StatelessBlockValidator: statelessBlockValidator,
createNodesChan: make(chan struct{}, 1),
sendRecordChan: make(chan struct{}, 1),
progressValidationsChan: make(chan struct{}, 1),
config: config,
fatalErr: fatalErr,
prevBatchCache: make(map[uint64][]byte),
remoteBlockValidatorClient: remoteBlockValidatorClient,
}
valInputsWriter, err := inputs.NewWriter(
inputs.WithBaseDir(ret.stack.InstanceDir()),
Expand All @@ -296,7 +315,7 @@ func NewBlockValidator(
}
ret.validationInputsWriter = valInputsWriter
if !config().Dangerous.ResetBlockValidation {
validated, err := ret.ReadLastValidatedInfo()
validated, err := ret.ReadLastValidatedInfo(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -421,8 +440,15 @@ func ReadLastValidatedInfo(db ethdb.Database) (*GlobalStateValidatedInfo, error)
return &validated, nil
}

func (v *BlockValidator) ReadLastValidatedInfo() (*GlobalStateValidatedInfo, error) {
return ReadLastValidatedInfo(v.db)
func (v *BlockValidator) ReadLastValidatedInfo(ctx context.Context) (*GlobalStateValidatedInfo, error) {
if v.remoteBlockValidatorClient == nil {
return ReadLastValidatedInfo(v.db)
}
var res GlobalStateValidatedInfo
if err := v.remoteBlockValidatorClient.CallContext(ctx, &res, "arb_latestValidated"); err != nil {
return nil, err
}
return &res, nil
}

func (v *BlockValidator) legacyReadLastValidatedInfo() (*legacyLastBlockValidatedDbInfo, error) {
Expand Down Expand Up @@ -763,7 +789,7 @@ func (v *BlockValidator) iterativeValidationEntryRecorder(ctx context.Context, i
}

func (v *BlockValidator) iterativeValidationPrint(ctx context.Context) time.Duration {
validated, err := v.ReadLastValidatedInfo()
validated, err := v.ReadLastValidatedInfo(ctx)
if err != nil {
log.Error("cannot read last validated data from database", "err", err)
return time.Second * 30
Expand Down
2 changes: 1 addition & 1 deletion staker/l1_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (v *L1Validator) generateNodeAction(
var validatedCount arbutil.MessageIndex
var validatedGlobalState validator.GoGlobalState
if v.blockValidator != nil {
valInfo, err := v.blockValidator.ReadLastValidatedInfo()
valInfo, err := v.blockValidator.ReadLastValidatedInfo(ctx)
if err != nil || valInfo == nil {
return nil, false, err
}
Expand Down
Loading
Loading