Skip to content

Commit 0a9804a

Browse files
authored
refactor: remove an unused chain store effect (#507)
Signed-off-by: etorreborre <etorreborre@yahoo.com>
1 parent f7d0bb2 commit 0a9804a

5 files changed

Lines changed: 0 additions & 65 deletions

File tree

crates/amaru-consensus/src/consensus/effects/store_effects.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ impl<T: SendData + Sync> ChainStore<BlockHeader> for Store<T> {
112112
self.external_sync(StoreBlockEffect::new(hash, block.clone()))
113113
}
114114

115-
fn remove_header(&self, hash: &HeaderHash) -> Result<(), StoreError> {
116-
self.external_sync(RemoveHeaderEffect::new(*hash))
117-
}
118-
119115
fn put_nonces(&self, header: &HeaderHash, nonces: &Nonces) -> Result<(), StoreError> {
120116
self.external_sync(PutNoncesEffect::new(*header, nonces.clone()))
121117
}
@@ -268,34 +264,6 @@ impl ExternalEffectAPI for UpdateBestChainEffect {
268264
type Response = Result<(), StoreError>;
269265
}
270266

271-
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]
272-
struct RemoveHeaderEffect {
273-
hash: HeaderHash,
274-
}
275-
276-
impl RemoveHeaderEffect {
277-
pub fn new(hash: HeaderHash) -> Self {
278-
Self { hash }
279-
}
280-
}
281-
282-
impl ExternalEffect for RemoveHeaderEffect {
283-
#[expect(clippy::expect_used)]
284-
fn run(self: Box<Self>, resources: Resources) -> BoxFuture<'static, Box<dyn SendData>> {
285-
Self::wrap(async move {
286-
let store = resources
287-
.get::<ResourceHeaderStore>()
288-
.expect("RemoveHeaderEffect requires a chain store")
289-
.clone();
290-
store.remove_header(&self.hash)
291-
})
292-
}
293-
}
294-
295-
impl ExternalEffectAPI for RemoveHeaderEffect {
296-
type Response = Result<(), StoreError>;
297-
}
298-
299267
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]
300268
struct PutNoncesEffect {
301269
hash: HeaderHash,

crates/amaru-consensus/src/consensus/stages/validate_header.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,6 @@ mod tests {
342342
self.store.store_block(hash, block)
343343
}
344344

345-
fn remove_header(&self, hash: &Hash<32>) -> Result<(), StoreError> {
346-
self.store.remove_header(hash)
347-
}
348-
349345
fn put_nonces(&self, hash: &Hash<32>, nonces: &Nonces) -> Result<(), StoreError> {
350346
self.store.put_nonces(hash, nonces)
351347
}

crates/amaru-ouroboros-traits/src/stores/consensus/in_memory_consensus_store.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,6 @@ impl<H: IsHeader + Send + Sync + Clone + 'static> ChainStore<H> for InMemConsens
201201
Ok(())
202202
}
203203

204-
#[expect(clippy::unwrap_used)]
205-
fn remove_header(&self, hash: &Hash<32>) -> Result<(), StoreError> {
206-
let mut inner = self.inner.lock().unwrap();
207-
// unlink from parent's children list if present
208-
if let Some(parent) = inner.headers.get(hash).and_then(|h| h.parent())
209-
&& let Some(children) = inner.parent_child_relationship.get_mut(&parent)
210-
{
211-
if let Some(pos) = children.iter().position(|h| h == hash) {
212-
children.swap_remove(pos);
213-
}
214-
if children.is_empty() {
215-
inner.parent_child_relationship.remove(&parent);
216-
}
217-
}
218-
219-
// remove this node's children list
220-
inner.parent_child_relationship.remove(hash);
221-
// finally remove the header
222-
inner.headers.remove(hash);
223-
Ok(())
224-
}
225-
226204
#[expect(clippy::unwrap_used)]
227205
fn set_anchor_hash(&self, hash: &Hash<32>) -> Result<(), StoreError> {
228206
let mut inner = self.inner.lock().unwrap();

crates/amaru-ouroboros-traits/src/stores/consensus/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ where
146146
fn set_anchor_hash(&self, hash: &Hash<32>) -> Result<(), StoreError>;
147147
fn set_best_chain_hash(&self, hash: &Hash<32>) -> Result<(), StoreError>;
148148
fn update_best_chain(&self, anchor: &Hash<32>, tip: &Hash<32>) -> Result<(), StoreError>;
149-
fn remove_header(&self, hash: &Hash<32>) -> Result<(), StoreError>;
150149
fn store_block(&self, hash: &Hash<32>, block: &RawBlock) -> Result<(), StoreError>;
151150
fn put_nonces(&self, header: &Hash<32>, nonces: &Nonces) -> Result<(), StoreError>;
152151
}

crates/amaru-stores/src/rocksdb/consensus.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,6 @@ impl<H: IsHeader + Clone + for<'d> cbor::Decode<'d, ()>> ChainStore<H> for Rocks
303303
})
304304
}
305305

306-
fn remove_header(&self, hash: &Hash<32>) -> Result<(), StoreError> {
307-
self.db.delete(hash).map_err(|e| StoreError::WriteError {
308-
error: e.to_string(),
309-
})
310-
}
311-
312306
fn set_anchor_hash(&self, hash: &Hash<32>) -> Result<(), StoreError> {
313307
self.db
314308
.put(ANCHOR_PREFIX, hash.as_ref())

0 commit comments

Comments
 (0)