Skip to content

Commit 6973184

Browse files
authored
Fix Redb implementation and add CI checks (#6856)
1 parent c6ebaba commit 6973184

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ lint-fix:
222222

223223
# Also run the lints on the optimized-only tests
224224
lint-full:
225-
RUSTFLAGS="-C debug-assertions=no $(RUSTFLAGS)" $(MAKE) lint
225+
TEST_FEATURES="beacon-node-leveldb,beacon-node-redb,${TEST_FEATURES}" RUSTFLAGS="-C debug-assertions=no $(RUSTFLAGS)" $(MAKE) lint
226226

227227
# Runs the makefile in the `ef_tests` repo.
228228
#

beacon_node/store/src/database/redb_impl.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ impl<E: EthSpec> Redb<E> {
215215
let table_definition: TableDefinition<'_, &[u8], &[u8]> =
216216
TableDefinition::new(column.into());
217217

218-
let iter = {
218+
let result = (|| {
219219
let open_db = self.db.read();
220220
let read_txn = open_db.begin_read()?;
221221
let table = read_txn.open_table(table_definition)?;
222-
table.range(from..)?.map(move |res| {
222+
let range = table.range(from..)?;
223+
Ok(range.map(move |res| {
223224
let (key, _) = res?;
224225
metrics::inc_counter_vec(&metrics::DISK_DB_KEY_READ_COUNT, &[column.into()]);
225226
metrics::inc_counter_vec_by(
@@ -228,10 +229,13 @@ impl<E: EthSpec> Redb<E> {
228229
key.value().len() as u64,
229230
);
230231
K::from_bytes(key.value())
231-
})
232-
};
232+
}))
233+
})();
233234

234-
Box::new(iter)
235+
match result {
236+
Ok(iter) => Box::new(iter),
237+
Err(err) => Box::new(std::iter::once(Err(err))),
238+
}
235239
}
236240

237241
/// Iterate through all keys and values in a particular column.
@@ -243,15 +247,13 @@ impl<E: EthSpec> Redb<E> {
243247
let table_definition: TableDefinition<'_, &[u8], &[u8]> =
244248
TableDefinition::new(column.into());
245249

246-
let prefix = from.to_vec();
247-
248-
let iter = {
250+
let result = (|| {
249251
let open_db = self.db.read();
250252
let read_txn = open_db.begin_read()?;
251253
let table = read_txn.open_table(table_definition)?;
254+
let range = table.range(from..)?;
252255

253-
table
254-
.range(from..)?
256+
Ok(range
255257
.take_while(move |res| match res.as_ref() {
256258
Ok((_, _)) => true,
257259
Err(_) => false,
@@ -265,14 +267,17 @@ impl<E: EthSpec> Redb<E> {
265267
value.value().len() as u64,
266268
);
267269
Ok((K::from_bytes(key.value())?, value.value().to_vec()))
268-
})
269-
};
270+
}))
271+
})();
270272

271-
Ok(Box::new(iter))
273+
match result {
274+
Ok(iter) => Box::new(iter),
275+
Err(err) => Box::new(std::iter::once(Err(err))),
276+
}
272277
}
273278

274279
pub fn iter_column<K: Key>(&self, column: DBColumn) -> ColumnIter<K> {
275-
self.iter_column_from(column, &vec![0; column.key_size()], |_, _| true)
280+
self.iter_column_from(column, &vec![0; column.key_size()])
276281
}
277282

278283
pub fn delete_batch(&self, col: DBColumn, ops: HashSet<&[u8]>) -> Result<(), Error> {

beacon_node/store/src/forwards_iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
158158
return None;
159159
}
160160
self.inner
161+
.as_mut()
161162
.next()?
162163
.and_then(|(slot_bytes, root_bytes)| {
163164
let slot = slot_bytes

beacon_node/store/src/hot_cold_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::metadata::{
1414
};
1515
use crate::state_cache::{PutStateOutcome, StateCache};
1616
use crate::{
17-
get_data_column_key, metrics, parse_data_column_key, BlobSidecarListFromRoot, DBColumn,
18-
DatabaseBlock, Error, ItemStore, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
17+
get_data_column_key, metrics, parse_data_column_key, BlobSidecarListFromRoot, ColumnKeyIter,
18+
DBColumn, DatabaseBlock, Error, ItemStore, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
1919
};
2020
use itertools::{process_results, Itertools};
2121
use lru::LruCache;
@@ -405,7 +405,7 @@ impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
405405
}
406406

407407
/// Return an iterator over the state roots of all temporary states.
408-
pub fn iter_temporary_state_roots(&self) -> impl Iterator<Item = Result<Hash256, Error>> + '_ {
408+
pub fn iter_temporary_state_roots(&self) -> ColumnKeyIter<Hash256> {
409409
self.hot_db
410410
.iter_column_keys::<Hash256>(DBColumn::BeaconStateTemporary)
411411
}

0 commit comments

Comments
 (0)