@@ -739,6 +739,18 @@ proc handleSyncCommitteeMessages(node: BeaconNode, head: BlockRef, slot: Slot) =
739
739
asyncSpawn createAndSendSyncCommitteeMessage (node, slot, validator,
740
740
subcommitteeIdx, head)
741
741
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
+
742
754
proc signAndSendContribution (node: BeaconNode ,
743
755
validator: AttachedValidator ,
744
756
contribution: SyncCommitteeContribution ,
@@ -841,14 +853,14 @@ proc handleSyncCommitteeContributions(node: BeaconNode,
841
853
slot, head, subnet_id = candidateAggregators[i].subcommitteeIdx
842
854
843
855
proc handleProposal (node: BeaconNode , head: BlockRef , slot: Slot ):
844
- Future [BlockRef ] {.async .} =
856
+ Future [tuple [head: BlockRef , didPropose: bool ] ] {.async .} =
845
857
# # Perform the proposal for the given slot, iff we have a validator attached
846
858
# # that is supposed to do so, given the shuffling at that slot for the given
847
859
# # head - to compute the proposer, we need to advance a state to the given
848
860
# # slot
849
861
let proposer = node.dag.getProposer (head, slot)
850
862
if proposer.isNone ():
851
- return head
863
+ return ( head: head, didPropose: false )
852
864
853
865
let
854
866
proposerKey = node.dag.validatorKey (proposer.get).get ().toPubKey
@@ -862,9 +874,12 @@ proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
862
874
proposer_index = proposer.get (),
863
875
proposer = shortLog (proposerKey)
864
876
865
- head
877
+ ( head: head, didPropose: false )
866
878
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
+ )
868
883
869
884
proc makeAggregateAndProof * (
870
885
pool: var AttestationPool , epochRef: EpochRef , slot: Slot , index: CommitteeIndex ,
@@ -1052,6 +1067,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
1052
1067
1053
1068
# Start by checking if there's work we should have done in the past that we
1054
1069
# can still meaningfully do
1070
+ var didPropose = false
1055
1071
while curSlot < slot:
1056
1072
notice " Catching up on validator duties" ,
1057
1073
curSlot = shortLog (curSlot),
@@ -1061,7 +1077,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
1061
1077
# For every slot we're catching up, we'll propose then send
1062
1078
# attestations - head should normally be advancing along the same branch
1063
1079
# in this case
1064
- head = await handleProposal (node, head, curSlot)
1080
+ ( head, didPropose) = await handleProposal (node, head, curSlot)
1065
1081
1066
1082
# For each slot we missed, we need to send out attestations - if we were
1067
1083
# 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.} =
1071
1087
1072
1088
curSlot += 1
1073
1089
1074
- head = await handleProposal (node, head, slot)
1090
+ ( head, didPropose) = await handleProposal (node, head, slot)
1075
1091
1076
1092
let
1077
1093
# The latest point in time when we'll be sending out attestations
@@ -1116,11 +1132,16 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
1116
1132
node.consensusManager[].updateHead (slot)
1117
1133
head = node.dag.head
1118
1134
1119
- static : doAssert attestationSlotOffset == syncCommitteeMessageSlotOffset
1120
-
1135
+ static :
1136
+ doAssert attestationSlotOffset == syncCommitteeMessageSlotOffset
1121
1137
handleAttestations (node, head, slot)
1122
1138
handleSyncCommitteeMessages (node, head, slot)
1123
1139
1140
+ if node.config.serveLightClientData:
1141
+ static :
1142
+ doAssert attestationSlotOffset == optimisticLightClientUpdateSlotOffset
1143
+ handleOptimisticLightClientUpdates (node, head, slot, didPropose)
1144
+
1124
1145
updateValidatorMetrics (node) # the important stuff is done, update the vanity numbers
1125
1146
1126
1147
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-aggregate
0 commit comments