Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7c78657
turn cuprated into a embeddable library
redsh4de Mar 16, 2026
4384a67
doc
redsh4de Mar 16, 2026
c837a95
align with #554 proposed API surface
redsh4de Mar 16, 2026
4a7b0a2
clippy
redsh4de Mar 16, 2026
3ba75a6
add command input/output handling
redsh4de Mar 16, 2026
6c56b98
more readable API
redsh4de Mar 16, 2026
477b7d5
add CommandHandler
redsh4de Mar 16, 2026
7f70a88
decouple config from CLI
redsh4de Mar 17, 2026
eb163df
move rayon init back to embedder
redsh4de Mar 17, 2026
1ee2a4d
return result for config processing, move exit to main.rs
redsh4de Mar 17, 2026
ee7c101
use actor pattern for commands, explicit lib/bin targets
redsh4de Mar 17, 2026
a8e6fc5
init lazylock in both lib and main
redsh4de Mar 17, 2026
29ce8e1
replace async loop with blocking thread for commands
redsh4de Mar 17, 2026
c98717a
remove mutable statics, add NodeContext for multi-instance support, docs
redsh4de Mar 18, 2026
8c1205d
set command request channel capacity to 1 to match main
redsh4de Mar 20, 2026
8dc2a1a
move pub use statement in config.rs
redsh4de Mar 20, 2026
38a2cad
restore backticks for init_blockchain_manager doc comment
redsh4de Mar 20, 2026
a15e571
make dry_run_check pure, add DryRunResult
redsh4de Mar 20, 2026
514efb9
nuke the remaining statics
redsh4de Mar 21, 2026
5c0bdb3
replace SyncState with Syncer/SyncerHandle, add target_height to Sync…
redsh4de Mar 24, 2026
541edb9
port shutdown monitor, return Result on node launch
redsh4de Mar 18, 2026
fc22951
shutdown api improvements
redsh4de Mar 19, 2026
3f86f09
clippy
redsh4de Mar 19, 2026
d7abf9b
spawn_critical
redsh4de Mar 18, 2026
de50d84
propagate service errors
redsh4de Mar 18, 2026
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
22 changes: 10 additions & 12 deletions binaries/cuprated/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,34 @@ use cuprate_types::{
VerifiedBlockInformation,
};

use crate::constants::PANIC_CRITICAL_SERVICE_ERROR;

mod chain_service;
mod fast_sync;
pub mod interface;
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.
pub async fn check_add_genesis(
blockchain_read_handle: &mut BlockchainReadHandle,
blockchain_write_handle: &mut BlockchainWriteHandle,
network: Network,
) {
) -> anyhow::Result<()> {
// Try to get the chain height, will fail if the genesis block is not in the DB.
if blockchain_read_handle
.ready()
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR)
.await?
.call(BlockchainReadRequest::ChainHeight)
.await
.is_ok()
{
return;
return Ok(());
}

let genesis = generate_genesis_block(network);
Expand All @@ -56,8 +54,7 @@ pub async fn check_add_genesis(

blockchain_write_handle
.ready()
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR)
.await?
.call(BlockchainWriteRequest::WriteBlock(
VerifiedBlockInformation {
block_blob: genesis.serialize(),
Expand All @@ -74,8 +71,9 @@ pub async fn check_add_genesis(
block: genesis,
},
))
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR);
.await?;

Ok(())
}

/// Initializes the consensus services.
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