Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Ban incoming invalid transactions (#4037)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored and gavofyork committed Nov 7, 2019
1 parent d682683 commit 438c0c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions core/transaction-pool/graph/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ impl<B: ChainApi> Pool<B> {
) -> impl Future<Output=ValidatedTransactionFor<B>> {
let (hash, bytes) = self.validated_pool.api().hash_and_length(&xt);
if !force && self.validated_pool.is_banned(&hash) {
return Either::Left(ready(ValidatedTransaction::Invalid(error::Error::TemporarilyBanned.into())))
return Either::Left(ready(ValidatedTransaction::Invalid(hash, error::Error::TemporarilyBanned.into())))
}

Either::Right(self.validated_pool.api().validate_transaction(block_id, xt.clone())
.then(move |validation_result| ready(match validation_result {
Ok(validity) => match validity {
Ok(validity) => if validity.provides.is_empty() {
ValidatedTransaction::Invalid(error::Error::NoTagsProvided.into())
ValidatedTransaction::Invalid(hash, error::Error::NoTagsProvided.into())
} else {
ValidatedTransaction::Valid(base::Transaction {
data: xt,
Expand All @@ -365,11 +365,11 @@ impl<B: ChainApi> Pool<B> {
})
},
Err(TransactionValidityError::Invalid(e)) =>
ValidatedTransaction::Invalid(error::Error::InvalidTransaction(e).into()),
ValidatedTransaction::Invalid(hash, error::Error::InvalidTransaction(e).into()),
Err(TransactionValidityError::Unknown(e)) =>
ValidatedTransaction::Unknown(hash, error::Error::UnknownTransaction(e).into()),
},
Err(e) => ValidatedTransaction::Invalid(e),
Err(e) => ValidatedTransaction::Invalid(hash, e),
})))
}
}
Expand Down
12 changes: 9 additions & 3 deletions core/transaction-pool/graph/src/validated_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum ValidatedTransaction<Hash, Ex, Error> {
/// Transaction that has been validated successfully.
Valid(base::Transaction<Hash, Ex>),
/// Transaction that is invalid.
Invalid(Error),
Invalid(Hash, Error),
/// Transaction which validity can't be determined.
///
/// We're notifying watchers about failure, if 'unknown' transaction is submitted.
Expand Down Expand Up @@ -125,7 +125,10 @@ impl<B: ChainApi> ValidatedPool<B> {
fire_events(&mut *listener, &imported);
Ok(imported.hash().clone())
}
ValidatedTransaction::Invalid(err) => Err(err.into()),
ValidatedTransaction::Invalid(hash, err) => {
self.rotator.ban(&std::time::Instant::now(), std::iter::once(hash));
Err(err.into())
},
ValidatedTransaction::Unknown(hash, err) => {
self.listener.write().invalid(&hash);
Err(err.into())
Expand Down Expand Up @@ -177,7 +180,10 @@ impl<B: ChainApi> ValidatedPool<B> {
.expect("One extrinsic passed; one result returned; qed")
.map(|_| watcher)
},
ValidatedTransaction::Invalid(err) => Err(err.into()),
ValidatedTransaction::Invalid(hash, err) => {
self.rotator.ban(&std::time::Instant::now(), std::iter::once(hash));
Err(err.into())
},
ValidatedTransaction::Unknown(_, err) => Err(err.into()),
}
}
Expand Down

0 comments on commit 438c0c8

Please sign in to comment.