Skip to content

Commit 87b0eaa

Browse files
committed
Tmp changes to runtime for runtime-wide hooks (failed)
1 parent 506d9ab commit 87b0eaa

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

runtimes/peregrine/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ use runtime_common::{
6464
FeeSplit, Hash, Header, Nonce, Signature, SlowAdjustingFeeUpdate,
6565
};
6666

67+
use crate::try_runtime::AllPalletsWithSystemAndRuntimeHooks;
6768
#[cfg(feature = "std")]
6869
use sp_version::NativeVersion;
70+
6971
#[cfg(feature = "runtime-benchmarks")]
7072
use {kilt_support::signature::AlwaysVerify, runtime_common::benchmarks::DummySignature};
7173

@@ -75,6 +77,9 @@ pub use sp_runtime::BuildStorage;
7577
#[cfg(test)]
7678
mod tests;
7779

80+
#[cfg(feature = "try-runtime")]
81+
mod try_runtime;
82+
7883
mod dip;
7984
mod weights;
8085
pub mod xcm_config;
@@ -1095,7 +1100,7 @@ pub type Executive = frame_executive::Executive<
10951100
frame_system::ChainContext<Runtime>,
10961101
Runtime,
10971102
// Executes pallet hooks in the order of definition in construct_runtime
1098-
AllPalletsWithSystem,
1103+
AllPalletsWithSystemAndRuntimeHooks,
10991104
(),
11001105
>;
11011106

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// KILT Blockchain – https://botlabs.org
2+
// Copyright (C) 2019-2024 BOTLabs GmbH
3+
4+
// The KILT Blockchain is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// The KILT Blockchain is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
// If you feel like getting in touch with us, you can do so at [email protected]
18+
19+
use frame_support::traits::{Hooks, OffchainWorker, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade, TryState};
20+
use runtime_common::BlockNumber;
21+
22+
use crate::{AllPalletsWithSystem, Runtime};
23+
24+
pub struct AllPalletsWithSystemAndRuntimeHooks;
25+
26+
impl OnRuntimeUpgrade for AllPalletsWithSystemAndRuntimeHooks {
27+
fn on_runtime_upgrade() -> xcm::prelude::Weight {
28+
AllPalletsWithSystem::on_runtime_upgrade()
29+
}
30+
31+
#[cfg(feature = "try-runtime")]
32+
fn try_on_runtime_upgrade(checks: bool) -> Result<sp_weights::Weight, sp_runtime::TryRuntimeError> {
33+
AllPalletsWithSystem::try_on_runtime_upgrade(checks)
34+
}
35+
36+
#[cfg(feature = "try-runtime")]
37+
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
38+
AllPalletsWithSystem::pre_upgrade()
39+
}
40+
41+
#[cfg(feature = "try-runtime")]
42+
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
43+
AllPalletsWithSystem::post_upgrade(state)
44+
}
45+
}
46+
47+
impl OnInitialize<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks {
48+
fn on_initialize(n: BlockNumber) -> xcm::prelude::Weight {
49+
AllPalletsWithSystem::on_initialize(n)
50+
}
51+
}
52+
53+
impl OnIdle<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks {
54+
fn on_idle(n: BlockNumber, remaining_weight: xcm::prelude::Weight) -> xcm::prelude::Weight {
55+
AllPalletsWithSystem::on_idle(n, remaining_weight)
56+
}
57+
}
58+
59+
impl OnFinalize<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks {
60+
fn on_finalize(n: BlockNumber) {
61+
AllPalletsWithSystem::on_finalize(n)
62+
}
63+
}
64+
65+
impl OffchainWorker<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks {
66+
fn offchain_worker(n: BlockNumber) {
67+
AllPalletsWithSystem::offchain_worker(n)
68+
}
69+
}
70+
71+
impl TryState<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks {
72+
fn try_state(n: BlockNumber, s: frame_try_runtime::TryStateSelect) -> Result<(), sp_runtime::TryRuntimeError> {
73+
log::trace!(target: "try_runtime::peregrine", "AAAAA");
74+
AllPalletsWithSystem::try_state(n, s)?;
75+
log::trace!(target: "try_runtime::peregrine", "BBBBB");
76+
<Runtime as Hooks<BlockNumber>>::try_state(n)
77+
}
78+
}
79+
80+
impl Hooks<BlockNumber> for Runtime {
81+
#[cfg(feature = "try-runtime")]
82+
fn try_state(n: BlockNumber) -> Result<(), sp_runtime::TryRuntimeError> {
83+
log::trace!(
84+
target: "try_runtime::peregrine",
85+
"Trying state for Peregrine runtime at block {n}"
86+
);
87+
Ok(())
88+
}
89+
}

0 commit comments

Comments
 (0)