Skip to content

Commit

Permalink
Refactor get local payload (#14327)
Browse files Browse the repository at this point in the history
* Refactor get local payload

* Fix go lint: new line
  • Loading branch information
terencechain authored Aug 9, 2024
1 parent e011f05 commit e3d27f2
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,26 @@ func (vs *Server) getLocalPayload(ctx context.Context, blk interfaces.ReadOnlyBe
slot := blk.Slot()
vIdx := blk.ProposerIndex()
headRoot := blk.ParentRoot()

return vs.getLocalPayloadFromEngine(ctx, st, headRoot, slot, vIdx)
}

// This returns the local execution payload of a slot, proposer ID, and parent root assuming payload Is cached.
// If the payload ID is not cached, the function will prepare a new payload through local EL engine and return it by using the head state.
func (vs *Server) getLocalPayloadFromEngine(
ctx context.Context,
st state.BeaconState,
parentRoot [32]byte,
slot primitives.Slot,
proposerId primitives.ValidatorIndex) (*consensusblocks.GetPayloadResponse, error) {
logFields := logrus.Fields{
"validatorIndex": vIdx,
"validatorIndex": proposerId,
"slot": slot,
"headRoot": fmt.Sprintf("%#x", headRoot),
"headRoot": fmt.Sprintf("%#x", parentRoot),
}
payloadId, ok := vs.PayloadIDCache.PayloadID(slot, headRoot)
payloadId, ok := vs.PayloadIDCache.PayloadID(slot, parentRoot)

val, tracked := vs.TrackedValidatorsCache.Validator(vIdx)
val, tracked := vs.TrackedValidatorsCache.Validator(proposerId)
if !tracked {
logrus.WithFields(logFields).Warn("could not find tracked proposer index")
}
Expand Down Expand Up @@ -135,7 +147,7 @@ func (vs *Server) getLocalPayload(ctx context.Context, blk interfaces.ReadOnlyBe
PrevRandao: random,
SuggestedFeeRecipient: val.FeeRecipient[:],
Withdrawals: withdrawals,
ParentBeaconBlockRoot: headRoot[:],
ParentBeaconBlockRoot: parentRoot[:],
})
if err != nil {
return nil, err
Expand Down

0 comments on commit e3d27f2

Please sign in to comment.