Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_json::Value;

use cuprate_helper::network::Network;

use crate::{config::Config, version::CupratedVersionInfo};
use cuprated::{config::Config, version::CupratedVersionInfo};

/// Cuprate Args.
#[derive(clap::Parser, Debug)]
Expand Down
57 changes: 53 additions & 4 deletions binaries/cuprated/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use tokio::sync::{mpsc, Notify};
use tower::{BoxError, Service, ServiceExt};

use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
use cuprate_consensus::{generate_genesis_block, BlockchainContextService, ContextConfig};
use cuprate_consensus::{
generate_genesis_block, BlockchainContext, BlockchainContextService, ContextConfig,
};
use cuprate_cryptonight::cryptonight_hash_v0;
use cuprate_p2p::{block_downloader::BlockDownloaderConfig, NetworkInterface};
use cuprate_p2p_core::{ClearNet, Network};
Expand All @@ -26,11 +28,58 @@ mod manager;
mod syncer;
mod types;

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

pub(crate) use manager::init_blockchain_manager;

/// The interface to the blockchain.
#[derive(Clone)]
pub struct BlockchainInterface {
/// A read handle to the blockchain database.
read: BlockchainReadHandle,
/// The blockchain context service.
context_svc: BlockchainContextService,
/// A handle to the blockchain manager.
manager: BlockchainManagerHandle,
}

impl BlockchainInterface {
pub(crate) const fn new(
read: BlockchainReadHandle,
context_svc: BlockchainContextService,
manager: BlockchainManagerHandle,
) -> Self {
Self {
read,
context_svc,
manager,
}
}

/// Returns a read handle to the blockchain database.
pub fn read(&self) -> BlockchainReadHandle {
self.read.clone()
}

/// Returns the current [`BlockchainContext`].
pub fn context(&mut self) -> &BlockchainContext {
self.context_svc.blockchain_context()
}

/// Returns a handle to the blockchain manager.
pub fn manager(&self) -> BlockchainManagerHandle {
self.manager.clone()
}

/// Returns the blockchain context service.
pub(crate) fn context_svc(&self) -> BlockchainContextService {
self.context_svc.clone()
}
}

/// Checks if the genesis block is in the blockchain and adds it if not.
pub async fn check_add_genesis(
blockchain_read_handle: &mut BlockchainReadHandle,
Expand Down
13 changes: 9 additions & 4 deletions binaries/cuprated/src/blockchain/chain_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 BlockchainReadHandle, pub &'static [[u8; 32]]);

impl<N: NetworkZone> Service<ChainSvcRequest<N>> for ChainService {
type Response = ChainSvcResponse<N>;
Expand Down Expand Up @@ -75,11 +75,16 @@ impl<N: NetworkZone> Service<ChainSvcRequest<N>> for ChainService {
.boxed(),
ChainSvcRequest::ValidateEntries(entries, start_height) => {
let mut blockchain_read_handle = self.0.clone();
let fast_sync_hashes = self.1;

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_handle,
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