@@ -8,7 +8,7 @@ use types::light_client_update::{FinalizedRootProofLen, FINALIZED_ROOT_INDEX};
88use types:: non_zero_usize:: new_non_zero_usize;
99use types:: {
1010 BeaconBlockRef , BeaconState , ChainSpec , EthSpec , ForkName , Hash256 , LightClientFinalityUpdate ,
11- LightClientHeader , LightClientOptimisticUpdate , Slot , SyncAggregate ,
11+ LightClientOptimisticUpdate , Slot , SyncAggregate ,
1212} ;
1313
1414/// A prev block cache miss requires to re-generate the state of the post-parent block. Items in the
@@ -71,24 +71,26 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
7171 /// results are cached either on disk or memory to be served via p2p and rest API
7272 pub fn recompute_and_cache_updates (
7373 & self ,
74- log : & Logger ,
7574 store : BeaconStore < T > ,
7675 block_parent_root : & Hash256 ,
7776 block_slot : Slot ,
7877 sync_aggregate : & SyncAggregate < T :: EthSpec > ,
78+ log : & Logger ,
79+ chain_spec : & ChainSpec ,
7980 ) -> Result < ( ) , BeaconChainError > {
8081 let _timer =
8182 metrics:: start_timer ( & metrics:: LIGHT_CLIENT_SERVER_CACHE_RECOMPUTE_UPDATES_TIMES ) ;
8283
8384 let signature_slot = block_slot;
8485 let attested_block_root = block_parent_root;
8586
86- let attested_block = store. get_blinded_block ( attested_block_root) ?. ok_or (
87- BeaconChainError :: DBInconsistent ( format ! (
88- "Block not available {:?}" ,
89- attested_block_root
90- ) ) ,
91- ) ?;
87+ let attested_block =
88+ store
89+ . get_full_block ( attested_block_root) ?
90+ . ok_or ( BeaconChainError :: DBInconsistent ( format ! (
91+ "Block not available {:?}" ,
92+ attested_block_root
93+ ) ) ) ?;
9294
9395 let cached_parts = self . get_or_compute_prev_block_cache (
9496 store. clone ( ) ,
@@ -109,11 +111,12 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
109111 } ;
110112 if is_latest_optimistic {
111113 // can create an optimistic update, that is more recent
112- * self . latest_optimistic_update . write ( ) = Some ( LightClientOptimisticUpdate {
113- attested_header : block_to_light_client_header ( attested_block. message ( ) ) ,
114- sync_aggregate : sync_aggregate . clone ( ) ,
114+ * self . latest_optimistic_update . write ( ) = Some ( LightClientOptimisticUpdate :: new (
115+ & attested_block,
116+ sync_aggregate. clone ( ) ,
115117 signature_slot,
116- } ) ;
118+ chain_spec,
119+ ) ?) ;
117120 } ;
118121
119122 // Spec: Full nodes SHOULD provide the LightClientFinalityUpdate with the highest
@@ -127,17 +130,16 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
127130 if is_latest_finality & !cached_parts. finalized_block_root . is_zero ( ) {
128131 // Immediately after checkpoint sync the finalized block may not be available yet.
129132 if let Some ( finalized_block) =
130- store. get_blinded_block ( & cached_parts. finalized_block_root ) ?
133+ store. get_full_block ( & cached_parts. finalized_block_root ) ?
131134 {
132- * self . latest_finality_update . write ( ) = Some ( LightClientFinalityUpdate {
133- // TODO: may want to cache this result from latest_optimistic_update if producing a
134- // light_client header becomes expensive
135- attested_header : block_to_light_client_header ( attested_block. message ( ) ) ,
136- finalized_header : block_to_light_client_header ( finalized_block. message ( ) ) ,
137- finality_branch : cached_parts. finality_branch . clone ( ) ,
138- sync_aggregate : sync_aggregate. clone ( ) ,
135+ * self . latest_finality_update . write ( ) = Some ( LightClientFinalityUpdate :: new (
136+ & attested_block,
137+ & finalized_block,
138+ cached_parts. finality_branch . clone ( ) ,
139+ sync_aggregate. clone ( ) ,
139140 signature_slot,
140- } ) ;
141+ chain_spec,
142+ ) ?) ;
141143 } else {
142144 debug ! (
143145 log,
@@ -214,7 +216,7 @@ impl LightClientCachedData {
214216 }
215217}
216218
217- // Implements spec priorization rules:
219+ // Implements spec prioritization rules:
218220// > Full nodes SHOULD provide the LightClientFinalityUpdate with the highest attested_header.beacon.slot (if multiple, highest signature_slot)
219221//
220222// ref: https://github.com/ethereum/consensus-specs/blob/113c58f9bf9c08867f6f5f633c4d98e0364d612a/specs/altair/light-client/full-node.md#create_light_client_finality_update
@@ -223,14 +225,15 @@ fn is_latest_finality_update<T: EthSpec>(
223225 attested_slot : Slot ,
224226 signature_slot : Slot ,
225227) -> bool {
226- if attested_slot > prev. attested_header . beacon . slot {
228+ let prev_slot = prev. get_attested_header_slot ( ) ;
229+ if attested_slot > prev_slot {
227230 true
228231 } else {
229- attested_slot == prev . attested_header . beacon . slot && signature_slot > prev. signature_slot
232+ attested_slot == prev_slot && signature_slot > * prev. signature_slot ( )
230233 }
231234}
232235
233- // Implements spec priorization rules:
236+ // Implements spec prioritization rules:
234237// > Full nodes SHOULD provide the LightClientOptimisticUpdate with the highest attested_header.beacon.slot (if multiple, highest signature_slot)
235238//
236239// ref: https://github.com/ethereum/consensus-specs/blob/113c58f9bf9c08867f6f5f633c4d98e0364d612a/specs/altair/light-client/full-node.md#create_light_client_optimistic_update
@@ -239,18 +242,10 @@ fn is_latest_optimistic_update<T: EthSpec>(
239242 attested_slot : Slot ,
240243 signature_slot : Slot ,
241244) -> bool {
242- if attested_slot > prev. attested_header . beacon . slot {
245+ let prev_slot = prev. get_slot ( ) ;
246+ if attested_slot > prev_slot {
243247 true
244248 } else {
245- attested_slot == prev. attested_header . beacon . slot && signature_slot > prev. signature_slot
246- }
247- }
248-
249- fn block_to_light_client_header < T : EthSpec > (
250- block : BeaconBlockRef < T , types:: BlindedPayload < T > > ,
251- ) -> LightClientHeader {
252- // TODO: make fork aware
253- LightClientHeader {
254- beacon : block. block_header ( ) ,
249+ attested_slot == prev_slot && signature_slot > * prev. signature_slot ( )
255250 }
256251}
0 commit comments