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
6 changes: 6 additions & 0 deletions binaries/cuprated/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ license = "AGPL-3.0-only"
authors = ["Boog900", "hinto-janai", "SyntheticBird45"]
repository = "https://github.com/Cuprate/cuprate/tree/main/binaries/cuprated"

[lib]
name = "cuprated"

[[bin]]
name = "cuprated"

[features]
default = ["arti"]
arti = ["arti-client", "tor-hsservice", "tor-persist", "tor-rtcompat", "cuprate-p2p-transport/arti"]
Expand Down
5 changes: 3 additions & 2 deletions binaries/cuprated/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ mod manager;
mod syncer;
mod types;

pub use fast_sync::set_fast_sync_hashes;
pub use fast_sync::get_fast_sync_hashes;
pub use interface::BlockchainManagerHandle;
pub use manager::init_blockchain_manager;
pub use syncer::SyncNotify;
pub use syncer::{Syncer, SyncerHandle};
pub use types::ConsensusBlockchainReadHandle;

/// Checks if the genesis block is in the blockchain and adds it if not.
Expand Down
30 changes: 18 additions & 12 deletions binaries/cuprated/src/blockchain/chain_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse};
///
/// This has a more minimal interface than [`BlockchainReadRequest`] to make using the p2p crates easier.
#[derive(Clone)]
pub struct ChainService(pub BlockchainReadHandle);
pub struct ChainService {
pub blockchain_read: BlockchainReadHandle,
pub fast_sync_hashes: &'static [[u8; 32]],
}

impl<N: NetworkZone> Service<ChainSvcRequest<N>> for ChainService {
type Response = ChainSvcResponse<N>;
type Error = tower::BoxError;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx).map_err(Into::into)
self.blockchain_read.poll_ready(cx).map_err(Into::into)
}

fn call(&mut self, req: ChainSvcRequest<N>) -> Self::Future {
Expand All @@ -42,21 +45,20 @@ impl<N: NetworkZone> Service<ChainSvcRequest<N>> for ChainService {
_ => unreachable!(),
};

let mut blockchain_read = self.blockchain_read.clone();

match req {
ChainSvcRequest::CompactHistory => self
.0
ChainSvcRequest::CompactHistory => blockchain_read
.call(BlockchainReadRequest::CompactChainHistory)
.map_ok(map_res)
.map_err(Into::into)
.boxed(),
ChainSvcRequest::FindFirstUnknown(req) => self
.0
ChainSvcRequest::FindFirstUnknown(req) => blockchain_read
.call(BlockchainReadRequest::FindFirstUnknown(req))
.map_ok(map_res)
.map_err(Into::into)
.boxed(),
ChainSvcRequest::CumulativeDifficulty => self
.0
ChainSvcRequest::CumulativeDifficulty => blockchain_read
.call(BlockchainReadRequest::CompactChainHistory)
.map_ok(|res| {
// TODO create a custom request instead of hijacking this one.
Expand All @@ -74,12 +76,16 @@ impl<N: NetworkZone> Service<ChainSvcRequest<N>> for ChainService {
.map_err(Into::into)
.boxed(),
ChainSvcRequest::ValidateEntries(entries, start_height) => {
let mut blockchain_read_handle = self.0.clone();
let fast_sync_hashes = self.fast_sync_hashes;

async move {
let (valid, unknown) =
validate_entries(entries, start_height, &mut blockchain_read_handle)
.await?;
let (valid, unknown) = validate_entries(
entries,
start_height,
&mut blockchain_read,
fast_sync_hashes,
)
.await?;

Ok(ChainSvcResponse::ValidateEntries { valid, unknown })
}
Expand Down
10 changes: 6 additions & 4 deletions binaries/cuprated/src/blockchain/fast_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ use cuprate_helper::network::Network;
/// See `build.rs` for how this file is generated.
static FAST_SYNC_HASHES: &[[u8; 32]] = &include!(concat!(env!("OUT_DIR"), "/fast_sync_hashes.rs"));

/// Set the fast-sync hashes according to the provided values.
pub fn set_fast_sync_hashes(fast_sync: bool, network: Network) {
cuprate_fast_sync::set_fast_sync_hashes(if fast_sync && network == Network::Mainnet {
/// Returns the fast-sync hashes for the given configuration.
///
/// Returns a non-empty slice only for mainnet with fast sync enabled.
pub fn get_fast_sync_hashes(fast_sync: bool, network: Network) -> &'static [[u8; 32]] {
if fast_sync && network == Network::Mainnet {
FAST_SYNC_HASHES
} else {
&[]
});
}
}

#[cfg(test)]
Expand Down
Loading
Loading