Skip to content

Commit e880964

Browse files
authored
Merge pull request #1929 from opentensor/disable-oldest-stored-round-migration
Set Oldest Stored Round
2 parents b6e8d80 + e3b3322 commit e880964

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

pallets/drand/src/benchmarking.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,15 @@ mod benchmarks {
7979
assert_eq!(Pulses::<T>::get(p.round), Some(p));
8080
}
8181

82+
#[benchmark]
83+
fn set_oldest_stored_round() {
84+
let oldest_stored_round: u64 = 10;
85+
86+
#[extrinsic_call]
87+
set_oldest_stored_round(RawOrigin::Root, oldest_stored_round);
88+
89+
assert_eq!(OldestStoredRound::<T>::get(), oldest_stored_round);
90+
}
91+
8292
impl_benchmark_test_suite!(Drand, crate::mock::new_test_ext(), crate::mock::Test);
8393
}

pallets/drand/src/lib.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,12 @@ pub mod pallet {
245245
#[pallet::event]
246246
#[pallet::generate_deposit(pub(super) fn deposit_event)]
247247
pub enum Event<T: Config> {
248+
/// Beacon Configuration has changed.
248249
BeaconConfigChanged,
249250
/// Successfully set a new pulse(s).
250-
NewPulse {
251-
rounds: Vec<RoundNumber>,
252-
},
251+
NewPulse { rounds: Vec<RoundNumber> },
252+
/// Oldest Stored Round has been set.
253+
SetOldestStoredRound(u64),
253254
}
254255

255256
#[pallet::error]
@@ -277,11 +278,12 @@ pub mod pallet {
277278
}
278279
}
279280
fn on_runtime_upgrade() -> frame_support::weights::Weight {
280-
let mut weight = frame_support::weights::Weight::from_parts(0, 0);
281+
/*let weight = */
282+
frame_support::weights::Weight::from_parts(0, 0) /*;*/
281283

282-
weight = weight.saturating_add(migrations::migrate_set_oldest_round::<T>());
284+
//weight = weight.saturating_add(migrations::migrate_set_oldest_round::<T>());
283285

284-
weight
286+
//weight
285287
}
286288
}
287289

@@ -420,6 +422,18 @@ pub mod pallet {
420422
Self::deposit_event(Event::BeaconConfigChanged {});
421423
Ok(())
422424
}
425+
426+
/// allows the root user to set the oldest stored round
427+
#[pallet::call_index(2)]
428+
#[pallet::weight(Weight::from_parts(5_630_000, 0)
429+
.saturating_add(T::DbWeight::get().reads(0_u64))
430+
.saturating_add(T::DbWeight::get().writes(1_u64)))]
431+
pub fn set_oldest_stored_round(origin: OriginFor<T>, oldest_round: u64) -> DispatchResult {
432+
ensure_root(origin)?;
433+
OldestStoredRound::<T>::put(oldest_round);
434+
Self::deposit_event(Event::SetOldestStoredRound(oldest_round));
435+
Ok(())
436+
}
423437
}
424438
}
425439

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
218218
// `spec_version`, and `authoring_version` are the same between Wasm and native.
219219
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
220220
// the compatible custom types.
221-
spec_version: 300,
221+
spec_version: 301,
222222
impl_version: 1,
223223
apis: RUNTIME_API_VERSIONS,
224224
transaction_version: 1,

0 commit comments

Comments
 (0)