Skip to content

Commit

Permalink
Do not ban local txs
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Jun 19, 2023
1 parent 575e194 commit 91a97c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bazuka"
version = "0.19.16"
version = "0.19.17"
authors = ["El Geuse <geusebetel@proton.me>"]
edition = "2021"

Expand Down
12 changes: 9 additions & 3 deletions src/blockchain/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::core::{
};
use crate::db::KvStore;
use crate::zk::MpnTransaction;
use std::collections::{HashMap, VecDeque};
use std::collections::{HashMap, HashSet, VecDeque};

trait Nonced {
fn nonce(&self) -> u32;
Expand Down Expand Up @@ -118,6 +118,7 @@ impl SingleMempool {
#[derive(Clone, Debug)]
pub struct Mempool {
min_balance_per_tx: Amount,
local_addrs: HashSet<GeneralAddress>,
banned: HashMap<GeneralAddress, u32>,
txs: HashMap<NonceGroup, SingleMempool>,
min_fees: HashMap<TransactionKind, Amount>,
Expand All @@ -139,6 +140,7 @@ impl Mempool {
.collect(),
rejected: Default::default(),
banned: Default::default(),
local_addrs: Default::default(),
}
}
}
Expand Down Expand Up @@ -173,7 +175,7 @@ impl Mempool {
NonceGroup::MpnWithdraw(addr) => blockchain.get_mpn_account(addr)?.withdraw_nonce,
};
mempool.update_nonce(nonce, local_ts);
if mempool.should_be_banned(local_ts) {
if !self.local_addrs.contains(&ng.address()) && mempool.should_be_banned(local_ts) {
const BAN_TIME: u32 = 1200; // 20 minutes ban-time
self.banned.insert(ng.address(), local_ts + BAN_TIME);
banned_ngs.push(ng.clone());
Expand All @@ -195,7 +197,11 @@ impl Mempool {
now: u32,
meta: Option<TransactionMetadata>,
) -> Result<(), BlockchainError> {
if self.is_banned(tx.sender(), now) {
if is_local {
self.local_addrs.insert(tx.nonce_group().address());
}

if !is_local && self.is_banned(tx.sender(), now) {
return Ok(());
}

Expand Down

0 comments on commit 91a97c5

Please sign in to comment.