Skip to content

Commit

Permalink
Merge branch 'master' into inbox-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacolvin0 authored Oct 13, 2023
2 parents a778d57 + 0b527c2 commit a26c9f3
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ solgen/go
**/node_modules

target/**/*
!target/machines
!target/machines/*
!target/machines/**/*
brotli/buildfiles/**/*

# these are used by environment outside the docker:
Expand Down
67 changes: 42 additions & 25 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"

"github.com/offchainlabs/nitro/arbnode/dataposter"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
"github.com/offchainlabs/nitro/arbnode/redislock"
Expand All @@ -47,6 +48,7 @@ import (
var (
batchPosterWalletBalance = metrics.NewRegisteredGaugeFloat64("arb/batchposter/wallet/balanceether", nil)
batchPosterGasRefunderBalance = metrics.NewRegisteredGaugeFloat64("arb/batchposter/gasrefunder/balanceether", nil)
batchPosterSimpleRedisLockKey = "node.batch-poster.redis-lock.simple-lock-key"
)

type batchPosterPosition struct {
Expand Down Expand Up @@ -166,7 +168,7 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".l1-block-bound", DefaultBatchPosterConfig.L1BlockBound, "only post messages to batches when they're within the max future block/timestamp as of this L1 block tag (\"safe\", \"finalized\", \"latest\", or \"ignore\" to ignore this check)")
f.Duration(prefix+".l1-block-bound-bypass", DefaultBatchPosterConfig.L1BlockBoundBypass, "post batches even if not within the layer 1 future bounds if we're within this margin of the max delay")
redislock.AddConfigOptions(prefix+".redis-lock", f)
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f)
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfig)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname)
}

Expand All @@ -187,6 +189,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
RedisLock: redislock.DefaultCfg,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Expand Down Expand Up @@ -214,66 +217,80 @@ var TestBatchPosterConfig = BatchPosterConfig{
L1BlockBoundBypass: time.Hour,
}

func NewBatchPoster(ctx context.Context, dataPosterDB ethdb.Database, l1Reader *headerreader.HeaderReader, inbox *InboxTracker, streamer *TransactionStreamer, syncMonitor *SyncMonitor, config BatchPosterConfigFetcher, deployInfo *chaininfo.RollupAddresses, transactOpts *bind.TransactOpts, daWriter das.DataAvailabilityServiceWriter) (*BatchPoster, error) {
seqInbox, err := bridgegen.NewSequencerInbox(deployInfo.SequencerInbox, l1Reader.Client())
type BatchPosterOpts struct {
DataPosterDB ethdb.Database
L1Reader *headerreader.HeaderReader
Inbox *InboxTracker
Streamer *TransactionStreamer
SyncMonitor *SyncMonitor
Config BatchPosterConfigFetcher
DeployInfo *chaininfo.RollupAddresses
TransactOpts *bind.TransactOpts
DAWriter das.DataAvailabilityServiceWriter
}

func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, error) {
seqInbox, err := bridgegen.NewSequencerInbox(opts.DeployInfo.SequencerInbox, opts.L1Reader.Client())
if err != nil {
return nil, err
}
bridge, err := bridgegen.NewBridge(deployInfo.Bridge, l1Reader.Client())
bridge, err := bridgegen.NewBridge(opts.DeployInfo.Bridge, opts.L1Reader.Client())
if err != nil {
return nil, err
}
if err = config().Validate(); err != nil {
if err = opts.Config().Validate(); err != nil {
return nil, err
}
seqInboxABI, err := bridgegen.SequencerInboxMetaData.GetAbi()
if err != nil {
return nil, err
}
redisClient, err := redisutil.RedisClientFromURL(config().RedisUrl)
redisClient, err := redisutil.RedisClientFromURL(opts.Config().RedisUrl)
if err != nil {
return nil, err
}
redisLockConfigFetcher := func() *redislock.SimpleCfg {
return &config().RedisLock
simpleRedisLockConfig := opts.Config().RedisLock
simpleRedisLockConfig.Key = batchPosterSimpleRedisLockKey
return &simpleRedisLockConfig
}
redisLock, err := redislock.NewSimple(redisClient, redisLockConfigFetcher, func() bool { return syncMonitor.Synced() })
redisLock, err := redislock.NewSimple(redisClient, redisLockConfigFetcher, func() bool { return opts.SyncMonitor.Synced() })
if err != nil {
return nil, err
}
b := &BatchPoster{
l1Reader: l1Reader,
inbox: inbox,
streamer: streamer,
syncMonitor: syncMonitor,
config: config,
l1Reader: opts.L1Reader,
inbox: opts.Inbox,
streamer: opts.Streamer,
syncMonitor: opts.SyncMonitor,
config: opts.Config,
bridge: bridge,
seqInbox: seqInbox,
seqInboxABI: seqInboxABI,
seqInboxAddr: deployInfo.SequencerInbox,
gasRefunderAddr: config().gasRefunder,
bridgeAddr: deployInfo.Bridge,
daWriter: daWriter,
seqInboxAddr: opts.DeployInfo.SequencerInbox,
gasRefunderAddr: opts.Config().gasRefunder,
bridgeAddr: opts.DeployInfo.Bridge,
daWriter: opts.DAWriter,
redisLock: redisLock,
accessList: func(SequencerInboxAccs, AfterDelayedMessagesRead int) types.AccessList {
return AccessList(&AccessListOpts{
SequencerInboxAddr: deployInfo.SequencerInbox,
DataPosterAddr: transactOpts.From,
BridgeAddr: deployInfo.Bridge,
GasRefunderAddr: config().gasRefunder,
SequencerInboxAddr: opts.DeployInfo.SequencerInbox,
DataPosterAddr: opts.TransactOpts.From,
BridgeAddr: opts.DeployInfo.Bridge,
GasRefunderAddr: opts.Config().gasRefunder,
SequencerInboxAccs: SequencerInboxAccs,
AfterDelayedMessagesRead: AfterDelayedMessagesRead,
})
},
}
dataPosterConfigFetcher := func() *dataposter.DataPosterConfig {
return &config().DataPoster
return &(opts.Config().DataPoster)
}
b.dataPoster, err = dataposter.NewDataPoster(ctx,
&dataposter.DataPosterOpts{
Database: dataPosterDB,
HeaderReader: l1Reader,
Auth: transactOpts,
Database: opts.DataPosterDB,
HeaderReader: opts.L1Reader,
Auth: opts.TransactOpts,
RedisClient: redisClient,
RedisLock: redisLock,
Config: dataPosterConfigFetcher,
Expand Down
30 changes: 15 additions & 15 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,21 +662,21 @@ type DangerousConfig struct {
// that flags can be reloaded dynamically.
type ConfigFetcher func() *DataPosterConfig

func DataPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".replacement-times", DefaultDataPosterConfig.ReplacementTimes, "comma-separated list of durations since first posting to attempt a replace-by-fee")
f.Bool(prefix+".wait-for-l1-finality", DefaultDataPosterConfig.WaitForL1Finality, "only treat a transaction as confirmed after L1 finality has been achieved (recommended)")
f.Uint64(prefix+".max-mempool-transactions", DefaultDataPosterConfig.MaxMempoolTransactions, "the maximum number of transactions to have queued in the mempool at once (0 = unlimited)")
f.Int(prefix+".max-queued-transactions", DefaultDataPosterConfig.MaxQueuedTransactions, "the maximum number of unconfirmed transactions to track at once (0 = unlimited)")
f.Float64(prefix+".target-price-gwei", DefaultDataPosterConfig.TargetPriceGwei, "the target price to use for maximum fee cap calculation")
f.Float64(prefix+".urgency-gwei", DefaultDataPosterConfig.UrgencyGwei, "the urgency to use for maximum fee cap calculation")
f.Float64(prefix+".min-fee-cap-gwei", DefaultDataPosterConfig.MinFeeCapGwei, "the minimum fee cap to post transactions at")
f.Float64(prefix+".min-tip-cap-gwei", DefaultDataPosterConfig.MinTipCapGwei, "the minimum tip cap to post transactions at")
f.Float64(prefix+".max-tip-cap-gwei", DefaultDataPosterConfig.MaxTipCapGwei, "the maximum tip cap to post transactions at")
f.Uint64(prefix+".nonce-rbf-soft-confs", DefaultDataPosterConfig.NonceRbfSoftConfs, "the maximum probable reorg depth, used to determine when a transaction will no longer likely need replaced-by-fee")
f.Bool(prefix+".allocate-mempool-balance", DefaultDataPosterConfig.AllocateMempoolBalance, "if true, don't put transactions in the mempool that spend a total greater than the batch poster's balance")
f.Bool(prefix+".use-db-storage", DefaultDataPosterConfig.UseDBStorage, "uses database storage when enabled")
f.Bool(prefix+".use-noop-storage", DefaultDataPosterConfig.UseNoOpStorage, "uses noop storage, it doesn't store anything")
f.Bool(prefix+".legacy-storage-encoding", DefaultDataPosterConfig.LegacyStorageEncoding, "encodes items in a legacy way (as it was before dropping generics)")
func DataPosterConfigAddOptions(prefix string, f *pflag.FlagSet, defaultDataPosterConfig DataPosterConfig) {
f.String(prefix+".replacement-times", defaultDataPosterConfig.ReplacementTimes, "comma-separated list of durations since first posting to attempt a replace-by-fee")
f.Bool(prefix+".wait-for-l1-finality", defaultDataPosterConfig.WaitForL1Finality, "only treat a transaction as confirmed after L1 finality has been achieved (recommended)")
f.Uint64(prefix+".max-mempool-transactions", defaultDataPosterConfig.MaxMempoolTransactions, "the maximum number of transactions to have queued in the mempool at once (0 = unlimited)")
f.Int(prefix+".max-queued-transactions", defaultDataPosterConfig.MaxQueuedTransactions, "the maximum number of unconfirmed transactions to track at once (0 = unlimited)")
f.Float64(prefix+".target-price-gwei", defaultDataPosterConfig.TargetPriceGwei, "the target price to use for maximum fee cap calculation")
f.Float64(prefix+".urgency-gwei", defaultDataPosterConfig.UrgencyGwei, "the urgency to use for maximum fee cap calculation")
f.Float64(prefix+".min-fee-cap-gwei", defaultDataPosterConfig.MinFeeCapGwei, "the minimum fee cap to post transactions at")
f.Float64(prefix+".min-tip-cap-gwei", defaultDataPosterConfig.MinTipCapGwei, "the minimum tip cap to post transactions at")
f.Float64(prefix+".max-tip-cap-gwei", defaultDataPosterConfig.MaxTipCapGwei, "the maximum tip cap to post transactions at")
f.Uint64(prefix+".nonce-rbf-soft-confs", defaultDataPosterConfig.NonceRbfSoftConfs, "the maximum probable reorg depth, used to determine when a transaction will no longer likely need replaced-by-fee")
f.Bool(prefix+".allocate-mempool-balance", defaultDataPosterConfig.AllocateMempoolBalance, "if true, don't put transactions in the mempool that spend a total greater than the batch poster's balance")
f.Bool(prefix+".use-db-storage", defaultDataPosterConfig.UseDBStorage, "uses database storage when enabled")
f.Bool(prefix+".use-noop-storage", defaultDataPosterConfig.UseNoOpStorage, "uses noop storage, it doesn't store anything")
f.Bool(prefix+".legacy-storage-encoding", defaultDataPosterConfig.LegacyStorageEncoding, "encodes items in a legacy way (as it was before dropping generics)")

signature.SimpleHmacConfigAddOptions(prefix+".redis-signer", f)
addDangerousOptions(prefix+".dangerous", f)
Expand Down
1 change: 1 addition & 0 deletions arbnode/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func MaintenanceConfigAddOptions(prefix string, f *flag.FlagSet) {

var DefaultMaintenanceConfig = MaintenanceConfig{
TimeOfDay: "",
Lock: redislock.DefaultCfg,

minutesAfterMidnight: 0,
}
Expand Down
13 changes: 12 additions & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ var ConfigDefault = Config{
Dangerous: DefaultDangerousConfig,
TransactionStreamer: DefaultTransactionStreamerConfig,
ResourceMgmt: resourcemanager.DefaultConfig,
Maintenance: DefaultMaintenanceConfig,
}

func ConfigDefaultL1Test() *Config {
Expand Down Expand Up @@ -841,7 +842,17 @@ func createNodeImpl(
if txOptsBatchPoster == nil {
return nil, errors.New("batchposter, but no TxOpts")
}
batchPoster, err = NewBatchPoster(ctx, rawdb.NewTable(arbDb, storage.BatchPosterPrefix), l1Reader, inboxTracker, txStreamer, syncMonitor, func() *BatchPosterConfig { return &configFetcher.Get().BatchPoster }, deployInfo, txOptsBatchPoster, daWriter)
batchPoster, err = NewBatchPoster(ctx, &BatchPosterOpts{
DataPosterDB: rawdb.NewTable(arbDb, storage.BatchPosterPrefix),
L1Reader: l1Reader,
Inbox: inboxTracker,
Streamer: txStreamer,
SyncMonitor: syncMonitor,
Config: func() *BatchPosterConfig { return &configFetcher.Get().BatchPoster },
DeployInfo: deployInfo,
TransactOpts: txOptsBatchPoster,
DAWriter: daWriter,
})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion arbnode/redislock/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func AddConfigOptions(prefix string, f *flag.FlagSet) {
f.String(prefix+".my-id", "", "this node's id prefix when acquiring the lock (optional)")
f.Duration(prefix+".lockout-duration", DefaultCfg.LockoutDuration, "how long lock is held")
f.Duration(prefix+".refresh-duration", DefaultCfg.RefreshDuration, "how long between consecutive calls to redis")
f.String(prefix+".key", prefix+".simple-lock-key", "key for lock")
f.String(prefix+".key", DefaultCfg.Key, "key for lock")
f.Bool(prefix+".background-lock", DefaultCfg.BackgroundLock, "should node always try grabing lock in background")
}

Expand Down
2 changes: 1 addition & 1 deletion broadcastclient/broadcastclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var DefaultConfig = Config{
RequireChainId: false,
RequireFeedVersion: false,
Verify: signature.DefultFeedVerifierConfig,
URL: []string{""},
URL: []string{},
Timeout: 20 * time.Second,
EnableCompression: true,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/genericconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ConfConfigAddOptions(prefix string, f *flag.FlagSet) {
var ConfConfigDefault = ConfConfig{
Dump: false,
EnvPrefix: "",
File: nil,
File: []string{},
S3: DefaultS3Config,
String: "",
ReloadInterval: 0,
Expand Down
6 changes: 3 additions & 3 deletions cmd/genericconf/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var HTTPConfigDefault = HTTPConfig{
Port: 8547,
API: append(node.DefaultConfig.HTTPModules, "eth", "arb"),
RPCPrefix: node.DefaultConfig.HTTPPathPrefix,
CORSDomain: node.DefaultConfig.HTTPCors,
CORSDomain: []string{},
VHosts: node.DefaultConfig.HTTPVirtualHosts,
ServerTimeouts: HTTPServerTimeoutConfigDefault,
}
Expand Down Expand Up @@ -91,7 +91,7 @@ var WSConfigDefault = WSConfig{
Port: 8548,
API: append(node.DefaultConfig.WSModules, "eth", "arb"),
RPCPrefix: node.DefaultConfig.WSPathPrefix,
Origins: node.DefaultConfig.WSOrigins,
Origins: []string{},
ExposeAll: node.DefaultConfig.WSExposeAll,
}

Expand Down Expand Up @@ -137,7 +137,7 @@ type GraphQLConfig struct {

var GraphQLConfigDefault = GraphQLConfig{
Enable: false,
CORSDomain: node.DefaultConfig.GraphQLCors,
CORSDomain: []string{},
VHosts: node.DefaultConfig.GraphQLVirtualHosts,
}

Expand Down
19 changes: 19 additions & 0 deletions cmd/nitro/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ import (
"time"

"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
"github.com/offchainlabs/nitro/util/colors"
"github.com/offchainlabs/nitro/util/testhelpers"

"github.com/r3labs/diff/v3"
flag "github.com/spf13/pflag"
)

func TestEmptyCliConfig(t *testing.T) {
f := flag.NewFlagSet("", flag.ContinueOnError)
NodeConfigAddOptions(f)
k, err := confighelpers.BeginCommonParse(f, []string{})
Require(t, err)
var emptyCliNodeConfig NodeConfig
err = confighelpers.EndCommonParse(k, &emptyCliNodeConfig)
Require(t, err)
if !reflect.DeepEqual(emptyCliNodeConfig, NodeConfigDefault) {
changelog, err := diff.Diff(emptyCliNodeConfig, NodeConfigDefault)
Require(t, err)
Fail(t, "empty cli config differs from expected default", changelog)
}
}

func TestSeqConfig(t *testing.T) {
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --parent-chain.wallet.pathname /l1keystore --parent-chain.wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
_, _, _, err := ParseNode(context.Background(), args)
Expand Down
3 changes: 2 additions & 1 deletion cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"math/big"
"os"
"reflect"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -296,7 +297,7 @@ func findImportantRoots(ctx context.Context, chainDb ethdb.Database, stack *node
return nil, err
}
if initConfig.Prune == "validator" {
if l1Client == nil {
if l1Client == nil || reflect.ValueOf(l1Client).IsNil() {
return nil, errors.New("an L1 connection is required for validator pruning")
}
callOpts := bind.CallOpts{
Expand Down
12 changes: 11 additions & 1 deletion cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ import (
)

func printSampleUsage(name string) {
fmt.Printf("Sample usage: %s --help \n", name)
fmt.Printf("Sample usage: %s [OPTIONS] \n\n", name)
fmt.Printf("Options:\n")
fmt.Printf(" --help\n")
fmt.Printf(" --dev: Start a default L2-only dev chain\n")
}

func addUnlockWallet(accountManager *accounts.Manager, walletConf *genericconf.WalletConfig) (common.Address, error) {
Expand Down Expand Up @@ -591,16 +594,23 @@ type NodeConfig struct {
var NodeConfigDefault = NodeConfig{
Conf: genericconf.ConfConfigDefault,
Node: arbnode.ConfigDefault,
Execution: gethexec.ConfigDefault,
Validation: valnode.DefaultValidationConfig,
ParentChain: conf.L1ConfigDefault,
Chain: conf.L2ConfigDefault,
LogLevel: int(log.LvlInfo),
LogType: "plaintext",
FileLogging: genericconf.DefaultFileLoggingConfig,
Persistent: conf.PersistentConfigDefault,
HTTP: genericconf.HTTPConfigDefault,
WS: genericconf.WSConfigDefault,
IPC: genericconf.IPCConfigDefault,
Auth: genericconf.AuthRPCConfigDefault,
GraphQL: genericconf.GraphQLConfigDefault,
Metrics: false,
MetricsServer: genericconf.MetricsServerConfigDefault,
Init: InitConfigDefault,
Rpc: genericconf.DefaultRpcConfig,
PProf: false,
PprofCfg: genericconf.PProfDefault,
}
Expand Down
22 changes: 22 additions & 0 deletions cmd/util/confighelpers/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,32 @@ func PrintErrorAndExit(err error, usage func(string)) {
}
}

func devFlagArgs() []string {
args := []string{
"--init.dev-init",
"--init.dev-init-address", "0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E",
"--node.dangerous.no-l1-listener",
"--node.parent-chain-reader.enable=false",
"--parent-chain.id=1337",
"--chain.id=412346",
"--persistent.chain", "/tmp/dev-test",
"--node.sequencer",
"--node.dangerous.no-sequencer-coordinator",
"--node.staker.enable=false",
"--init.empty=false",
"--http.port", "8547",
"--http.addr", "127.0.0.1",
}
return args
}

func BeginCommonParse(f *flag.FlagSet, args []string) (*koanf.Koanf, error) {
for _, arg := range args {
if arg == "--version" || arg == "-v" {
return nil, ErrVersion
} else if arg == "--dev" {
args = devFlagArgs()
break
}
}
if err := f.Parse(args); err != nil {
Expand Down
1 change: 1 addition & 0 deletions das/das.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var DefaultDataAvailabilityConfig = DataAvailabilityConfig{
RestAggregator: DefaultRestfulClientAggregatorConfig,
ParentChainConnectionAttempts: 15,
PanicOnError: false,
IpfsStorage: DefaultIpfsStorageServiceConfig,
}

func OptionalAddressFromString(s string) (*common.Address, error) {
Expand Down
Loading

0 comments on commit a26c9f3

Please sign in to comment.