Skip to content
3 changes: 1 addition & 2 deletions src/beacon/drand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ use super::{
PublicKeyOnG1, PublicKeyOnG2, SignatureOnG1, SignatureOnG2, verify_messages_chained,
},
};
use crate::prelude::*;
use crate::shim::clock::ChainEpoch;
use crate::shim::version::NetworkVersion;
use crate::utils::cache::SizeTrackingLruCache;
use crate::utils::misc::env::is_env_truthy;
use crate::utils::net::global_http_client;
use ambassador::{Delegate, delegatable_trait};
use anyhow::Context as _;
use backon::{ExponentialBuilder, Retryable};
use bls_signatures::Serialize as _;
use itertools::Itertools as _;
use nonzero_ext::nonzero;
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};
use tracing::debug;
Expand Down
31 changes: 16 additions & 15 deletions src/blocks/chain4u.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ use crate::{
blocks::*,
db::{MemoryDB, car::PlainCar},
networks,
prelude::*,
shim::{
address::Address, clock::ChainEpoch, crypto::Signature, econ::TokenAmount,
sector::PoStProof,
},
};
use chain4u::header::{FILECOIN_GENESIS_BLOCK, FILECOIN_GENESIS_CID, GENESIS_BLOCK_PARENTS};
use cid::Cid;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::CborStore;
use itertools::Itertools as _;
use num_bigint::BigInt;
use petgraph::Direction;
use std::{borrow::Borrow, fmt::Debug, hash::Hash};
use std::{
borrow::Borrow,
collections::hash_map::Entry::{Occupied, Vacant},
fmt::Debug,
hash::Hash,
iter,
};

Expand Down Expand Up @@ -173,16 +173,23 @@ impl<T> Chain4U<T> {
inner: Default::default(),
}
}

pub fn blockstore(&self) -> &T {
&self.blockstore
}

pub fn get<Q>(&self, ident: &Q) -> Option<RawBlockHeader>
where
String: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.inner.lock().ident2header.get(ident).cloned()
}

pub fn tipset(&self, of: &[&str]) -> Tipset {
Tipset::new(of.iter().map(|it| self.get(*it).unwrap())).unwrap()
}

/// Insert a header.
/// Header fields (epoch etc) will be set accordingly.
pub fn insert(
Expand All @@ -206,16 +213,6 @@ impl<T> Chain4U<T> {
}
}

impl<T: Blockstore> Blockstore for Chain4U<T> {
fn get(&self, k: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
self.blockstore.get(k)
}

fn put_keyed(&self, k: &Cid, block: &[u8]) -> anyhow::Result<()> {
self.blockstore.put_keyed(k, block)
}
}

#[derive(Default)]
struct Chain4UInner {
ident2header: ahash::HashMap<String, RawBlockHeader>,
Expand Down Expand Up @@ -693,7 +690,11 @@ fn test_chain4u() {
itertools::assert_equal(
iter::successors(Some(t3.clone()), |t| match t.epoch() {
0 => None,
_ => Some(Tipset::load(&c4u, t.parents()).unwrap().unwrap()),
_ => Some(
Tipset::load(c4u.blockstore(), t.parents())
.unwrap()
.unwrap(),
),
}),
[t3, t2, t1, t0],
);
Expand Down
6 changes: 1 addition & 5 deletions src/blocks/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ use crate::{
chain_sync::TipsetValidator,
cid_collections::SmallCidNonEmptyVec,
networks::{calibnet, mainnet},
prelude::*,
shim::clock::ChainEpoch,
utils::{
ShallowClone,
cid::CidCborExt,
db::{CborStoreExt, car_stream::CarBlock},
get_size::nunny_vec_heap_size_helper,
multihash::MultihashCode,
},
};
use ahash::HashMap;
use anyhow::Context as _;
use cid::Cid;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::CborStore;
use get_size2::GetSize;
use itertools::Itertools as _;
use multihash_derive::MultihashDigest as _;
use num::BigInt;
use nunny::{Vec as NonEmpty, vec as nonempty};
Expand Down
12 changes: 5 additions & 7 deletions src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ use crate::cid_collections::CidHashSetLike;
use crate::db::car::forest::{self, ForestCarFrame, finalize_frame};
use crate::db::{SettingsStore, SettingsStoreExt};
use crate::ipld::stream_chain;
use crate::utils::ShallowClone as _;
use crate::prelude::*;
use crate::utils::db::car_stream::{CarBlock, CarBlockWrite};
use crate::utils::io::{AsyncWriterWithChecksum, Checksum};
use crate::utils::multihash::MultihashCode;
use crate::utils::stream::par_buffer;
use anyhow::Context as _;
use cid::Cid;
use futures::StreamExt as _;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::DAG_CBOR;
use multihash_derive::MultihashDigest as _;
use nunny::Vec as NonEmpty;
use sha2::digest::{self, Digest};
use std::io::{Read, Seek, SeekFrom};
use std::sync::Arc;
use tokio::io::{AsyncWrite, AsyncWriteExt, BufWriter};

pub struct ExportOptions<S> {
Expand All @@ -53,7 +51,7 @@ impl<S: Default> Default for ExportOptions<S> {
}

pub async fn export_from_head<D: Digest, S: CidHashSetLike + Send + Sync + 'static>(
db: &Arc<impl Blockstore + SettingsStore + Send + Sync + 'static>,
db: &(impl Blockstore + ShallowClone + SettingsStore + Unpin + Send + Sync + 'static),
lookup_depth: ChainEpochDelta,
writer: impl AsyncWrite + Unpin,
options: ExportOptions<S>,
Expand All @@ -68,7 +66,7 @@ pub async fn export_from_head<D: Digest, S: CidHashSetLike + Send + Sync + 'stat
/// Exports a Filecoin snapshot in v1 format
/// See <https://github.com/filecoin-project/FIPs/blob/98e33b9fa306959aa0131519eb4cc155522b2081/FRCs/frc-0108.md#v1-specification>
pub async fn export<D: Digest, S: CidHashSetLike + Send + Sync + 'static>(
db: &Arc<impl Blockstore + Send + Sync + 'static>,
db: &(impl Blockstore + ShallowClone + Unpin + Send + Sync + 'static),
tipset: &Tipset,
lookup_depth: ChainEpochDelta,
writer: impl AsyncWrite + Unpin,
Expand All @@ -81,7 +79,7 @@ pub async fn export<D: Digest, S: CidHashSetLike + Send + Sync + 'static>(
/// Exports a Filecoin snapshot in v2 format
/// See <https://github.com/filecoin-project/FIPs/blob/98e33b9fa306959aa0131519eb4cc155522b2081/FRCs/frc-0108.md#v2-specification>
pub async fn export_v2<D: Digest, F: Seek + Read, S: CidHashSetLike + Send + Sync + 'static>(
db: &Arc<impl Blockstore + Send + Sync + 'static>,
db: &(impl Blockstore + ShallowClone + Unpin + Send + Sync + 'static),
mut f3: Option<(Cid, F)>,
tipset: &Tipset,
lookup_depth: ChainEpochDelta,
Expand Down Expand Up @@ -148,7 +146,7 @@ pub async fn export_v2<D: Digest, F: Seek + Read, S: CidHashSetLike + Send + Syn
async fn export_to_forest_car<D: Digest, S: CidHashSetLike + Send + Sync + 'static>(
roots: NonEmpty<Cid>,
prefix_data_frames: Option<Vec<anyhow::Result<ForestCarFrame>>>,
db: &Arc<impl Blockstore + Send + Sync + 'static>,
db: &(impl Blockstore + ShallowClone + Unpin + Send + Sync + 'static),
tipset: &Tipset,
lookup_depth: ChainEpochDelta,
writer: impl AsyncWrite + Unpin,
Expand Down
3 changes: 1 addition & 2 deletions src/chain/snapshot_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::lotus_json::lotus_json_with_self;
use cid::Cid;
use itertools::Itertools as _;
use crate::prelude::*;
use num::FromPrimitive as _;
use num_derive::FromPrimitive;
use nunny::Vec as NonEmpty;
Expand Down
Loading
Loading