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 (
}
ChannelConfig struct {
// ChannelTimeout is the maximum duration, in seconds, to attempt completing
// an opened channel. The batcher can decide to set it shorter than the
// actual timeout, since submitting continued channel data to L1 is not
// instantaneous. It's not worth it to work with nearly timed-out channels.
// The maximum number of L1 blocks that the inclusion transactions of a
// channel's frames can span.
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.
MaxFrameSize uint64
// The target number of frames to create per channel. Note that if the
......@@ -116,11 +121,11 @@ func (c *channelBuilder) Reset() error {
return c.co.Reset()
}
// FramePublished calculates the timeout of this channel from the given frame
// inclusion tx timestamp. If an older frame tx has already been seen, the
// timeout is not updated.
// FramePublished calculates the submission timeout of this channel from the
// given frame inclusion tx timestamp. If an older frame tx has already been
// seen, the timeout is not updated.
func (c *channelBuilder) FramePublished(ts uint64) {
timeout := ts + c.cfg.ChannelTimeout
timeout := ts + c.cfg.ChannelSubTimeout
if c.timeout == 0 || c.timeout > timeout {
c.timeout = timeout
}
......
......@@ -50,10 +50,18 @@ type CLIConfig struct {
// RollupRpc is the HTTP provider URL for the L2 rollup node.
RollupRpc string
// ChannelTimeout is the maximum amount of time to attempt completing an opened channel,
// as opposed to submitting missing blocks in new channels
// The maximum number of L1 blocks that the inclusion transactions of a
// channel's frames can span.
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
// and creating a new batch.
PollInterval time.Duration
......@@ -141,6 +149,7 @@ func NewConfig(ctx *cli.Context) CLIConfig {
L2EthRpc: ctx.GlobalString(flags.L2EthRpcFlag.Name),
RollupRpc: ctx.GlobalString(flags.RollupRpcFlag.Name),
ChannelTimeout: ctx.GlobalUint64(flags.ChannelTimeoutFlag.Name),
ChannelSubTimeout: ctx.GlobalUint64(flags.ChannelSubTimeoutFlag.Name),
PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name),
NumConfirmations: ctx.GlobalUint64(flags.NumConfirmationsFlag.Name),
SafeAbortNonceTooLowCount: ctx.GlobalUint64(flags.SafeAbortNonceTooLowCountFlag.Name),
......
......@@ -93,11 +93,12 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger) (*BatchSubmitte
SignerFnFactory: signer,
BatchInboxAddress: batchInboxAddress,
Channel: ChannelConfig{
ChannelTimeout: cfg.ChannelTimeout,
MaxFrameSize: cfg.MaxL1TxSize - 1, // subtract 1 byte for version
TargetFrameSize: cfg.TargetL1TxSize - 1, // subtract 1 byte for version
TargetNumFrames: cfg.TargetNumFrames,
ApproxComprRatio: cfg.ApproxComprRatio,
ChannelTimeout: cfg.ChannelTimeout,
ChannelSubTimeout: cfg.ChannelSubTimeout,
MaxFrameSize: cfg.MaxL1TxSize - 1, // subtract 1 byte for version
TargetFrameSize: cfg.TargetL1TxSize - 1, // subtract 1 byte for version
TargetNumFrames: cfg.TargetNumFrames,
ApproxComprRatio: cfg.ApproxComprRatio,
},
}
......
......@@ -36,10 +36,16 @@ var (
}
ChannelTimeoutFlag = cli.Uint64Flag{
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,
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{
Name: "poll-interval",
Usage: "Delay between querying L2 for more transactions and " +
......@@ -126,6 +132,7 @@ var requiredFlags = []cli.Flag{
L2EthRpcFlag,
RollupRpcFlag,
ChannelTimeoutFlag,
ChannelSubTimeoutFlag,
PollIntervalFlag,
NumConfirmationsFlag,
SafeAbortNonceTooLowCountFlag,
......
......@@ -328,6 +328,7 @@ func TestMigration(t *testing.T) {
TargetNumFrames: 1,
ApproxComprRatio: 1.0,
ChannelTimeout: deployCfg.ChannelTimeout,
ChannelSubTimeout: 24,
PollInterval: 50 * time.Millisecond,
NumConfirmations: 1,
ResubmissionTimeout: 5 * time.Second,
......
......@@ -531,6 +531,7 @@ func (cfg SystemConfig) Start() (*System, error) {
TargetNumFrames: 1,
ApproxComprRatio: 1.0,
ChannelTimeout: cfg.DeployConfig.ChannelTimeout,
ChannelSubTimeout: 24,
PollInterval: 50 * time.Millisecond,
NumConfirmations: 1,
ResubmissionTimeout: 5 * time.Second,
......
......@@ -124,6 +124,7 @@ services:
OP_BATCHER_TARGET_NUM_FRAMES: 1
OP_BATCHER_APPROX_COMPR_RATIO: 1.0
OP_BATCHER_CHANNEL_TIMEOUT: 40
OP_BATCHER_CHANNEL_SUB_TIMEOUT: 0
OP_BATCHER_POLL_INTERVAL: 1s
OP_BATCHER_NUM_CONFIRMATIONS: 1
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