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:
Jimmy Chen
2025-08-20 15:08:53 +10:00
committed by GitHub
parent f6859b1137
commit 2d223575d6
3 changed files with 136 additions and 2 deletions

View File

@@ -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> {