Skip to content

Commit

Permalink
fix: temp fix tx relay flood
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad authored and doitian committed Apr 10, 2019
1 parent 79a9ea2 commit b34a0c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion rpc/src/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl<CI: ChainIndex + 'static> PoolRpc for PoolRpcImpl<CI> {
Ok(cycles) => Some(cycles),
};
let entry = PoolEntry::new(tx.clone(), 0, cycles);
chain_state.mut_tx_pool().enqueue_tx(entry);
if !chain_state.mut_tx_pool().enqueue_tx(entry) {
// Duplicate tx
return Ok(tx_hash);
}
cycles
};
match cycles {
Expand Down
13 changes: 11 additions & 2 deletions shared/src/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ impl<CI: ChainIndex> ChainState<CI> {
let short_id = tx.proposal_short_id();
let rtx = self.resolve_tx_from_pool(&tx, &tx_pool);
let verify_result = self.verify_rtx(&rtx, max_cycles);
let tx_hash = tx.hash();
if self.contains_proposal_id(&short_id) {
if !self.filter.insert(tx_hash.clone()) {
trace!(target: "tx_pool", "discarding already known transaction {:#x}", tx_hash);
return Err(PoolError::Duplicate);
}
let entry = PoolEntry::new(tx, 0, verify_result.map(Some).unwrap_or(None));
self.staging_tx(&mut tx_pool, entry, max_cycles)?;
Ok(verify_result.map_err(PoolError::InvalidTx)?)
Expand All @@ -113,12 +118,16 @@ impl<CI: ChainIndex> ChainState<CI> {
Ok(cycles) => {
// enqueue tx with cycles
let entry = PoolEntry::new(tx, 0, Some(cycles));
tx_pool.enqueue_tx(entry);
if !tx_pool.enqueue_tx(entry) {
return Err(PoolError::Duplicate);
}
Ok(cycles)
}
Err(TransactionError::UnknownInput) => {
let entry = PoolEntry::new(tx, 0, None);
tx_pool.enqueue_tx(entry);
if !tx_pool.enqueue_tx(entry) {
return Err(PoolError::Duplicate);
}
Err(PoolError::InvalidTx(TransactionError::UnknownInput))
}
Err(err) => Err(PoolError::InvalidTx(err)),
Expand Down
2 changes: 2 additions & 0 deletions shared/src/tx_pool/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub enum PoolError {
TimeOut,
/// BlockNumber is not right
InvalidBlockNumber,
/// Duplicate tx
Duplicate,
}

impl fmt::Display for PoolError {
Expand Down

0 comments on commit b34a0c0

Please sign in to comment.