Skip to content
236 changes: 0 additions & 236 deletions op-acceptance-tests/tests/sync/elsync/gap_elp2p/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,248 +4,12 @@ import (
"testing"

"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-devstack/sysgo"
"github.com/ethereum-optimism/optimism/op-service/eth"

safety "github.com/ethereum-optimism/optimism/op-service/eth/safety"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
)

// TestL2ELP2PCanonicalChainAdvancedByFCU verifies the interaction between NewPayload,
// ForkchoiceUpdate (FCU), and ELP2P/EL sync in a multi-node L2 test network.
//
// Scenario
// - Start a single-chain, multi-node system without ELP2P connectivity for L2ELB.
// - Advance the reference node (L2EL) so it is ahead of L2ELB.
//
// Expectations covered by this test
//
// NewPayload without parents present:
// - Does NOT trigger EL sync.
// - Returns SYNCING for future blocks (startNum+3/5/4/6).
//
// NewPayload on a non canonical chain with available state:
// - Can extend a non canonical chain (startNum+1 then +2) and returns VALID.
// - These non canonical chain blocks are retrievable by hash but remain non-canonical
// (BlockRefByNumber returns NotFound) until FCU marks them valid.
//
// FCU promoting non canonical chain to canonical:
// - FCU to startNum+2 marks the previously imported non canonical blocks valid
// and advances L2ELB canonical head to startNum+2.
//
// FCU targeting a block that cannot yet be validated (missing ancestors):
// - Triggers EL sync on L2EL (skeleton/backfill logs), returns SYNCING,
// and does not advance the head while ELP2P is still unavailable.
//
// Enabling ELP2P and eventual validation:
// - After peering L2ELB with L2EL, FCU to startNum+4 eventually becomes VALID
// once EL sync completes; the test waits for canonicalization and confirms head advances.
// - Subsequent gaps (to startNum+6, then +8) are resolved by FCU with
// WaitUntilValid, advancing the canonical head each time.
//
// NewPayload still does not initiate EL sync:
// - A NewPayload to startNum+10 returns SYNCING and the block remains unknown by number
// until an FCU is issued, which initially returns SYNCING.
//
// Insights
// - NewPayload alone never initiates EL sync, but can build a non canonical chain if state exists.
// - FCU is the mechanism that (a) promotes non canonical chain blocks to canonical when they are
// already fully validated, and (b) triggers EL sync when ancestors are missing.
// - Previously submitted NewPayloads that returned SYNCING are not retained to automatically
// assemble a non canonical chain later.
// - With ELP2P enabled, repeated FCU attempts eventually validate and advance the canonical chain.
func TestL2ELP2PCanonicalChainAdvancedByFCU(gt *testing.T) {
t := devtest.ParallelT(gt)
// Example error with op-reth:
//
// assertions.go:387: ERROR[03-31|09:58:15.522]
// assertions.go:387: Error Trace: /optimism/op-devstack/dsl/l2_el.go:64
// assertions.go:387: /optimism/op-acceptance-tests/tests/sync/elsync/gap_elp2p/sync_test.go:111
// assertions.go:387: Error: Received unexpected error:
// assertions.go:387: failed to determine block-hash of hash 0x8b94830f261ef4568bc2ba248f52b27f9a7c366e8157794c93bdd05ca4735564, could not get payload: not found
// assertions.go:387: Test: TestL2ELP2PCanonicalChainAdvancedByFCU
// assertions.go:387: Messages: block not found using block hash
// assertions.go:387:
sysgo.SkipOnOpReth(t, "not supported")
sys := newGapELP2PSystem(t)
require := t.Require()
logger := t.Logger()

// Advance few blocks to make sure reference node advanced
sys.L2CL.Advanced(safety.LocalUnsafe, 10, 30)

sys.L2CLB.Stop()

// At this point, L2ELB has no ELP2P, and L2CL connection
startNum := sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number

// NewPayload does not trigger the EL Sync
// Example logs from L2EL(geth)
// New skeleton head announced
// Ignoring payload with missing parent
targetNum := startNum + 3
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsSyncing()

// NewPayload does not trigger the EL Sync
// Example logs from L2EL(geth)
// New skeleton head announced
// Ignoring payload with missing parent
targetNum = startNum + 5
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsSyncing()

// NewPayload does not trigger the EL Sync
// Example logs from L2EL(geth)
// New skeleton head announced
// Ignoring payload with missing parent
targetNum = startNum + 4
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsSyncing()

// NewPayload can extend non canonical chain because L2EL has state for startNum and can validate payload
// Example logs from L2EL(geth)
// Inserting block without sethead
// Persisted trie from memory database
// Imported new potential chain segment
targetNum = startNum + 1
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsValid()
logger.Info("Non canonical chain advanced", "number", targetNum)

// NewPayload can extend non canonical chain because L2EL has state for startNum+1 and can validate payload
// Example logs from L2EL(geth)
// Inserting block without sethead
// Persisted trie from memory database
// Imported new potential chain segment
targetNum = startNum + 2
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsValid()
logger.Info("Non canonical chain advanced", "number", targetNum)

// Non canonical chain can be fetched via blockhash
blockRef := sys.L2EL.BlockRefByNumber(targetNum)
nonCan := sys.L2ELB.BlockRefByHash(blockRef.Hash)
require.Equal(uint64(targetNum), nonCan.Number)
require.Equal(blockRef.Hash, nonCan.Hash)
// Still targetNum block is non canonicalized
_, err := sys.L2ELB.Escape().L2EthClient().BlockRefByNumber(t.Ctx(), targetNum)
require.ErrorIs(err, ethereum.NotFound)

// Previously inserted payloads are not used to make non-canonical chain automatically
blockRef = sys.L2EL.BlockRefByNumber(startNum + 3)
_, err = sys.L2ELB.Escape().EthClient().BlockRefByHash(t.Ctx(), blockRef.Hash)
require.ErrorIs(err, ethereum.NotFound)
blockRef = sys.L2EL.BlockRefByNumber(startNum + 5)
_, err = sys.L2ELB.Escape().EthClient().BlockRefByHash(t.Ctx(), blockRef.Hash)
require.ErrorIs(err, ethereum.NotFound)

// No FCU yet so head not advanced yet
require.Equal(startNum, sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// NewPayload does not trigger the EL Sync
// Example logs from L2EL(geth)
// New skeleton head announced
// Ignoring payload with missing parent
targetNum = startNum + 6
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsSyncing()

// FCU marks startNum + 2 as valid, promoting non canonical blocks to canonical blocks
// Example logs from L2EL(geth)
// Extend chain
// Chain head was updated
targetNum = startNum + 2
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).IsValid()
logger.Info("Canonical chain advanced", "number", targetNum)

// Head advanced, canonical head bumped
require.Equal(uint64(targetNum), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// FCU to target block which cannot be validated, triggers EL Sync but ELP2P not yet available
// Example logs from L2EL(geth)
// New skeleton head announced
// created initial skeleton subchain
// Starting reverse header sync cycle
// Block synchronisation started
// Backfilling with the network
targetNum = startNum + 3
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).IsSyncing()

// head not advanced
require.Equal(uint64(startNum+2), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// FCU to target block which cannot be validated
// Example logs from L2EL(geth)
// New skeleton head announced
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).IsSyncing()

// head not advanced
require.Equal(uint64(startNum+2), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// FCU to target block which cannot be validated
// Example logs from L2EL(geth)
// New skeleton head announced
targetNum = startNum + 4
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).IsSyncing()

// head not advanced
require.Equal(uint64(startNum+2), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// Finally peer for enabling ELP2P
sys.L2ELB.PeerWith(sys.L2EL)

// We do NOT need to resend the same FCU just because peers have connected;
// the EL continues syncing toward the last forkchoice target asynchronously.
//
// Once the EL has downloaded and validated the required data,
// a subsequent FCU call (even with the same target) may immediately return VALID.
//
// In practice, after peers are established, one or two FCU calls
// typically observe VALID — though this depends on the EL’s sync progress
// and network conditions.
attempts := 3

// Retry a few times until the first EL Sync is complete
sys.L2ELB.FinishedELSync(sys.L2EL, targetNum, 0, 0)

// Wait until L2EL finishes EL Sync and canonicalizes until targetNum
sys.L2ELB.Reached(eth.Unsafe, targetNum, 3)

sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).WaitUntilValid(attempts)
logger.Info("Canonical chain advanced", "number", targetNum)

// head advanced
require.Equal(uint64(targetNum), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// FCU to target block which can be eventually validated, because ELP2P enabled
// Example logs from L2EL(geth)
// "Restarting sync cycle" reason="chain gapped, head: 4, newHead: 6"
targetNum = startNum + 6
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).WaitUntilValid(attempts)
logger.Info("Canonical chain advanced", "number", targetNum)

// head advanced
require.Equal(uint64(targetNum), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// FCU to target block which can be eventually validated, because ELP2P enabled
// Example logs from L2EL(geth)
// "Restarting sync cycle" reason="chain gapped, head: 6, newHead: 8"
targetNum = startNum + 8
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).WaitUntilValid(attempts)
logger.Info("Canonical chain advanced", "number", targetNum)

// head advanced
require.Equal(uint64(targetNum), sys.L2ELB.BlockRefByLabel(eth.Unsafe).Number)

// NewPayload does not trigger EL Sync
targetNum = startNum + 10
sys.L2ELB.NewPayload(sys.L2EL, targetNum).IsSyncing()
_, err = sys.L2ELB.Escape().L2EthClient().BlockRefByNumber(t.Ctx(), targetNum)
require.ErrorIs(err, ethereum.NotFound)
sys.L2ELB.ForkchoiceUpdate(sys.L2EL, targetNum, 0, 0, nil).IsSyncing()

t.Cleanup(func() {
sys.L2CLB.Start()
sys.L2ELB.DisconnectPeerWith(sys.L2EL)
})
}

// TestELP2PFCUUnavailableHash verifies that when an Execution Layer (EL) client
// receives a Forkchoice Update (FCU) with an unknown head hash (invalid or
// non-existent) during EL syncing, it remains in the "SYNCING" state and does
Expand Down
13 changes: 0 additions & 13 deletions op-acceptance-tests/tests/sync/manual/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ import (

func TestVerifierManualSync(gt *testing.T) {
t := devtest.ParallelT(gt)
// Example error using op-reth:
//
// assertions.go:387: ERROR[03-31|10:02:09.740]
// assertions.go:387: Error Trace: /optimism/op-devstack/dsl/l2_el.go:64
// assertions.go:387: /optimism/op-acceptance-tests/tests/sync/manual/sync_test.go:53
// assertions.go:387: Error: Received unexpected error:
// assertions.go:387: failed to determine block-hash of hash 0x2f6324eaff3942802eff5ddd47872544aa02182c222bf90042d5f715dfa72308, could not get payload: not found
// assertions.go:387: Test: TestVerifierManualSync
// assertions.go:387: Messages: block not found using block hash
sysgo.SkipOnOpReth(t, "not supported")

// Disable ELP2P and Batcher
sys := presets.NewSingleChainMultiNodeWithoutP2PWithoutCheck(t,
presets.WithBatcherOption(func(_ sysgo.ComponentTarget, cfg *bss.CLIConfig) {
Expand Down Expand Up @@ -60,8 +49,6 @@ func TestVerifierManualSync(gt *testing.T) {
// Payload valid but not canonicalized. Cannot fetch block by number
_, err = sys.L2ELB.Escape().EthClient().BlockRefByNumber(t.Ctx(), blockNum)
require.Error(err, ethereum.NotFound)
// Now fetchable by hash
require.Equal(blockNum, sys.L2ELB.BlockRefByHash(block.Hash).Number)

// FCU
logger.Info("ForkchoiceUpdate", "target", blockNum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ func simpleWithSyncTesterOpts() []presets.Option {

func TestSyncTesterHardforks(gt *testing.T) {
t := devtest.ParallelT(gt)
// Example error with op-reth:
//
// assertions.go:387: ERROR[03-31|10:08:04.055]
// assertions.go:387: Error Trace: /optimism/op-devstack/dsl/check.go:26
// assertions.go:387: /optimism/op-acceptance-tests/tests/sync_tester/sync_tester_hfs/sync_tester_hfs_test.go:54
// assertions.go:387: Error: Received unexpected error:
// assertions.go:387: operation failed permanently after 42 attempts: expected head to advance: unsafe
// assertions.go:387: Test: TestSyncTesterHardforks
sysgo.SkipOnOpReth(t, "not supported")

sys := presets.NewSimpleWithSyncTester(t, simpleWithSyncTesterOpts()...)
require := t.Require()
logger := t.Logger()
Expand Down
19 changes: 0 additions & 19 deletions op-devstack/dsl/l2_el.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dsl

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -599,24 +598,6 @@ func (el *L2ELNode) ForkchoiceUpdateRaw(unsafe, safe, finalized common.Hash, att
return result
}

func (el *L2ELNode) FinishedELSync(refNode *L2ELNode, unsafe, safe, finalized uint64) {
el.log.Info("Trigger EL Sync", "unsafe", unsafe, "safe", safe, "finalized", finalized)
trial := 1
el.require.NoError(retry.Do0(el.ctx, 5, &retry.FixedStrategy{Dur: 2 * time.Second}, func() error {
el.log.Info("FCU to trigger EL Sync", "trial", trial)
res := el.ForkchoiceUpdate(refNode, unsafe, safe, finalized, nil)
// If EL Sync triggered, Example logs from L2EL(geth)
// New skeleton head announced
// Backfilling with the network
if res.Result.PayloadStatus.Status == eth.ExecutionValid {
el.log.Info("Finished EL Sync")
return nil
}
trial += 1
return errors.New("EL Sync not finished")
}))
}

func (el *L2ELNode) ChainSyncStatus(chainID eth.ChainID, lvl safety.Level) eth.BlockID {
el.require.Equal(chainID, el.inner.ChainID(), "chain ID mismatch")
var blockRef eth.L2BlockRef
Expand Down
20 changes: 6 additions & 14 deletions rust/kona/crates/node/engine/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use alloy_eips::{BlockId, eip1898::BlockNumberOrTag};
use alloy_json_rpc::{RequestPacket, ResponsePacket};
use alloy_network::{Ethereum, Network};
use alloy_primitives::Bytes;
use alloy_provider::{EthGetBlock, Provider, RootProvider, ext::EngineApi};
use alloy_provider::{EthGetBlock, Provider, RootProvider};
use alloy_rpc_client::ClientBuilder;
use alloy_rpc_types_engine::{ExecutionPayloadV1, JwtSecret, PayloadStatus};
use alloy_rpc_types_engine::JwtSecret;
use alloy_rpc_types_eth::Block;
use alloy_transport::{
RpcError, TransportError, TransportErrorKind, TransportFut, TransportResult,
};
use alloy_transport::{RpcError, TransportError, TransportErrorKind, TransportFut};
use alloy_transport_http::{
AuthLayer, Http, HyperClient,
hyper_util::{client::legacy::Client, rt::TokioExecutor},
Expand Down Expand Up @@ -200,14 +198,6 @@ impl EngineClient {
self.engine.get_block(block)
}

/// Submits a Paris payload, whose method is provided by Alloy's Ethereum Engine API extension.
pub async fn new_payload_v1(
&self,
payload: ExecutionPayloadV1,
) -> TransportResult<PayloadStatus> {
self.engine.new_payload_v1(payload).await
}

/// Fetches an L2 block with full transactions.
pub async fn l2_block_by_label(
&self,
Expand Down Expand Up @@ -380,7 +370,9 @@ mod request_observability_tests {
BuildTask, ExecutableEngineTask,
test_utils::{RpcMock, TestAttributesBuilder, TestEngineStateBuilder, test_block_info},
};
use alloy_rpc_types_engine::{ForkchoiceUpdated, PayloadId, PayloadStatusEnum};
use alloy_rpc_types_engine::{
ForkchoiceUpdated, PayloadId, PayloadStatus, PayloadStatusEnum,
};

let logs = LogWriter::default();
let writer = logs.clone();
Expand Down
4 changes: 2 additions & 2 deletions rust/kona/crates/node/engine/src/task_queue/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod recovery_tests {
let config = Arc::new(config);
let (client, l1, l2) = test_engine_client(config.clone());
let client = Arc::new(client);
l2.expect_error("engine_newPayloadV1");
l2.expect_error("engine_newPayloadV2");
let (state_tx, _state_rx) = tokio::sync::watch::channel(EngineState::default());
let mut engine = Engine::new(EngineState::default(), state_tx);
engine.enqueue(EngineTask::Insert(Box::new(InsertTask::new(
Expand Down Expand Up @@ -254,7 +254,7 @@ mod recovery_tests {
))));
}
for _ in 0..4 {
l2.expect("engine_newPayloadV1", PayloadStatus::from_status(PayloadStatusEnum::Valid));
l2.expect("engine_newPayloadV2", PayloadStatus::from_status(PayloadStatusEnum::Valid));
l2.expect(
"engine_forkchoiceUpdatedV3",
ForkchoiceUpdated::new(PayloadStatus::from_status(PayloadStatusEnum::Valid)),
Expand Down
Loading
Loading