syncer -> blockchain

This commit is contained in:
Boog900 2024-06-03 23:01:50 +01:00
parent 25a472dd9b
commit 84656df08a
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
5 changed files with 65 additions and 22 deletions

1
Cargo.lock generated
View file

@ -656,6 +656,7 @@ dependencies = [
"monero-p2p",
"monero-serai",
"tokio",
"tower",
]
[[package]]

View file

@ -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 }

View 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,
{
}

View file

@ -1,6 +1,6 @@
mod blockchain;
mod network;
mod p2p_request_handler;
mod syncer;
mod tx_pool;
fn main() {

View file

@ -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,
}