From 84656df08a3ad546ebf360d118ed0b7f4a119ef4 Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Mon, 3 Jun 2024 23:01:50 +0100 Subject: [PATCH] syncer -> blockchain --- Cargo.lock | 1 + binaries/cuprated/Cargo.toml | 1 + binaries/cuprated/src/blockchain.rs | 62 +++++++++++++++++++++++++++++ binaries/cuprated/src/main.rs | 2 +- binaries/cuprated/src/syncer.rs | 21 ---------- 5 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 binaries/cuprated/src/blockchain.rs delete mode 100644 binaries/cuprated/src/syncer.rs diff --git a/Cargo.lock b/Cargo.lock index a8c3e0da..6e27911b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -656,6 +656,7 @@ dependencies = [ "monero-p2p", "monero-serai", "tokio", + "tower", ] [[package]] diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index f2614081..be5276d9 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -21,6 +21,7 @@ monero-serai = { workspace = true } # Async tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } futures = { workspace = true } +tower = { workspace = true } # Utils bytes = { workspace = true } diff --git a/binaries/cuprated/src/blockchain.rs b/binaries/cuprated/src/blockchain.rs new file mode 100644 index 00000000..4f950e04 --- /dev/null +++ b/binaries/cuprated/src/blockchain.rs @@ -0,0 +1,62 @@ +//! # The Syncer +//! +//! The syncer is the part of Cuprate that handles keeping the blockchain state, it handles syncing if +//! we have fallen behind, and it handles incoming blocks. +use cuprate_blockchain::service::DatabaseWriteHandle; +use monero_serai::{block::Block, transaction::Transaction}; +use tokio::sync::mpsc; +use tower::Service; + +use cuprate_consensus::{ + BlockChainContextRequest, BlockChainContextResponse, ExtendedConsensusError, + VerifyBlockRequest, VerifyBlockResponse, +}; +use monero_p2p::handles::ConnectionHandle; + +pub struct IncomingBlock { + block: Block, + included_txs: Vec, + peer_handle: ConnectionHandle, +} + +/// A response to an [`IncomingBlock`] +pub enum IncomingBlockResponse { + /// We are missing these transactions from the block. + MissingTransactions(Vec<[u8; 32]>), + /// A generic ok response. + Ok, +} + +struct BlockBatch; + +/// The blockchain. +/// +/// This struct represents the task that syncs and maintains Cuprate's blockchain state. +pub struct Blockchain { + /// The blockchain context service. + /// + /// This service handles keeping all the data needed to verify new blocks. + context_svc: C, + /// The block verifier service, handles block verification. + block_verifier_svc: BV, + + /// The blockchain database write handle. + database_svc: DatabaseWriteHandle, + + incoming_block_rx: mpsc::Receiver, + + incoming_block_batch_rx: mpsc::Receiver, +} + +impl Blockchain +where + C: Service< + BlockChainContextRequest, + Response = BlockChainContextResponse, + Error = tower::BoxError, + >, + C::Future: Send + 'static, + BV: Service, + BV::Future: Send + 'static, +{ +} diff --git a/binaries/cuprated/src/main.rs b/binaries/cuprated/src/main.rs index 6d1b81d7..f75c1712 100644 --- a/binaries/cuprated/src/main.rs +++ b/binaries/cuprated/src/main.rs @@ -1,6 +1,6 @@ +mod blockchain; mod network; mod p2p_request_handler; -mod syncer; mod tx_pool; fn main() { diff --git a/binaries/cuprated/src/syncer.rs b/binaries/cuprated/src/syncer.rs deleted file mode 100644 index 93912e9f..00000000 --- a/binaries/cuprated/src/syncer.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! # The Syncer -//! -//! The syncer is the part of Cuprate that handles keeping the blockchain state, it handles syncing if -//! we have fallen behind, and it handles incoming blocks. -use monero_serai::{block::Block, transaction::Transaction}; - -use monero_p2p::handles::ConnectionHandle; - -pub struct IncomingFluffyBlock { - block: Block, - included_txs: Vec, - peer_handle: ConnectionHandle, -} - -/// A response to an [`IncomingFluffyBlock`] -pub enum IncomingFluffyBlockResponse { - /// We are missing these transactions from the block. - MissingTransactions(Vec<[u8; 32]>), - /// A generic ok response. - Ok, -}