Skip to content

Commit ee7109c

Browse files
committed
Simplifcation to get_data_columns.
1 parent 7b0e862 commit ee7109c

5 files changed

Lines changed: 26 additions & 76 deletions

File tree

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,46 +1111,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
11111111
block_root: Hash256,
11121112
indices: &[ColumnIndex],
11131113
) -> Result<Option<DataColumnSidecarList<T::EthSpec>>, Error> {
1114-
if indices.is_empty() {
1115-
return Ok(None);
1116-
}
1117-
1118-
let mut columns = vec![];
1119-
let mut indices: HashSet<ColumnIndex> = indices.iter().copied().collect();
1120-
1121-
if let Some(all_cols) = self
1114+
let all_cached_columns_opt = self
11221115
.data_availability_checker
1123-
.get_data_columns(block_root)?
1124-
{
1125-
let filtered = all_cols
1126-
.into_iter()
1127-
.filter(|col| indices.remove(&col.index))
1128-
.collect::<Vec<_>>();
1129-
columns.extend(filtered);
1130-
1131-
if indices.is_empty() {
1132-
return Ok(Some(columns));
1133-
}
1134-
}
1135-
if let Some(all_cols) = self.early_attester_cache.get_data_columns(block_root) {
1136-
let filtered = all_cols
1137-
.into_iter()
1138-
.filter(|col| indices.remove(&col.index))
1139-
.collect::<Vec<_>>();
1140-
columns.extend(filtered);
1141-
1142-
if indices.is_empty() {
1143-
return Ok(Some(columns));
1144-
}
1145-
}
1146-
if let Some(filtered) = self.get_data_columns(&block_root, Some(&mut indices))? {
1147-
columns.extend(filtered)
1148-
};
1116+
.get_data_columns(block_root)
1117+
.or_else(|| self.early_attester_cache.get_data_columns(block_root));
11491118

1150-
if columns.is_empty() {
1151-
Ok(None)
1119+
if let Some(mut all_cached_columns) = all_cached_columns_opt {
1120+
all_cached_columns.retain(|col| indices.contains(&col.index));
1121+
Ok(Some(all_cached_columns))
11521122
} else {
1153-
Ok(Some(columns))
1123+
self.get_data_columns(&block_root, Some(&indices.iter().cloned().collect()))
11541124
}
11551125
}
11561126

@@ -1235,7 +1205,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
12351205
pub fn get_data_columns(
12361206
&self,
12371207
block_root: &Hash256,
1238-
indices: Option<&mut HashSet<ColumnIndex>>,
1208+
indices: Option<&HashSet<ColumnIndex>>,
12391209
) -> Result<Option<DataColumnSidecarList<T::EthSpec>>, Error> {
12401210
self.store
12411211
.get_data_columns(block_root, indices)

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
167167
pub fn get_data_columns(
168168
&self,
169169
block_root: Hash256,
170-
) -> Result<Option<DataColumnSidecarList<T::EthSpec>>, AvailabilityCheckError> {
170+
) -> Option<DataColumnSidecarList<T::EthSpec>> {
171171
self.availability_cache.peek_data_columns(block_root)
172172
}
173173

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,12 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
408408
pub fn peek_data_columns(
409409
&self,
410410
block_root: Hash256,
411-
) -> Result<Option<DataColumnSidecarList<T::EthSpec>>, AvailabilityCheckError> {
412-
if let Some(pending_components) = self.critical.read().peek(&block_root) {
413-
Ok(Some(
414-
pending_components
411+
) -> Option<DataColumnSidecarList<T::EthSpec>> {
412+
self.critical.read().peek(&block_root).map(|pending_components| pending_components
415413
.verified_data_columns
416414
.iter()
417415
.map(|col| col.clone_arc())
418-
.collect(),
419-
))
420-
} else {
421-
Ok(None)
422-
}
416+
.collect())
423417
}
424418

425419
pub fn peek_pending_components<R, F: FnOnce(Option<&PendingComponents<T::EthSpec>>) -> R>(

beacon_node/store/src/hot_cold_store.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,10 @@ impl<E: EthSpec> BlockCache<E> {
117117
pub fn get_blobs<'a>(&'a mut self, block_root: &Hash256) -> Option<&'a BlobSidecarList<E>> {
118118
self.blob_cache.get(block_root)
119119
}
120-
pub fn get_data_columns(
121-
&mut self,
122-
block_root: &Hash256,
123-
indices: &mut Option<&mut HashSet<ColumnIndex>>,
124-
) -> Option<DataColumnSidecarList<E>> {
125-
self.data_column_cache.get(block_root).map(|map| {
126-
map.values()
127-
.filter(|col| {
128-
if let Some(set) = indices.as_mut() {
129-
set.remove(&col.index)
130-
} else {
131-
true
132-
}
133-
})
134-
.cloned()
135-
.collect::<Vec<_>>()
136-
})
120+
pub fn get_data_columns(&mut self, block_root: &Hash256) -> Option<DataColumnSidecarList<E>> {
121+
self.data_column_cache
122+
.get(block_root)
123+
.map(|map| map.values().cloned().collect::<Vec<_>>())
137124
}
138125
pub fn get_data_column<'a>(
139126
&'a mut self,
@@ -2048,19 +2035,18 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
20482035
pub fn get_data_columns(
20492036
&self,
20502037
block_root: &Hash256,
2051-
mut indices: Option<&mut HashSet<ColumnIndex>>,
2038+
indices: Option<&HashSet<ColumnIndex>>,
20522039
) -> Result<Option<DataColumnSidecarList<E>>, Error> {
2053-
if let Some(columns) = self
2054-
.block_cache
2055-
.lock()
2056-
.get_data_columns(block_root, &mut indices)
2057-
{
2040+
// TODO: The block cache may not have all columns.
2041+
if let Some(columns) = self.block_cache.lock().get_data_columns(block_root) {
20582042
metrics::inc_counter(&metrics::BEACON_DATA_COLUMNS_CACHE_HIT_COUNT);
20592043
return Ok(Some(columns));
20602044
}
2045+
// FIXME: refactor this
2046+
let indices = indices.cloned();
20612047

20622048
let byte_columns: Result<Vec<Vec<u8>>, Error> = match indices {
2063-
Some(indices) => {
2049+
Some(mut indices) => {
20642050
let indices_snapshot: Vec<_> = indices.iter().copied().collect();
20652051
indices_snapshot
20662052
.iter()

testing/ef_tests/tests/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,10 @@ mod ssz_static {
670670
#[ignore]
671671
// TODO(das): enable once EF tests are updated to latest release.
672672
fn data_column_by_root_identifier() {
673-
SszStaticHandler::<DataColumnsByRootIdentifier, MinimalEthSpec>::default()
674-
.run_for_feature(FeatureName::Fulu);
675-
SszStaticHandler::<DataColumnsByRootIdentifier, MainnetEthSpec>::default()
676-
.run_for_feature(FeatureName::Fulu);
673+
// SszStaticHandler::<DataColumnsByRootIdentifier, MinimalEthSpec>::default()
674+
// .run_for_feature(FeatureName::Fulu);
675+
// SszStaticHandler::<DataColumnsByRootIdentifier, MainnetEthSpec>::default()
676+
// .run_for_feature(FeatureName::Fulu);
677677
}
678678

679679
#[test]

0 commit comments

Comments
 (0)