@@ -364,18 +364,28 @@ impl Miner {
364
364
365
365
let client = self . pool_client ( chain) ;
366
366
let engine_params = self . engine . params ( ) ;
367
- let min_tx_gas = self . engine . schedule ( chain_info. best_block_number ) . tx_gas . into ( ) ;
367
+ let min_tx_gas: U256 = self . engine . schedule ( chain_info. best_block_number ) . tx_gas . into ( ) ;
368
368
let nonce_cap: Option < U256 > = if chain_info. best_block_number + 1 >= engine_params. dust_protection_transition {
369
369
Some ( ( engine_params. nonce_cap_increment * ( chain_info. best_block_number + 1 ) ) . into ( ) )
370
370
} else {
371
371
None
372
372
} ;
373
+ // we will never need more transactions than limit divided by min gas
374
+ let max_transactions = if min_tx_gas. is_zero ( ) {
375
+ usize:: max_value ( )
376
+ } else {
377
+ ( * open_block. block ( ) . header ( ) . gas_limit ( ) / min_tx_gas) . as_u64 ( ) as usize
378
+ } ;
373
379
374
380
let pending: Vec < Arc < _ > > = self . transaction_queue . pending (
375
381
client. clone ( ) ,
376
- chain_info. best_block_number ,
377
- chain_info. best_block_timestamp ,
378
- nonce_cap,
382
+ pool:: PendingSettings {
383
+ block_number : chain_info. best_block_number ,
384
+ current_timestamp : chain_info. best_block_timestamp ,
385
+ nonce_cap,
386
+ max_len : max_transactions,
387
+ ordering : miner:: PendingOrdering :: Priority ,
388
+ }
379
389
) ;
380
390
381
391
let took_ms = |elapsed : & Duration | {
@@ -807,20 +817,28 @@ impl miner::MinerService for Miner {
807
817
self . transaction_queue . all_transactions ( )
808
818
}
809
819
810
- fn ready_transactions < C > ( & self , chain : & C ) -> Vec < Arc < VerifiedTransaction > > where
820
+ fn ready_transactions < C > ( & self , chain : & C , max_len : usize , ordering : miner:: PendingOrdering )
821
+ -> Vec < Arc < VerifiedTransaction > >
822
+ where
811
823
C : ChainInfo + Nonce + Sync ,
812
824
{
813
825
let chain_info = chain. chain_info ( ) ;
814
826
815
827
let from_queue = || {
828
+ // We propagate transactions over the nonce cap.
829
+ // The mechanism is only to limit number of transactions in pending block
830
+ // those transactions are valid and will just be ready to be included in next block.
831
+ let nonce_cap = None ;
832
+
816
833
self . transaction_queue . pending (
817
834
CachedNonceClient :: new ( chain, & self . nonce_cache ) ,
818
- chain_info. best_block_number ,
819
- chain_info. best_block_timestamp ,
820
- // We propagate transactions over the nonce cap.
821
- // The mechanism is only to limit number of transactions in pending block
822
- // those transactions are valid and will just be ready to be included in next block.
823
- None ,
835
+ pool:: PendingSettings {
836
+ block_number : chain_info. best_block_number ,
837
+ current_timestamp : chain_info. best_block_timestamp ,
838
+ nonce_cap,
839
+ max_len,
840
+ ordering,
841
+ } ,
824
842
)
825
843
} ;
826
844
@@ -830,6 +848,7 @@ impl miner::MinerService for Miner {
830
848
. iter ( )
831
849
. map ( |signed| pool:: VerifiedTransaction :: from_pending_block_transaction ( signed. clone ( ) ) )
832
850
. map ( Arc :: new)
851
+ . take ( max_len)
833
852
. collect ( )
834
853
} , chain_info. best_block_number )
835
854
} ;
@@ -1083,7 +1102,7 @@ mod tests {
1083
1102
use rustc_hex:: FromHex ;
1084
1103
1085
1104
use client:: { TestBlockChainClient , EachBlockWith , ChainInfo , ImportSealedBlock } ;
1086
- use miner:: MinerService ;
1105
+ use miner:: { MinerService , PendingOrdering } ;
1087
1106
use test_helpers:: { generate_dummy_client, generate_dummy_client_with_spec_and_accounts} ;
1088
1107
use transaction:: { Transaction } ;
1089
1108
@@ -1179,7 +1198,7 @@ mod tests {
1179
1198
assert_eq ! ( res. unwrap( ) , ( ) ) ;
1180
1199
assert_eq ! ( miner. pending_transactions( best_block) . unwrap( ) . len( ) , 1 ) ;
1181
1200
assert_eq ! ( miner. pending_receipts( best_block) . unwrap( ) . len( ) , 1 ) ;
1182
- assert_eq ! ( miner. ready_transactions( & client) . len( ) , 1 ) ;
1201
+ assert_eq ! ( miner. ready_transactions( & client, 10 , PendingOrdering :: Priority ) . len( ) , 1 ) ;
1183
1202
// This method will let us know if pending block was created (before calling that method)
1184
1203
assert ! ( !miner. prepare_pending_block( & client) ) ;
1185
1204
}
@@ -1198,7 +1217,7 @@ mod tests {
1198
1217
assert_eq ! ( res. unwrap( ) , ( ) ) ;
1199
1218
assert_eq ! ( miner. pending_transactions( best_block) , None ) ;
1200
1219
assert_eq ! ( miner. pending_receipts( best_block) , None ) ;
1201
- assert_eq ! ( miner. ready_transactions( & client) . len( ) , 1 ) ;
1220
+ assert_eq ! ( miner. ready_transactions( & client, 10 , PendingOrdering :: Priority ) . len( ) , 1 ) ;
1202
1221
}
1203
1222
1204
1223
#[ test]
@@ -1217,11 +1236,11 @@ mod tests {
1217
1236
assert_eq ! ( miner. pending_transactions( best_block) , None ) ;
1218
1237
assert_eq ! ( miner. pending_receipts( best_block) , None ) ;
1219
1238
// By default we use PendingSet::AlwaysSealing, so no transactions yet.
1220
- assert_eq ! ( miner. ready_transactions( & client) . len( ) , 0 ) ;
1239
+ assert_eq ! ( miner. ready_transactions( & client, 10 , PendingOrdering :: Priority ) . len( ) , 0 ) ;
1221
1240
// This method will let us know if pending block was created (before calling that method)
1222
1241
assert ! ( miner. prepare_pending_block( & client) ) ;
1223
1242
// After pending block is created we should see a transaction.
1224
- assert_eq ! ( miner. ready_transactions( & client) . len( ) , 1 ) ;
1243
+ assert_eq ! ( miner. ready_transactions( & client, 10 , PendingOrdering :: Priority ) . len( ) , 1 ) ;
1225
1244
}
1226
1245
1227
1246
#[ test]
0 commit comments