From 02a032dca806621efc5e9015f7f3fd0e8c3295ab Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Mon, 17 Oct 2022 13:12:55 -0600 Subject: [PATCH] op-node: Log sync start --- op-node/rollup/derive/engine_queue.go | 2 +- op-node/rollup/sync/start.go | 5 ++++- op-node/rollup/sync/start_test.go | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/op-node/rollup/derive/engine_queue.go b/op-node/rollup/derive/engine_queue.go index ae4cac54aa530..65ae7b787ba6e 100644 --- a/op-node/rollup/derive/engine_queue.go +++ b/op-node/rollup/derive/engine_queue.go @@ -405,7 +405,7 @@ func (eq *EngineQueue) forceNextSafeAttributes(ctx context.Context) error { // ResetStep Walks the L2 chain backwards until it finds an L2 block whose L1 origin is canonical. // The unsafe head is set to the head of the L2 chain, unless the existing safe head is not canonical. func (eq *EngineQueue) Reset(ctx context.Context, _ eth.L1BlockRef) error { - result, err := sync.FindL2Heads(ctx, eq.cfg, eq.l1Fetcher, eq.engine) + result, err := sync.FindL2Heads(ctx, eq.cfg, eq.l1Fetcher, eq.engine, eq.log) if err != nil { return NewTemporaryError(fmt.Errorf("failed to find the L2 Heads to start from: %w", err)) } diff --git a/op-node/rollup/sync/start.go b/op-node/rollup/sync/start.go index 02f5513c4f438..5ade51532aacf 100644 --- a/op-node/rollup/sync/start.go +++ b/op-node/rollup/sync/start.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/log" ) type L1Chain interface { @@ -101,7 +102,7 @@ func currentHeads(ctx context.Context, cfg *rollup.Config, l2 L2Chain) (*FindHea // Plausible: meaning that the blockhash of the L2 block's L1 origin // (as reported in the L1 Attributes deposit within the L2 block) is not canonical at another height in the L1 chain, // and the same holds for all its ancestors. -func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain) (result *FindHeadsResult, err error) { +func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain, lgr log.Logger) (result *FindHeadsResult, err error) { // Fetch current L2 forkchoice state result, err = currentHeads(ctx, cfg, l2) if err != nil { @@ -137,6 +138,8 @@ func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain ahead = notFound } + lgr.Trace("walking sync start", "number", n.Number) + // Don't walk past genesis. If we were at the L2 genesis, but could not find its L1 origin, // the L2 chain is building on the wrong L1 branch. if n.Number == cfg.Genesis.L2.Number { diff --git a/op-node/rollup/sync/start_test.go b/op-node/rollup/sync/start_test.go index addaccfdd9502..7382db8bdda57 100644 --- a/op-node/rollup/sync/start_test.go +++ b/op-node/rollup/sync/start_test.go @@ -73,7 +73,9 @@ func (c *syncStartTestCase) Run(t *testing.T) { Genesis: genesis, SeqWindowSize: c.SeqWindowSize, } - result, err := FindL2Heads(context.Background(), cfg, chain, chain) + lgr := log.New() + lgr.SetHandler(log.DiscardHandler()) + result, err := FindL2Heads(context.Background(), cfg, chain, chain, lgr) if c.ExpectedErr != nil { require.ErrorIs(t, err, c.ExpectedErr, "expected error") return