Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(driver): update ForkchoiceStateV1 params (#640)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
mask-pp and davidtaikocha authored Mar 16, 2024
1 parent fbd4d06 commit 9cbe4b8
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,12 @@ func (s *Syncer) insertNewHead(
return nil, fmt.Errorf("failed to create execution payloads: %w", err)
}

fc := &engine.ForkchoiceStateV1{HeadBlockHash: parent.Hash()}
fc := &engine.ForkchoiceStateV1{HeadBlockHash: payload.BlockHash}
if err = s.fillForkchoiceState(ctx, event, fc); err != nil {
return nil, err
}

// Update the fork choice
fc.HeadBlockHash = payload.BlockHash
fcRes, err := s.rpc.L2Engine.ForkchoiceUpdate(ctx, fc, nil)
if err != nil {
return nil, err
Expand All @@ -392,6 +394,37 @@ func (s *Syncer) insertNewHead(
return payload, nil
}

// fillForkchoiceState fills the forkchoice state with the finalized block hash and the safe block hash.
func (s *Syncer) fillForkchoiceState(
ctx context.Context,
event *bindings.TaikoL1ClientBlockProposed,
fc *engine.ForkchoiceStateV1,
) error {
// If the event is emitted from the genesis block, we don't need to fill the forkchoice state,
// should only happen when testing.
if event.Raw.BlockNumber == 0 {
return nil
}

// Fetch the latest verified block's header from protocol.
variables, err := s.rpc.GetProtocolStateVariables(
&bind.CallOpts{Context: ctx, BlockNumber: new(big.Int).SetUint64(event.Raw.BlockNumber - 1)},
)
if err != nil {
return err
}
finalizeHeader, err := s.rpc.L2.HeaderByNumber(ctx, new(big.Int).SetUint64(variables.B.LastVerifiedBlockId))
if err != nil {
return err
}

// Fill the forkchoice state.
fc.FinalizedBlockHash = finalizeHeader.Hash()
fc.SafeBlockHash = finalizeHeader.ParentHash

return nil
}

// createExecutionPayloads creates a new execution payloads through
// Engine APIs.
func (s *Syncer) createExecutionPayloads(
Expand Down

0 comments on commit 9cbe4b8

Please sign in to comment.