Skip to content

Commit

Permalink
Merge pull request OffchainLabs#1579 from OffchainLabs/batch-delay
Browse files Browse the repository at this point in the history
Add an option to wait for the max batch delay, even if the batch is full
  • Loading branch information
PlasmaPower authored Apr 20, 2023
2 parents 2475e11 + 721c3ae commit 8af02e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
36 changes: 21 additions & 15 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ 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"`
MaxBatchPostInterval time.Duration `koanf:"max-interval" 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"`
Expand Down Expand Up @@ -98,7 +99,8 @@ func BatchPosterConfigAddOptions(prefix string, f *flag.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-interval", DefaultBatchPosterConfig.MaxBatchPostInterval, "maximum batch posting interval")
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+".compression-level", DefaultBatchPosterConfig.CompressionLevel, "batch compression level")
Expand All @@ -116,7 +118,8 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
MaxBatchSize: 100000,
BatchPollDelay: time.Second * 10,
PostingErrorDelay: time.Second * 10,
MaxBatchPostInterval: time.Hour,
MaxBatchPostDelay: time.Hour,
WaitForMaxBatchPostDelay: false,
CompressionLevel: brotli.BestCompression,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
Expand All @@ -125,16 +128,17 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
}

var TestBatchPosterConfig = BatchPosterConfig{
Enable: true,
MaxBatchSize: 100000,
BatchPollDelay: time.Millisecond * 10,
PostingErrorDelay: time.Millisecond * 10,
MaxBatchPostInterval: 0,
CompressionLevel: 2,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
DataPoster: dataposter.TestDataPosterConfig,
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,
}

func NewBatchPoster(l1Reader *headerreader.HeaderReader, inbox *InboxTracker, streamer *TransactionStreamer, syncMonitor *SyncMonitor, config BatchPosterConfigFetcher, deployInfo *RollupAddresses, transactOpts *bind.TransactOpts, daWriter das.DataAvailabilityServiceWriter) (*BatchPoster, error) {
Expand Down Expand Up @@ -559,7 +563,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
nextMessageTime := time.Unix(int64(firstMsg.Message.Header.Timestamp), 0)

config := b.config()
forcePostBatch := time.Since(nextMessageTime) >= config.MaxBatchPostInterval
forcePostBatch := time.Since(nextMessageTime) >= config.MaxBatchPostDelay
haveUsefulMessage := false

for b.building.msgCount < msgCount {
Expand All @@ -576,7 +580,9 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}
if !success {
// this batch is full
forcePostBatch = true
if !config.WaitForMaxBatchPostDelay {
forcePostBatch = true
}
haveUsefulMessage = true
break
}
Expand Down
2 changes: 1 addition & 1 deletion system_tests/batch_poster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestBatchPosterKeepsUp(t *testing.T) {

conf := arbnode.ConfigDefaultL1Test()
conf.BatchPoster.CompressionLevel = brotli.BestCompression
conf.BatchPoster.MaxBatchPostInterval = time.Hour
conf.BatchPoster.MaxBatchPostDelay = time.Hour
conf.RPC.RPCTxFeeCap = 1000.
l2info, nodeA, l2clientA, _, _, _, l1stack := createTestNodeOnL1WithConfig(t, ctx, true, conf, nil, nil)
defer requireClose(t, l1stack)
Expand Down
2 changes: 1 addition & 1 deletion testnode-scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function writeConfigs(argv: any) {
"batch-poster": {
"enable": false,
"redis-url": argv.redisUrl,
"max-interval": "30s",
"max-delay": "30s",
"data-poster": {
"redis-signer": {
"signing-key": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Expand Down

0 comments on commit 8af02e0

Please sign in to comment.