diff --git a/rpc/src/tests/module/pool.rs b/rpc/src/tests/module/pool.rs index 2b1c726e11..f96bb1f24b 100644 --- a/rpc/src/tests/module/pool.rs +++ b/rpc/src/tests/module/pool.rs @@ -1,5 +1,3 @@ -use std::{thread::sleep, time::Duration}; - use ckb_store::ChainStore; use ckb_test_chain_utils::{always_success_cell, always_success_consensus, ckb_testnet_consensus}; use ckb_types::{ @@ -145,11 +143,17 @@ fn test_send_transaction_exceeded_maximum_ancestors_count() { let tip_block = store.get_block(&tip.hash()).unwrap(); let mut parent_tx_hash = tip_block.transactions().first().unwrap().hash(); - // generate 30 child-spends-parent txs - for i in 0..130 { + // generate 2000 child-spends-parent txs + for i in 0..2001 { let input = CellInput::new(OutPoint::new(parent_tx_hash.clone(), 0), 0); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(1000 - i).unwrap().pack()) + .capacity( + Capacity::bytes(1000) + .unwrap() + .safe_sub(Capacity::shannons(i * 41 * 1000)) + .unwrap() + .pack(), + ) .lock(always_success_cell().2.clone()) .build(); let cell_dep = CellDep::new_builder() @@ -162,43 +166,22 @@ fn test_send_transaction_exceeded_maximum_ancestors_count() { .cell_dep(cell_dep) .build(); let new_tx: ckb_jsonrpc_types::Transaction = tx.data().into(); - suite.rpc(&RpcTestRequest { + let response = suite.rpc(&RpcTestRequest { id: 42, jsonrpc: "2.0".to_string(), method: "send_transaction".to_string(), params: vec![json!(new_tx), json!("passthrough")], }); + if i != 2000 { + assert_eq!(response.error.to_string(), "null".to_string()); + } else { + assert!(response + .error + .to_string() + .contains("ExceededMaximumAncestorsCount")); + } parent_tx_hash = tx.hash(); } - - suite.wait_block_template_array_ge("proposals", 125); - - // 130 txs will be added to proposal list - while store.get_tip_header().unwrap().number() != (tip.number() + 2) { - sleep(Duration::from_millis(400)); - suite.rpc(&RpcTestRequest { - id: 42, - jsonrpc: "2.0".to_string(), - method: "generate_block".to_string(), - params: vec![], - }); - } - - // the default value of pool config `max_ancestors_count` is 125, - // only 125 txs will be added to committed list of the block template - suite.wait_block_template_array_ge("transactions", 1); - - let response = suite.rpc(&RpcTestRequest { - id: 42, - jsonrpc: "2.0".to_string(), - method: "get_block_template".to_string(), - params: vec![], - }); - - assert_eq!( - 125, - response.result["transactions"].as_array().unwrap().len() - ); } fn build_tx( diff --git a/test/src/specs/tx_pool/limit.rs b/test/src/specs/tx_pool/limit.rs index 9d532db630..d03152f343 100644 --- a/test/src/specs/tx_pool/limit.rs +++ b/test/src/specs/tx_pool/limit.rs @@ -72,7 +72,7 @@ impl Spec for TxPoolLimitAncestorCount { fn run(&self, nodes: &mut Vec) { let node0 = &nodes[0]; - let initial_inputs = gen_spendable(node0, 256); + let initial_inputs = gen_spendable(node0, 3100); let input_a = &initial_inputs[0]; // Commit transaction root @@ -90,7 +90,7 @@ impl Spec for TxPoolLimitAncestorCount { // Create 250 transactions cell dep on tx_a // we can have more than config.max_ancestors_count number of txs using one cell ref let mut cell_ref_txs = vec![]; - for i in 1..=250 { + for i in 1..=3000 { let cur = always_success_transaction(node0, initial_inputs.get(i).unwrap()); let cur = cur.as_advanced_builder().cell_dep(cell_dep.clone()).build(); let res = node0 @@ -106,10 +106,10 @@ impl Spec for TxPoolLimitAncestorCount { .build(); let last = always_success_transaction(node0, &input); - // now there are 252 ancestors for the last tx in the pool: - // 252 = 250 ref cell + 1 parent + 1 for self + // now there are 3002 ancestors for the last tx in the pool: + // 3002 = 3000 ref cell + 1 parent + 1 for self // to make sure this consuming cell dep transaction submitted, - // we need to evict 127 = 252 - 125 cell ref transactions + // we need to evict 1002 = 3002 - 2000 cell ref transactions let res = node0 .rpc_client() .send_transaction_result(last.data().into()); @@ -120,7 +120,7 @@ impl Spec for TxPoolLimitAncestorCount { let res = node0 .rpc_client() .get_transaction_with_verbosity(tx.hash(), 2); - if i < 127 { + if i < 1002 { assert!(matches!(res.tx_status.status, Status::Rejected)); } else { assert!(matches!(res.tx_status.status, Status::Pending)); @@ -128,7 +128,7 @@ impl Spec for TxPoolLimitAncestorCount { } // create a transaction chain - let input_c = &initial_inputs[251]; + let input_c = &initial_inputs[3001]; // Commit transaction root let tx_c = { let tx_c = always_success_transaction(node0, input_c); @@ -138,7 +138,7 @@ impl Spec for TxPoolLimitAncestorCount { let mut prev = tx_c.clone(); // Create transaction chain - for i in 0..125 { + for i in 0..2000 { let input = CellMetaBuilder::from_cell_output(prev.output(0).unwrap(), Default::default()) .out_point(OutPoint::new(prev.hash(), 0)) @@ -148,7 +148,7 @@ impl Spec for TxPoolLimitAncestorCount { .rpc_client() .send_transaction_result(cur.data().into()); prev = cur.clone(); - if i >= 124 { + if i >= 1999 { assert!(res.is_err()); let msg = res.err().unwrap().to_string(); assert!(msg.contains("PoolRejectedTransactionByMaxAncestorsCountLimit")); diff --git a/test/src/specs/tx_pool/send_tx_chain.rs b/test/src/specs/tx_pool/send_tx_chain.rs index 9d596d0613..99164f664b 100644 --- a/test/src/specs/tx_pool/send_tx_chain.rs +++ b/test/src/specs/tx_pool/send_tx_chain.rs @@ -12,7 +12,8 @@ use ckb_types::{ pub struct SendTxChain; -const MAX_ANCESTORS_COUNT: usize = 125; +const MAX_ANCESTORS_COUNT: usize = 2000; +const PROPOSAL_LIMIT: usize = 1500; impl Spec for SendTxChain { fn run(&self, nodes: &mut Vec) { @@ -69,7 +70,23 @@ impl Spec for SendTxChain { let template = node0.new_block(None, None, None); let block_with_proposals = template .as_advanced_builder() - .set_proposals(txs.iter().map(|tx| tx.proposal_short_id()).collect()) + .set_proposals( + txs.iter() + .take(PROPOSAL_LIMIT) + .map(|tx| tx.proposal_short_id()) + .collect(), + ) + .set_transactions(vec![template.transaction(0).unwrap()]) + .build(); + node0.submit_block(&block_with_proposals); + let block_with_proposals = template + .as_advanced_builder() + .set_proposals( + txs.iter() + .skip(PROPOSAL_LIMIT) + .map(|tx| tx.proposal_short_id()) + .collect(), + ) .set_transactions(vec![template.transaction(0).unwrap()]) .build(); node0.submit_block(&block_with_proposals); diff --git a/util/app-config/src/legacy/tx_pool.rs b/util/app-config/src/legacy/tx_pool.rs index 562f3ac6a6..214aaffa70 100644 --- a/util/app-config/src/legacy/tx_pool.rs +++ b/util/app-config/src/legacy/tx_pool.rs @@ -12,7 +12,7 @@ const DEFAULT_MIN_RBF_RATE: FeeRate = FeeRate::from_u64(1500); // default max tx verify cycles const DEFAULT_MAX_TX_VERIFY_CYCLES: Cycle = TWO_IN_TWO_OUT_CYCLES * 20; // default max ancestors count -const DEFAULT_MAX_ANCESTORS_COUNT: usize = 125; +const DEFAULT_MAX_ANCESTORS_COUNT: usize = 2_000; // Default expiration time for pool transactions in hours const DEFAULT_EXPIRY_HOURS: u8 = 12; // Default max_tx_pool_size 180mb