Skip to content

Commit 511639d

Browse files
committed
fix merge
1 parent 5ba2bf0 commit 511639d

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

binaries/cuprated/src/p2p/request_handler.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
use bytes::Bytes;
2+
use futures::{future::BoxFuture, FutureExt};
3+
use monero_serai::{block::Block, transaction::Transaction};
4+
use std::hash::Hash;
15
use std::{
26
collections::HashSet,
37
future::{ready, Ready},
48
task::{Context, Poll},
59
};
6-
7-
use bytes::Bytes;
8-
use futures::{future::BoxFuture, FutureExt};
9-
use monero_serai::{block::Block, transaction::Transaction};
1010
use tower::{Service, ServiceExt};
1111

1212
use cuprate_blockchain::service::BlockchainReadHandle;
1313
use cuprate_consensus::{transactions::new_tx_verification_data, BlockChainContextService};
1414
use cuprate_fixed_bytes::ByteArrayVec;
15+
use cuprate_helper::cast::u64_to_usize;
1516
use cuprate_helper::{
1617
asynch::rayon_spawn_async,
1718
cast::usize_to_u64,
1819
map::{combine_low_high_bits_to_u128, split_u128_into_low_high_bits},
1920
};
2021
use cuprate_p2p::constants::MAX_BLOCK_BATCH_LEN;
2122
use cuprate_p2p_core::{client::PeerInformation, NetworkZone, ProtocolRequest, ProtocolResponse};
23+
use cuprate_txpool::service::TxpoolReadHandle;
2224
use cuprate_types::{
2325
blockchain::{BlockchainReadRequest, BlockchainResponse},
2426
BlockCompleteEntry, MissingTxsInBlock, TransactionBlobs,
@@ -35,6 +37,8 @@ use crate::blockchain::interface::{self as blockchain_interface, IncomingBlockEr
3537
pub struct P2pProtocolRequestHandlerMaker {
3638
/// The [`BlockchainReadHandle`]
3739
pub blockchain_read_handle: BlockchainReadHandle,
40+
/// The [`TxpoolReadHandle`].
41+
pub txpool_read_handle: TxpoolReadHandle,
3842
}
3943

4044
impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMaker {
@@ -50,10 +54,12 @@ impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMa
5054
// TODO: check sync info?
5155

5256
let blockchain_read_handle = self.blockchain_read_handle.clone();
57+
let txpool_read_handle = self.txpool_read_handle.clone();
5358

5459
ready(Ok(P2pProtocolRequestHandler {
5560
peer_information,
5661
blockchain_read_handle,
62+
txpool_read_handle,
5763
}))
5864
}
5965
}
@@ -63,8 +69,10 @@ impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMa
6369
pub struct P2pProtocolRequestHandler<N: NetworkZone> {
6470
/// The [`PeerInformation`] for this peer.
6571
peer_information: PeerInformation<N>,
66-
/// The [`BlockchainReadHandle`]
72+
/// The [`BlockchainReadHandle`].
6773
blockchain_read_handle: BlockchainReadHandle,
74+
/// The [`TxpoolReadHandle`].
75+
txpool_read_handle: TxpoolReadHandle,
6876
}
6977

7078
impl<Z: NetworkZone> Service<ProtocolRequest> for P2pProtocolRequestHandler<Z> {
@@ -91,9 +99,12 @@ impl<Z: NetworkZone> Service<ProtocolRequest> for P2pProtocolRequestHandler<Z> {
9199
"Peer sent a full block when we support fluffy blocks"
92100
)))
93101
.boxed(),
94-
ProtocolRequest::NewFluffyBlock(r) => {
95-
new_fluffy_block(r, self.blockchain_read_handle.clone()).boxed()
96-
}
102+
ProtocolRequest::NewFluffyBlock(r) => new_fluffy_block(
103+
r,
104+
self.blockchain_read_handle.clone(),
105+
self.txpool_read_handle.clone(),
106+
)
107+
.boxed(),
97108
ProtocolRequest::GetTxPoolCompliment(_) | ProtocolRequest::NewTransactions(_) => {
98109
ready(Ok(ProtocolResponse::NA)).boxed()
99110
} // TODO: tx-pool
@@ -233,6 +244,7 @@ async fn fluffy_missing_txs(
233244
async fn new_fluffy_block(
234245
request: NewFluffyBlock,
235246
mut blockchain_read_handle: BlockchainReadHandle,
247+
mut txpool_read_handle: TxpoolReadHandle,
236248
) -> anyhow::Result<ProtocolResponse> {
237249
let current_blockchain_height = request.current_blockchain_height;
238250

@@ -251,7 +263,7 @@ async fn new_fluffy_block(
251263
.map(|tx_blob| {
252264
let tx = Transaction::read(&mut tx_blob.as_ref())?;
253265

254-
Ok(tx)
266+
Ok((tx.hash(), tx))
255267
})
256268
.collect::<Result<_, anyhow::Error>>()?;
257269

@@ -261,16 +273,21 @@ async fn new_fluffy_block(
261273
})
262274
.await?;
263275

264-
let res =
265-
blockchain_interface::handle_incoming_block(block, txs, &mut blockchain_read_handle).await;
276+
let res = blockchain_interface::handle_incoming_block(
277+
block,
278+
txs,
279+
&mut blockchain_read_handle,
280+
&mut txpool_read_handle,
281+
)
282+
.await;
266283

267284
match res {
268285
Ok(_) => Ok(ProtocolResponse::NA),
269286
Err(IncomingBlockError::UnknownTransactions(block_hash, missing_tx_indices)) => Ok(
270287
ProtocolResponse::FluffyMissingTransactionsRequest(FluffyMissingTransactionsRequest {
271288
block_hash: block_hash.into(),
272289
current_blockchain_height,
273-
missing_tx_indices,
290+
missing_tx_indices: missing_tx_indices.into_iter().map(usize_to_u64).collect(),
274291
}),
275292
),
276293
Err(IncomingBlockError::Orphan) => {

0 commit comments

Comments
 (0)