@@ -739,6 +739,18 @@ proc handleSyncCommitteeMessages(node: BeaconNode, head: BlockRef, slot: Slot) =
739739 asyncSpawn createAndSendSyncCommitteeMessage (node, slot, validator,
740740 subcommitteeIdx, head)
741741
742+ proc handleOptimisticLightClientUpdates (
743+ node: BeaconNode , head: BlockRef , slot: Slot , didPropose: bool ) =
744+ if not didPropose:
745+ return
746+ let msg = node.dag.optimisticLightClientUpdate
747+ if msg.attested_header.slot != head.parent.bid.slot:
748+ notice " No optimistic light client update for proposed block" ,
749+ slot = slot, block_root = shortLog (head.root)
750+ return
751+ node.network.broadcastOptimisticLightClientUpdate (msg)
752+ notice " Sent optimistic light client update" , message = shortLog (msg)
753+
742754proc signAndSendContribution (node: BeaconNode ,
743755 validator: AttachedValidator ,
744756 contribution: SyncCommitteeContribution ,
@@ -841,14 +853,14 @@ proc handleSyncCommitteeContributions(node: BeaconNode,
841853 slot, head, subnet_id = candidateAggregators[i].subcommitteeIdx
842854
843855proc handleProposal (node: BeaconNode , head: BlockRef , slot: Slot ):
844- Future [BlockRef ] {.async .} =
856+ Future [tuple [head: BlockRef , didPropose: bool ] ] {.async .} =
845857 # # Perform the proposal for the given slot, iff we have a validator attached
846858 # # that is supposed to do so, given the shuffling at that slot for the given
847859 # # head - to compute the proposer, we need to advance a state to the given
848860 # # slot
849861 let proposer = node.dag.getProposer (head, slot)
850862 if proposer.isNone ():
851- return head
863+ return ( head: head, didPropose: false )
852864
853865 let
854866 proposerKey = node.dag.validatorKey (proposer.get).get ().toPubKey
@@ -862,9 +874,12 @@ proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
862874 proposer_index = proposer.get (),
863875 proposer = shortLog (proposerKey)
864876
865- head
877+ ( head: head, didPropose: false )
866878 else :
867- await proposeBlock (node, validator, proposer.get (), head, slot)
879+ (
880+ head: await proposeBlock (node, validator, proposer.get (), head, slot),
881+ didPropose: true
882+ )
868883
869884proc makeAggregateAndProof * (
870885 pool: var AttestationPool , epochRef: EpochRef , slot: Slot , index: CommitteeIndex ,
@@ -1052,6 +1067,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
10521067
10531068 # Start by checking if there's work we should have done in the past that we
10541069 # can still meaningfully do
1070+ var didPropose = false
10551071 while curSlot < slot:
10561072 notice " Catching up on validator duties" ,
10571073 curSlot = shortLog (curSlot),
@@ -1061,7 +1077,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
10611077 # For every slot we're catching up, we'll propose then send
10621078 # attestations - head should normally be advancing along the same branch
10631079 # in this case
1064- head = await handleProposal (node, head, curSlot)
1080+ ( head, didPropose) = await handleProposal (node, head, curSlot)
10651081
10661082 # For each slot we missed, we need to send out attestations - if we were
10671083 # proposing during this time, we'll use the newly proposed head, else just
@@ -1071,7 +1087,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
10711087
10721088 curSlot += 1
10731089
1074- head = await handleProposal (node, head, slot)
1090+ ( head, didPropose) = await handleProposal (node, head, slot)
10751091
10761092 let
10771093 # The latest point in time when we'll be sending out attestations
@@ -1116,11 +1132,16 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
11161132 node.consensusManager[].updateHead (slot)
11171133 head = node.dag.head
11181134
1119- static : doAssert attestationSlotOffset == syncCommitteeMessageSlotOffset
1120-
1135+ static :
1136+ doAssert attestationSlotOffset == syncCommitteeMessageSlotOffset
11211137 handleAttestations (node, head, slot)
11221138 handleSyncCommitteeMessages (node, head, slot)
11231139
1140+ if node.config.serveLightClientData:
1141+ static :
1142+ doAssert attestationSlotOffset == optimisticLightClientUpdateSlotOffset
1143+ handleOptimisticLightClientUpdates (node, head, slot, didPropose)
1144+
11241145 updateValidatorMetrics (node) # the important stuff is done, update the vanity numbers
11251146
11261147 # https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-aggregate
0 commit comments