Skip to content

Commit

Permalink
Merge pull request #4487 from zhangsoledad/zhangsoledad/tweak_max_anc…
Browse files Browse the repository at this point in the history
…estors_count

chore: tweak max_ancestors_count
  • Loading branch information
quake authored Jun 20, 2024
2 parents 60b1654 + 10794e2 commit 247befe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
53 changes: 18 additions & 35 deletions rpc/src/tests/module/pool.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions test/src/specs/tx_pool/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Spec for TxPoolLimitAncestorCount {
fn run(&self, nodes: &mut Vec<Node>) {
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
Expand All @@ -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
Expand All @@ -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());
Expand All @@ -120,15 +120,15 @@ 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));
}
}

// 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);
Expand All @@ -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))
Expand All @@ -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"));
Expand Down
21 changes: 19 additions & 2 deletions test/src/specs/tx_pool/send_tx_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node>) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion util/app-config/src/legacy/tx_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 247befe

Please sign in to comment.