Skip to content

Commit

Permalink
separate staker from validator
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Dec 11, 2022
1 parent b20fa84 commit 3bbba27
Show file tree
Hide file tree
Showing 30 changed files with 719 additions and 673 deletions.
6 changes: 3 additions & 3 deletions arbnode/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/validator"
"github.com/pkg/errors"
)

type BlockValidatorAPI struct {
val *validator.BlockValidator
val *staker.BlockValidator
}

func (a *BlockValidatorAPI) LatestValidatedBlock(ctx context.Context) (hexutil.Uint64, error) {
Expand All @@ -40,7 +40,7 @@ func (a *BlockValidatorAPI) LatestValidatedBlockHash(ctx context.Context) (commo
}

type BlockValidatorDebugAPI struct {
val *validator.StatelessBlockValidator
val *staker.StatelessBlockValidator
blockchain *core.BlockChain
}

Expand Down
6 changes: 3 additions & 3 deletions arbnode/inbox_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
"github.com/offchainlabs/nitro/arbos"
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/validator"
"github.com/offchainlabs/nitro/staker"
"github.com/pkg/errors"
)

type InboxTracker struct {
db ethdb.Database
txStreamer *TransactionStreamer
mutex sync.Mutex
validator *validator.BlockValidator
validator *staker.BlockValidator
das arbstate.DataAvailabilityReader
}

Expand All @@ -41,7 +41,7 @@ func NewInboxTracker(db ethdb.Database, txStreamer *TransactionStreamer, das arb
return tracker, nil
}

func (t *InboxTracker) SetBlockValidator(validator *validator.BlockValidator) {
func (t *InboxTracker) SetBlockValidator(validator *staker.BlockValidator) {
t.validator = validator
}

Expand Down
92 changes: 48 additions & 44 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/offchainlabs/nitro/solgen/go/challengegen"
"github.com/offchainlabs/nitro/solgen/go/ospgen"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/statetransfer"
"github.com/offchainlabs/nitro/util/contracts"
"github.com/offchainlabs/nitro/util/headerreader"
Expand Down Expand Up @@ -398,27 +399,27 @@ func DeployOnL1(ctx context.Context, l1client arbutil.L1Interface, deployAuth *b
}

type Config struct {
RPC arbitrum.Config `koanf:"rpc"`
Sequencer SequencerConfig `koanf:"sequencer" reload:"hot"`
L1Reader headerreader.Config `koanf:"l1-reader" reload:"hot"`
InboxReader InboxReaderConfig `koanf:"inbox-reader" reload:"hot"`
DelayedSequencer DelayedSequencerConfig `koanf:"delayed-sequencer" reload:"hot"`
BatchPoster BatchPosterConfig `koanf:"batch-poster" reload:"hot"`
ForwardingTargetImpl string `koanf:"forwarding-target"`
Forwarder ForwarderConfig `koanf:"forwarder"`
TxPreCheckerStrictness uint `koanf:"tx-pre-checker-strictness" reload:"hot"`
BlockValidator validator.BlockValidatorConfig `koanf:"block-validator" reload:"hot"`
Feed broadcastclient.FeedConfig `koanf:"feed" reload:"hot"`
Validator validator.L1ValidatorConfig `koanf:"validator"`
SeqCoordinator SeqCoordinatorConfig `koanf:"seq-coordinator"`
DataAvailability das.DataAvailabilityConfig `koanf:"data-availability"`
Wasm WasmConfig `koanf:"wasm"`
SyncMonitor SyncMonitorConfig `koanf:"sync-monitor"`
Dangerous DangerousConfig `koanf:"dangerous"`
Caching CachingConfig `koanf:"caching"`
Archive bool `koanf:"archive"`
TxLookupLimit uint64 `koanf:"tx-lookup-limit"`
TransactionStreamer TransactionStreamerConfig `koanf:"transaction-streamer" reload:"hot"`
RPC arbitrum.Config `koanf:"rpc"`
Sequencer SequencerConfig `koanf:"sequencer" reload:"hot"`
L1Reader headerreader.Config `koanf:"l1-reader" reload:"hot"`
InboxReader InboxReaderConfig `koanf:"inbox-reader" reload:"hot"`
DelayedSequencer DelayedSequencerConfig `koanf:"delayed-sequencer" reload:"hot"`
BatchPoster BatchPosterConfig `koanf:"batch-poster" reload:"hot"`
ForwardingTargetImpl string `koanf:"forwarding-target"`
Forwarder ForwarderConfig `koanf:"forwarder"`
TxPreCheckerStrictness uint `koanf:"tx-pre-checker-strictness" reload:"hot"`
BlockValidator staker.BlockValidatorConfig `koanf:"block-validator" reload:"hot"`
Feed broadcastclient.FeedConfig `koanf:"feed" reload:"hot"`
Validator staker.L1ValidatorConfig `koanf:"validator"`
SeqCoordinator SeqCoordinatorConfig `koanf:"seq-coordinator"`
DataAvailability das.DataAvailabilityConfig `koanf:"data-availability"`
Wasm WasmConfig `koanf:"wasm"`
SyncMonitor SyncMonitorConfig `koanf:"sync-monitor"`
Dangerous DangerousConfig `koanf:"dangerous"`
Caching CachingConfig `koanf:"caching"`
Archive bool `koanf:"archive"`
TxLookupLimit uint64 `koanf:"tx-lookup-limit"`
TransactionStreamer TransactionStreamerConfig `koanf:"transaction-streamer" reload:"hot"`
}

func (c *Config) Validate() error {
Expand Down Expand Up @@ -470,9 +471,9 @@ func ConfigAddOptions(prefix string, f *flag.FlagSet, feedInputEnable bool, feed
"10 = should never reject anything that'd succeed, 20 = likely won't reject anything that'd succeed, " +
"30 = full validation which may reject txs that would succeed"
f.Uint(prefix+".tx-pre-checker-strictness", ConfigDefault.TxPreCheckerStrictness, txPreCheckerDescription)
validator.BlockValidatorConfigAddOptions(prefix+".block-validator", f)
staker.BlockValidatorConfigAddOptions(prefix+".block-validator", f)
broadcastclient.FeedConfigAddOptions(prefix+".feed", f, feedInputEnable, feedOutputEnable)
validator.L1ValidatorConfigAddOptions(prefix+".validator", f)
staker.L1ValidatorConfigAddOptions(prefix+".validator", f)
SeqCoordinatorConfigAddOptions(prefix+".seq-coordinator", f)
das.DataAvailabilityConfigAddOptions(prefix+".data-availability", f)
WasmConfigAddOptions(prefix+".wasm", f)
Expand All @@ -495,9 +496,9 @@ var ConfigDefault = Config{
BatchPoster: DefaultBatchPosterConfig,
ForwardingTargetImpl: "",
TxPreCheckerStrictness: TxPreCheckerStrictnessNone,
BlockValidator: validator.DefaultBlockValidatorConfig,
BlockValidator: staker.DefaultBlockValidatorConfig,
Feed: broadcastclient.FeedConfigDefault,
Validator: validator.DefaultL1ValidatorConfig,
Validator: staker.DefaultL1ValidatorConfig,
SeqCoordinator: DefaultSeqCoordinatorConfig,
DataAvailability: das.DefaultDataAvailabilityConfig,
Wasm: DefaultWasmConfig,
Expand Down Expand Up @@ -528,7 +529,7 @@ func ConfigDefaultL1NonSequencerTest() *Config {
config.BatchPoster.Enable = false
config.SeqCoordinator.Enable = false
config.Wasm.RootPath = validator.DefaultNitroMachineConfig.RootPath
config.BlockValidator = validator.TestBlockValidatorConfig
config.BlockValidator = staker.TestBlockValidatorConfig

return &config
}
Expand Down Expand Up @@ -670,9 +671,9 @@ type Node struct {
InboxTracker *InboxTracker
DelayedSequencer *DelayedSequencer
BatchPoster *BatchPoster
BlockValidator *validator.BlockValidator
StatelessBlockValidator *validator.StatelessBlockValidator
Staker *validator.Staker
BlockValidator *staker.BlockValidator
StatelessBlockValidator *staker.StatelessBlockValidator
Staker *staker.Staker
BroadcastServer *broadcaster.Broadcaster
BroadcastClients *broadcastclients.BroadcastClients
SeqCoordinator *SeqCoordinator
Expand Down Expand Up @@ -979,12 +980,16 @@ func createNodeImpl(
nitroMachineConfig.JitCranelift = blockValidatorConf.JitValidatorCranelift
nitroMachineLoader := validator.NewNitroMachineLoader(nitroMachineConfig, fatalErrChan)

var blockValidator *validator.BlockValidator
var statelessBlockValidator *validator.StatelessBlockValidator
var blockValidator *staker.BlockValidator
var statelessBlockValidator *staker.StatelessBlockValidator

if foundMachines {
statelessBlockValidator, err = validator.NewStatelessBlockValidator(
nitroMachineLoader,
spawner, err := validator.NewValidationSpawner(nitroMachineLoader)
if err != nil {
return nil, err
}
statelessBlockValidator, err = staker.NewStatelessBlockValidator(
spawner,
inboxReader,
inboxTracker,
txStreamer,
Expand All @@ -1005,23 +1010,22 @@ func createNodeImpl(
}

if blockValidatorConf.Enable {
blockValidator, err = validator.NewBlockValidator(
blockValidator, err = staker.NewBlockValidator(
statelessBlockValidator,
inboxTracker,
txStreamer,
nitroMachineLoader,
reorgingToBlock,
func() *validator.BlockValidatorConfig { return &configFetcher.Get().BlockValidator },
func() *staker.BlockValidatorConfig { return &configFetcher.Get().BlockValidator },
fatalErrChan,
)
if err != nil {
return nil, err
}
}

var staker *validator.Staker
var stakerObj *staker.Staker
if config.Validator.Enable {
var wallet validator.ValidatorWalletInterface
var wallet staker.ValidatorWalletInterface
if config.Validator.UseSmartContractWallet || txOpts == nil {
var existingWalletAddress *common.Address
if len(config.Validator.ContractWalletAddress) > 0 {
Expand All @@ -1032,24 +1036,24 @@ func createNodeImpl(
tmpAddress := common.HexToAddress(config.Validator.ContractWalletAddress)
existingWalletAddress = &tmpAddress
}
wallet, err = validator.NewContractValidatorWallet(existingWalletAddress, deployInfo.ValidatorWalletCreator, deployInfo.Rollup, l1Reader, txOpts, int64(deployInfo.DeployedAt), func(common.Address) {})
wallet, err = staker.NewContractValidatorWallet(existingWalletAddress, deployInfo.ValidatorWalletCreator, deployInfo.Rollup, l1Reader, txOpts, int64(deployInfo.DeployedAt), func(common.Address) {})
if err != nil {
return nil, err
}
} else {
if len(config.Validator.ContractWalletAddress) > 0 {
return nil, errors.New("validator contract wallet specified but flag to use a smart contract wallet was not specified")
}
wallet, err = validator.NewEoaValidatorWallet(deployInfo.Rollup, l1client, txOpts)
wallet, err = staker.NewEoaValidatorWallet(deployInfo.Rollup, l1client, txOpts)
if err != nil {
return nil, err
}
}
staker, err = validator.NewStaker(l1Reader, wallet, bind.CallOpts{}, config.Validator, blockValidator, statelessBlockValidator, deployInfo.ValidatorUtils)
stakerObj, err = staker.NewStaker(l1Reader, wallet, bind.CallOpts{}, config.Validator, blockValidator, statelessBlockValidator, deployInfo.ValidatorUtils)
if err != nil {
return nil, err
}
if staker.Strategy() != validator.WatchtowerStrategy {
if stakerObj.Strategy() != staker.WatchtowerStrategy {
err := wallet.Initialize(ctx)
if err != nil {
return nil, err
Expand All @@ -1059,7 +1063,7 @@ func createNodeImpl(
if txOpts != nil {
txSenderPtr = &txOpts.From
}
whitelisted, err := staker.IsWhitelisted(ctx)
whitelisted, err := stakerObj.IsWhitelisted(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1100,7 +1104,7 @@ func createNodeImpl(
batchPoster,
blockValidator,
statelessBlockValidator,
staker,
stakerObj,
broadcastServer,
broadcastClients,
coordinator,
Expand Down
6 changes: 3 additions & 3 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/broadcaster"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/sharedmetrics"
"github.com/offchainlabs/nitro/util/stopwaiter"
"github.com/offchainlabs/nitro/validator"
)

// TransactionStreamer produces blocks from a node's L1 messages, storing the results in the blockchain and recording their positions
Expand Down Expand Up @@ -72,7 +72,7 @@ type TransactionStreamer struct {

coordinator *SeqCoordinator
broadcastServer *broadcaster.Broadcaster
validator *validator.BlockValidator
validator *staker.BlockValidator
inboxReader *InboxReader
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func uint64ToKey(x uint64) []byte {
return data
}

func (s *TransactionStreamer) SetBlockValidator(validator *validator.BlockValidator) {
func (s *TransactionStreamer) SetBlockValidator(validator *staker.BlockValidator) {
if s.Started() {
panic("trying to set block validator after start")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ import (
"github.com/offchainlabs/nitro/cmd/util"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
_ "github.com/offchainlabs/nitro/nodeInterface"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/colors"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/util/signature"
"github.com/offchainlabs/nitro/util/stopwaiter"
"github.com/offchainlabs/nitro/validator"
)

func printSampleUsage(name string) {
Expand Down Expand Up @@ -323,7 +323,7 @@ func mainImpl() int {
if err != nil {
log.Crit("error getting deployment info for creating validator wallet contract", "error", err)
}
addr, err := validator.GetValidatorWalletContract(ctx, deployInfo.ValidatorWalletCreator, int64(deployInfo.DeployedAt), l1TransactionOpts, l1Reader, true)
addr, err := staker.GetValidatorWalletContract(ctx, deployInfo.ValidatorWalletCreator, int64(deployInfo.DeployedAt), l1TransactionOpts, l1Reader, true)
if err != nil {
log.Crit("error creating validator wallet contract", "error", err, "address", l1TransactionOpts.From.Hex())
}
Expand Down
4 changes: 2 additions & 2 deletions nodeInterface/NodeInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/merkletree"
"github.com/offchainlabs/nitro/validator"
)

// To avoid creating new RPC methods for client-side tooling, nitro Geth's InterceptRPCMessage() hook provides
Expand Down Expand Up @@ -555,7 +555,7 @@ func findBatchContainingBlock(node *arbnode.Node, genesis uint64, block uint64)
blockAfterLatestBatch, block, latestBlock, high,
)
}
return validator.FindBatchContainingMessageIndex(node.InboxTracker, pos, high)
return staker.FindBatchContainingMessageIndex(node.InboxTracker, pos, high)
}

func (n NodeInterface) LegacyLookupMessageBatchProof(c ctx, evm mech, batchNum huge, index uint64) (
Expand Down
Loading

0 comments on commit 3bbba27

Please sign in to comment.