Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
46167be
turn cuprated into a embeddable library
redsh4de Mar 16, 2026
7824ba1
doc
redsh4de Mar 16, 2026
6209a65
align with #554 proposed API surface
redsh4de Mar 16, 2026
43024c2
clippy
redsh4de Mar 16, 2026
e2f329b
add command input/output handling
redsh4de Mar 16, 2026
7ad9471
more readable API
redsh4de Mar 16, 2026
0aa8e28
add CommandHandler
redsh4de Mar 16, 2026
a944853
decouple config from CLI
redsh4de Mar 17, 2026
149b4d9
move rayon init back to embedder
redsh4de Mar 17, 2026
4ae0c01
return result for config processing, move exit to main.rs
redsh4de Mar 17, 2026
aa77d0d
use actor pattern for commands, explicit lib/bin targets
redsh4de Mar 17, 2026
021a1e1
init lazylock in both lib and main
redsh4de Mar 17, 2026
f319fa0
replace async loop with blocking thread for commands
redsh4de Mar 17, 2026
dae5ae8
remove mutable statics, add NodeContext for multi-instance support, docs
redsh4de Mar 18, 2026
0519501
set command request channel capacity to 1 to match main
redsh4de Mar 20, 2026
ecc2a94
move pub use statement in config.rs
redsh4de Mar 20, 2026
acd102c
restore backticks for init_blockchain_manager doc comment
redsh4de Mar 20, 2026
c198738
make dry_run_check pure, add DryRunResult
redsh4de Mar 20, 2026
90bb7fb
nuke the remaining statics
redsh4de Mar 21, 2026
71b6dcc
replace SyncState with Syncer/SyncerHandle, add target_height to Sync…
redsh4de Mar 24, 2026
96b81dd
port shutdown monitor, return Result on node launch
redsh4de Apr 26, 2026
d6c42d4
introduce typed service errors and spawn_critical
redsh4de Apr 26, 2026
cde7c11
main() errors, exit codes
redsh4de Apr 26, 2026
b211471
detach blockchain drop log from caller span
redsh4de Apr 26, 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
24 changes: 11 additions & 13 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 manager::init_blockchain_manager;
pub use syncer::SyncNotify;
pub use fast_sync::get_fast_sync_hashes;
pub use interface::BlockchainManagerHandle;
pub use manager::{init_blockchain_manager, IncomingBlockError, IncomingBlockOk};
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