Commit 43d516dd authored by Sebastian Stammler's avatar Sebastian Stammler

op-batcher: Add channel submission timeout parameter

The batcher needs to observe two different channel timeouts.
1. the consensus channel timeout, so it knows when to resubmit a channel
   whose frames didn't land on L1 quickly enough and
2. the channel submission timeout, by which time it closes the channel
   even if the target amount of data hasn't been put into the channel
   yet.
parent b7d57608
...@@ -32,11 +32,16 @@ type ( ...@@ -32,11 +32,16 @@ type (
} }
ChannelConfig struct { ChannelConfig struct {
// ChannelTimeout is the maximum duration, in seconds, to attempt completing // The maximum number of L1 blocks that the inclusion transactions of a
// an opened channel. The batcher can decide to set it shorter than the // channel's frames can span.
// actual timeout, since submitting continued channel data to L1 is not
// instantaneous. It's not worth it to work with nearly timed-out channels.
ChannelTimeout uint64 ChannelTimeout uint64
// ChannelSubTimeout is the maximum duration, in seconds, to attempt
// completing an opened channel. When reached, the channel is closed and all
// remaining frames are submitted. The batcher should set it shorter than
// the actual channel timeout (specified in number of L1 blocks), since
// submitting continued channel data to L1 is not instantaneous. It's not
// worth it to work with nearly timed-out channels.
ChannelSubTimeout uint64
// The maximum byte-size a frame can have. // The maximum byte-size a frame can have.
MaxFrameSize uint64 MaxFrameSize uint64
// The target number of frames to create per channel. Note that if the // The target number of frames to create per channel. Note that if the
...@@ -116,11 +121,11 @@ func (c *channelBuilder) Reset() error { ...@@ -116,11 +121,11 @@ func (c *channelBuilder) Reset() error {
return c.co.Reset() return c.co.Reset()
} }
// FramePublished calculates the timeout of this channel from the given frame // FramePublished calculates the submission timeout of this channel from the
// inclusion tx timestamp. If an older frame tx has already been seen, the // given frame inclusion tx timestamp. If an older frame tx has already been
// timeout is not updated. // seen, the timeout is not updated.
func (c *channelBuilder) FramePublished(ts uint64) { func (c *channelBuilder) FramePublished(ts uint64) {
timeout := ts + c.cfg.ChannelTimeout timeout := ts + c.cfg.ChannelSubTimeout
if c.timeout == 0 || c.timeout > timeout { if c.timeout == 0 || c.timeout > timeout {
c.timeout = timeout c.timeout = timeout
} }
......
...@@ -50,10 +50,18 @@ type CLIConfig struct { ...@@ -50,10 +50,18 @@ type CLIConfig struct {
// RollupRpc is the HTTP provider URL for the L2 rollup node. // RollupRpc is the HTTP provider URL for the L2 rollup node.
RollupRpc string RollupRpc string
// ChannelTimeout is the maximum amount of time to attempt completing an opened channel, // The maximum number of L1 blocks that the inclusion transactions of a
// as opposed to submitting missing blocks in new channels // channel's frames can span.
ChannelTimeout uint64 ChannelTimeout uint64
// ChannelSubTimeout is the maximum duration, in seconds, to attempt
// completing an opened channel. When reached, the channel is closed and all
// remaining frames are submitted. The batcher should set it shorter than
// the actual channel timeout (specified in number of L1 blocks), since
// submitting continued channel data to L1 is not instantaneous. It's not
// worth it to work with nearly timed-out channels.
ChannelSubTimeout uint64
// PollInterval is the delay between querying L2 for more transaction // PollInterval is the delay between querying L2 for more transaction
// and creating a new batch. // and creating a new batch.
PollInterval time.Duration PollInterval time.Duration
...@@ -141,6 +149,7 @@ func NewConfig(ctx *cli.Context) CLIConfig { ...@@ -141,6 +149,7 @@ func NewConfig(ctx *cli.Context) CLIConfig {
L2EthRpc: ctx.GlobalString(flags.L2EthRpcFlag.Name), L2EthRpc: ctx.GlobalString(flags.L2EthRpcFlag.Name),
RollupRpc: ctx.GlobalString(flags.RollupRpcFlag.Name), RollupRpc: ctx.GlobalString(flags.RollupRpcFlag.Name),
ChannelTimeout: ctx.GlobalUint64(flags.ChannelTimeoutFlag.Name), ChannelTimeout: ctx.GlobalUint64(flags.ChannelTimeoutFlag.Name),
ChannelSubTimeout: ctx.GlobalUint64(flags.ChannelSubTimeoutFlag.Name),
PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name), PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name),
NumConfirmations: ctx.GlobalUint64(flags.NumConfirmationsFlag.Name), NumConfirmations: ctx.GlobalUint64(flags.NumConfirmationsFlag.Name),
SafeAbortNonceTooLowCount: ctx.GlobalUint64(flags.SafeAbortNonceTooLowCountFlag.Name), SafeAbortNonceTooLowCount: ctx.GlobalUint64(flags.SafeAbortNonceTooLowCountFlag.Name),
......
...@@ -94,6 +94,7 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger) (*BatchSubmitte ...@@ -94,6 +94,7 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger) (*BatchSubmitte
BatchInboxAddress: batchInboxAddress, BatchInboxAddress: batchInboxAddress,
Channel: ChannelConfig{ Channel: ChannelConfig{
ChannelTimeout: cfg.ChannelTimeout, ChannelTimeout: cfg.ChannelTimeout,
ChannelSubTimeout: cfg.ChannelSubTimeout,
MaxFrameSize: cfg.MaxL1TxSize - 1, // subtract 1 byte for version MaxFrameSize: cfg.MaxL1TxSize - 1, // subtract 1 byte for version
TargetFrameSize: cfg.TargetL1TxSize - 1, // subtract 1 byte for version TargetFrameSize: cfg.TargetL1TxSize - 1, // subtract 1 byte for version
TargetNumFrames: cfg.TargetNumFrames, TargetNumFrames: cfg.TargetNumFrames,
......
...@@ -36,10 +36,16 @@ var ( ...@@ -36,10 +36,16 @@ var (
} }
ChannelTimeoutFlag = cli.Uint64Flag{ ChannelTimeoutFlag = cli.Uint64Flag{
Name: "channel-timeout", Name: "channel-timeout",
Usage: "The maximum duration (in seconds) to attempt completing an opened channel, as opposed to submitting L2 blocks into a new channel.", Usage: "The maximum number of L1 blocks that the inclusion transactions of a channel's frames can span",
Required: true, Required: true,
EnvVar: opservice.PrefixEnvVar(envVarPrefix, "CHANNEL_TIMEOUT"), EnvVar: opservice.PrefixEnvVar(envVarPrefix, "CHANNEL_TIMEOUT"),
} }
ChannelSubTimeoutFlag = cli.Uint64Flag{
Name: "channel-sub-timeout",
Usage: "The maximum duration (in seconds) to attempt completing an opened channel, as opposed to submitting L2 blocks into a new channel.",
Required: true,
EnvVar: opservice.PrefixEnvVar(envVarPrefix, "CHANNEL_SUB_TIMEOUT"),
}
PollIntervalFlag = cli.DurationFlag{ PollIntervalFlag = cli.DurationFlag{
Name: "poll-interval", Name: "poll-interval",
Usage: "Delay between querying L2 for more transactions and " + Usage: "Delay between querying L2 for more transactions and " +
...@@ -126,6 +132,7 @@ var requiredFlags = []cli.Flag{ ...@@ -126,6 +132,7 @@ var requiredFlags = []cli.Flag{
L2EthRpcFlag, L2EthRpcFlag,
RollupRpcFlag, RollupRpcFlag,
ChannelTimeoutFlag, ChannelTimeoutFlag,
ChannelSubTimeoutFlag,
PollIntervalFlag, PollIntervalFlag,
NumConfirmationsFlag, NumConfirmationsFlag,
SafeAbortNonceTooLowCountFlag, SafeAbortNonceTooLowCountFlag,
......
...@@ -328,6 +328,7 @@ func TestMigration(t *testing.T) { ...@@ -328,6 +328,7 @@ func TestMigration(t *testing.T) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 1.0, ApproxComprRatio: 1.0,
ChannelTimeout: deployCfg.ChannelTimeout, ChannelTimeout: deployCfg.ChannelTimeout,
ChannelSubTimeout: 24,
PollInterval: 50 * time.Millisecond, PollInterval: 50 * time.Millisecond,
NumConfirmations: 1, NumConfirmations: 1,
ResubmissionTimeout: 5 * time.Second, ResubmissionTimeout: 5 * time.Second,
......
...@@ -531,6 +531,7 @@ func (cfg SystemConfig) Start() (*System, error) { ...@@ -531,6 +531,7 @@ func (cfg SystemConfig) Start() (*System, error) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 1.0, ApproxComprRatio: 1.0,
ChannelTimeout: cfg.DeployConfig.ChannelTimeout, ChannelTimeout: cfg.DeployConfig.ChannelTimeout,
ChannelSubTimeout: 24,
PollInterval: 50 * time.Millisecond, PollInterval: 50 * time.Millisecond,
NumConfirmations: 1, NumConfirmations: 1,
ResubmissionTimeout: 5 * time.Second, ResubmissionTimeout: 5 * time.Second,
......
...@@ -124,6 +124,7 @@ services: ...@@ -124,6 +124,7 @@ services:
OP_BATCHER_TARGET_NUM_FRAMES: 1 OP_BATCHER_TARGET_NUM_FRAMES: 1
OP_BATCHER_APPROX_COMPR_RATIO: 1.0 OP_BATCHER_APPROX_COMPR_RATIO: 1.0
OP_BATCHER_CHANNEL_TIMEOUT: 40 OP_BATCHER_CHANNEL_TIMEOUT: 40
OP_BATCHER_CHANNEL_SUB_TIMEOUT: 0
OP_BATCHER_POLL_INTERVAL: 1s OP_BATCHER_POLL_INTERVAL: 1s
OP_BATCHER_NUM_CONFIRMATIONS: 1 OP_BATCHER_NUM_CONFIRMATIONS: 1
OP_BATCHER_SAFE_ABORT_NONCE_TOO_LOW_COUNT: 3 OP_BATCHER_SAFE_ABORT_NONCE_TOO_LOW_COUNT: 3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment