Skip to content

Commit

Permalink
feat: allow FG to be opt-in (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bap2pecs authored Nov 4, 2024
1 parent 7914128 commit 0a0265d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 72 deletions.
44 changes: 1 addition & 43 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -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
74 changes: 45 additions & 29 deletions op-node/rollup/finality/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0a0265d

Please sign in to comment.