From 0a0265d4feed3a81b7fcb0afe4e9a0aa58e2756e Mon Sep 17 00:00:00 2001 From: bap2pecs <111917526+bap2pecs@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:52:31 -0500 Subject: [PATCH] feat: allow FG to be opt-in (#17) --- .github/CODEOWNERS | 44 +---------------- op-node/rollup/finality/finalizer.go | 74 +++++++++++++++++----------- 2 files changed, 46 insertions(+), 72 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 23ac0fa26cf5..ca1355928c36 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,43 +1 @@ -# Packages -/packages/contracts-bedrock @ethereum-optimism/contract-reviewers -/packages/sdk @ethereum-optimism/devxpod - -# Bedrock codebases -/bedrock-devnet @ethereum-optimism/go-reviewers -/cannon @ethereum-optimism/go-reviewers -/op-batcher @ethereum-optimism/go-reviewers -/op-bootnode @ethereum-optimism/go-reviewers -/op-chain-ops @ethereum-optimism/go-reviewers -/op-challenger @ethereum-optimism/go-reviewers -/op-dispute-mon @ethereum-optimism/go-reviewers -/op-e2e @ethereum-optimism/go-reviewers -/op-node @ethereum-optimism/go-reviewers -/op-node/rollup @protolambda @ajsutton -/op-alt-da @ethereum-optimism/go-reviewers -/op-preimage @ethereum-optimism/go-reviewers -/op-program @ethereum-optimism/go-reviewers -/op-proposer @ethereum-optimism/go-reviewers -/op-service @ethereum-optimism/go-reviewers -/op-supervisor @ethereum-optimism/go-reviewers -/op-wheel @ethereum-optimism/go-reviewers -/ops-bedrock @ethereum-optimism/go-reviewers -/op-conductor @0x00101010 @zhwrd @mslipper - -# Ops -/.circleci @ethereum-optimism/monorepo-ops-reviewers -/.github @ethereum-optimism/monorepo-ops-reviewers -/ops @ethereum-optimism/monorepo-ops-reviewers -/docker-bake.hcl @ethereum-optimism/monorepo-ops-reviewers - -# Misc -/proxyd @ethereum-optimism/infra-reviewers -/infra @ethereum-optimism/infra-reviewers -/specs @ethereum-optimism/contract-reviewers @ethereum-optimism/go-reviewers - -# Don't add owners if only package.json is updated -/packages/*/package.json -/*/package.json - -# JavaScript Releases -/packages/*/CHANGELOG.md @ethereum-optimism/release-managers -/*/CHANGELOG.md @ethereum-optimism/release-managers +* @bap2pecs @lesterli @parketh @SebastianElvis @maurolacy @gusin13 \ No newline at end of file diff --git a/op-node/rollup/finality/finalizer.go b/op-node/rollup/finality/finalizer.go index e393e6ad63fe..010554172bb5 100644 --- a/op-node/rollup/finality/finalizer.go +++ b/op-node/rollup/finality/finalizer.go @@ -110,15 +110,19 @@ type Finalizer struct { func NewFinalizer(ctx context.Context, log log.Logger, cfg *rollup.Config, l1Fetcher FinalizerL1Interface, l2Fetcher FinalizerL2Interface) *Finalizer { lookback := calcFinalityLookback(cfg) - // Initialize the Babylon finality gadget client - log.Debug( - "creating Babylon Finality client", - "rpc_addr", cfg.BabylonFinalityGadgetRpc, - ) - babylonFinalityClient, err := fgclient.NewFinalityGadgetGrpcClient(cfg.BabylonFinalityGadgetRpc) - if err != nil { - log.Error("failed to initialize Babylon Finality client", "error", err) - return nil + var babylonFinalityClient IFinalityGadgetClient + var err error + if cfg.BabylonFinalityGadgetRpc != "" { + // Initialize the Babylon finality gadget client + log.Debug( + "creating Babylon Finality client", + "rpc_addr", cfg.BabylonFinalityGadgetRpc, + ) + babylonFinalityClient, err = fgclient.NewFinalityGadgetGrpcClient(cfg.BabylonFinalityGadgetRpc) + if err != nil { + log.Error("failed to initialize Babylon Finality client", "error", err) + return nil + } } return &Finalizer{ @@ -231,37 +235,49 @@ func (fi *Finalizer) tryFinalize() { fi.mu.Lock() defer fi.mu.Unlock() - gadgetActivatedTimestamp, err := fi.babylonFinalityClient.QueryBtcStakingActivatedTimestamp() - if err != nil && !strings.Contains(err.Error(), fgtypes.ErrBtcStakingNotActivated.Error()) { - fi.emitter.Emit(rollup.CriticalErrorEvent{Err: fmt.Errorf("failed to query BTC staking activated timestamp: %w", err)}) - return - } - // overwritten if we finalize finalizedL2 := fi.lastFinalizedL2 // may be zeroed if nothing was finalized since startup. var finalizedDerivedFrom eth.BlockID + // go through the latest inclusion data, and find the last L2 block that was derived from a finalized L1 block fi.log.Debug("try finalize", "finality_data", fi.finalityData, "last_finalized_l2", finalizedL2) - for _, fd := range fi.finalityData { - if fd.L2Block.Number > finalizedL2.Number && fd.L1Block.Number <= fi.finalizedL1.Number { - lastFinalizedBlock := fi.findLastBtcFinalizedL2Block( - fd.L2Block.Number, finalizedL2.Number, gadgetActivatedTimestamp) - - // set finalized block(s) - if lastFinalizedBlock != nil { - finalizedL2 = *lastFinalizedBlock + if fi.babylonFinalityClient == nil { + for _, fd := range fi.finalityData { + if fd.L2Block.Number > finalizedL2.Number && fd.L1Block.Number <= fi.finalizedL1.Number { + finalizedL2 = fd.L2Block finalizedDerivedFrom = fd.L1Block - fi.log.Debug("set finalized block", "finalized_l2", finalizedL2, "finalized_derived_from", finalizedDerivedFrom, "fd_l2_block", fd.L2Block) + // keep iterating, there may be later L2 blocks that can also be finalized } + } + } else { + gadgetActivatedTimestamp, err := fi.babylonFinalityClient.QueryBtcStakingActivatedTimestamp() + if err != nil && !strings.Contains(err.Error(), fgtypes.ErrBtcStakingNotActivated.Error()) { + fi.emitter.Emit(rollup.CriticalErrorEvent{Err: fmt.Errorf("failed to query BTC staking activated timestamp: %w", err)}) + return + } - // some blocks in the queried range is not BTC finalized, stop iterating to honor consecutive quorom - if lastFinalizedBlock == nil || lastFinalizedBlock.Number != fd.L2Block.Number { - break - } + for _, fd := range fi.finalityData { + if fd.L2Block.Number > finalizedL2.Number && fd.L1Block.Number <= fi.finalizedL1.Number { + lastFinalizedBlock := fi.findLastBtcFinalizedL2Block( + fd.L2Block.Number, finalizedL2.Number, gadgetActivatedTimestamp) - // keep iterating, there may be later L2 blocks that can also be finalized + // set finalized block(s) + if lastFinalizedBlock != nil { + finalizedL2 = *lastFinalizedBlock + finalizedDerivedFrom = fd.L1Block + fi.log.Debug("set finalized block", "finalized_l2", finalizedL2, "finalized_derived_from", finalizedDerivedFrom, "fd_l2_block", fd.L2Block) + } + + // some blocks in the queried range is not BTC finalized, stop iterating to honor consecutive quorom + if lastFinalizedBlock == nil || lastFinalizedBlock.Number != fd.L2Block.Number { + break + } + + // keep iterating, there may be later L2 blocks that can also be finalized + } } } + if finalizedDerivedFrom != (eth.BlockID{}) { ctx, cancel := context.WithTimeout(fi.ctx, time.Second*10) defer cancel()