Skip to content

Commit

Permalink
Merge pull request #1813 from OffchainLabs/fix-koanf-lint-errors
Browse files Browse the repository at this point in the history
Fix koanf lint errors by matching koanf tags with field names
  • Loading branch information
anodar authored Aug 17, 2023
2 parents 4e7b9d2 + eda4972 commit 56b8434
Show file tree
Hide file tree
Showing 54 changed files with 661 additions and 653 deletions.
111 changes: 58 additions & 53 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,28 @@ const (
)

type BatchPosterConfig struct {
Enable bool `koanf:"enable"`
DisableDasFallbackStoreDataOnChain bool `koanf:"disable-das-fallback-store-data-on-chain" reload:"hot"`
MaxBatchSize int `koanf:"max-size" reload:"hot"`
MaxBatchPostDelay time.Duration `koanf:"max-delay" reload:"hot"`
WaitForMaxBatchPostDelay bool `koanf:"wait-for-max-delay" reload:"hot"`
BatchPollDelay time.Duration `koanf:"poll-delay" reload:"hot"`
PostingErrorDelay time.Duration `koanf:"error-delay" reload:"hot"`
CompressionLevel int `koanf:"compression-level" reload:"hot"`
DASRetentionPeriod time.Duration `koanf:"das-retention-period" reload:"hot"`
GasRefunderAddress string `koanf:"gas-refunder-address" reload:"hot"`
DataPoster dataposter.DataPosterConfig `koanf:"data-poster" reload:"hot"`
RedisUrl string `koanf:"redis-url"`
RedisLock redislock.SimpleCfg `koanf:"redis-lock" reload:"hot"`
ExtraBatchGas uint64 `koanf:"extra-batch-gas" reload:"hot"`
L1Wallet genericconf.WalletConfig `koanf:"parent-chain-wallet"`
L1BlockBound string `koanf:"l1-block-bound" reload:"hot"`
L1BlockBoundBypass time.Duration `koanf:"l1-block-bound-bypass" reload:"hot"`
Enable bool `koanf:"enable"`
DisableDasFallbackStoreDataOnChain bool `koanf:"disable-das-fallback-store-data-on-chain" reload:"hot"`
// Max batch size.
MaxSize int `koanf:"max-size" reload:"hot"`
// Max batch post delay.
MaxDelay time.Duration `koanf:"max-delay" reload:"hot"`
// Wait for max BatchPost delay.
WaitForMaxDelay bool `koanf:"wait-for-max-delay" reload:"hot"`
// Batch post polling delay.
PollDelay time.Duration `koanf:"poll-delay" reload:"hot"`
// Batch posting error delay.
ErrorDelay time.Duration `koanf:"error-delay" reload:"hot"`
CompressionLevel int `koanf:"compression-level" reload:"hot"`
DASRetentionPeriod time.Duration `koanf:"das-retention-period" reload:"hot"`
GasRefunderAddress string `koanf:"gas-refunder-address" reload:"hot"`
DataPoster dataposter.DataPosterConfig `koanf:"data-poster" reload:"hot"`
RedisUrl string `koanf:"redis-url"`
RedisLock redislock.SimpleCfg `koanf:"redis-lock" reload:"hot"`
ExtraBatchGas uint64 `koanf:"extra-batch-gas" reload:"hot"`
ParentChainWallet genericconf.WalletConfig `koanf:"parent-chain-wallet"`
L1BlockBound string `koanf:"l1-block-bound" reload:"hot"`
L1BlockBoundBypass time.Duration `koanf:"l1-block-bound-bypass" reload:"hot"`

gasRefunder common.Address
l1BlockBound l1BlockBound
Expand All @@ -115,7 +120,7 @@ func (c *BatchPosterConfig) Validate() error {
return fmt.Errorf("invalid gas refunder address \"%v\"", c.GasRefunderAddress)
}
c.gasRefunder = common.HexToAddress(c.GasRefunderAddress)
if c.MaxBatchSize <= 40 {
if c.MaxSize <= 40 {
return errors.New("MaxBatchSize too small")
}
if c.L1BlockBound == "" {
Expand All @@ -139,11 +144,11 @@ type BatchPosterConfigFetcher func() *BatchPosterConfig
func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".enable", DefaultBatchPosterConfig.Enable, "enable posting batches to l1")
f.Bool(prefix+".disable-das-fallback-store-data-on-chain", DefaultBatchPosterConfig.DisableDasFallbackStoreDataOnChain, "If unable to batch to DAS, disable fallback storing data on chain")
f.Int(prefix+".max-size", DefaultBatchPosterConfig.MaxBatchSize, "maximum batch size")
f.Duration(prefix+".max-delay", DefaultBatchPosterConfig.MaxBatchPostDelay, "maximum batch posting delay")
f.Bool(prefix+".wait-for-max-delay", DefaultBatchPosterConfig.WaitForMaxBatchPostDelay, "wait for the max batch delay, even if the batch is full")
f.Duration(prefix+".poll-delay", DefaultBatchPosterConfig.BatchPollDelay, "how long to delay after successfully posting batch")
f.Duration(prefix+".error-delay", DefaultBatchPosterConfig.PostingErrorDelay, "how long to delay after error posting batch")
f.Int(prefix+".max-size", DefaultBatchPosterConfig.MaxSize, "maximum batch size")
f.Duration(prefix+".max-delay", DefaultBatchPosterConfig.MaxDelay, "maximum batch posting delay")
f.Bool(prefix+".wait-for-max-delay", DefaultBatchPosterConfig.WaitForMaxDelay, "wait for the max batch delay, even if the batch is full")
f.Duration(prefix+".poll-delay", DefaultBatchPosterConfig.PollDelay, "how long to delay after successfully posting batch")
f.Duration(prefix+".error-delay", DefaultBatchPosterConfig.ErrorDelay, "how long to delay after error posting batch")
f.Int(prefix+".compression-level", DefaultBatchPosterConfig.CompressionLevel, "batch compression level")
f.Duration(prefix+".das-retention-period", DefaultBatchPosterConfig.DASRetentionPeriod, "In AnyTrust mode, the period which DASes are requested to retain the stored batches.")
f.String(prefix+".gas-refunder-address", DefaultBatchPosterConfig.GasRefunderAddress, "The gas refunder contract address (optional)")
Expand All @@ -153,50 +158,50 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
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)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.L1Wallet.Pathname)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname)
}

var DefaultBatchPosterConfig = BatchPosterConfig{
Enable: false,
DisableDasFallbackStoreDataOnChain: false,
MaxBatchSize: 100000,
BatchPollDelay: time.Second * 10,
PostingErrorDelay: time.Second * 10,
MaxBatchPostDelay: time.Hour,
WaitForMaxBatchPostDelay: false,
MaxSize: 100000,
PollDelay: time.Second * 10,
ErrorDelay: time.Second * 10,
MaxDelay: time.Hour,
WaitForMaxDelay: false,
CompressionLevel: brotli.BestCompression,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 50_000,
DataPoster: dataposter.DefaultDataPosterConfig,
L1Wallet: DefaultBatchPosterL1WalletConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Pathname: "batch-poster-wallet",
PasswordImpl: genericconf.WalletConfigDefault.PasswordImpl,
Password: genericconf.WalletConfigDefault.Password,
PrivateKey: genericconf.WalletConfigDefault.PrivateKey,
Account: genericconf.WalletConfigDefault.Account,
OnlyCreateKey: genericconf.WalletConfigDefault.OnlyCreateKey,
}

var TestBatchPosterConfig = BatchPosterConfig{
Enable: true,
MaxBatchSize: 100000,
BatchPollDelay: time.Millisecond * 10,
PostingErrorDelay: time.Millisecond * 10,
MaxBatchPostDelay: 0,
WaitForMaxBatchPostDelay: false,
CompressionLevel: 2,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
DataPoster: dataposter.TestDataPosterConfig,
L1Wallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
Enable: true,
MaxSize: 100000,
PollDelay: time.Millisecond * 10,
ErrorDelay: time.Millisecond * 10,
MaxDelay: 0,
WaitForMaxDelay: false,
CompressionLevel: 2,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
DataPoster: dataposter.TestDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
}

func NewBatchPoster(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) {
Expand Down Expand Up @@ -374,8 +379,8 @@ type buildingBatch struct {
}

func newBatchSegments(firstDelayed uint64, config *BatchPosterConfig, backlog uint64) *batchSegments {
compressedBuffer := bytes.NewBuffer(make([]byte, 0, config.MaxBatchSize*2))
if config.MaxBatchSize <= 40 {
compressedBuffer := bytes.NewBuffer(make([]byte, 0, config.MaxSize*2))
if config.MaxSize <= 40 {
panic("MaxBatchSize too small")
}
compressionLevel := config.CompressionLevel
Expand All @@ -401,7 +406,7 @@ func newBatchSegments(firstDelayed uint64, config *BatchPosterConfig, backlog ui
return &batchSegments{
compressedBuffer: compressedBuffer,
compressedWriter: brotli.NewWriterLevel(compressedBuffer, compressionLevel),
sizeLimit: config.MaxBatchSize - 40, // TODO
sizeLimit: config.MaxSize - 40, // TODO
recompressionLevel: recompressionLevel,
rawSegments: make([][]byte, 0, 128),
delayedMsg: firstDelayed,
Expand Down Expand Up @@ -717,7 +722,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
firstMsgTime := time.Unix(int64(firstMsg.Message.Header.Timestamp), 0)

config := b.config()
forcePostBatch := time.Since(firstMsgTime) >= config.MaxBatchPostDelay
forcePostBatch := time.Since(firstMsgTime) >= config.MaxDelay

var l1BoundMaxBlockNumber uint64 = math.MaxUint64
var l1BoundMaxTimestamp uint64 = math.MaxUint64
Expand Down Expand Up @@ -815,7 +820,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}
if !success {
// this batch is full
if !config.WaitForMaxBatchPostDelay {
if !config.WaitForMaxDelay {
forcePostBatch = true
}
b.building.haveUsefulMessage = true
Expand Down Expand Up @@ -930,7 +935,7 @@ func (b *BatchPoster) Start(ctxIn context.Context) {
}
if !b.redisLock.AttemptLock(ctx) {
b.building = nil
return b.config().BatchPollDelay
return b.config().PollDelay
}
posted, err := b.maybePostSequencerBatch(ctx)
if err != nil {
Expand All @@ -949,11 +954,11 @@ func (b *BatchPoster) Start(ctxIn context.Context) {
b.firstAccErr = time.Time{}
}
logLevel("error posting batch", "err", err)
return b.config().PostingErrorDelay
return b.config().ErrorDelay
} else if posted {
return 0
} else {
return b.config().BatchPollDelay
return b.config().PollDelay
}
})
}
Expand Down
40 changes: 20 additions & 20 deletions arbnode/execution/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (
)

type CachingConfig struct {
Archive bool `koanf:"archive"`
BlockCount uint64 `koanf:"block-count"`
BlockAge time.Duration `koanf:"block-age"`
TrieTimeLimit time.Duration `koanf:"trie-time-limit"`
TrieDirtyCache int `koanf:"trie-dirty-cache"`
TrieCleanCache int `koanf:"trie-clean-cache"`
SnapshotCache int `koanf:"snapshot-cache"`
DatabaseCache int `koanf:"database-cache"`
SnapshotRestoreMaxGas uint64 `koanf:"snapshot-restore-gas-limit"`
Archive bool `koanf:"archive"`
BlockCount uint64 `koanf:"block-count"`
BlockAge time.Duration `koanf:"block-age"`
TrieTimeLimit time.Duration `koanf:"trie-time-limit"`
TrieDirtyCache int `koanf:"trie-dirty-cache"`
TrieCleanCache int `koanf:"trie-clean-cache"`
SnapshotCache int `koanf:"snapshot-cache"`
DatabaseCache int `koanf:"database-cache"`
SnapshotRestoreGasLimit uint64 `koanf:"snapshot-restore-gas-limit"`
}

func CachingConfigAddOptions(prefix string, f *flag.FlagSet) {
Expand All @@ -46,19 +46,19 @@ func CachingConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Int(prefix+".trie-clean-cache", DefaultCachingConfig.TrieCleanCache, "amount of memory in megabytes to cache unchanged state trie nodes with")
f.Int(prefix+".snapshot-cache", DefaultCachingConfig.SnapshotCache, "amount of memory in megabytes to cache state snapshots with")
f.Int(prefix+".database-cache", DefaultCachingConfig.DatabaseCache, "amount of memory in megabytes to cache database contents with")
f.Uint64(prefix+".snapshot-restore-gas-limit", DefaultCachingConfig.SnapshotRestoreMaxGas, "maximum gas rolled back to recover snapshot")
f.Uint64(prefix+".snapshot-restore-gas-limit", DefaultCachingConfig.SnapshotRestoreGasLimit, "maximum gas rolled back to recover snapshot")
}

var DefaultCachingConfig = CachingConfig{
Archive: false,
BlockCount: 128,
BlockAge: 30 * time.Minute,
TrieTimeLimit: time.Hour,
TrieDirtyCache: 1024,
TrieCleanCache: 600,
SnapshotCache: 400,
DatabaseCache: 2048,
SnapshotRestoreMaxGas: 300_000_000_000,
Archive: false,
BlockCount: 128,
BlockAge: 30 * time.Minute,
TrieTimeLimit: time.Hour,
TrieDirtyCache: 1024,
TrieCleanCache: 600,
SnapshotCache: 400,
DatabaseCache: 2048,
SnapshotRestoreGasLimit: 300_000_000_000,
}

func DefaultCacheConfigFor(stack *node.Node, cachingConfig *CachingConfig) *core.CacheConfig {
Expand All @@ -79,7 +79,7 @@ func DefaultCacheConfigFor(stack *node.Node, cachingConfig *CachingConfig) *core
TrieRetention: cachingConfig.BlockAge,
SnapshotLimit: cachingConfig.SnapshotCache,
Preimages: baseConf.Preimages,
SnapshotRestoreMaxGas: cachingConfig.SnapshotRestoreMaxGas,
SnapshotRestoreMaxGas: cachingConfig.SnapshotRestoreGasLimit,
}
}

Expand Down
17 changes: 9 additions & 8 deletions arbnode/message_pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ type MessagePruner struct {
}

type MessagePrunerConfig struct {
Enable bool `koanf:"enable"`
MessagePruneInterval time.Duration `koanf:"prune-interval" reload:"hot"`
MinBatchesLeft uint64 `koanf:"min-batches-left" reload:"hot"`
Enable bool `koanf:"enable"`
// Message pruning interval.
PruneInterval time.Duration `koanf:"prune-interval" reload:"hot"`
MinBatchesLeft uint64 `koanf:"min-batches-left" reload:"hot"`
}

type MessagePrunerConfigFetcher func() *MessagePrunerConfig

var DefaultMessagePrunerConfig = MessagePrunerConfig{
Enable: true,
MessagePruneInterval: time.Minute,
MinBatchesLeft: 2,
Enable: true,
PruneInterval: time.Minute,
MinBatchesLeft: 2,
}

func MessagePrunerConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".enable", DefaultMessagePrunerConfig.Enable, "enable message pruning")
f.Duration(prefix+".prune-interval", DefaultMessagePrunerConfig.MessagePruneInterval, "interval for running message pruner")
f.Duration(prefix+".prune-interval", DefaultMessagePrunerConfig.PruneInterval, "interval for running message pruner")
f.Uint64(prefix+".min-batches-left", DefaultMessagePrunerConfig.MinBatchesLeft, "min number of batches not pruned")
}

Expand All @@ -70,7 +71,7 @@ func (m *MessagePruner) UpdateLatestConfirmed(count arbutil.MessageIndex, global
return
}

if m.lastPruneDone.Add(m.config().MessagePruneInterval).After(time.Now()) {
if m.lastPruneDone.Add(m.config().PruneInterval).After(time.Now()) {
m.pruningLock.Unlock()
return
}
Expand Down
Loading

0 comments on commit 56b8434

Please sign in to comment.