Skip to content

Commit

Permalink
Merge pull request #2148 from OffchainLabs/require-beacon-client-rpc
Browse files Browse the repository at this point in the history
Require beacon client RPC
  • Loading branch information
PlasmaPower authored Feb 16, 2024
2 parents a20a1c7 + 308fd45 commit 2e5db55
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 76 deletions.
34 changes: 23 additions & 11 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type Config struct {
Staker staker.L1ValidatorConfig `koanf:"staker" reload:"hot"`
SeqCoordinator SeqCoordinatorConfig `koanf:"seq-coordinator"`
DataAvailability das.DataAvailabilityConfig `koanf:"data-availability"`
BlobClient BlobClientConfig `koanf:"blob-client"`
SyncMonitor SyncMonitorConfig `koanf:"sync-monitor"`
Dangerous DangerousConfig `koanf:"dangerous"`
TransactionStreamer TransactionStreamerConfig `koanf:"transaction-streamer" reload:"hot"`
Expand Down Expand Up @@ -152,7 +151,6 @@ func ConfigAddOptions(prefix string, f *flag.FlagSet, feedInputEnable bool, feed
staker.L1ValidatorConfigAddOptions(prefix+".staker", f)
SeqCoordinatorConfigAddOptions(prefix+".seq-coordinator", f)
das.DataAvailabilityConfigAddNodeOptions(prefix+".data-availability", f)
BlobClientAddOptions(prefix+".blob-client", f)
SyncMonitorConfigAddOptions(prefix+".sync-monitor", f)
DangerousConfigAddOptions(prefix+".dangerous", f)
TransactionStreamerConfigAddOptions(prefix+".transaction-streamer", f)
Expand Down Expand Up @@ -191,6 +189,7 @@ func ConfigDefaultL1Test() *Config {

func ConfigDefaultL1NonSequencerTest() *Config {
config := ConfigDefault
config.Dangerous = TestDangerousConfig
config.ParentChainReader = headerreader.TestConfig
config.InboxReader = TestInboxReaderConfig
config.DelayedSequencer.Enable = false
Expand All @@ -206,6 +205,7 @@ func ConfigDefaultL1NonSequencerTest() *Config {

func ConfigDefaultL2Test() *Config {
config := ConfigDefault
config.Dangerous = TestDangerousConfig
config.ParentChainReader.Enable = false
config.SeqCoordinator = TestSeqCoordinatorConfig
config.Feed.Input.Verify.Dangerous.AcceptMissing = true
Expand All @@ -223,16 +223,25 @@ func ConfigDefaultL2Test() *Config {
type DangerousConfig struct {
NoL1Listener bool `koanf:"no-l1-listener"`
NoSequencerCoordinator bool `koanf:"no-sequencer-coordinator"`
DisableBlobReader bool `koanf:"disable-blob-reader"`
}

var DefaultDangerousConfig = DangerousConfig{
NoL1Listener: false,
NoSequencerCoordinator: false,
DisableBlobReader: false,
}

var TestDangerousConfig = DangerousConfig{
NoL1Listener: false,
NoSequencerCoordinator: false,
DisableBlobReader: true,
}

func DangerousConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".no-l1-listener", DefaultDangerousConfig.NoL1Listener, "DANGEROUS! disables listening to L1. To be used in test nodes only")
f.Bool(prefix+".no-sequencer-coordinator", DefaultDangerousConfig.NoSequencerCoordinator, "DANGEROUS! allows sequencing without sequencer-coordinator")
f.Bool(prefix+".disable-blob-reader", DefaultDangerousConfig.DisableBlobReader, "DANGEROUS! disables the EIP-4844 blob reader, which is necessary to read batches")
}

type Node struct {
Expand All @@ -242,6 +251,7 @@ type Node struct {
L1Reader *headerreader.HeaderReader
TxStreamer *TransactionStreamer
DeployInfo *chaininfo.RollupAddresses
BlobReader arbstate.BlobReader
InboxReader *InboxReader
InboxTracker *InboxTracker
DelayedSequencer *DelayedSequencer
Expand Down Expand Up @@ -360,6 +370,7 @@ func createNodeImpl(
dataSigner signature.DataSignerFunc,
fatalErrChan chan error,
parentChainID *big.Int,
blobReader arbstate.BlobReader,
) (*Node, error) {
config := configFetcher.Get()

Expand Down Expand Up @@ -463,6 +474,7 @@ func createNodeImpl(
L1Reader: nil,
TxStreamer: txStreamer,
DeployInfo: nil,
BlobReader: blobReader,
InboxReader: nil,
InboxTracker: nil,
DelayedSequencer: nil,
Expand Down Expand Up @@ -523,14 +535,6 @@ func createNodeImpl(
return nil, errors.New("a data availability service is required for this chain, but it was not configured")
}

var blobReader arbstate.BlobReader
if config.BlobClient.BeaconChainUrl != "" {
blobReader, err = NewBlobClient(config.BlobClient, l1client)
if err != nil {
return nil, err
}
}

inboxTracker, err := NewInboxTracker(arbDb, txStreamer, daReader, blobReader)
if err != nil {
return nil, err
Expand Down Expand Up @@ -688,6 +692,7 @@ func createNodeImpl(
L1Reader: l1Reader,
TxStreamer: txStreamer,
DeployInfo: deployInfo,
BlobReader: blobReader,
InboxReader: inboxReader,
InboxTracker: inboxTracker,
DelayedSequencer: delayedSequencer,
Expand Down Expand Up @@ -727,8 +732,9 @@ func CreateNode(
dataSigner signature.DataSignerFunc,
fatalErrChan chan error,
parentChainID *big.Int,
blobReader arbstate.BlobReader,
) (*Node, error) {
currentNode, err := createNodeImpl(ctx, stack, exec, arbDb, configFetcher, l2Config, l1client, deployInfo, txOptsValidator, txOptsBatchPoster, dataSigner, fatalErrChan, parentChainID)
currentNode, err := createNodeImpl(ctx, stack, exec, arbDb, configFetcher, l2Config, l1client, deployInfo, txOptsValidator, txOptsBatchPoster, dataSigner, fatalErrChan, parentChainID, blobReader)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -777,6 +783,12 @@ func (n *Node) Start(ctx context.Context) error {
if err != nil {
return fmt.Errorf("error starting exec client: %w", err)
}
if n.BlobReader != nil {
err = n.BlobReader.Initialize(ctx)
if err != nil {
return fmt.Errorf("error initializing blob reader: %w", err)
}
}
if n.InboxTracker != nil {
err = n.InboxTracker.Initialize()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions arbstate/inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type BlobReader interface {
batchBlockHash common.Hash,
versionedHashes []common.Hash,
) ([]kzg4844.Blob, error)
Initialize(ctx context.Context) error
}

type sequencerMessage struct {
Expand Down
18 changes: 11 additions & 7 deletions cmd/conf/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
"time"

"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/util/rpcclient"
flag "github.com/spf13/pflag"
)

type L1Config struct {
ID uint64 `koanf:"id"`
Connection rpcclient.ClientConfig `koanf:"connection" reload:"hot"`
Wallet genericconf.WalletConfig `koanf:"wallet"`
type ParentChainConfig struct {
ID uint64 `koanf:"id"`
Connection rpcclient.ClientConfig `koanf:"connection" reload:"hot"`
Wallet genericconf.WalletConfig `koanf:"wallet"`
BlobClient headerreader.BlobClientConfig `koanf:"blob-client"`
}

var L1ConnectionConfigDefault = rpcclient.ClientConfig{
Expand All @@ -25,10 +27,11 @@ var L1ConnectionConfigDefault = rpcclient.ClientConfig{
ArgLogLimit: 2048,
}

var L1ConfigDefault = L1Config{
var L1ConfigDefault = ParentChainConfig{
ID: 0,
Connection: L1ConnectionConfigDefault,
Wallet: DefaultL1WalletConfig,
BlobClient: headerreader.DefaultBlobClientConfig,
}

var DefaultL1WalletConfig = genericconf.WalletConfig{
Expand All @@ -43,13 +46,14 @@ func L1ConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Uint64(prefix+".id", L1ConfigDefault.ID, "if set other than 0, will be used to validate database and L1 connection")
rpcclient.RPCClientAddOptions(prefix+".connection", f, &L1ConfigDefault.Connection)
genericconf.WalletConfigAddOptions(prefix+".wallet", f, L1ConfigDefault.Wallet.Pathname)
headerreader.BlobClientAddOptions(prefix+".blob-client", f)
}

func (c *L1Config) ResolveDirectoryNames(chain string) {
func (c *ParentChainConfig) ResolveDirectoryNames(chain string) {
c.Wallet.ResolveDirectoryNames(chain)
}

func (c *L1Config) Validate() error {
func (c *ParentChainConfig) Validate() error {
return c.Connection.Validate()
}

Expand Down
30 changes: 24 additions & 6 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

"github.com/offchainlabs/nitro/arbnode"
"github.com/offchainlabs/nitro/arbnode/resourcemanager"
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/arbutil"
blocksreexecutor "github.com/offchainlabs/nitro/blocks_reexecutor"
"github.com/offchainlabs/nitro/cmd/chaininfo"
Expand Down Expand Up @@ -329,6 +330,8 @@ func mainImpl() int {

var rollupAddrs chaininfo.RollupAddresses
var l1Client *ethclient.Client
var l1Reader *headerreader.HeaderReader
var blobReader arbstate.BlobReader
if nodeConfig.Node.ParentChainReader.Enable {
confFetcher := func() *rpcclient.ClientConfig { return &liveNodeConfig.Get().ParentChain.Connection }
rpcClient := rpcclient.NewRpcClient(confFetcher, nil)
Expand All @@ -351,19 +354,33 @@ func mainImpl() int {
if err != nil {
log.Crit("error getting rollup addresses", "err", err)
}
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1Client)
l1Reader, err = headerreader.New(ctx, l1Client, func() *headerreader.Config { return &liveNodeConfig.Get().Node.ParentChainReader }, arbSys)
if err != nil {
log.Crit("failed to get L1 headerreader", "err", err)
}
if !l1Reader.IsParentChainArbitrum() && !nodeConfig.Node.Dangerous.DisableBlobReader {
if nodeConfig.ParentChain.BlobClient.BeaconUrl == "" {
flag.Usage()
log.Crit("a beacon chain RPC URL is required to read batches, but it was not configured (CLI argument: --parent-chain.blob-client.beacon-url [URL])")
}
blobClient, err := headerreader.NewBlobClient(nodeConfig.ParentChain.BlobClient, l1Client)
if err != nil {
log.Crit("failed to initialize blob client", "err", err)
}
blobReader = blobClient
}
}

if nodeConfig.Node.Staker.OnlyCreateWalletContract {
if !nodeConfig.Node.Staker.UseSmartContractWallet {
flag.Usage()
log.Crit("--node.validator.only-create-wallet-contract requires --node.validator.use-smart-contract-wallet")
}
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1Client)
l1Reader, err := headerreader.New(ctx, l1Client, func() *headerreader.Config { return &liveNodeConfig.Get().Node.ParentChainReader }, arbSys)
if err != nil {
log.Crit("failed to get L1 headerreader", "error", err)
if l1Reader == nil {
flag.Usage()
log.Crit("--node.validator.only-create-wallet-contract conflicts with --node.dangerous.no-l1-listener")
}

// Just create validator smart wallet if needed then exit
deployInfo, err := chaininfo.GetRollupAddressesConfig(nodeConfig.Chain.ID, nodeConfig.Chain.Name, combinedL2ChainInfoFile, nodeConfig.Chain.InfoJson)
if err != nil {
Expand Down Expand Up @@ -536,6 +553,7 @@ func mainImpl() int {
dataSigner,
fatalErrChan,
big.NewInt(int64(nodeConfig.ParentChain.ID)),
blobReader,
)
if err != nil {
log.Error("failed to create node", "err", err)
Expand Down Expand Up @@ -667,7 +685,7 @@ type NodeConfig struct {
Node arbnode.Config `koanf:"node" reload:"hot"`
Execution gethexec.Config `koanf:"execution" reload:"hot"`
Validation valnode.Config `koanf:"validation" reload:"hot"`
ParentChain conf.L1Config `koanf:"parent-chain" reload:"hot"`
ParentChain conf.ParentChainConfig `koanf:"parent-chain" reload:"hot"`
Chain conf.L2Config `koanf:"chain"`
LogLevel int `koanf:"log-level" reload:"hot"`
LogType string `koanf:"log-type" reload:"hot"`
Expand Down
4 changes: 4 additions & 0 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func (r *BlobPreimageReader) GetBlobs(
return blobs, nil
}

func (r *BlobPreimageReader) Initialize(ctx context.Context) error {
return nil
}

// To generate:
// key, _ := crypto.HexToECDSA("0000000000000000000000000000000000000000000000000000000000000001")
// sig, _ := crypto.Sign(make([]byte, 32), key)
Expand Down
2 changes: 1 addition & 1 deletion system_tests/blocks_reexecutor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestBlocksReExecutorModes(t *testing.T) {

parentChainID := big.NewInt(1234)
feedErrChan := make(chan error, 10)
node, err := arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(arbnode.ConfigDefaultL2Test()), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan, parentChainID)
node, err := arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(arbnode.ConfigDefaultL2Test()), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan, parentChainID, nil)
Require(t, err)
err = node.TxStreamer.AddFakeInitMessage()
Require(t, err)
Expand Down
6 changes: 3 additions & 3 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ func createTestNodeWithL1(
Require(t, err)
currentNode, err = arbnode.CreateNode(
ctx, l2stack, execNode, l2arbDb, NewFetcherFromConfig(nodeConfig), l2blockchain.Config(), l1client,
addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, dataSigner, fatalErrChan, big.NewInt(1337),
addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, dataSigner, fatalErrChan, big.NewInt(1337), nil,
)
Require(t, err)

Expand Down Expand Up @@ -825,7 +825,7 @@ func createTestNode(
execNode, err := gethexec.CreateExecutionNode(ctx, stack, chainDb, blockchain, nil, execConfigFetcher)
Require(t, err)

currentNode, err := arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(nodeConfig), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan, big.NewInt(1337))
currentNode, err := arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(nodeConfig), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan, big.NewInt(1337), nil)
Require(t, err)

// Give the node an init message
Expand Down Expand Up @@ -930,7 +930,7 @@ func Create2ndNodeWithConfig(
currentExec, err := gethexec.CreateExecutionNode(ctx, l2stack, l2chainDb, l2blockchain, l1client, configFetcher)
Require(t, err)

currentNode, err := arbnode.CreateNode(ctx, l2stack, currentExec, l2arbDb, NewFetcherFromConfig(nodeConfig), l2blockchain.Config(), l1client, first.DeployInfo, &txOpts, &txOpts, dataSigner, feedErrChan, big.NewInt(1337))
currentNode, err := arbnode.CreateNode(ctx, l2stack, currentExec, l2arbDb, NewFetcherFromConfig(nodeConfig), l2blockchain.Config(), l1client, first.DeployInfo, &txOpts, &txOpts, dataSigner, feedErrChan, big.NewInt(1337), nil)
Require(t, err)

err = currentNode.Start(ctx)
Expand Down
6 changes: 3 additions & 3 deletions system_tests/das_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestDASRekey(t *testing.T) {
l1NodeConfigA.DataAvailability.ParentChainNodeURL = "none"
execA, err := gethexec.CreateExecutionNode(ctx, l2stackA, l2chainDb, l2blockchain, l1client, gethexec.ConfigDefaultTest)
Require(t, err)
nodeA, err := arbnode.CreateNode(ctx, l2stackA, execA, l2arbDb, NewFetcherFromConfig(l1NodeConfigA), l2blockchain.Config(), l1client, addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, nil, feedErrChan, parentChainID)
nodeA, err := arbnode.CreateNode(ctx, l2stackA, execA, l2arbDb, NewFetcherFromConfig(l1NodeConfigA), l2blockchain.Config(), l1client, addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, nil, feedErrChan, parentChainID, nil)
Require(t, err)
Require(t, nodeA.Start(ctx))
l2clientA := ClientForStack(t, l2stackA)
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestDASRekey(t *testing.T) {
Require(t, err)

l1NodeConfigA.DataAvailability.RPCAggregator = aggConfigForBackend(t, backendConfigB)
nodeA, err := arbnode.CreateNode(ctx, l2stackA, execA, l2arbDb, NewFetcherFromConfig(l1NodeConfigA), l2blockchain.Config(), l1client, addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, nil, feedErrChan, parentChainID)
nodeA, err := arbnode.CreateNode(ctx, l2stackA, execA, l2arbDb, NewFetcherFromConfig(l1NodeConfigA), l2blockchain.Config(), l1client, addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, nil, feedErrChan, parentChainID, nil)
Require(t, err)
Require(t, nodeA.Start(ctx))
l2clientA := ClientForStack(t, l2stackA)
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestDASComplexConfigAndRestMirror(t *testing.T) {

sequencerTxOpts := l1info.GetDefaultTransactOpts("Sequencer", ctx)
sequencerTxOptsPtr := &sequencerTxOpts
nodeA, err := arbnode.CreateNode(ctx, l2stackA, execA, l2arbDb, NewFetcherFromConfig(l1NodeConfigA), l2blockchain.Config(), l1client, addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, dataSigner, feedErrChan, big.NewInt(1337))
nodeA, err := arbnode.CreateNode(ctx, l2stackA, execA, l2arbDb, NewFetcherFromConfig(l1NodeConfigA), l2blockchain.Config(), l1client, addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, dataSigner, feedErrChan, big.NewInt(1337), nil)
Require(t, err)
Require(t, nodeA.Start(ctx))
l2clientA := ClientForStack(t, l2stackA)
Expand Down
4 changes: 2 additions & 2 deletions system_tests/full_challenge_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
asserterExec, err := gethexec.CreateExecutionNode(ctx, asserterL2Stack, asserterL2ChainDb, asserterL2Blockchain, l1Backend, gethexec.ConfigDefaultTest)
Require(t, err)
parentChainID := big.NewInt(1337)
asserterL2, err := arbnode.CreateNode(ctx, asserterL2Stack, asserterExec, asserterL2ArbDb, NewFetcherFromConfig(conf), chainConfig, l1Backend, asserterRollupAddresses, nil, nil, nil, fatalErrChan, parentChainID)
asserterL2, err := arbnode.CreateNode(ctx, asserterL2Stack, asserterExec, asserterL2ArbDb, NewFetcherFromConfig(conf), chainConfig, l1Backend, asserterRollupAddresses, nil, nil, nil, fatalErrChan, parentChainID, nil)
Require(t, err)
err = asserterL2.Start(ctx)
Require(t, err)
Expand All @@ -296,7 +296,7 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
challengerRollupAddresses.SequencerInbox = challengerSeqInboxAddr
challengerExec, err := gethexec.CreateExecutionNode(ctx, challengerL2Stack, challengerL2ChainDb, challengerL2Blockchain, l1Backend, gethexec.ConfigDefaultTest)
Require(t, err)
challengerL2, err := arbnode.CreateNode(ctx, challengerL2Stack, challengerExec, challengerL2ArbDb, NewFetcherFromConfig(conf), chainConfig, l1Backend, &challengerRollupAddresses, nil, nil, nil, fatalErrChan, parentChainID)
challengerL2, err := arbnode.CreateNode(ctx, challengerL2Stack, challengerExec, challengerL2ArbDb, NewFetcherFromConfig(conf), chainConfig, l1Backend, &challengerRollupAddresses, nil, nil, nil, fatalErrChan, parentChainID, nil)
Require(t, err)
err = challengerL2.Start(ctx)
Require(t, err)
Expand Down
4 changes: 2 additions & 2 deletions system_tests/recreatestate_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func testSkippingSavingStateAndRecreatingAfterRestart(t *testing.T, cacheConfig
Require(t, err)

parentChainID := big.NewInt(1337)
node, err := arbnode.CreateNode(ctx1, stack, execNode, arbDb, NewFetcherFromConfig(arbnode.ConfigDefaultL2Test()), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan, parentChainID)
node, err := arbnode.CreateNode(ctx1, stack, execNode, arbDb, NewFetcherFromConfig(arbnode.ConfigDefaultL2Test()), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan, parentChainID, nil)
Require(t, err)
err = node.TxStreamer.AddFakeInitMessage()
Require(t, err)
Expand Down Expand Up @@ -376,7 +376,7 @@ func testSkippingSavingStateAndRecreatingAfterRestart(t *testing.T, cacheConfig
execNode, err = gethexec.CreateExecutionNode(ctx1, stack, chainDb, blockchain, nil, execConfigFetcher)
Require(t, err)

node, err = arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(arbnode.ConfigDefaultL2Test()), blockchain.Config(), nil, node.DeployInfo, nil, nil, nil, feedErrChan, parentChainID)
node, err = arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(arbnode.ConfigDefaultL2Test()), blockchain.Config(), nil, node.DeployInfo, nil, nil, nil, feedErrChan, parentChainID, nil)
Require(t, err)
Require(t, node.Start(ctx))
client = ClientForStack(t, stack)
Expand Down
Loading

0 comments on commit 2e5db55

Please sign in to comment.