Skip to content

Commit 8093469

Browse files
authored
feat: forest-tool benchmark blockstore (#6331)
1 parent b156748 commit 8093469

File tree

8 files changed

+278
-122
lines changed

8 files changed

+278
-122
lines changed

Cargo.lock

Lines changed: 32 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ name = "forest"
1414
[workspace.dependencies]
1515
anyhow = "1"
1616
cid = { version = "0.11", default-features = false, features = ["std"] }
17-
flume = "0.11"
17+
flume = "0.12"
1818
futures = "0.3"
1919
get-size2 = { version = "0.7", features = ["derive", "hashbrown"] }
2020
hashlink = "0.11"
@@ -254,7 +254,7 @@ predicates = "3"
254254
proc-macro2 = { version = "1", default-features = false, features = ["span-locations"] }
255255
quickcheck = "1"
256256
quickcheck_macros = "1"
257-
ra_ap_syntax = "0.0.308"
257+
ra_ap_syntax = "0.0.309"
258258
regex-automata = "0.4"
259259
serial_test = "3"
260260
syn = { version = "2", default-features = false, features = ["full", "parsing", "visit", "printing", "extra-traits"] }

src/db/either.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2019-2025 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use super::*;
5+
6+
pub enum Either<A: Blockstore, B: Blockstore> {
7+
Left(A),
8+
Right(B),
9+
}
10+
11+
impl<A: Blockstore, B: Blockstore> Blockstore for Either<A, B> {
12+
fn has(&self, k: &Cid) -> anyhow::Result<bool> {
13+
match self {
14+
Self::Left(v) => v.has(k),
15+
Self::Right(v) => v.has(k),
16+
}
17+
}
18+
19+
#[allow(clippy::disallowed_types)]
20+
fn put<D>(
21+
&self,
22+
mh_code: multihash_codetable::Code,
23+
block: &fvm_ipld_blockstore::Block<D>,
24+
) -> anyhow::Result<Cid>
25+
where
26+
Self: Sized,
27+
D: AsRef<[u8]>,
28+
{
29+
match self {
30+
Self::Left(v) => v.put(mh_code, block),
31+
Self::Right(v) => v.put(mh_code, block),
32+
}
33+
}
34+
35+
#[allow(clippy::disallowed_types)]
36+
fn put_many<D, I>(&self, blocks: I) -> anyhow::Result<()>
37+
where
38+
Self: Sized,
39+
D: AsRef<[u8]>,
40+
I: IntoIterator<Item = (multihash_codetable::Code, fvm_ipld_blockstore::Block<D>)>,
41+
{
42+
match self {
43+
Self::Left(v) => v.put_many(blocks),
44+
Self::Right(v) => v.put_many(blocks),
45+
}
46+
}
47+
48+
fn put_many_keyed<D, I>(&self, blocks: I) -> anyhow::Result<()>
49+
where
50+
Self: Sized,
51+
D: AsRef<[u8]>,
52+
I: IntoIterator<Item = (Cid, D)>,
53+
{
54+
match self {
55+
Self::Left(v) => v.put_many_keyed(blocks),
56+
Self::Right(v) => v.put_many_keyed(blocks),
57+
}
58+
}
59+
60+
fn get(&self, k: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
61+
match self {
62+
Self::Left(v) => v.get(k),
63+
Self::Right(v) => v.get(k),
64+
}
65+
}
66+
67+
fn put_keyed(&self, k: &Cid, block: &[u8]) -> anyhow::Result<()> {
68+
match self {
69+
Self::Left(v) => v.put_keyed(k, block),
70+
Self::Right(v) => v.put_keyed(k, block),
71+
}
72+
}
73+
}

src/db/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ pub use blockstore_with_read_cache::*;
1414
pub use blockstore_with_write_buffer::BlockstoreWithWriteBuffer;
1515
pub use memory::MemoryDB;
1616
mod db_mode;
17+
mod either;
1718
pub mod migration;
19+
pub use either::Either;
1820

1921
use crate::blocks::TipsetKey;
2022
use crate::rpc::eth::types::EthHash;
2123
use anyhow::{Context as _, bail};
2224
use cid::Cid;
23-
use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore};
25+
pub use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore};
2426
use serde::Serialize;
2527
use serde::de::DeserializeOwned;
2628
use std::sync::Arc;

src/tool/subcommands/archive_cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ async fn merge_f3_snapshot(filecoin: PathBuf, f3: PathBuf, output: PathBuf) -> a
679679
let f3_cid = crate::f3::snapshot::get_f3_snapshot_cid(&mut f3_data)?;
680680

681681
let car_stream = CarStream::new_from_path(&filecoin).await?;
682-
let chain_head = car_stream.header_v1.roots.clone();
682+
let chain_head = car_stream.head_tipset_key().to_cids();
683683

684684
println!("f3 snapshot cid: {f3_cid}");
685685
println!(

0 commit comments

Comments
 (0)