Skip to content

Commit e75b84f

Browse files
committed
add better comments, return helpful error messages over http and rpc
1 parent 8ef297b commit e75b84f

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

beacon_node/beacon_chain/src/light_client_server_cache.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
399399
self.latest_optimistic_update.read().clone()
400400
}
401401

402+
/// Fetches a `sync_committee_branch` for a given `block_root`
403+
///
404+
/// Note:
402405
pub fn get_sync_committee_branch(
403406
&self,
404407
store: &BeaconStore<T>,
@@ -410,9 +413,9 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
410413
.hot_db
411414
.get_bytes(column.into(), &block_root.as_ssz_bytes())?
412415
{
413-
// TODO unwrap
414416
let sync_committee_branch: FixedVector<Hash256, CurrentSyncCommitteeProofLen> =
415-
FixedVector::from_ssz_bytes(&bytes).unwrap();
417+
FixedVector::from_ssz_bytes(&bytes)
418+
.map_err(store::errors::Error::SszDecodeError)?;
416419

417420
return Ok(Some(sync_committee_branch));
418421
}
@@ -432,13 +435,20 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
432435
.get_bytes(column.into(), &sync_committee_period.as_ssz_bytes())?
433436
{
434437
let sync_committee: SyncCommittee<T::EthSpec> =
435-
SyncCommittee::from_ssz_bytes(&bytes).unwrap();
438+
SyncCommittee::from_ssz_bytes(&bytes)
439+
.map_err(store::errors::Error::SszDecodeError)?;
436440
return Ok(Some(sync_committee));
437441
}
438442

439443
Ok(None)
440444
}
441445

446+
/// Fetches a light client bootstrap for a given finalized checkpoint `block_root`. We eagerly persist
447+
/// `sync_committee_branch and `sync_committee` to allow for a more efficient bootstrap construction.
448+
///
449+
/// Note: It should be the case that a `sync_committee_branch` and `sync_committee` exist in the db
450+
/// for a finalized checkpoint block root. However, we currently have no backfill mechanism for these values.
451+
/// Therefore, `sync_committee_branch` and `sync_committee` are only persisted while a node is synced.
442452
#[allow(clippy::type_complexity)]
443453
pub fn get_light_client_bootstrap(
444454
&self,

beacon_node/network/src/network_beacon_processor/rpc_methods.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
328328
Ok(Some((bootstrap, _))) => Ok(Arc::new(bootstrap)),
329329
Ok(None) => Err((
330330
RPCResponseErrorCode::ResourceUnavailable,
331-
"Bootstrap not available",
331+
"Bootstrap not available".to_string(),
332332
)),
333333
Err(e) => {
334334
error!(self.log, "Error getting LightClientBootstrap instance";
@@ -338,7 +338,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
338338
);
339339
Err((
340340
RPCResponseErrorCode::ResourceUnavailable,
341-
"Bootstrap not available",
341+
format!("{:?}", e),
342342
))
343343
}
344344
},
@@ -363,7 +363,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
363363
Some(update) => Ok(Arc::new(update)),
364364
None => Err((
365365
RPCResponseErrorCode::ResourceUnavailable,
366-
"Latest optimistic update not available",
366+
"Latest optimistic update not available".to_string(),
367367
)),
368368
},
369369
Response::LightClientOptimisticUpdate,
@@ -387,7 +387,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
387387
Some(update) => Ok(Arc::new(update)),
388388
None => Err((
389389
RPCResponseErrorCode::ResourceUnavailable,
390-
"Latest finality update not available",
390+
"Latest finality update not available".to_string(),
391391
)),
392392
},
393393
Response::LightClientFinalityUpdate,
@@ -821,7 +821,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
821821
&self,
822822
peer_id: PeerId,
823823
request_id: PeerRequestId,
824-
result: Result<R, (RPCResponseErrorCode, &'static str)>,
824+
result: Result<R, (RPCResponseErrorCode, String)>,
825825
into_response: F,
826826
) {
827827
match result {
@@ -836,7 +836,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
836836
});
837837
}
838838
Err((error_code, reason)) => {
839-
self.send_error_response(peer_id, error_code, reason.into(), request_id);
839+
self.send_error_response(peer_id, error_code, reason, request_id);
840840
}
841841
}
842842
}

0 commit comments

Comments
 (0)