Skip to content

Commit

Permalink
fix rbf check rule nervosnetwork#5
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 13, 2023
1 parent e286be9 commit 7353f4b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tx-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::collections::HashSet;
use std::sync::Arc;

const COMMITTED_HASH_CACHE_SIZE: usize = 100_000;

const MAX_REPLACEMENT_CANDIDATES: usize = 100;
/// Tx-pool implementation
pub struct TxPool {
pub(crate) config: TxPoolConfig,
Expand Down Expand Up @@ -544,14 +544,15 @@ impl TxPool {
}

// Rule #5, new replaced tx's descendants can not more than 100
let mut replace_count: usize = 0;
for conflict in conflicts.iter() {
let id = conflict.proposal_short_id();
let mut ids = vec![id.clone()];
ids.extend(self.pool_map.calc_descendants(&id));
if ids.len() >= 100 {
let descendants = self.pool_map.calc_descendants(&id);
replace_count += descendants.len() + 1;
if replace_count > MAX_REPLACEMENT_CANDIDATES {
return Err(Reject::RBFRejected(format!(
"tx conflict too many txs, conflict txs count: {}",
ids.len(),
replace_count,
)));
}
}
Expand Down

0 comments on commit 7353f4b

Please sign in to comment.