1
+ use bytes:: Bytes ;
2
+ use futures:: { future:: BoxFuture , FutureExt } ;
3
+ use monero_serai:: { block:: Block , transaction:: Transaction } ;
4
+ use std:: hash:: Hash ;
1
5
use std:: {
2
6
collections:: HashSet ,
3
7
future:: { ready, Ready } ,
4
8
task:: { Context , Poll } ,
5
9
} ;
6
-
7
- use bytes:: Bytes ;
8
- use futures:: { future:: BoxFuture , FutureExt } ;
9
- use monero_serai:: { block:: Block , transaction:: Transaction } ;
10
10
use tower:: { Service , ServiceExt } ;
11
11
12
12
use cuprate_blockchain:: service:: BlockchainReadHandle ;
13
13
use cuprate_consensus:: { transactions:: new_tx_verification_data, BlockChainContextService } ;
14
14
use cuprate_fixed_bytes:: ByteArrayVec ;
15
+ use cuprate_helper:: cast:: u64_to_usize;
15
16
use cuprate_helper:: {
16
17
asynch:: rayon_spawn_async,
17
18
cast:: usize_to_u64,
18
19
map:: { combine_low_high_bits_to_u128, split_u128_into_low_high_bits} ,
19
20
} ;
20
21
use cuprate_p2p:: constants:: MAX_BLOCK_BATCH_LEN ;
21
22
use cuprate_p2p_core:: { client:: PeerInformation , NetworkZone , ProtocolRequest , ProtocolResponse } ;
23
+ use cuprate_txpool:: service:: TxpoolReadHandle ;
22
24
use cuprate_types:: {
23
25
blockchain:: { BlockchainReadRequest , BlockchainResponse } ,
24
26
BlockCompleteEntry , MissingTxsInBlock , TransactionBlobs ,
@@ -35,6 +37,8 @@ use crate::blockchain::interface::{self as blockchain_interface, IncomingBlockEr
35
37
pub struct P2pProtocolRequestHandlerMaker {
36
38
/// The [`BlockchainReadHandle`]
37
39
pub blockchain_read_handle : BlockchainReadHandle ,
40
+ /// The [`TxpoolReadHandle`].
41
+ pub txpool_read_handle : TxpoolReadHandle ,
38
42
}
39
43
40
44
impl < N : NetworkZone > Service < PeerInformation < N > > for P2pProtocolRequestHandlerMaker {
@@ -50,10 +54,12 @@ impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMa
50
54
// TODO: check sync info?
51
55
52
56
let blockchain_read_handle = self . blockchain_read_handle . clone ( ) ;
57
+ let txpool_read_handle = self . txpool_read_handle . clone ( ) ;
53
58
54
59
ready ( Ok ( P2pProtocolRequestHandler {
55
60
peer_information,
56
61
blockchain_read_handle,
62
+ txpool_read_handle,
57
63
} ) )
58
64
}
59
65
}
@@ -63,8 +69,10 @@ impl<N: NetworkZone> Service<PeerInformation<N>> for P2pProtocolRequestHandlerMa
63
69
pub struct P2pProtocolRequestHandler < N : NetworkZone > {
64
70
/// The [`PeerInformation`] for this peer.
65
71
peer_information : PeerInformation < N > ,
66
- /// The [`BlockchainReadHandle`]
72
+ /// The [`BlockchainReadHandle`].
67
73
blockchain_read_handle : BlockchainReadHandle ,
74
+ /// The [`TxpoolReadHandle`].
75
+ txpool_read_handle : TxpoolReadHandle ,
68
76
}
69
77
70
78
impl < Z : NetworkZone > Service < ProtocolRequest > for P2pProtocolRequestHandler < Z > {
@@ -91,9 +99,12 @@ impl<Z: NetworkZone> Service<ProtocolRequest> for P2pProtocolRequestHandler<Z> {
91
99
"Peer sent a full block when we support fluffy blocks"
92
100
) ) )
93
101
. 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 ( ) ,
97
108
ProtocolRequest :: GetTxPoolCompliment ( _) | ProtocolRequest :: NewTransactions ( _) => {
98
109
ready ( Ok ( ProtocolResponse :: NA ) ) . boxed ( )
99
110
} // TODO: tx-pool
@@ -233,6 +244,7 @@ async fn fluffy_missing_txs(
233
244
async fn new_fluffy_block (
234
245
request : NewFluffyBlock ,
235
246
mut blockchain_read_handle : BlockchainReadHandle ,
247
+ mut txpool_read_handle : TxpoolReadHandle ,
236
248
) -> anyhow:: Result < ProtocolResponse > {
237
249
let current_blockchain_height = request. current_blockchain_height ;
238
250
@@ -251,7 +263,7 @@ async fn new_fluffy_block(
251
263
. map ( |tx_blob| {
252
264
let tx = Transaction :: read ( & mut tx_blob. as_ref ( ) ) ?;
253
265
254
- Ok ( tx )
266
+ Ok ( ( tx . hash ( ) , tx ) )
255
267
} )
256
268
. collect :: < Result < _ , anyhow:: Error > > ( ) ?;
257
269
@@ -261,16 +273,21 @@ async fn new_fluffy_block(
261
273
} )
262
274
. await ?;
263
275
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 ;
266
283
267
284
match res {
268
285
Ok ( _) => Ok ( ProtocolResponse :: NA ) ,
269
286
Err ( IncomingBlockError :: UnknownTransactions ( block_hash, missing_tx_indices) ) => Ok (
270
287
ProtocolResponse :: FluffyMissingTransactionsRequest ( FluffyMissingTransactionsRequest {
271
288
block_hash : block_hash. into ( ) ,
272
289
current_blockchain_height,
273
- missing_tx_indices,
290
+ missing_tx_indices : missing_tx_indices . into_iter ( ) . map ( usize_to_u64 ) . collect ( ) ,
274
291
} ) ,
275
292
) ,
276
293
Err ( IncomingBlockError :: Orphan ) => {
0 commit comments