mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-22 10:44:36 +00:00
syncer -> blockchain
This commit is contained in:
parent
25a472dd9b
commit
84656df08a
5 changed files with 65 additions and 22 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -656,6 +656,7 @@ dependencies = [
|
|||
"monero-p2p",
|
||||
"monero-serai",
|
||||
"tokio",
|
||||
"tower",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -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 }
|
||||
|
|
62
binaries/cuprated/src/blockchain.rs
Normal file
62
binaries/cuprated/src/blockchain.rs
Normal file
|
@ -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<Transaction>,
|
||||
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<C, BV> {
|
||||
/// 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<IncomingBlock>,
|
||||
|
||||
incoming_block_batch_rx: mpsc::Receiver<BlockBatch>,
|
||||
}
|
||||
|
||||
impl<C, BV> Blockchain<C, BV>
|
||||
where
|
||||
C: Service<
|
||||
BlockChainContextRequest,
|
||||
Response = BlockChainContextResponse,
|
||||
Error = tower::BoxError,
|
||||
>,
|
||||
C::Future: Send + 'static,
|
||||
BV: Service<VerifyBlockRequest, Response = VerifyBlockResponse, Error = ExtendedConsensusError>,
|
||||
BV::Future: Send + 'static,
|
||||
{
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
mod blockchain;
|
||||
mod network;
|
||||
mod p2p_request_handler;
|
||||
mod syncer;
|
||||
mod tx_pool;
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -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<Transaction>,
|
||||
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,
|
||||
}
|
Loading…
Reference in a new issue