Skip to content

Commit 928915c

Browse files
authored
as_store_bytes not fallible (#5285)
1 parent 5dfc5c1 commit 928915c

19 files changed

+92
-102
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
614614
// but absent in the DB. This inconsistency halts pruning and dramastically increases disk
615615
// size. Ref: https://github.com/sigp/lighthouse/issues/4773
616616
let head_tracker = self.head_tracker.0.read();
617-
batch.push(self.persist_head_in_batch(&head_tracker)?);
617+
batch.push(self.persist_head_in_batch(&head_tracker));
618618

619619
let _fork_choice_timer = metrics::start_timer(&metrics::PERSIST_FORK_CHOICE);
620-
batch.push(self.persist_fork_choice_in_batch()?);
620+
batch.push(self.persist_fork_choice_in_batch());
621621

622622
self.store.hot_db.do_atomically(batch)?;
623623
drop(head_tracker);
@@ -641,14 +641,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
641641
pub fn persist_head_in_batch(
642642
&self,
643643
head_tracker_reader: &HeadTrackerReader,
644-
) -> Result<KeyValueStoreOp, DBError> {
644+
) -> KeyValueStoreOp {
645645
Self::persist_head_in_batch_standalone(self.genesis_block_root, head_tracker_reader)
646646
}
647647

648648
pub fn persist_head_in_batch_standalone(
649649
genesis_block_root: Hash256,
650650
head_tracker_reader: &HeadTrackerReader,
651-
) -> Result<KeyValueStoreOp, DBError> {
651+
) -> KeyValueStoreOp {
652652
Self::make_persisted_head(genesis_block_root, head_tracker_reader)
653653
.as_kv_store_op(BEACON_CHAIN_DB_KEY)
654654
}

beacon_node/beacon_chain/src/builder.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,7 @@ where
578578
// This prevents the database from restarting in an inconsistent state if the anchor
579579
// info or split point is written before the `PersistedBeaconChain`.
580580
let retain_historic_states = self.chain_config.reconstruct_historic_states;
581-
self.pending_io_batch.push(
582-
store
583-
.store_split_in_batch()
584-
.map_err(|e| format!("Failed to store split: {:?}", e))?,
585-
);
581+
self.pending_io_batch.push(store.store_split_in_batch());
586582
self.pending_io_batch.push(
587583
store
588584
.init_anchor_info(weak_subj_block.message(), retain_historic_states)
@@ -875,19 +871,16 @@ where
875871
// This *must* be stored before constructing the `BeaconChain`, so that its `Drop` instance
876872
// doesn't write a `PersistedBeaconChain` without the rest of the batch.
877873
let head_tracker_reader = head_tracker.0.read();
878-
self.pending_io_batch
879-
.push(BeaconChain::<
880-
Witness<TSlotClock, TEth1Backend, TEthSpec, THotStore, TColdStore>,
881-
>::persist_head_in_batch_standalone(
882-
genesis_block_root,
883-
&head_tracker_reader,
884-
)
885-
.map_err(|e| format!("{e:?}"))?);
874+
self.pending_io_batch.push(BeaconChain::<
875+
Witness<TSlotClock, TEth1Backend, TEthSpec, THotStore, TColdStore>,
876+
>::persist_head_in_batch_standalone(
877+
genesis_block_root, &head_tracker_reader
878+
));
886879
self.pending_io_batch.push(BeaconChain::<
887880
Witness<TSlotClock, TEth1Backend, TEthSpec, THotStore, TColdStore>,
888881
>::persist_fork_choice_in_batch_standalone(
889882
&fork_choice
890-
).map_err(|e| format!("{e:?}"))?);
883+
));
891884
store
892885
.hot_db
893886
.do_atomically(self.pending_io_batch)

beacon_node/beacon_chain/src/canonical_head.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
10161016
}
10171017

10181018
/// Return a database operation for writing fork choice to disk.
1019-
pub fn persist_fork_choice_in_batch(&self) -> Result<KeyValueStoreOp, store::Error> {
1019+
pub fn persist_fork_choice_in_batch(&self) -> KeyValueStoreOp {
10201020
Self::persist_fork_choice_in_batch_standalone(&self.canonical_head.fork_choice_read_lock())
10211021
}
10221022

10231023
/// Return a database operation for writing fork choice to disk.
10241024
pub fn persist_fork_choice_in_batch_standalone(
10251025
fork_choice: &BeaconForkChoice<T>,
1026-
) -> Result<KeyValueStoreOp, store::Error> {
1026+
) -> KeyValueStoreOp {
10271027
let persisted_fork_choice = PersistedForkChoice {
10281028
fork_choice: fork_choice.to_persisted(),
10291029
fork_choice_store: fork_choice.fc_store().to_persisted(),

beacon_node/beacon_chain/src/eth1_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ impl StoreItem for SszEth1 {
178178
DBColumn::Eth1Cache
179179
}
180180

181-
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
182-
Ok(self.as_ssz_bytes())
181+
fn as_store_bytes(&self) -> Vec<u8> {
182+
self.as_ssz_bytes()
183183
}
184184

185185
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {

beacon_node/beacon_chain/src/migrate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
741741
};
742742
drop(head_tracker_lock);
743743
batch.push(StoreOp::KeyValueOp(
744-
persisted_head.as_kv_store_op(BEACON_CHAIN_DB_KEY)?,
744+
persisted_head.as_kv_store_op(BEACON_CHAIN_DB_KEY),
745745
));
746746

747747
store.do_atomically_with_block_and_blobs_cache(batch)?;

beacon_node/beacon_chain/src/otb_verification_service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl StoreItem for OptimisticTransitionBlock {
8585
OTBColumn
8686
}
8787

88-
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
89-
Ok(self.as_ssz_bytes())
88+
fn as_store_bytes(&self) -> Vec<u8> {
89+
self.as_ssz_bytes()
9090
}
9191

9292
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {

beacon_node/beacon_chain/src/persisted_beacon_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl StoreItem for PersistedBeaconChain {
2626
DBColumn::BeaconChain
2727
}
2828

29-
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
30-
Ok(self.as_ssz_bytes())
29+
fn as_store_bytes(&self) -> Vec<u8> {
30+
self.as_ssz_bytes()
3131
}
3232

3333
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {

beacon_node/beacon_chain/src/persisted_fork_choice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ macro_rules! impl_store_item {
4545
DBColumn::ForkChoice
4646
}
4747

48-
fn as_store_bytes(&self) -> Result<Vec<u8>, Error> {
49-
Ok(self.as_ssz_bytes())
48+
fn as_store_bytes(&self) -> Vec<u8> {
49+
self.as_ssz_bytes()
5050
}
5151

5252
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {

beacon_node/beacon_chain/src/schema_change/migration_schema_v17.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn upgrade_to_v17<T: BeaconChainTypes>(
6565
"Removing unused best_justified_checkpoint from fork choice store."
6666
);
6767

68-
Ok(vec![v17.as_kv_store_op(FORK_CHOICE_DB_KEY)?])
68+
Ok(vec![v17.as_kv_store_op(FORK_CHOICE_DB_KEY)])
6969
}
7070

7171
pub fn downgrade_from_v17<T: BeaconChainTypes>(
@@ -84,5 +84,5 @@ pub fn downgrade_from_v17<T: BeaconChainTypes>(
8484
"Adding junk best_justified_checkpoint to fork choice store."
8585
);
8686

87-
Ok(vec![v11.as_kv_store_op(FORK_CHOICE_DB_KEY)?])
87+
Ok(vec![v11.as_kv_store_op(FORK_CHOICE_DB_KEY)])
8888
}

beacon_node/network/src/persisted_dht.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ impl StoreItem for PersistedDht {
4444
DBColumn::DhtEnrs
4545
}
4646

47-
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
48-
Ok(rlp::encode_list(&self.enrs).to_vec())
47+
fn as_store_bytes(&self) -> Vec<u8> {
48+
rlp::encode_list(&self.enrs).to_vec()
4949
}
5050

5151
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {

0 commit comments

Comments
 (0)