Skip to content

Commit 3083001

Browse files
HoOngEeforiequal0
authored andcommitted
Add a new type of users called immune users
Immune users are immune from getting banned.
1 parent fc8bb8c commit 3083001

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/src/miner/miner.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub struct Miner {
128128
accounts: Option<Arc<AccountProvider>>,
129129
notifiers: RwLock<Vec<Box<dyn NotifyWork>>>,
130130
malicious_users: RwLock<HashSet<Address>>,
131+
immune_users: RwLock<HashSet<Address>>,
131132
}
132133

133134
impl Miner {
@@ -186,6 +187,7 @@ impl Miner {
186187
accounts,
187188
notifiers: RwLock::new(notifiers),
188189
malicious_users: RwLock::new(HashSet::new()),
190+
immune_users: RwLock::new(HashSet::new()),
189191
}
190192
}
191193

@@ -274,6 +276,10 @@ impl Miner {
274276
// FIXME: Refactoring is needed. recover_public is calling in verify_transaction_unordered.
275277
let signer_public = tx.recover_public()?;
276278
let signer_address = public_to_address(&signer_public);
279+
if default_origin.is_local() {
280+
self.immune_users.write().insert(signer_address);
281+
}
282+
277283
let origin = self
278284
.accounts
279285
.as_ref()
@@ -295,6 +301,7 @@ impl Miner {
295301
if !self.is_allowed_transaction(&tx.action) {
296302
cdebug!(MINER, "Rejected transaction {:?}: {:?} is not allowed transaction", hash, tx.action);
297303
}
304+
let immune_users = self.immune_users.read();
298305
let tx = tx
299306
.verify_basic()
300307
.map_err(From::from)
@@ -305,7 +312,7 @@ impl Miner {
305312
.and_then(|_| CodeChainMachine::verify_transaction_seal(tx, &fake_header))
306313
.map_err(|e| {
307314
match e {
308-
Error::Syntax(_) if !origin.is_local() => {
315+
Error::Syntax(_) if !origin.is_local() && !immune_users.contains(&signer_address) => {
309316
self.malicious_users.write().insert(signer_address);
310317
}
311318
_ => {}
@@ -317,7 +324,7 @@ impl Miner {
317324
// This check goes here because verify_transaction takes SignedTransaction parameter
318325
self.engine.machine().verify_transaction(&tx, &fake_header, client, false).map_err(|e| {
319326
match e {
320-
Error::Syntax(_) if !origin.is_local() => {
327+
Error::Syntax(_) if !origin.is_local() && !immune_users.contains(&signer_address) => {
321328
self.malicious_users.write().insert(signer_address);
322329
}
323330
_ => {}
@@ -520,6 +527,8 @@ impl Miner {
520527
let mut tx_count: usize = 0;
521528
let tx_total = transactions.len();
522529
let mut invalid_tx_users = HashSet::new();
530+
531+
let immune_users = self.immune_users.read();
523532
for tx in transactions {
524533
let signer_public = tx.signer_public();
525534
let signer_address = public_to_address(&signer_public);
@@ -557,6 +566,7 @@ impl Miner {
557566
.read()
558567
.is_local_transaction(hash)
559568
.expect("The tx is clearly fetched from the mempool")
569+
&& !immune_users.contains(&signer_address)
560570
{
561571
self.malicious_users.write().insert(signer_address);
562572
}

0 commit comments

Comments
 (0)