Skip to content

Commit 32c5b23

Browse files
authored
fix(manager): refactor lazy mode flags (#1800)
## Overview Following up #1779 the new flag `LazyBufferTime` has been removed to simplify lazy mode flags. We use a hardcoded value of `defaultLazySleepPercent = 10` to indicate a wait time equal to 10% of the block time. It might be possible to expose this as a flag if users request. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced configurability of transaction accumulation by shifting from a static time-based approach to a dynamic percentage-based system. - **Bug Fixes** - Improved accuracy in sleep duration calculations related to block manager behavior. - **Chores** - Simplified node configuration by removing the `LazyBufferTime` parameter, streamlining operational parameters. - Simplified command-line options by removing the `--rollkit.lazy_buffer_time` parameter. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3e85450 commit 32c5b23

5 files changed

Lines changed: 8 additions & 25 deletions

File tree

block/manager.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ import (
3535
"github.com/rollkit/rollkit/types"
3636
)
3737

38-
// defaultLazyBufferTime is the additional time to wait to accumulate transactions
39-
// in lazy mode
40-
const defaultLazyBufferTime = 1 * time.Second
38+
// defaultLazySleepPercent is the percentage of block time to wait to accumulate transactions
39+
// in lazy mode.
40+
// A value of 10 for e.g. corresponds to 10% of the block time. Must be between 0 and 100.
41+
const defaultLazySleepPercent = 10
4142

4243
// defaultDABlockTime is used only if DABlockTime is not configured for manager
4344
const defaultDABlockTime = 15 * time.Second
@@ -202,11 +203,6 @@ func NewManager(
202203
conf.LazyBlockTime = defaultLazyBlockTime
203204
}
204205

205-
if conf.LazyBufferTime == 0 {
206-
logger.Info("Using default lazy buffer time", "LazyBufferTime", defaultLazyBufferTime)
207-
conf.LazyBufferTime = defaultLazyBufferTime
208-
}
209-
210206
if conf.DAMempoolTTL == 0 {
211207
logger.Info("Using default mempool ttl", "MempoolTTL", defaultMempoolTTL)
212208
conf.DAMempoolTTL = defaultMempoolTTL
@@ -363,12 +359,9 @@ func (m *Manager) getRemainingSleep(start time.Time) time.Duration {
363359

364360
if m.conf.LazyAggregator {
365361
if m.buildingBlock && elapsed >= interval {
366-
// LazyBufferTime is used to give time for transactions to
367-
// accumulate if we are coming out of a period of inactivity. If we
368-
// had recently produced a block (i.e. within the block time) then
369-
// we will sleep for the remaining time within the block time
370-
// interval.
371-
return m.conf.LazyBufferTime
362+
// Special case to give time for transactions to accumulate if we
363+
// are coming out of a period of inactivity.
364+
return (interval * time.Duration(defaultLazySleepPercent) / 100)
372365
} else if !m.buildingBlock {
373366
interval = m.conf.LazyBlockTime
374367
}

block/manager_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,12 @@ func TestManager_getRemainingSleep(t *testing.T) {
724724
conf: config.BlockManagerConfig{
725725
BlockTime: 10 * time.Second,
726726
LazyBlockTime: 20 * time.Second,
727-
LazyBufferTime: defaultLazyBufferTime,
728727
LazyAggregator: true,
729728
},
730729
buildingBlock: true,
731730
},
732731
start: time.Now().Add(-15 * time.Second),
733-
expectedSleep: defaultLazyBufferTime,
732+
expectedSleep: (10 * time.Second * time.Duration(defaultLazySleepPercent) / 100),
734733
},
735734
{
736735
name: "Lazy aggregation, not building block, elapsed < interval",

cmd/rollkit/docs/rollkit_start.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ rollkit start [flags]
4141
--rollkit.da_start_height uint starting DA block height (for syncing)
4242
--rollkit.lazy_aggregator wait for transactions, don't build empty blocks
4343
--rollkit.lazy_block_time duration block time (for lazy mode) (default 1m0s)
44-
--rollkit.lazy_buffer_time duration additional time to wait to accumulate transactions in lazy mode (default 1s)
4544
--rollkit.light run light client
4645
--rollkit.max_pending_blocks uint limit of blocks pending DA submission (0 for no limit)
4746
--rollkit.trusted_hash string initial trusted hash to start the header exchange service

config/config.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ const (
4040
FlagDAMempoolTTL = "rollkit.da_mempool_ttl"
4141
// FlagLazyBlockTime is a flag for specifying the block time in lazy mode
4242
FlagLazyBlockTime = "rollkit.lazy_block_time"
43-
// FlagLazyBufferTime is a flag for specifying the additional time to wait to accumulate transactions in lazy mode
44-
FlagLazyBufferTime = "rollkit.lazy_buffer_time"
4543
)
4644

4745
// NodeConfig stores Rollkit node configuration.
@@ -89,9 +87,6 @@ type BlockManagerConfig struct {
8987
// LazyBlockTime defines how often new blocks are produced in lazy mode
9088
// even if there are no transactions
9189
LazyBlockTime time.Duration `mapstructure:"lazy_block_time"`
92-
// LazyBufferTime defines the additional time to wait to accumulate
93-
// transactions in lazy mode
94-
LazyBufferTime time.Duration `mapstructure:"lazy_buffer_time"`
9590
}
9691

9792
// GetNodeConfig translates Tendermint's configuration into Rollkit configuration.
@@ -140,7 +135,6 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
140135
nc.MaxPendingBlocks = v.GetUint64(FlagMaxPendingBlocks)
141136
nc.DAMempoolTTL = v.GetUint64(FlagDAMempoolTTL)
142137
nc.LazyBlockTime = v.GetDuration(FlagLazyBlockTime)
143-
nc.LazyBufferTime = v.GetDuration(FlagLazyBufferTime)
144138
return nil
145139
}
146140

@@ -164,5 +158,4 @@ func AddFlags(cmd *cobra.Command) {
164158
cmd.Flags().Uint64(FlagMaxPendingBlocks, def.MaxPendingBlocks, "limit of blocks pending DA submission (0 for no limit)")
165159
cmd.Flags().Uint64(FlagDAMempoolTTL, def.DAMempoolTTL, "number of DA blocks until transaction is dropped from the mempool")
166160
cmd.Flags().Duration(FlagLazyBlockTime, def.LazyBlockTime, "block time (for lazy mode)")
167-
cmd.Flags().Duration(FlagLazyBufferTime, def.LazyBufferTime, "additional time to wait to accumulate transactions in lazy mode")
168161
}

config/defaults.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var DefaultNodeConfig = NodeConfig{
2626
DABlockTime: 15 * time.Second,
2727
LazyAggregator: false,
2828
LazyBlockTime: 60 * time.Second,
29-
LazyBufferTime: 1 * time.Second,
3029
},
3130
DAAddress: "http://localhost:26658",
3231
DAGasPrice: -1,

0 commit comments

Comments
 (0)