Mandatory dispatch class (#5515)

* Mandatory dispatch class

* Tweaks

* Docs

* Fix test

* Update frame/support/src/weights.rs

Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Introduce logic that was stated in PR.

* Use

* Docs.

* Fix test

* Fix merge

* Update frame/support/src/weights.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Fix.

* Fix

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Gavin Wood
2020-04-05 14:27:30 +02:00
committed by GitHub
parent 392571d78c
commit abd822692d
10 changed files with 132 additions and 25 deletions
@@ -52,6 +52,13 @@ pub enum InvalidTransaction {
ExhaustsResources,
/// Any other custom invalid validity that is not covered by this enum.
Custom(u8),
/// An extrinsic with a Mandatory dispatch resulted in Error. This is indicative of either a
/// malicious validator or a buggy `provide_inherent`. In any case, it can result in dangerously
/// overweight blocks and therefore if found, invalidates the block.
BadMandatory,
/// A transaction with a mandatory dispatch. This is invalid; only inherent extrinsics are
/// allowed to have mandatory dispatches.
MandatoryDispatch,
}
impl InvalidTransaction {
@@ -62,6 +69,14 @@ impl InvalidTransaction {
_ => false,
}
}
/// Returns if the reason for the invalidity was a mandatory call failing.
pub fn was_mandatory(&self) -> bool {
match self {
Self::BadMandatory => true,
_ => false,
}
}
}
impl From<InvalidTransaction> for &'static str {
@@ -76,6 +91,10 @@ impl From<InvalidTransaction> for &'static str {
"Transaction would exhausts the block limits",
InvalidTransaction::Payment =>
"Inability to pay some fees (e.g. account balance too low)",
InvalidTransaction::BadMandatory =>
"A call was labelled as mandatory, but resulted in an Error.",
InvalidTransaction::MandatoryDispatch =>
"Tranaction dispatch is mandatory; transactions may not have mandatory dispatches.",
InvalidTransaction::Custom(_) => "InvalidTransaction custom error",
}
}
@@ -123,6 +142,15 @@ impl TransactionValidityError {
Self::Unknown(_) => false,
}
}
/// Returns `true` if the reason for the error was it being a mandatory dispatch that could not
/// be completed successfully.
pub fn was_mandatory(&self) -> bool {
match self {
Self::Invalid(e) => e.was_mandatory(),
Self::Unknown(_) => false,
}
}
}
impl From<TransactionValidityError> for &'static str {