Skip to content

Commit

Permalink
Merge pull request #5 from hemilabs/clayton/non-sequence-keystone-not…
Browse files Browse the repository at this point in the history
…ification

bss keystone notification on non-sequencing unsafe block
  • Loading branch information
ClaytonNorthey92 authored Jul 5, 2024
2 parents adf6892 + c545964 commit d3f734b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions op-node/rollup/derive/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,45 @@ func (e *EngineController) InsertUnsafePayload(ctx context.Context, envelope *et
e.syncStatus = syncStatusFinishedEL
}

e.log.Info("checking whether to notify bss from InsertUnsafePayload")
bn := &bssNotification{
unsafeL2: *envelope.ExecutionPayload,
}

l2BlockHeight := envelope.ExecutionPayload.BlockNumber

prevKeystoneHeight := int64(l2BlockHeight-(l2BlockHeight%hemi.KeystoneHeaderPeriod)) - hemi.KeystoneHeaderPeriod
if l2BlockHeight%hemi.KeystoneHeaderPeriod != 0 {
prevKeystoneHeight = prevKeystoneHeight + hemi.KeystoneHeaderPeriod
}

e.log.Info(fmt.Sprintf("For block %d, previous keystone height=%d", l2BlockHeight, prevKeystoneHeight))

var prevKeystoneRef *eth.L2BlockRef = nil

if prevKeystoneHeight > 0 {
prevKeystone, err := e.engine.PayloadByNumber(ctx, uint64(prevKeystoneHeight))
if err != nil {
return NewResetError(fmt.Errorf("failed to fetch previous keystone from engine at index %d", prevKeystoneHeight))
}

ref, err := PayloadToBlockRef(e.rollupCfg, prevKeystone.ExecutionPayload)
if err != nil {
return NewResetError(fmt.Errorf("failed to convert payload at height %d to block ref", prevKeystoneHeight))
}
prevKeystoneRef = &ref
}

if prevKeystoneRef != nil {
bn.unsafeL2PrevKeystone = *prevKeystoneRef
}

select {
case e.bssNotifierCh <- bn:
default:
e.log.Warn("BSS notifier channel full, dropping event...")
}

return nil
}

Expand Down

0 comments on commit d3f734b

Please sign in to comment.