Skip to content

Commit

Permalink
Expose UpdateAccumulator + merge with the upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Jan 31, 2025
1 parent 5796a3e commit 410fd2a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 21 additions & 15 deletions pallets/core/src/util/batch_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,12 @@ where
U: GetUpdateKind<Option<<C::Target as KeyValue>::Value>>,
C::Target: KeyValue,
{
type Targets<'a> = alloc::collections::btree_map::Keys<'a, <C::Target as KeyValue>::Key, U> where
Self: 'a,
<C::Target as KeyValue>::Key: 'a,
C: 'a;
type Targets<'a>
= alloc::collections::btree_map::Keys<'a, <C::Target as KeyValue>::Key, U>
where
Self: 'a,
<C::Target as KeyValue>::Key: 'a,
C: 'a;

fn targets<'targets>(&'targets self, _entity: &'targets C) -> Self::Targets<'targets> {
self.keys()
Expand Down Expand Up @@ -549,7 +551,12 @@ where
U: GetUpdateKind<Option<<C::Target as KeyValue>::Value>>,
C::Target: KeyValue,
{
type Targets<'a> = core::iter::Once<&'a <C::Target as KeyValue>::Key> where U: 'a, C: 'a, <C::Target as KeyValue>::Key: 'a;
type Targets<'a>
= core::iter::Once<&'a <C::Target as KeyValue>::Key>
where
U: 'a,
C: 'a,
<C::Target as KeyValue>::Key: 'a;

fn targets<'targets>(&'targets self, _entity: &'targets C) -> Self::Targets<'targets> {
once(&self.key)
Expand Down Expand Up @@ -909,16 +916,15 @@ where
C::Target: KeyValue,
U: KeyedUpdate<C>,
{
type Targets<'a> = Either<
core::iter::Chain<
<C::Target as KeyValue>::Keys<'a>,
<C::Target as KeyValue>::Keys<'a>,
>,
U::Targets<'a>
> where
Self: 'a,
<C::Target as KeyValue>::Key: 'a,
C: 'a;
type Targets<'a>
= Either<
core::iter::Chain<<C::Target as KeyValue>::Keys<'a>, <C::Target as KeyValue>::Keys<'a>>,
U::Targets<'a>,
>
where
Self: 'a,
<C::Target as KeyValue>::Key: 'a,
C: 'a;

fn targets<'targets>(&'targets self, entity: &'targets C) -> Self::Targets<'targets> {
match self {
Expand Down
24 changes: 20 additions & 4 deletions pallets/core/src/util/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ impl<K: Ord + Clone, V: Clone, S: Get<u32>> KeyValue for BoundedBTreeMap<K, V, S
type Key = K;
type Value = V;

type Keys<'keys> = alloc::collections::btree_map::Keys<'keys, K, V> where Self: 'keys, K: 'keys;
type Keys<'keys>
= alloc::collections::btree_map::Keys<'keys, K, V>
where
Self: 'keys,
K: 'keys;

fn capacity(&self) -> Option<u32> {
Some(S::get())
Expand Down Expand Up @@ -73,7 +77,11 @@ impl<V: Ord + Clone, S: Get<u32>> KeyValue for BoundedBTreeSet<V, S> {
type Key = V;
type Value = ();

type Keys<'keys> = alloc::collections::btree_set::Iter<'keys, V> where Self: 'keys, V: 'keys;
type Keys<'keys>
= alloc::collections::btree_set::Iter<'keys, V>
where
Self: 'keys,
V: 'keys;

fn capacity(&self) -> Option<u32> {
Some(S::get())
Expand All @@ -100,7 +108,11 @@ impl<K: Ord + Clone, V: Clone> KeyValue for BTreeMap<K, V> {
type Key = K;
type Value = V;

type Keys<'keys> = alloc::collections::btree_map::Keys<'keys, K, V> where Self: 'keys, K: 'keys;
type Keys<'keys>
= alloc::collections::btree_map::Keys<'keys, K, V>
where
Self: 'keys,
K: 'keys;

fn capacity(&self) -> Option<u32> {
None
Expand Down Expand Up @@ -133,7 +145,11 @@ impl<V: Ord + Clone> KeyValue for BTreeSet<V> {
type Key = V;
type Value = ();

type Keys<'keys> = alloc::collections::btree_set::Iter<'keys, V> where Self: 'keys, V: 'keys;
type Keys<'keys>
= alloc::collections::btree_set::Iter<'keys, V>
where
Self: 'keys,
V: 'keys;

fn capacity(&self) -> Option<u32> {
None
Expand Down
21 changes: 21 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
};

pub struct ChangeValidatorsConfiguration;

#[cfg(feature = "mainnet")]
impl ChangeValidatorsConfiguration {
pub const VALIDATOR_COUNT: u32 = 10;
}

#[cfg(not(feature = "mainnet"))]
impl ChangeValidatorsConfiguration {
pub const VALIDATOR_COUNT: u32 = 2;
}

impl OnRuntimeUpgrade for ChangeValidatorsConfiguration {
fn on_runtime_upgrade() -> Weight {
pallet_staking::ValidatorCount::<Runtime>::put(Self::VALIDATOR_COUNT);

<Runtime as frame_system::Config>::DbWeight::get().writes(1)
}
}

/// `fastblock` reduces the block time for faster testing. It isn't recommended for production.
/// Also build the node in release mode to support small block times (< 1 sec)
/// TODO: Support instant seal
Expand Down Expand Up @@ -1859,6 +1879,7 @@ type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
ChangeValidatorsConfiguration,
>;

/// The address format for describing accounts.
Expand Down

0 comments on commit 410fd2a

Please sign in to comment.