@@ -21,6 +21,7 @@ extern crate tracing;
21
21
use snarkos_account:: Account ;
22
22
use snarkos_node_bft:: {
23
23
BFT ,
24
+ MAX_BATCH_DELAY_IN_MS ,
24
25
Primary ,
25
26
helpers:: {
26
27
ConsensusReceiver ,
@@ -49,7 +50,7 @@ use colored::Colorize;
49
50
use indexmap:: IndexMap ;
50
51
use lru:: LruCache ;
51
52
use parking_lot:: Mutex ;
52
- use std:: { future:: Future , net:: SocketAddr , num:: NonZeroUsize , sync:: Arc } ;
53
+ use std:: { future:: Future , net:: SocketAddr , num:: NonZeroUsize , sync:: Arc , time :: Duration } ;
53
54
use tokio:: {
54
55
sync:: { OnceCell , oneshot} ,
55
56
task:: JoinHandle ,
@@ -296,7 +297,7 @@ impl<N: Network> Consensus<N> {
296
297
. lock ( )
297
298
. insert ( TransmissionID :: Solution ( solution. id ( ) , checksum) , timestamp) ;
298
299
}
299
- // Process the unconfirmed solution.
300
+ // Queue the unconfirmed solution.
300
301
{
301
302
let solution_id = solution. id ( ) ;
302
303
@@ -316,6 +317,12 @@ impl<N: Network> Consensus<N> {
316
317
}
317
318
}
318
319
320
+ // Try to process the unconfirmed solutions in the memory pool.
321
+ self . process_unconfirmed_solutions ( ) . await
322
+ }
323
+
324
+ /// Processes unconfirmed transactions in the memory pool.
325
+ pub async fn process_unconfirmed_solutions ( & self ) -> Result < ( ) > {
319
326
// If the memory pool of this node is full, return early.
320
327
let num_unconfirmed_solutions = self . num_unconfirmed_solutions ( ) ;
321
328
let num_unconfirmed_transmissions = self . num_unconfirmed_transmissions ( ) ;
@@ -365,7 +372,7 @@ impl<N: Network> Consensus<N> {
365
372
. lock ( )
366
373
. insert ( TransmissionID :: Transaction ( transaction. id ( ) , checksum) , timestamp) ;
367
374
}
368
- // Process the unconfirmed transaction.
375
+ // Queue the unconfirmed transaction.
369
376
{
370
377
let transaction_id = transaction. id ( ) ;
371
378
@@ -391,8 +398,14 @@ impl<N: Network> Consensus<N> {
391
398
} else if self . transactions_queue . lock ( ) . executions . put ( transaction_id, transaction) . is_some ( ) {
392
399
bail ! ( "Transaction '{}' exists in the memory pool" , fmt_id( transaction_id) ) ;
393
400
}
401
+
402
+ // Try to process the unconfirmed transactions in the memory pool.
403
+ self . process_unconfirmed_transactions ( ) . await
394
404
}
405
+ }
395
406
407
+ /// Processes unconfirmed transactions in the memory pool.
408
+ pub async fn process_unconfirmed_transactions ( & self ) -> Result < ( ) > {
396
409
// If the memory pool of this node is full, return early.
397
410
let num_unconfirmed_transmissions = self . num_unconfirmed_transmissions ( ) ;
398
411
if num_unconfirmed_transmissions >= Primary :: < N > :: MAX_TRANSMISSIONS_TOLERANCE {
@@ -455,6 +468,23 @@ impl<N: Network> Consensus<N> {
455
468
self_. process_bft_subdag ( committed_subdag, transmissions, callback) . await ;
456
469
}
457
470
} ) ;
471
+
472
+ // Process the unconfirmed transactions in the memory pool.
473
+ let self_ = self . clone ( ) ;
474
+ self . spawn ( async move {
475
+ loop {
476
+ // Sleep briefly.
477
+ tokio:: time:: sleep ( Duration :: from_millis ( MAX_BATCH_DELAY_IN_MS ) ) . await ;
478
+ // Process the unconfirmed transactions in the memory pool.
479
+ if let Err ( e) = self_. process_unconfirmed_transactions ( ) . await {
480
+ warn ! ( "Cannot process unconfirmed transactions - {e}" ) ;
481
+ }
482
+ // Process the unconfirmed solutions in the memory pool.
483
+ if let Err ( e) = self_. process_unconfirmed_solutions ( ) . await {
484
+ warn ! ( "Cannot process unconfirmed solutions - {e}" ) ;
485
+ }
486
+ }
487
+ } ) ;
458
488
}
459
489
460
490
/// Processes the committed subdag and transmissions from the BFT.
0 commit comments