Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions op-devstack/sysgo/l2_cl_kona_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func resolveKonaL2CLConfig(t devtest.T, key string, chainID eth.ChainID, isSeque
unsupported.VerifierSyncMode = baseCfg.VerifierSyncMode
unsupported.SafeDBPath = ""
unsupported.VerifierL1Confs = 0
unsupported.OffsetELSafe = 0
unsupported.NoDiscovery = baseCfg.NoDiscovery
unsupported.FollowSource = ""
if isSequencer {
Expand All @@ -57,6 +58,7 @@ func resolveKonaL2CLConfig(t devtest.T, key string, chainID eth.ChainID, isSeque
unsupported.ConductorRPCTimeout = 0
t.Require().Equal(baseCfg, unsupported, "unsupported L2CL option for kona-node")

t.Require().GreaterOrEqual(cfg.OffsetELSafe, time.Duration(0), "EL-sync safe offset must not be negative")
if cfg.ConductorRPC != "" {
t.Require().Positive(cfg.ConductorRPCTimeout, "conductor RPC timeout must be positive")
t.Require().Zero(cfg.ConductorRPCTimeout%time.Second, "Kona conductor RPC timeout must use whole seconds")
Expand All @@ -69,6 +71,18 @@ func konaL2CLEnv(cfg *L2CLConfig, sequencerStopped bool) []string {
fmt.Sprintf("KONA_NODE_P2P_NO_DISCOVERY=%t", cfg.NoDiscovery),
fmt.Sprintf("KONA_NODE_VERIFIER_L1_CONFS=%d", cfg.VerifierL1Confs),
}
// kona-node has no CL-sync mode: it completes EL sync whenever its execution layer has no
// finality yet. Like op-node, apply the offset only to a node configured for EL sync. Any
// other node keeps kona-node's 12h default, which on a young devnet places safe and
// finalized at genesis instead of marking unsafe blocks final.
syncMode := cfg.VerifierSyncMode
if cfg.IsSequencer {
syncMode = cfg.SequencerSyncMode
}
if syncMode == nodeSync.ELSync {
extraEnv = append(extraEnv,
fmt.Sprintf("KONA_NODE_SYNCMODE_OFFSET_EL_SAFE=%dms", cfg.OffsetELSafe.Milliseconds()))
}
if cfg.SafeDBPath != "" {
extraEnv = append(extraEnv, "KONA_NODE_SAFEDB_PATH="+cfg.SafeDBPath)
}
Expand Down
34 changes: 32 additions & 2 deletions op-devstack/sysgo/l2_cl_kona_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ func TestKonaL2CLEnvAcceptsSyncModeCompatibilityInputs(t *testing.T) {
})}
// Neither compatibility mode emits a flag pretending to select a
// native mode: Kona always drives EL sync through Engine API responses.
require.Equal(t, []string{"KONA_NODE_P2P_NO_DISCOVERY=true", "KONA_NODE_VERIFIER_L1_CONFS=0"},
// EL sync only adds its safe offset, as it does for op-node.
want := []string{"KONA_NODE_P2P_NO_DISCOVERY=true", "KONA_NODE_VERIFIER_L1_CONFS=0"}
if mode == nodeSync.ELSync {
want = append(want, "KONA_NODE_SYNCMODE_OFFSET_EL_SAFE=0ms")
}
require.Equal(t, want,
konaL2CLEnv(resolveKonaL2CLConfig(devtest.SerialT(t), "node", eth.ChainIDFromUInt64(901), isSequencer, "", opts), false))
})
}
Expand Down Expand Up @@ -136,7 +141,7 @@ func TestKonaL2CLConfigRejectsUnsupportedOptions(t *testing.T) {
apply func(*L2CLConfig)
message string
}{
{"safe offset", true, func(cfg *L2CLConfig) { cfg.OffsetELSafe = time.Second }, "unsupported L2CL option"},
{"negative safe offset", true, func(cfg *L2CLConfig) { cfg.OffsetELSafe = -time.Second }, "must not be negative"},
{"role override", true, func(cfg *L2CLConfig) { cfg.IsSequencer = false }, "unsupported L2CL option"},
{"sequencer sync", true, func(cfg *L2CLConfig) { cfg.SequencerSyncMode = nodeSync.Mode(99) }, "unknown effective sync mode"},
{"verifier sync", false, func(cfg *L2CLConfig) { cfg.VerifierSyncMode = nodeSync.Mode(99) }, "unknown effective sync mode"},
Expand Down Expand Up @@ -216,3 +221,28 @@ func TestKonaL2CLEnvVerifierL1Confs(t *testing.T) {
}
}
}

func TestKonaL2CLEnvOffsetELSafe(t *testing.T) {
t.Setenv("KONA_NODE_P2P_NO_DISCOVERY", "true")
for _, isSequencer := range []bool{false, true} {
for _, mode := range nodeSync.Modes {
for offset, want := range map[time.Duration]string{0: "0ms", 90 * time.Second: "90000ms", 1500 * time.Millisecond: "1500ms"} {
t.Run(fmt.Sprintf("sequencer=%t/mode=%s/offset=%s", isSequencer, mode, offset), func(t *testing.T) {
opts := []L2CLOption{L2CLOptionFn(func(_ devtest.T, _ ComponentTarget, cfg *L2CLConfig) {
cfg.SequencerSyncMode, cfg.VerifierSyncMode = mode, mode
cfg.OffsetELSafe = offset
})}
env := konaL2CLEnv(resolveKonaL2CLConfig(devtest.SerialT(t), "node", eth.ChainIDFromUInt64(901), isSequencer, "", opts), false)
if mode == nodeSync.ELSync {
require.Contains(t, env, "KONA_NODE_SYNCMODE_OFFSET_EL_SAFE="+want)
} else {
// Like op-node, the offset applies only to EL sync.
for _, entry := range env {
require.NotContains(t, entry, "KONA_NODE_SYNCMODE_OFFSET_EL_SAFE")
}
}
})
}
}
}
}
3 changes: 1 addition & 2 deletions op-devstack/sysgo/singlechain_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sysgo
import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand All @@ -20,7 +19,7 @@ func TestKonaOptionsRejectedBeforeStartup(t *testing.T) {
dt := &rejectedKonaOptionTest{T: devtest.SerialT(t)}
network := &L2Network{chainID: eth.ChainIDFromUInt64(901)}
opts := []L2CLOption{L2CLOptionFn(func(_ devtest.T, _ ComponentTarget, cfg *L2CLConfig) {
cfg.OffsetELSafe = time.Second
cfg.IsSequencer = false
})}
// Nil startup dependencies ensure validation runs before starting any process or RPC.
require.PanicsWithValue(t, "Kona option rejected", func() {
Expand Down
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/kona/bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ op-alloy-network.workspace = true
# general
url.workspace = true
dirs.workspace = true
humantime.workspace = true
strum.workspace = true
discv5.workspace = true
enr.workspace = true
Expand Down
15 changes: 15 additions & 0 deletions rust/kona/bin/node/src/commands/node/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use anyhow::{Context as _, Result, bail};
use backon::{ExponentialBuilder, Retryable};
use clap::Parser;
use kona_cli::{LogConfig, MetricsArgs};
use kona_engine::DEFAULT_EL_SYNC_SAFE_OFFSET;
use kona_genesis::{L1ChainConfig, RollupConfig};
use kona_interop::DependencySet;
use kona_node_service::{EngineConfig, L1ConfigBuilder, NodeMode, RollupNodeBuilder};
Expand All @@ -29,6 +30,7 @@ use std::{
num::NonZeroUsize,
path::PathBuf,
sync::Arc,
time::Duration,
};
use strum::IntoEnumIterator;
use tracing::{debug, error, info};
Expand Down Expand Up @@ -145,6 +147,17 @@ pub struct NodeCommand {
/// Reorgs are supported, but may be slow to recover from.
#[arg(long = "verifier.l1-confs", env = "KONA_NODE_VERIFIER_L1_CONFS", default_value_t = 0)]
pub verifier_l1_confs: u64,
/// After execution-layer sync, set the safe and finalized heads this far behind the synced tip
/// (converted to L2 blocks with ceiling division). Mirrors op-node's
/// `--syncmode.offset-el-safe`. kona-node has no consensus-layer sync mode, so this applies on
/// any start where the execution layer has no finalized block beyond genesis.
#[arg(
long = "syncmode.offset-el-safe",
env = "KONA_NODE_SYNCMODE_OFFSET_EL_SAFE",
default_value = "12h",
value_parser = humantime::parse_duration,
)]
pub el_sync_safe_offset: Duration,
/// P2P CLI arguments.
#[command(flatten)]
pub p2p_flags: P2PArgs,
Expand All @@ -167,6 +180,7 @@ impl Default for NodeCommand {
interop_dependency_set: None,
safedb_path: None,
verifier_l1_confs: 0,
el_sync_safe_offset: DEFAULT_EL_SYNC_SAFE_OFFSET,
node_mode: NodeMode::Validator,
p2p_flags: P2PArgs::default(),
rpc_flags: RpcArgs::default(),
Expand Down Expand Up @@ -363,6 +377,7 @@ impl NodeCommand {
.with_dependency_set(dependency_set)
.with_safe_db(safe_db)
.with_verifier_l1_confs(self.verifier_l1_confs)
.with_el_sync_safe_offset(self.el_sync_safe_offset)
.build()
.start()
.await
Expand Down
35 changes: 35 additions & 0 deletions rust/kona/bin/node/src/commands/node/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ fn verifier_confirmation_depth_has_the_expected_environment_variable() {
assert_eq!(arg.get_env().unwrap(), "KONA_NODE_VERIFIER_L1_CONFS");
}

/// Like op-node, the EL-sync safe offset defaults to 12h and takes durations such as `30m`,
/// including the milliseconds devstack passes and Go's `12h0m0s` form.
#[rstest::rstest]
#[case::default(None, 12 * 60 * 60)]
#[case::minutes(Some("30m"), 30 * 60)]
#[case::disabled(Some("0s"), 0)]
#[case::milliseconds(Some("90000ms"), 90)]
#[case::zero_milliseconds(Some("0ms"), 0)]
#[case::go_duration(Some("12h0m0s"), 12 * 60 * 60)]
fn el_sync_safe_offset_parses_durations(#[case] flag: Option<&str>, #[case] seconds: u64) {
let flag = flag.map(|value| ["--syncmode.offset-el-safe", value]);
let args = NodeCommand::parse_from(
std::iter::once("node")
.chain(default_flags().iter().copied())
.chain(flag.into_iter().flatten()),
);
assert_eq!(args.el_sync_safe_offset, std::time::Duration::from_secs(seconds));
}

#[test]
fn el_sync_safe_offset_default_matches_the_engine() {
assert_eq!(
NodeCommand::default().el_sync_safe_offset,
kona_engine::DEFAULT_EL_SYNC_SAFE_OFFSET
);
}

#[test]
fn el_sync_safe_offset_has_the_expected_environment_variable() {
use clap::CommandFactory;
let command = NodeCommand::command();
let arg = command.get_arguments().find(|arg| arg.get_id() == "el_sync_safe_offset").unwrap();
assert_eq!(arg.get_env().unwrap(), "KONA_NODE_SYNCMODE_OFFSET_EL_SAFE");
}

#[test]
fn test_node_cli_missing_l1_eth_rpc() {
let err = NodeCommand::try_parse_from(["node"]).unwrap_err();
Expand Down
5 changes: 4 additions & 1 deletion rust/kona/crates/node/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ mod metrics;
pub use metrics::Metrics;

mod sync;
pub use sync::{L2ForkchoiceState, SyncStartError, find_starting_forkchoice};
pub use sync::{
DEFAULT_EL_SYNC_SAFE_OFFSET, L2ForkchoiceState, SyncStartError, find_el_sync_forkchoice,
find_starting_forkchoice,
};

#[cfg(any(test, feature = "test-utils"))]
/// Utilities that are useful when creating unit tests using structs within this library.
Expand Down
Loading
Loading