@@ -20,7 +20,7 @@ from ../consensus_object_pools/consensus_manager import
2020 updateHeadWithExecution
2121from ../ consensus_object_pools/ blockchain_dag import
2222 getBlockRef, getForkedBlock, getProposer, forkAtEpoch, loadExecutionBlockHash,
23- markBlockVerified, validatorKey
23+ markBlockVerified, validatorKey, is_optimistic
2424from ../ beacon_clock import GetBeaconTimeFn , toFloatSeconds
2525from ../ consensus_object_pools/ block_dag import BlockRef , root, shortLog, slot
2626from ../ consensus_object_pools/ block_pools_types import
@@ -230,19 +230,24 @@ from web3/engine_api_types import
230230 PayloadAttributesV1 , PayloadAttributesV2 , PayloadAttributesV3 ,
231231 PayloadExecutionStatus , PayloadStatusV1
232232from ../ el/ el_manager import
233- ELManager , forkchoiceUpdated, hasConnection, hasProperlyConfiguredConnection ,
234- sendNewPayload
233+ ELManager , DeadlineObject , forkchoiceUpdated, hasConnection ,
234+ hasProperlyConfiguredConnection, sendNewPayload, init
235235
236236proc expectValidForkchoiceUpdated (
237237 elManager: ELManager , headBlockPayloadAttributesType: typedesc ,
238238 headBlockHash, safeBlockHash, finalizedBlockHash: Eth2Digest ,
239- receivedBlock: ForkySignedBeaconBlock ): Future [void ] {.async : (raises: [CancelledError ]).} =
239+ receivedBlock: ForkySignedBeaconBlock ,
240+ deadlineObj: DeadlineObject ,
241+ maxRetriesCount: int
242+ ): Future [void ] {.async : (raises: [CancelledError ]).} =
240243 let
241244 (payloadExecutionStatus, _) = await elManager.forkchoiceUpdated (
242245 headBlockHash = headBlockHash,
243246 safeBlockHash = safeBlockHash,
244247 finalizedBlockHash = finalizedBlockHash,
245- payloadAttributes = Opt .none headBlockPayloadAttributesType)
248+ payloadAttributes = Opt .none headBlockPayloadAttributesType,
249+ deadlineObj = deadlineObj,
250+ maxRetriesCount = maxRetriesCount)
246251 receivedExecutionBlockHash =
247252 when typeof (receivedBlock).kind >= ConsensusFork .Bellatrix :
248253 receivedBlock.message.body.execution_payload.block_hash
@@ -277,8 +282,11 @@ from ../consensus_object_pools/attestation_pool import
277282from ../ consensus_object_pools/ spec_cache import get_attesting_indices
278283
279284proc newExecutionPayload * (
280- elManager: ELManager , blck: SomeForkyBeaconBlock ):
281- Future [Opt [PayloadExecutionStatus ]] {.async : (raises: [CancelledError ]).} =
285+ elManager: ELManager ,
286+ blck: SomeForkyBeaconBlock ,
287+ deadlineObj: DeadlineObject ,
288+ maxRetriesCount: int
289+ ): Future [Opt [PayloadExecutionStatus ]] {.async : (raises: [CancelledError ]).} =
282290
283291 template executionPayload : untyped = blck.body.execution_payload
284292
@@ -295,7 +303,8 @@ proc newExecutionPayload*(
295303 executionPayload = shortLog (executionPayload)
296304
297305 try :
298- let payloadStatus = await elManager.sendNewPayload (blck)
306+ let payloadStatus =
307+ await elManager.sendNewPayload (blck, deadlineObj, maxRetriesCount)
299308
300309 debug " newPayload: succeeded" ,
301310 parentHash = executionPayload.parent_hash,
@@ -312,22 +321,34 @@ proc newExecutionPayload*(
312321 blockNumber = executionPayload.block_number
313322 return Opt .none PayloadExecutionStatus
314323
324+ proc newExecutionPayload * (
325+ elManager: ELManager ,
326+ blck: SomeForkyBeaconBlock
327+ ): Future [Opt [PayloadExecutionStatus ]] {.
328+ async : (raises: [CancelledError ], raw: true ).} =
329+ newExecutionPayload (
330+ elManager, blck, DeadlineObject .init (FORKCHOICEUPDATED_TIMEOUT ),
331+ high (int ))
332+
315333proc getExecutionValidity (
316334 elManager: ELManager ,
317335 blck: bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock |
318- deneb.SignedBeaconBlock | electra.SignedBeaconBlock ):
319- Future [NewPayloadStatus ] {.async : (raises: [CancelledError ]).} =
336+ deneb.SignedBeaconBlock | electra.SignedBeaconBlock ,
337+ deadlineObj: DeadlineObject ,
338+ maxRetriesCount: int
339+ ): Future [NewPayloadStatus ] {.async : (raises: [CancelledError ]).} =
320340 if not blck.message.is_execution_block:
321341 return NewPayloadStatus .valid # vacuously
322342
323343 try :
324344 let executionPayloadStatus = await elManager.newExecutionPayload (
325- blck.message)
345+ blck.message, deadlineObj, maxRetriesCount )
326346 if executionPayloadStatus.isNone:
327347 return NewPayloadStatus .noResponse
328348
329349 case executionPayloadStatus.get
330- of PayloadExecutionStatus .invalid, PayloadExecutionStatus .invalid_block_hash:
350+ of PayloadExecutionStatus .invalid,
351+ PayloadExecutionStatus .invalid_block_hash:
331352 # Blocks come either from gossip or request manager requests. In the
332353 # former case, they've passed libp2p gosisp validation which implies
333354 # correct signature for correct proposer,which makes spam expensive,
@@ -413,6 +434,20 @@ proc storeBlock(
413434 vm = self.validatorMonitor
414435 dag = self.consensusManager.dag
415436 wallSlot = wallTime.slotOrZero
437+ deadlineTime =
438+ block :
439+ let slotTime = (wallSlot + 1 ).start_beacon_time () - 1 .seconds
440+ if slotTime <= wallTime:
441+ 0 .seconds
442+ else :
443+ chronos.nanoseconds ((slotTime - wallTime).nanoseconds)
444+ deadlineObj = DeadlineObject .init (deadlineTime)
445+
446+ func getRetriesCount (): int =
447+ if dag.is_optimistic (dag.head.bid):
448+ 1
449+ else :
450+ high (int )
416451
417452 # If the block is missing its parent, it will be re-orphaned below
418453 self.consensusManager.quarantine[].removeOrphan (signedBlock)
@@ -518,7 +553,8 @@ proc storeBlock(
518553 NewPayloadStatus .noResponse
519554 else :
520555 when typeof (signedBlock).kind >= ConsensusFork .Bellatrix :
521- await self.consensusManager.elManager.getExecutionValidity (signedBlock)
556+ await self.consensusManager.elManager.getExecutionValidity (
557+ signedBlock, deadlineObj, getRetriesCount ())
522558 else :
523559 NewPayloadStatus .valid # vacuously
524560 payloadValid = payloadStatus == NewPayloadStatus .valid
@@ -685,7 +721,9 @@ proc storeBlock(
685721 self.consensusManager[].optimisticExecutionBlockHash,
686722 safeBlockHash = newHead.get.safeExecutionBlockHash,
687723 finalizedBlockHash = newHead.get.finalizedExecutionBlockHash,
688- payloadAttributes = Opt .none attributes)
724+ payloadAttributes = Opt .none attributes,
725+ deadlineObj = deadlineObj,
726+ maxRetriesCount = getRetriesCount ())
689727
690728 let consensusFork = self.consensusManager.dag.cfg.consensusForkAtEpoch (
691729 newHead.get.blck.bid.slot.epoch)
@@ -712,7 +750,9 @@ proc storeBlock(
712750 headBlockHash = headExecutionBlockHash,
713751 safeBlockHash = newHead.get.safeExecutionBlockHash,
714752 finalizedBlockHash = newHead.get.finalizedExecutionBlockHash,
715- receivedBlock = signedBlock)
753+ receivedBlock = signedBlock,
754+ deadlineObj = deadlineObj,
755+ maxRetriesCount = getRetriesCount ())
716756
717757 template callForkChoiceUpdated : auto =
718758 case self.consensusManager.dag.cfg.consensusForkAtEpoch (
0 commit comments