Commit 787ec266 authored by Axel Kingsley's avatar Axel Kingsley Committed by GitHub

Apply Finality to blocks prior to L1 Finality Singal (#13708)

* Apply Finality to blocks prior to L1 Finality Singal

* add Log when Finality is assumed from newer Finality Signal
parent 973b2dd0
...@@ -171,6 +171,28 @@ func (db *ChainsDB) Finalized(chainID types.ChainID) (types.BlockSeal, error) { ...@@ -171,6 +171,28 @@ func (db *ChainsDB) Finalized(chainID types.ChainID) (types.BlockSeal, error) {
if finalizedL1 == (eth.L1BlockRef{}) { if finalizedL1 == (eth.L1BlockRef{}) {
return types.BlockSeal{}, fmt.Errorf("no finalized L1 signal, cannot determine L2 finality of chain %s yet", chainID) return types.BlockSeal{}, fmt.Errorf("no finalized L1 signal, cannot determine L2 finality of chain %s yet", chainID)
} }
// compare the finalized L1 block with the last derived block in the cross DB
xDB, ok := db.crossDBs.Get(chainID)
if !ok {
return types.BlockSeal{}, types.ErrUnknownChain
}
latestDerivedFrom, latestDerived, err := xDB.Latest()
if err != nil {
return types.BlockSeal{}, fmt.Errorf("could not get the latest derived pair for chain %s: %w", chainID, err)
}
// if the finalized L1 block is newer than the latest L1 block used to derive L2 blocks,
// the finality signal automatically applies to all previous blocks, including the latest derived block
if finalizedL1.Number > latestDerivedFrom.Number {
db.logger.Warn("Finalized L1 block is newer than the latest L1 for this chain. Assuming latest L2 is finalized",
"chain", chainID,
"finalizedL1", finalizedL1.Number,
"latestDerivedFrom", latestDerivedFrom.Number,
"latestDerived", latestDerivedFrom)
return latestDerived, nil
}
// otherwise, use the finalized L1 block to determine the final L2 block that was derived from it
derived, err := db.LastDerivedFrom(chainID, finalizedL1.ID()) derived, err := db.LastDerivedFrom(chainID, finalizedL1.ID())
if err != nil { if err != nil {
return types.BlockSeal{}, fmt.Errorf("could not find what was last derived in L2 chain %s from the finalized L1 block %s: %w", chainID, finalizedL1, err) return types.BlockSeal{}, fmt.Errorf("could not find what was last derived in L2 chain %s from the finalized L1 block %s: %w", chainID, finalizedL1, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment