mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-21 02:04:33 +00:00
fix merge
This commit is contained in:
parent
5ba2bf020a
commit
511639d1b4
1 changed files with 29 additions and 12 deletions
|
@ -1,17 +1,18 @@
|
||||||
|
use bytes::Bytes;
|
||||||
|
use futures::{future::BoxFuture, FutureExt};
|
||||||
|
use monero_serai::{block::Block, transaction::Transaction};
|
||||||
|
use std::hash::Hash;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
future::{ready, Ready},
|
future::{ready, Ready},
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use bytes::Bytes;
|
|
||||||
use futures::{future::BoxFuture, FutureExt};
|
|
||||||
use monero_serai::{block::Block, transaction::Transaction};
|
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_blockchain::service::BlockchainReadHandle;
|
use cuprate_blockchain::service::BlockchainReadHandle;
|
||||||
use cuprate_consensus::{transactions::new_tx_verification_data, BlockChainContextService};
|
use cuprate_consensus::{transactions::new_tx_verification_data, BlockChainContextService};
|
||||||
use cuprate_fixed_bytes::ByteArrayVec;
|
use cuprate_fixed_bytes::ByteArrayVec;
|
||||||
|
use cuprate_helper::cast::u64_to_usize;
|
||||||
use cuprate_helper::{
|
use cuprate_helper::{
|
||||||
asynch::rayon_spawn_async,
|
asynch::rayon_spawn_async,
|
||||||
cast::usize_to_u64,
|
cast::usize_to_u64,
|
||||||
|
@ -19,6 +20,7 @@ use cuprate_helper::{
|
||||||
};
|
};
|
||||||
use cuprate_p2p::constants::MAX_BLOCK_BATCH_LEN;
|
use cuprate_p2p::constants::MAX_BLOCK_BATCH_LEN;
|
||||||
use cuprate_p2p_core::{client::PeerInformation, NetworkZone, ProtocolRequest, ProtocolResponse};
|
use cuprate_p2p_core::{client::PeerInformation, NetworkZone, ProtocolRequest, ProtocolResponse};
|
||||||
|
use cuprate_txpool::service::TxpoolReadHandle;
|
||||||
use cuprate_types::{
|
use cuprate_types::{
|
||||||
blockchain::{BlockchainReadRequest, BlockchainResponse},
|
blockchain::{BlockchainReadRequest, BlockchainResponse},
|
||||||
BlockCompleteEntry, MissingTxsInBlock, TransactionBlobs,
|
BlockCompleteEntry, MissingTxsInBlock, TransactionBlobs,
|
||||||
|
@ -35,6 +37,8 @@ use crate::blockchain::interface::{self as blockchain_interface, IncomingBlockEr
|
||||||
pub struct P2pProtocolRequestHandlerMaker {
|
pub struct P2pProtocolRequestHandlerMaker {
|
||||||
/// The [`BlockchainReadHandle`]
|
/// The [`BlockchainReadHandle`]
|
||||||
pub blockchain_read_handle: BlockchainReadHandle,
|
pub blockchain_read_handle: BlockchainReadHandle,
|
||||||
|
/// The [`TxpoolReadHandle`].
|
||||||
|
pub txpool_read_handle: TxpoolReadHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMaker {
|
impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMaker {
|
||||||
|
@ -50,10 +54,12 @@ impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMa
|
||||||
// TODO: check sync info?
|
// TODO: check sync info?
|
||||||
|
|
||||||
let blockchain_read_handle = self.blockchain_read_handle.clone();
|
let blockchain_read_handle = self.blockchain_read_handle.clone();
|
||||||
|
let txpool_read_handle = self.txpool_read_handle.clone();
|
||||||
|
|
||||||
ready(Ok(P2pProtocolRequestHandler {
|
ready(Ok(P2pProtocolRequestHandler {
|
||||||
peer_information,
|
peer_information,
|
||||||
blockchain_read_handle,
|
blockchain_read_handle,
|
||||||
|
txpool_read_handle,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +69,10 @@ impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMa
|
||||||
pub struct P2pProtocolRequestHandler<N: NetworkZone> {
|
pub struct P2pProtocolRequestHandler<N: NetworkZone> {
|
||||||
/// The [`PeerInformation`] for this peer.
|
/// The [`PeerInformation`] for this peer.
|
||||||
peer_information: PeerInformation<N>,
|
peer_information: PeerInformation<N>,
|
||||||
/// The [`BlockchainReadHandle`]
|
/// The [`BlockchainReadHandle`].
|
||||||
blockchain_read_handle: BlockchainReadHandle,
|
blockchain_read_handle: BlockchainReadHandle,
|
||||||
|
/// The [`TxpoolReadHandle`].
|
||||||
|
txpool_read_handle: TxpoolReadHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Z: NetworkZone> Service<ProtocolRequest> for P2pProtocolRequestHandler<Z> {
|
impl<Z: NetworkZone> Service<ProtocolRequest> for P2pProtocolRequestHandler<Z> {
|
||||||
|
@ -91,9 +99,12 @@ impl<Z: NetworkZone> Service<ProtocolRequest> for P2pProtocolRequestHandler<Z> {
|
||||||
"Peer sent a full block when we support fluffy blocks"
|
"Peer sent a full block when we support fluffy blocks"
|
||||||
)))
|
)))
|
||||||
.boxed(),
|
.boxed(),
|
||||||
ProtocolRequest::NewFluffyBlock(r) => {
|
ProtocolRequest::NewFluffyBlock(r) => new_fluffy_block(
|
||||||
new_fluffy_block(r, self.blockchain_read_handle.clone()).boxed()
|
r,
|
||||||
}
|
self.blockchain_read_handle.clone(),
|
||||||
|
self.txpool_read_handle.clone(),
|
||||||
|
)
|
||||||
|
.boxed(),
|
||||||
ProtocolRequest::GetTxPoolCompliment(_) | ProtocolRequest::NewTransactions(_) => {
|
ProtocolRequest::GetTxPoolCompliment(_) | ProtocolRequest::NewTransactions(_) => {
|
||||||
ready(Ok(ProtocolResponse::NA)).boxed()
|
ready(Ok(ProtocolResponse::NA)).boxed()
|
||||||
} // TODO: tx-pool
|
} // TODO: tx-pool
|
||||||
|
@ -233,6 +244,7 @@ async fn fluffy_missing_txs(
|
||||||
async fn new_fluffy_block(
|
async fn new_fluffy_block(
|
||||||
request: NewFluffyBlock,
|
request: NewFluffyBlock,
|
||||||
mut blockchain_read_handle: BlockchainReadHandle,
|
mut blockchain_read_handle: BlockchainReadHandle,
|
||||||
|
mut txpool_read_handle: TxpoolReadHandle,
|
||||||
) -> anyhow::Result<ProtocolResponse> {
|
) -> anyhow::Result<ProtocolResponse> {
|
||||||
let current_blockchain_height = request.current_blockchain_height;
|
let current_blockchain_height = request.current_blockchain_height;
|
||||||
|
|
||||||
|
@ -251,7 +263,7 @@ async fn new_fluffy_block(
|
||||||
.map(|tx_blob| {
|
.map(|tx_blob| {
|
||||||
let tx = Transaction::read(&mut tx_blob.as_ref())?;
|
let tx = Transaction::read(&mut tx_blob.as_ref())?;
|
||||||
|
|
||||||
Ok(tx)
|
Ok((tx.hash(), tx))
|
||||||
})
|
})
|
||||||
.collect::<Result<_, anyhow::Error>>()?;
|
.collect::<Result<_, anyhow::Error>>()?;
|
||||||
|
|
||||||
|
@ -261,8 +273,13 @@ async fn new_fluffy_block(
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let res =
|
let res = blockchain_interface::handle_incoming_block(
|
||||||
blockchain_interface::handle_incoming_block(block, txs, &mut blockchain_read_handle).await;
|
block,
|
||||||
|
txs,
|
||||||
|
&mut blockchain_read_handle,
|
||||||
|
&mut txpool_read_handle,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(_) => Ok(ProtocolResponse::NA),
|
Ok(_) => Ok(ProtocolResponse::NA),
|
||||||
|
@ -270,7 +287,7 @@ async fn new_fluffy_block(
|
||||||
ProtocolResponse::FluffyMissingTransactionsRequest(FluffyMissingTransactionsRequest {
|
ProtocolResponse::FluffyMissingTransactionsRequest(FluffyMissingTransactionsRequest {
|
||||||
block_hash: block_hash.into(),
|
block_hash: block_hash.into(),
|
||||||
current_blockchain_height,
|
current_blockchain_height,
|
||||||
missing_tx_indices,
|
missing_tx_indices: missing_tx_indices.into_iter().map(usize_to_u64).collect(),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
Err(IncomingBlockError::Orphan) => {
|
Err(IncomingBlockError::Orphan) => {
|
||||||
|
|
Loading…
Reference in a new issue