Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/benchmark_private/tipset_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ async fn prepare_validation(
db.clone(),
db.clone(),
db.clone(),
db.clone(),
chain_config,
genesis_header,
)?);
Expand Down
37 changes: 4 additions & 33 deletions src/chain/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
index::{ChainIndex, ResolveNullTipset},
tipset_tracker::TipsetTracker,
};
use crate::db::{EthMappingsStore, EthMappingsStoreExt, IndicesStore, IndicesStoreExt};
use crate::db::{EthMappingsStore, EthMappingsStoreExt};
use crate::interpreter::{BlockMessages, VMTrace};
use crate::libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
use crate::message::{ChainMessage, Message as MessageTrait, SignedMessage};
Expand Down Expand Up @@ -82,9 +82,6 @@ pub struct ChainStore<DB> {
/// Ethereum mappings store
eth_mappings: Arc<dyn EthMappingsStore + Sync + Send>,

/// Indices store
indices: Arc<dyn IndicesStore + Sync + Send>,

/// Needed by the Ethereum mapping.
chain_config: Arc<ChainConfig>,
}
Expand Down Expand Up @@ -121,7 +118,6 @@ where
db: Arc<DB>,
heaviest_tipset_key_provider: Arc<dyn HeaviestTipsetKeyProvider + Sync + Send>,
eth_mappings: Arc<dyn EthMappingsStore + Sync + Send>,
indices: Arc<dyn IndicesStore + Sync + Send>,
chain_config: Arc<ChainConfig>,
genesis_block_header: CachingBlockHeader,
) -> anyhow::Result<Self> {
Expand All @@ -139,7 +135,6 @@ where
genesis_block_header,
validated_blocks,
eth_mappings,
indices,
chain_config,
};

Expand Down Expand Up @@ -204,15 +199,6 @@ where
.map(|(cid, _)| cid))
}

pub fn put_index<V: Serialize>(&self, key: &Cid, value: &V) -> Result<(), Error> {
self.indices.write_obj(key, value)?;
Ok(())
}

pub fn get_tipset_key(&self, key: &Cid) -> Result<Option<TipsetKey>, Error> {
Ok(self.indices.read_obj(key)?)
}

/// Expands tipset to tipset with all other headers in the same epoch using
/// the tipset tracker.
fn expand_tipset(&self, header: CachingBlockHeader) -> Result<Tipset, Error> {
Expand Down Expand Up @@ -754,15 +740,8 @@ mod tests {
message_receipts: Cid::new_v1(DAG_CBOR, MultihashCode::Identity.digest(&[])),
..Default::default()
});
let cs = ChainStore::new(
db.clone(),
db.clone(),
db.clone(),
db,
chain_config,
gen_block.clone(),
)
.unwrap();
let cs =
ChainStore::new(db.clone(), db.clone(), db, chain_config, gen_block.clone()).unwrap();

assert_eq!(cs.genesis_block_header(), &gen_block);
}
Expand All @@ -776,15 +755,7 @@ mod tests {
..Default::default()
});

let cs = ChainStore::new(
db.clone(),
db.clone(),
db.clone(),
db,
chain_config,
gen_block,
)
.unwrap();
let cs = ChainStore::new(db.clone(), db.clone(), db, chain_config, gen_block).unwrap();

let cid = Cid::new_v1(DAG_CBOR, MultihashCode::Blake2b256.digest(&[1, 2, 3]));
assert!(!cs.is_block_validated(&cid));
Expand Down
1 change: 0 additions & 1 deletion src/chain_sync/chain_follower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ mod tests {
db.clone(),
db.clone(),
db.clone(),
db.clone(),
Default::default(),
genesis_header.clone().into(),
)
Expand Down
1 change: 0 additions & 1 deletion src/daemon/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ async fn create_state_manager(
Arc::clone(db),
Arc::new(db.clone()),
eth_mappings,
db.writer().clone(),
chain_config.clone(),
genesis_header.clone(),
)?);
Expand Down
7 changes: 1 addition & 6 deletions src/daemon/db_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,9 @@ where
let epoch = ts.epoch();
let tsk = ts.key().clone();

let state_output = state_manager
state_manager
.compute_tipset_state(ts.clone(), NO_CALLBACK, VMTrace::NotTraced)
.await?;
for events_root in state_output.events_roots.iter().flatten() {
tracing::trace!("Indexing events root @{epoch}: {events_root}");

state_manager.chain_store().put_index(events_root, &tsk)?;
}

delegated_messages.append(
&mut state_manager
Expand Down
18 changes: 2 additions & 16 deletions src/db/car/many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use super::{AnyCar, ZstdFrameCache};
use crate::blocks::TipsetKey;
use crate::db::{
BlockstoreWriteOpsSubscribable, EthMappingsStore, IndicesStore, MemoryDB, PersistentStore,
SettingsStore, SettingsStoreExt,
BlockstoreWriteOpsSubscribable, EthMappingsStore, MemoryDB, PersistentStore, SettingsStore,
SettingsStoreExt,
};
use crate::libp2p_bitswap::BitswapStoreReadWrite;
use crate::rpc::eth::types::EthHash;
Expand Down Expand Up @@ -251,20 +251,6 @@ impl<WriterT: EthMappingsStore> EthMappingsStore for ManyCar<WriterT> {
}
}

impl<WriterT: IndicesStore> IndicesStore for ManyCar<WriterT> {
fn read_bin(&self, key: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
IndicesStore::read_bin(self.writer(), key)
}

fn write_bin(&self, key: &Cid, value: &[u8]) -> anyhow::Result<()> {
IndicesStore::write_bin(self.writer(), key, value)
}

fn exists(&self, key: &Cid) -> anyhow::Result<bool> {
IndicesStore::exists(self.writer(), key)
}
}

impl<T: Blockstore + SettingsStore> super::super::HeaviestTipsetKeyProvider for ManyCar<T> {
fn heaviest_tipset_key(&self) -> anyhow::Result<TipsetKey> {
match SettingsStoreExt::read_obj::<TipsetKey>(self, crate::db::setting_keys::HEAD_KEY)? {
Expand Down
20 changes: 1 addition & 19 deletions src/db/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use super::{EthMappingsStore, SettingsStore, SettingsStoreExt};
use crate::blocks::TipsetKey;
use crate::db::{IndicesStore, PersistentStore};
use crate::db::PersistentStore;
use crate::libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
use crate::rpc::eth::types::EthHash;
use crate::utils::db::car_stream::CarBlock;
Expand All @@ -21,7 +21,6 @@ pub struct MemoryDB {
blockchain_persistent_db: RwLock<HashMap<Cid, Vec<u8>>>,
settings_db: RwLock<HashMap<String, Vec<u8>>>,
pub eth_mappings_db: RwLock<HashMap<EthHash, Vec<u8>>>,
pub indices_db: RwLock<HashMap<Cid, Vec<u8>>>,
}

impl MemoryDB {
Expand Down Expand Up @@ -110,23 +109,6 @@ impl EthMappingsStore for MemoryDB {
}
}

impl IndicesStore for MemoryDB {
fn read_bin(&self, key: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
Ok(self.indices_db.read().get(key).cloned())
}

fn write_bin(&self, key: &Cid, value: &[u8]) -> anyhow::Result<()> {
self.indices_db
.write()
.insert(key.to_owned(), value.to_vec());
Ok(())
}

fn exists(&self, key: &Cid) -> anyhow::Result<bool> {
Ok(self.indices_db.read().contains_key(key))
}
}

impl Blockstore for MemoryDB {
fn get(&self, k: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
Ok(self.blockchain_db.read().get(k).cloned().or(self
Expand Down
41 changes: 0 additions & 41 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,47 +191,6 @@ impl<T: ?Sized + EthMappingsStore> EthMappingsStoreExt for T {
}
}

pub trait IndicesStore {
fn read_bin(&self, key: &Cid) -> anyhow::Result<Option<Vec<u8>>>;

fn write_bin(&self, key: &Cid, value: &[u8]) -> anyhow::Result<()>;

#[allow(dead_code)]
fn exists(&self, key: &Cid) -> anyhow::Result<bool>;
}

impl<T: IndicesStore> IndicesStore for Arc<T> {
fn read_bin(&self, key: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
IndicesStore::read_bin(self.as_ref(), key)
}

fn write_bin(&self, key: &Cid, value: &[u8]) -> anyhow::Result<()> {
IndicesStore::write_bin(self.as_ref(), key, value)
}

fn exists(&self, key: &Cid) -> anyhow::Result<bool> {
IndicesStore::exists(self.as_ref(), key)
}
}

pub trait IndicesStoreExt {
fn read_obj<V: DeserializeOwned>(&self, key: &Cid) -> anyhow::Result<Option<V>>;
fn write_obj<V: Serialize>(&self, key: &Cid, value: &V) -> anyhow::Result<()>;
}

impl<T: ?Sized + IndicesStore> IndicesStoreExt for T {
fn read_obj<V: DeserializeOwned>(&self, key: &Cid) -> anyhow::Result<Option<V>> {
match self.read_bin(key)? {
Some(bytes) => Ok(Some(fvm_ipld_encoding::from_slice(&bytes)?)),
None => Ok(None),
}
}

fn write_obj<V: Serialize>(&self, key: &Cid, value: &V) -> anyhow::Result<()> {
self.write_bin(key, &fvm_ipld_encoding::to_vec(value)?)
}
}

/// Traits for collecting DB stats
pub trait DBStatistics {
fn get_statistics(&self) -> Option<String> {
Expand Down
28 changes: 1 addition & 27 deletions src/db/parity_db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::{EthMappingsStore, IndicesStore, PersistentStore, SettingsStore};
use super::{EthMappingsStore, PersistentStore, SettingsStore};
use crate::blocks::TipsetKey;
use crate::db::{DBStatistics, parity_db_config::ParityDbConfig};
use crate::libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
Expand Down Expand Up @@ -39,8 +39,6 @@ pub enum DbColumn {
/// Anything stored in this column can be considered permanent, unless manually
/// deleted.
PersistentGraph,
/// Column for storing indexed values.
Indices,
}

impl DbColumn {
Expand Down Expand Up @@ -77,12 +75,6 @@ impl DbColumn {
compression,
..Default::default()
},
DbColumn::Indices => parity_db::ColumnOptions {
preimage: false,
btree_index: false,
compression,
..Default::default()
},
}
})
.collect()
Expand Down Expand Up @@ -229,23 +221,6 @@ impl EthMappingsStore for ParityDb {
}
}

impl IndicesStore for ParityDb {
fn read_bin(&self, key: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
self.read_from_column(key.to_bytes(), DbColumn::Indices)
}

fn write_bin(&self, key: &Cid, value: &[u8]) -> anyhow::Result<()> {
self.write_to_column(key.to_bytes(), value, DbColumn::Indices)
}

fn exists(&self, key: &Cid) -> anyhow::Result<bool> {
self.db
.get_size(DbColumn::Indices as u8, &key.to_bytes())
.map(|size| size.is_some())
.context("error checking if key exists")
}
}

fn has_subscribers<T>(tx: &tokio::sync::broadcast::Sender<T>) -> bool {
tx.closed().now_or_never().is_none()
}
Expand Down Expand Up @@ -463,7 +438,6 @@ mod test {
DbColumn::Settings => panic!("invalid column for IPLD data"),
DbColumn::EthMappings => panic!("invalid column for IPLD data"),
DbColumn::PersistentGraph => panic!("invalid column for GC enabled IPLD data"),
DbColumn::Indices => panic!("invalid indices column for IPLD data"),
};
let actual = db.read_from_column(cid.to_bytes(), other_column).unwrap();
assert!(actual.is_none());
Expand Down
1 change: 0 additions & 1 deletion src/libp2p/chain_exchange/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ mod tests {

let response = make_chain_exchange_response(
&ChainStore::new(
db.clone(),
db.clone(),
db.clone(),
db,
Expand Down
12 changes: 1 addition & 11 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,7 @@ impl RpcMethod<1> for ChainGetEvents {
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(root_cid,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let tsk = ctx
.state_manager
.chain_store()
.get_tipset_key(&root_cid)?
.with_context(|| format!("can't find events with cid {root_cid}"))?;

let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;

let events = EthEventHandler::collect_chain_events(&ctx, &ts, &root_cid).await?;

let events = EthEventHandler::get_events_by_event_root(&ctx, &root_cid)?;
Ok(events)
}
}
Expand Down Expand Up @@ -1620,7 +1611,6 @@ mod tests {
db,
Arc::new(MemoryDB::default()),
Arc::new(MemoryDB::default()),
Arc::new(MemoryDB::default()),
Arc::new(ChainConfig::calibnet()),
genesis_block_header,
)
Expand Down
Loading
Loading