Decrease peer reputation on bad transactions (#4035)

* Decrease reputation on bad transactions

* Don't punish on duplicate transactions
This commit is contained in:
Arkadiy Paronyan
2019-11-07 12:00:14 +01:00
committed by Gavin Wood
parent 9515d34aee
commit e73436d818
4 changed files with 28 additions and 7 deletions
+13 -3
View File
@@ -615,7 +615,14 @@ where
self.pool.hash_of(transaction)
}
fn import(&self, report_handle: ReportHandle, who: PeerId, reputation_change: i32, transaction: B::Extrinsic) {
fn import(
&self,
report_handle: ReportHandle,
who: PeerId,
reputation_change_good: i32,
reputation_change_bad: i32,
transaction: B::Extrinsic
) {
if !self.imports_external_transactions {
debug!("Transaction rejected");
return;
@@ -629,10 +636,13 @@ where
let import_future = import_future
.then(move |import_result| {
match import_result {
Ok(_) => report_handle.report_peer(who, reputation_change),
Ok(_) => report_handle.report_peer(who, reputation_change_good),
Err(e) => match e.into_pool_error() {
Ok(txpool::error::Error::AlreadyImported(_)) => (),
Ok(e) => debug!("Error adding transaction to the pool: {:?}", e),
Ok(e) => {
report_handle.report_peer(who, reputation_change_bad);
debug!("Error adding transaction to the pool: {:?}", e)
}
Err(e) => debug!("Error converting pool error: {:?}", e),
}
}