Skip to content

Commit 8f65a0b

Browse files
author
Seonpyo Kim
committed
Block malicious users who generated syntax errors
1 parent 4a0d62c commit 8f65a0b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

core/src/miner/miner.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ impl Miner {
270270
.into_iter()
271271
.map(|tx| {
272272
let hash = tx.hash();
273+
let signer_public = tx.recover_public()?;
274+
275+
if self.malicious_users.read().contains(&signer_public) {
276+
// FIXME: just to skip, think about another way.
277+
return Ok(())
278+
}
273279
if client.transaction_block(&TransactionId::Hash(hash)).is_some() {
274280
cdebug!(MINER, "Rejected transaction {:?}: already in the blockchain", hash);
275281
return Err(HistoryError::TransactionAlreadyImported.into())
@@ -283,12 +289,29 @@ impl Miner {
283289
.and_then(|_| self.engine.verify_transaction_unordered(tx, &best_block_header))
284290
{
285291
Err(e) => {
292+
match e {
293+
Error::Syntax(_) if !self.mem_pool.read().is_local_transaction(hash) => {
294+
self.malicious_users.write().insert(signer_public);
295+
}
296+
_ => {}
297+
}
286298
cdebug!(MINER, "Rejected transaction {:?} with invalid signature: {:?}", hash, e);
287299
Err(e)
288300
}
289301
Ok(tx) => {
290302
// This check goes here because verify_transaction takes SignedTransaction parameter
291-
self.engine.machine().verify_transaction(&tx, &best_block_header, client, false)?;
303+
self.engine.machine().verify_transaction(&tx, &best_block_header, client, false).map_err(
304+
|e| {
305+
match e {
306+
Error::Syntax(_) if !self.mem_pool.read().is_local_transaction(hash) => {
307+
self.malicious_users.write().insert(tx.signer_public());
308+
}
309+
_ => {}
310+
};
311+
e
312+
},
313+
)?;
314+
292315

293316
let origin = self
294317
.accounts

0 commit comments

Comments
 (0)