Skip to content

Commit

Permalink
feat(l1Origin): remove the reverted l1Origins (#355)
Browse files Browse the repository at this point in the history
* remove the reverted l1Origins

* feat: add more comments

---------

Co-authored-by: David <[email protected]>
  • Loading branch information
mask-pp and davidtaikocha authored Nov 27, 2024
1 parent 5c649ba commit e3eb72f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/rawdb/taiko_l1_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func WriteL1Origin(db ethdb.KeyValueWriter, blockID *big.Int, l1Origin *L1Origin
}
}

// DeleteL1Origin removes the L1Origin.
func DeleteL1Origin(db ethdb.KeyValueWriter, blockID *big.Int) {
_ = db.Delete(l1OriginKey(blockID))
}

// ReadL1Origin retrieves the L1Origin of the given blockID from the database.
func ReadL1Origin(db ethdb.KeyValueReader, blockID *big.Int) (*L1Origin, error) {
data, _ := db.Get(l1OriginKey(blockID))
Expand Down
5 changes: 5 additions & 0 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
// generating the payload. It's a special corner case that a few slots are
// missing and we are requested to generate the payload in slot.
} else if isTaiko { // CHANGE(taiko): reorg is allowed in L2.
// After inserting a new canonical head, we delete all L1Origin data of the pending soft blocks.
head := api.eth.BlockChain().CurrentBlock()
for number := head.Number.Uint64(); number > block.NumberU64(); number-- {
rawdb.DeleteL1Origin(api.eth.ChainDb(), new(big.Int).SetUint64(number))
}
if latestValid, err := api.eth.BlockChain().SetCanonical(block); err != nil {
return engine.ForkChoiceResponse{PayloadStatus: engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: &latestValid}}, err
}
Expand Down

0 comments on commit e3eb72f

Please sign in to comment.