Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
cb8c482
add specific method for context
Boog900 Jan 17, 2025
14a53ca
add new statemachine for tx verification
Boog900 Jan 19, 2025
7a0f015
fix consensus crates build
Boog900 Jan 19, 2025
7228bda
working builds
Boog900 Jan 19, 2025
b86e0a9
Merge branch 'main' into imporve-consensus-api
Boog900 Jan 19, 2025
da938b9
fix CI
Boog900 Jan 19, 2025
6e8e580
add docs
Boog900 Jan 20, 2025
b680d8d
fix CI
Boog900 Jan 20, 2025
dc63950
fix docs
Boog900 Jan 20, 2025
e884cd1
fix clippy
Boog900 Jan 20, 2025
caab94c
cleanup
Boog900 Jan 21, 2025
a425713
add docs to `blockchain_context`
Boog900 Jan 21, 2025
2756d96
fix doc tests
Boog900 Jan 21, 2025
918d818
add output cache
Boog900 Jan 24, 2025
fe3f6ac
new monero-serai
Boog900 Jan 25, 2025
26fbde2
todo
Boog900 Jan 25, 2025
51b4a3e
todo
Boog900 Jan 26, 2025
4e805b3
Revert "new monero-serai"
Boog900 Jan 29, 2025
241b7fc
use indexmap to request outputs
Boog900 Feb 9, 2025
6cb3ec1
Merge branch 'main' into batch-outputs
Boog900 Feb 9, 2025
5054f4a
clean up
Boog900 Feb 22, 2025
cb43a73
fix typos
Boog900 Feb 22, 2025
da884b3
fix CI
Boog900 Feb 22, 2025
8cf2210
fix cargo hack
Boog900 Feb 22, 2025
eedbd55
fix reorgs
Boog900 Feb 22, 2025
6c7424e
check if a block is already present before adding it to the alt block…
Boog900 Feb 22, 2025
dfdd8f4
fmt
Boog900 Feb 25, 2025
e1d1f61
update to new monero oxide API
Boog900 Feb 25, 2025
c43fab3
fmt & fix cache
Boog900 Feb 25, 2025
57ce4b5
update config values
Boog900 Feb 25, 2025
c9261b3
fix tests
Boog900 Feb 26, 2025
67dcc4a
add fast sync
Boog900 Feb 28, 2025
619040b
fix start_height check
Boog900 Mar 1, 2025
003f435
disable kill switch for now
Boog900 Mar 2, 2025
5d67c15
add fast sync config options
Boog900 Mar 3, 2025
ca4f95e
add docs
Boog900 Mar 3, 2025
066bb4e
wait for all blocks to download before starting the syncer again.
Boog900 Mar 4, 2025
86a6bf0
fix permit
Boog900 Mar 4, 2025
7d7208e
typo
Boog900 Mar 4, 2025
7226d4d
fix import order
Boog900 Mar 6, 2025
693b7a9
Merge branch 'main' into fast-sync-clean
Boog900 Mar 6, 2025
8c268aa
fmt
Boog900 Mar 6, 2025
d71c5aa
add docs + order imports
Boog900 Mar 6, 2025
435c6b7
fix clippy
Boog900 Mar 6, 2025
f15a754
update rust to 2024
Boog900 Mar 7, 2025
ac5c173
update update deps and fix doc
Boog900 Mar 7, 2025
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
810 changes: 434 additions & 376 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ bytes = { version = "1", default-features = false }
cfg-if = { version = "1", default-features = false }
clap = { version = "4", default-features = false }
chrono = { version = "0.4", default-features = false }
crypto-bigint = { version = "0.5", default-features = false }
crypto-bigint = { version = "0.6", default-features = false }
crossbeam = { version = "0.8", default-features = false }
const_format = { version = "0.2", default-features = false }
curve25519-dalek = { version = "4", default-features = false }
dashmap = { version = "6", default-features = false }
dirs = { version = "5", default-features = false }
dirs = { version = "6", default-features = false }
futures = { version = "0.3", default-features = false }
hex = { version = "0.4", default-features = false }
hex-literal = { version = "0.4", default-features = false }
hex-literal = { version = "1", default-features = false }
indexmap = { version = "2", default-features = false }
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "e6ae8c2", default-features = false }
nu-ansi-term = { version = "0.46", default-features = false }
Expand All @@ -132,8 +132,8 @@ rayon = { version = "1", default-features = false }
serde_bytes = { version = "0.11", default-features = false }
serde_json = { version = "1", default-features = false }
serde = { version = "1", default-features = false }
strum = { version = "0.26", default-features = false }
thiserror = { version = "1", default-features = false }
strum = { version = "0.27", default-features = false }
thiserror = { version = "2", default-features = false }
thread_local = { version = "1", default-features = false }
tokio-util = { version = "0.7", default-features = false }
tokio-stream = { version = "0.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion binaries/cuprated/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cuprated"
version = "0.0.1"
edition = "2021"
edition = "2024"
description = "The Cuprate Rust Monero node."
license = "AGPL-3.0-only"
authors = ["Boog900", "hinto-janai", "SyntheticBird45"]
Expand Down
10 changes: 6 additions & 4 deletions binaries/cuprated/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
use std::sync::Arc;

use futures::FutureExt;
use tokio::sync::{mpsc, Notify};
use tokio::sync::{Notify, mpsc};
use tower::{BoxError, Service, ServiceExt};

use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
use cuprate_consensus::{generate_genesis_block, BlockchainContextService, ContextConfig};
use cuprate_consensus::{BlockchainContextService, ContextConfig, generate_genesis_block};
use cuprate_cryptonight::cryptonight_hash_v0;
use cuprate_p2p::{block_downloader::BlockDownloaderConfig, NetworkInterface};
use cuprate_p2p::{NetworkInterface, block_downloader::BlockDownloaderConfig};
use cuprate_p2p_core::{ClearNet, Network};
use cuprate_types::{
blockchain::{BlockchainReadRequest, BlockchainWriteRequest},
VerifiedBlockInformation,
blockchain::{BlockchainReadRequest, BlockchainWriteRequest},
};

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 types::ConsensusBlockchainReadHandle;

Expand Down
22 changes: 18 additions & 4 deletions binaries/cuprated/src/blockchain/chain_service.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::task::{Context, Poll};

use futures::{future::BoxFuture, FutureExt, TryFutureExt};
use futures::{FutureExt, TryFutureExt, future::BoxFuture};
use tower::Service;

use cuprate_blockchain::service::BlockchainReadHandle;
use cuprate_fast_sync::validate_entries;
use cuprate_p2p::block_downloader::{ChainSvcRequest, ChainSvcResponse};
use cuprate_p2p_core::NetworkZone;
use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse};

/// That service that allows retrieving the chain state to give to the P2P crates, so we can figure out
Expand All @@ -14,16 +16,16 @@ use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse};
#[derive(Clone)]
pub struct ChainService(pub BlockchainReadHandle);

impl Service<ChainSvcRequest> for ChainService {
type Response = ChainSvcResponse;
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)
}

fn call(&mut self, req: ChainSvcRequest) -> Self::Future {
fn call(&mut self, req: ChainSvcRequest<N>) -> Self::Future {
let map_res = |res: BlockchainResponse| match res {
BlockchainResponse::CompactChainHistory {
block_ids,
Expand Down Expand Up @@ -67,6 +69,18 @@ impl Service<ChainSvcRequest> for ChainService {
})
.map_err(Into::into)
.boxed(),
ChainSvcRequest::ValidateEntries(entries, start_height) => {
let mut blockchain_read_handle = self.0.clone();

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

Ok(ChainSvcResponse::ValidateEntries { valid, unknown })
}
.boxed()
}
}
}
}
24 changes: 24 additions & 0 deletions binaries/cuprated/src/blockchain/fast_sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::slice;

use cuprate_helper::network::Network;

/// The hashes of the compiled in fast sync file.
static FAST_SYNC_HASHES: &[[u8; 32]] = unsafe {
let bytes = include_bytes!("./fast_sync/fast_sync_hashes.bin");

#[expect(clippy::manual_assert, reason = "assert is not const")]
if bytes.len() % 32 != 0 {
panic!()
}

slice::from_raw_parts(bytes.as_ptr().cast::<[u8; 32]>(), bytes.len() / 32)
};

/// 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 {
FAST_SYNC_HASHES
} else {
&[]
});
}
Binary file not shown.
2 changes: 1 addition & 1 deletion binaries/cuprated/src/blockchain/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use tower::{Service, ServiceExt};
use cuprate_blockchain::service::BlockchainReadHandle;
use cuprate_consensus::transactions::new_tx_verification_data;
use cuprate_txpool::service::{
interface::{TxpoolReadRequest, TxpoolReadResponse},
TxpoolReadHandle,
interface::{TxpoolReadRequest, TxpoolReadResponse},
};
use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse};

Expand Down
12 changes: 7 additions & 5 deletions binaries/cuprated/src/blockchain/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc};

use futures::StreamExt;
use monero_serai::block::Block;
use tokio::sync::{mpsc, oneshot, Notify};
use tokio::sync::{Notify, OwnedSemaphorePermit, mpsc, oneshot};
use tower::{BoxError, Service, ServiceExt};
use tracing::error;

Expand All @@ -12,14 +12,14 @@ use cuprate_consensus::{
ExtendedConsensusError,
};
use cuprate_p2p::{
block_downloader::{BlockBatch, BlockDownloaderConfig},
BroadcastSvc, NetworkInterface,
block_downloader::{BlockBatch, BlockDownloaderConfig},
};
use cuprate_p2p_core::ClearNet;
use cuprate_txpool::service::TxpoolWriteHandle;
use cuprate_types::{
blockchain::{BlockchainReadRequest, BlockchainResponse},
Chain, TransactionVerificationData,
blockchain::{BlockchainReadRequest, BlockchainResponse},
};

use crate::{
Expand Down Expand Up @@ -106,15 +106,17 @@ impl BlockchainManager {
/// The [`BlockchainManager`] task.
pub async fn run(
mut self,
mut block_batch_rx: mpsc::Receiver<BlockBatch>,
mut block_batch_rx: mpsc::Receiver<(BlockBatch, Arc<OwnedSemaphorePermit>)>,
mut command_rx: mpsc::Receiver<BlockchainManagerCommand>,
) {
loop {
tokio::select! {
Some(batch) = block_batch_rx.recv() => {
Some((batch, permit)) = block_batch_rx.recv() => {
self.handle_incoming_block_batch(
batch,
).await;

drop(permit);
}
Some(incoming_command) = command_rx.recv() => {
self.handle_command(incoming_command).await;
Expand Down
Loading
Loading