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

BREAKING - Try-runtime: Use proper error types #13993

Merged
merged 38 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9e030be
Try-state: DispatchResult as return type
Szegoo Apr 24, 2023
1b0155e
try_state for the rest of the pallets
Szegoo Apr 24, 2023
c78308b
pre_upgrade
Szegoo Apr 26, 2023
733d461
post_upgrade
Szegoo Apr 26, 2023
388bf12
try_runtime_upgrade
Szegoo Apr 26, 2023
3cd0012
fixes
Szegoo Apr 27, 2023
8776628
bags-list fix
Szegoo Apr 27, 2023
f7aa4d6
fix
Szegoo Apr 27, 2023
fd44013
update test
Szegoo Apr 27, 2023
a5693f7
warning fix
Szegoo Apr 27, 2023
f38a40e
...
Szegoo Apr 27, 2023
113aeac
final fixes 🤞
Szegoo Apr 27, 2023
65ffe15
warning..
Szegoo Apr 27, 2023
d0ea89f
frame-support
Szegoo Apr 27, 2023
e6a37c7
warnings
Szegoo Apr 27, 2023
49ac4db
Update frame/staking/src/migrations.rs
Szegoo Apr 28, 2023
83b5cdf
fix
Szegoo Apr 28, 2023
773f4ad
fix warning
Szegoo Apr 28, 2023
962ad7f
nit fix
Szegoo Apr 28, 2023
103c755
Merge branch 'paritytech:master' into try-state-error
Szegoo Apr 28, 2023
ae24d0e
merge fixes
Szegoo Apr 28, 2023
f22801c
small fix
Szegoo Apr 28, 2023
d994291
should be good now
Szegoo Apr 29, 2023
5e7110c
missed these ones
Szegoo Apr 29, 2023
0a3267a
introduce TryRuntimeError and TryRuntimeResult
Szegoo May 2, 2023
bf4663c
fixes
Szegoo May 2, 2023
f63ee59
fix
Szegoo May 2, 2023
a4d2f88
Merge branch 'master' into try-state-error
Szegoo May 5, 2023
b79d04b
Merge branch 'master' into try-state-error
Szegoo May 12, 2023
c0a0420
removed TryRuntimeResult & made some fixes
Szegoo May 13, 2023
a778238
fix testsg
Szegoo May 13, 2023
3271ab2
tests passing
Szegoo May 13, 2023
ac20486
unnecessary imports
Szegoo May 13, 2023
0fed96e
Update frame/assets/src/migration.rs
Szegoo May 16, 2023
21976bf
Merge branch 'paritytech:master' into try-state-error
Szegoo May 17, 2023
8b55d8c
Merge branch 'paritytech:master' into try-state-error
Szegoo May 17, 2023
d304ce6
Merge branch 'paritytech:master' into try-state-error
Szegoo May 22, 2023
39756d4
Merge branch 'paritytech:master' into try-state-error
Szegoo May 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
final fixes 🤞
  • Loading branch information
Szegoo committed Apr 27, 2023
commit 113aeac26c0923619f100e81240c30c02b488812
2 changes: 1 addition & 1 deletion frame/bags-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub mod pallet {
}

#[cfg(feature = "try-runtime")]
fn try_state(_: BlockNumberFor<T>) -> Result<(), &'static str> {
fn try_state(_: BlockNumberFor<T>) -> DispatchResult {
<Self as SortedListProvider<T::AccountId>>::try_state()
}
}
Expand Down
13 changes: 9 additions & 4 deletions frame/bags-list/src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use crate::Config;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::ScoreProvider;
use frame_support::{
defensive, ensure,
defensive,
dispatch::{DispatchError, DispatchResult},
ensure,
traits::{Defensive, DefensiveOption, Get},
DefaultNoBound, PalletError,
};
Expand Down Expand Up @@ -516,7 +518,7 @@ impl<T: Config<I>, I: 'static> List<T, I> {
let mut seen_in_list = BTreeSet::new();
ensure!(
Self::iter().map(|node| node.id).all(|id| seen_in_list.insert(id)),
ListError::Duplicate,
DispatchError::Other("duplicate identified")
);

let iter_count = Self::iter().count() as u32;
Expand Down Expand Up @@ -778,7 +780,7 @@ impl<T: Config<I>, I: 'static> Bag<T, I> {
.map(|node| node.id)
// each voter is only seen once, thus there is no cycle within a bag
.all(|voter| seen_in_bag.insert(voter)),
ListError::Duplicate
DispatchError::Other("duplicate found in bag")
);

Ok(())
Expand Down Expand Up @@ -903,7 +905,10 @@ impl<T: Config<I>, I: 'static> Node<T, I> {

let id = self.id();

frame_support::ensure!(expected_bag.contains(id), ListError::NodeNotFound);
frame_support::ensure!(
expected_bag.contains(id),
DispatchError::Other("node does not exist in the bag")
);

let non_terminal_check = !self.is_terminal() &&
expected_bag.head.as_ref() != Some(id) &&
Expand Down
12 changes: 6 additions & 6 deletions frame/bags-list/src/list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ use crate::{
ListBags, ListNodes,
};
use frame_election_provider_support::{SortedListProvider, VoteWeight};
use frame_support::{
assert_ok, assert_storage_noop,
dispatch::{DispatchError, DispatchResult},
};
use frame_support::{assert_ok, assert_storage_noop, dispatch::DispatchError};

fn node(
id: AccountId,
Expand Down Expand Up @@ -362,7 +359,10 @@ mod list {
// make sure there are no duplicates.
ExtBuilder::default().build_and_execute_no_post_check(|| {
Bag::<Runtime>::get(10).unwrap().insert_unchecked(2, 10);
assert_eq!(List::<Runtime>::do_try_state(), ListError::Duplicate);
assert_eq!(
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
List::<Runtime>::do_try_state(),
DispatchError::Other("duplicate identified").into()
);
});

// ensure count is in sync with `ListNodes::count()`.
Expand All @@ -378,7 +378,7 @@ mod list {

assert_eq!(
List::<Runtime>::do_try_state(),
DispatchError::Other("iter_count != stored_count")
DispatchError::Other("iter_count != stored_count").into()
);
});
}
Expand Down