mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +00:00
Avoid unnecessary database lookups in data column RPC requests (#7897)
This PR is an optimisation to avoid unnecessary database lookups when peer requests data columns that the node doesn't custody (advertised via `cgc`). e.g. an extreme but realistic example - a full node only store 4 custody columns by default, but it may receive a range request of 32 slots with all 128 columns, and this would result in 4096 database lookups but the node is only able to get 128 (4 * 32) of them. - Filter data column RPC requests (`DataColumnsByRoot`, `DataColumnsByRange`) to only lookup columns the node custodies - Prevents unnecessary database queries that would always fail for non-custody columns
This commit is contained in:
@@ -7153,6 +7153,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.custody_context()
|
||||
.sampling_columns_for_epoch(epoch, &self.spec)
|
||||
}
|
||||
|
||||
/// Returns a list of column indices that the node is expected to custody for a given epoch.
|
||||
/// i.e. the node must have validated and persisted the column samples and should be able to
|
||||
/// serve them to peers.
|
||||
///
|
||||
/// If epoch is `None`, this function computes the custody columns at head.
|
||||
pub fn custody_columns_for_epoch(&self, epoch_opt: Option<Epoch>) -> &[ColumnIndex] {
|
||||
self.data_availability_checker
|
||||
.custody_context()
|
||||
.custody_columns_for_epoch(epoch_opt, &self.spec)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BeaconChainTypes> Drop for BeaconChain<T> {
|
||||
|
||||
Reference in New Issue
Block a user