Introduces account existence providers reference counting (#7363)

* Initial draft

* Latest changes

* Final bits.

* Fixes

* Fixes

* Test fixes

* Fix tests

* Fix babe tests

* Fix

* Fix

* Fix

* Fix

* Fix

* fix warnings in assets

* Fix UI tests

* fix line width

* Fix

* Update frame/system/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/system/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Fix

* fix unused warnings

* Fix

* Update frame/system/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Update frame/system/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Fix

* fix slash and comprehensive slash test

* fix reserved slash and comprehensive tests

* check slash on non-existent account

* Revert "Fix UI tests"

This reverts commit e0002c0f13442f7d0c95a054a6c515536328a4a0.

* Fix

* Fix utility tests

* keep dispatch error backwards compatible

* Fix

* Fix

* fix ui test

* Companion checker shouldn't be so anal.

* Fix

* Fix

* Fix

* Apply suggestions from code review

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update frame/balances/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* return correct slash info when failing gracefully

* fix missing import

* Update frame/system/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Fix

* Update frame/balances/src/tests_local.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Fixes

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Gavin Wood
2021-01-16 18:47:28 +01:00
committed by GitHub
parent 660cf13e6d
commit f1d36a7103
34 changed files with 814 additions and 447 deletions
+19 -2
View File
@@ -411,6 +411,10 @@ pub enum DispatchError {
#[cfg_attr(feature = "std", serde(skip_deserializing))]
message: Option<&'static str>,
},
/// At least one consumer is remaining so the account cannot be destroyed.
ConsumerRemaining,
/// There are no providers so the account cannot be created.
NoProviders,
}
/// Result of a `Dispatchable` which contains the `DispatchResult` and additional information about
@@ -460,6 +464,15 @@ impl From<crate::traits::BadOrigin> for DispatchError {
}
}
impl From<crate::traits::StoredMapError> for DispatchError {
fn from(e: crate::traits::StoredMapError) -> Self {
match e {
crate::traits::StoredMapError::ConsumerRemaining => Self::ConsumerRemaining,
crate::traits::StoredMapError::NoProviders => Self::NoProviders,
}
}
}
impl From<&'static str> for DispatchError {
fn from(err: &'static str) -> DispatchError {
DispatchError::Other(err)
@@ -470,9 +483,11 @@ impl From<DispatchError> for &'static str {
fn from(err: DispatchError) -> &'static str {
match err {
DispatchError::Other(msg) => msg,
DispatchError::CannotLookup => "Can not lookup",
DispatchError::CannotLookup => "Cannot lookup",
DispatchError::BadOrigin => "Bad origin",
DispatchError::Module { message, .. } => message.unwrap_or("Unknown module error"),
DispatchError::ConsumerRemaining => "Consumer remaining",
DispatchError::NoProviders => "No providers",
}
}
}
@@ -490,7 +505,7 @@ impl traits::Printable for DispatchError {
"DispatchError".print();
match self {
Self::Other(err) => err.print(),
Self::CannotLookup => "Can not lookup".print(),
Self::CannotLookup => "Cannot lookup".print(),
Self::BadOrigin => "Bad origin".print(),
Self::Module { index, error, message } => {
index.print();
@@ -499,6 +514,8 @@ impl traits::Printable for DispatchError {
msg.print();
}
}
Self::ConsumerRemaining => "Consumer remaining".print(),
Self::NoProviders => "No providers".print(),
}
}
}
@@ -153,6 +153,25 @@ impl From<BadOrigin> for &'static str {
}
}
/// Error that can be returned by our impl of `StoredMap`.
#[derive(Encode, Decode, RuntimeDebug)]
pub enum StoredMapError {
/// Attempt to create map value when it is a consumer and there are no providers in place.
NoProviders,
/// Attempt to anull/remove value when it is the last provider and there is still at
/// least one consumer left.
ConsumerRemaining,
}
impl From<StoredMapError> for &'static str {
fn from(e: StoredMapError) -> &'static str {
match e {
StoredMapError::NoProviders => "No providers",
StoredMapError::ConsumerRemaining => "Consumer remaining",
}
}
}
/// An error that indicates that a lookup failed.
#[derive(Encode, Decode, RuntimeDebug)]
pub struct LookupError;