Skip to content

Commit 43a9704

Browse files
committed
fix
1 parent acf1d92 commit 43a9704

File tree

7 files changed

+342
-381
lines changed

7 files changed

+342
-381
lines changed

src/chain/store/tipset_tracker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<DB: Blockstore> TipsetTracker<DB> {
6060
cids.push(*header.cid());
6161
drop(map_lock);
6262

63-
self.check_consensus_fault(header);
63+
self.check_consensus_faults(header);
6464
self.check_multiple_blocks_from_same_miner(&cids_to_verify, header);
6565
self.prune_entries(header.epoch);
6666
}
@@ -88,7 +88,7 @@ impl<DB: Blockstore> TipsetTracker<DB> {
8888
}
8989

9090
/// Process block with slasher service for consensus fault detection
91-
fn check_consensus_fault(&self, header: &CachingBlockHeader) {
91+
fn check_consensus_faults(&self, header: &CachingBlockHeader) {
9292
if let Some(slasher) = &self.slasher_service {
9393
let slasher = slasher.clone();
9494
let header = header.clone();

src/slasher/db.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2019-2025 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use crate::blocks::CachingBlockHeader;
5+
use anyhow::Result;
6+
use parity_db::{Db, Options};
7+
8+
pub struct SlasherDb {
9+
db: Db,
10+
}
11+
12+
pub enum SlasherDbColumns {
13+
ByEpoch = 0,
14+
ByParents = 1,
15+
}
16+
17+
impl SlasherDb {
18+
pub fn new(data_dir: std::path::PathBuf) -> Result<Self> {
19+
std::fs::create_dir_all(&data_dir)?;
20+
21+
let mut options = Options::with_columns(&data_dir, 2);
22+
if let Some(column) = options.columns.get_mut(SlasherDbColumns::ByEpoch as usize) {
23+
column.btree_index = true;
24+
column.uniform = false;
25+
}
26+
if let Some(column) = options
27+
.columns
28+
.get_mut(SlasherDbColumns::ByParents as usize)
29+
{
30+
column.btree_index = true;
31+
column.uniform = false;
32+
}
33+
34+
let db = Db::open_or_create(&options)?;
35+
36+
Ok(Self { db })
37+
}
38+
39+
pub fn put(&mut self, header: &CachingBlockHeader) -> Result<()> {
40+
let miner = header.miner_address;
41+
let epoch = header.epoch;
42+
43+
let epoch_key = format!("{}/{}", miner, epoch);
44+
let parent_key = format!("{}/{}", miner, header.parents);
45+
46+
self.db.commit(vec![
47+
(
48+
SlasherDbColumns::ByEpoch as u8,
49+
epoch_key.as_bytes(),
50+
Some(header.cid().to_bytes()),
51+
),
52+
(
53+
SlasherDbColumns::ByParents as u8,
54+
parent_key.as_bytes(),
55+
Some(header.cid().to_bytes()),
56+
),
57+
])?;
58+
59+
Ok(())
60+
}
61+
62+
pub fn get(&self, column: u8, key: &[u8]) -> Result<Option<Vec<u8>>> {
63+
Ok(self.db.get(column, key)?)
64+
}
65+
}

src/slasher/filter.rs

Lines changed: 0 additions & 232 deletions
This file was deleted.

src/slasher/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2019-2025 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
pub mod filter;
4+
pub mod db;
55
pub mod service;
66
pub mod types;
77

0 commit comments

Comments
 (0)