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

feat(driver): update ForkchoiceStateV1 params #640

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading