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

Commit 67b6898

Browse files
authored
Companion for init the RuntimeLogger automatically (#2522)
* Lol * Add the features * Remove some more runtime logger init calls * Make companion check work * Revert "Make companion check work" This reverts commit a255c79. * Update Substrate
1 parent 71d46a0 commit 67b6898

18 files changed

Lines changed: 231 additions & 192 deletions

File tree

Cargo.lock

Lines changed: 175 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/kusama/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build = "build.rs"
88
[dependencies]
99
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"] }
1010
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
11-
log = { version = "0.4.13", optional = true }
11+
log = { version = "0.4.14", default-features = false }
1212
rustc-hex = { version = "2.1.0", default-features = false }
1313
serde = { version = "1.0.123", default-features = false }
1414
serde_derive = { version = "1.0.117", optional = true }
@@ -145,7 +145,7 @@ std = [
145145
"pallet-vesting/std",
146146
"serde_derive",
147147
"serde/std",
148-
"log",
148+
"log/std",
149149
"pallet-babe/std",
150150
"babe-primitives/std",
151151
"sp-session/std",
@@ -194,3 +194,10 @@ try-runtime = [
194194
# runtime without clashing with the runtime api exported functions
195195
# in WASM.
196196
disable-runtime-api = []
197+
198+
# A feature that should be enabled when the runtime should be build for on-chain
199+
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
200+
# to make it smaller like logging for example.
201+
on-chain-release-build = [
202+
"sp-api/disable-logging",
203+
]

runtime/kusama/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ use sp_version::NativeVersion;
5656
use sp_core::OpaqueMetadata;
5757
use sp_staking::SessionIndex;
5858
use frame_support::{
59-
parameter_types, construct_runtime, debug, RuntimeDebug,
59+
parameter_types, construct_runtime, RuntimeDebug,
6060
traits::{KeyOwnerProofSystem, Randomness, LockIdentifier, Filter, InstanceFilter},
6161
weights::Weight,
6262
};
6363
use frame_system::{EnsureRoot, EnsureOneOf};
6464
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
6565
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
6666
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
67-
use pallet_session::{historical as session_historical};
67+
use pallet_session::historical as session_historical;
6868
use static_assertions::const_assert;
6969

7070
#[cfg(feature = "std")]
@@ -696,7 +696,7 @@ impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for R
696696
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
697697
);
698698
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
699-
debug::warn!("Unable to create signed payload: {:?}", e);
699+
log::warn!("Unable to create signed payload: {:?}", e);
700700
}).ok()?;
701701
let signature = raw_payload.using_encoded(|payload| {
702702
C::sign(payload, public)
@@ -1318,7 +1318,6 @@ sp_api::impl_runtime_apis! {
13181318
#[cfg(feature = "try-runtime")]
13191319
impl frame_try_runtime::TryRuntime<Block> for Runtime {
13201320
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
1321-
frame_support::debug::RuntimeLogger::init();
13221321
let weight = Executive::try_runtime_upgrade()?;
13231322
Ok((weight, BlockWeights::get().max_block))
13241323
}

runtime/parachains/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77
[dependencies]
88
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"] }
99
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
10-
log = "0.4.13"
10+
log = { version = "0.4.14", default-features = false }
1111
rustc-hex = { version = "2.1.0", default-features = false }
1212
serde = { version = "1.0.123", features = [ "derive" ], optional = true }
1313
derive_more = "0.99.11"
@@ -86,6 +86,7 @@ std = [
8686
"pallet-vesting/std",
8787
"xcm/std",
8888
"xcm-executor/std",
89+
"log/std",
8990
]
9091
runtime-benchmarks = [
9192
"libsecp256k1/hmac",

runtime/parachains/src/inclusion.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use primitives::v1::{
2828
CandidateReceipt, HeadData, CandidateHash, Hash,
2929
};
3030
use frame_support::{
31-
decl_storage, decl_module, decl_error, decl_event, ensure, debug,
32-
dispatch::DispatchResult, IterableStorageMap, weights::Weight, traits::Get,
31+
decl_storage, decl_module, decl_error, decl_event, ensure, dispatch::DispatchResult, IterableStorageMap,
32+
weights::Weight, traits::Get,
3333
};
3434
use parity_scale_codec::{Encode, Decode};
3535
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
@@ -213,7 +213,7 @@ decl_module! {
213213
}
214214
}
215215

216-
const LOG_TARGET: &str = "parachains_runtime_inclusion";
216+
const LOG_TARGET: &str = "runtime::inclusion";
217217

218218
impl<T: Config> Module<T> {
219219
/// Block initialization logic, called by initializer.
@@ -343,11 +343,11 @@ impl<T: Config> Module<T> {
343343
let commitments = match PendingAvailabilityCommitments::take(&para_id) {
344344
Some(commitments) => commitments,
345345
None => {
346-
debug::warn!(r#"
347-
Inclusion::process_bitfields:
348-
PendingAvailability and PendingAvailabilityCommitments
349-
are out of sync, did someone mess with the storage?
350-
"#);
346+
log::warn!(
347+
target: LOG_TARGET,
348+
"Inclusion::process_bitfields: PendingAvailability and PendingAvailabilityCommitments
349+
are out of sync, did someone mess with the storage?",
350+
);
351351
continue;
352352
}
353353
};
@@ -460,7 +460,6 @@ impl<T: Config> Module<T> {
460460
&candidate.candidate.commitments.horizontal_messages,
461461
)
462462
{
463-
frame_support::debug::RuntimeLogger::init();
464463
log::debug!(
465464
target: LOG_TARGET,
466465
"Validation outputs checking during inclusion of a candidate {} for parachain `{}` failed: {:?}",
@@ -631,7 +630,6 @@ impl<T: Config> Module<T> {
631630
T::BlockNumber::from(validation_outputs.hrmp_watermark),
632631
&validation_outputs.horizontal_messages,
633632
) {
634-
frame_support::debug::RuntimeLogger::init();
635633
log::debug!(
636634
target: LOG_TARGET,
637635
"Validation outputs checking for parachain `{}` failed: {:?}",

runtime/parachains/src/inclusion_inherent.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ impl<T: Config> ProvideInherent for Module<T> {
227227
) {
228228
Ok(_) => (signed_bitfields, backed_candidates),
229229
Err(err) => {
230-
frame_support::debug::RuntimeLogger::init();
231-
frame_support::debug::warn!(
230+
log::warn!(
232231
target: "runtime_inclusion_inherent",
233232
"dropping signed_bitfields and backed_candidates because they produced \
234233
an invalid inclusion inherent: {:?}",

runtime/parachains/src/runtime_api_impl/v1.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use primitives::v1::{
2727
GroupIndex, CandidateEvent, PersistedValidationData, SessionInfo,
2828
InboundDownwardMessage, InboundHrmpMessage, Hash, AuthorityDiscoveryId
2929
};
30-
use frame_support::debug;
3130
use crate::{initializer, inclusion, scheduler, configuration, paras, session_info, dmp, hrmp, shared};
3231

3332

@@ -85,8 +84,11 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
8584
match <scheduler::Module<T>>::group_assigned_to_core(core_index, backed_in_number) {
8685
Some(g) => g,
8786
None => {
88-
debug::warn!("Could not determine the group responsible for core extracted \
89-
from list of cores for some prior block in same session");
87+
log::warn!(
88+
target: "runtime::polkadot-api::v1",
89+
"Could not determine the group responsible for core extracted \
90+
from list of cores for some prior block in same session",
91+
);
9092

9193
GroupIndex(0)
9294
}

runtime/parachains/src/ump.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ impl<Config: xcm_executor::Config> UmpSink for XcmSink<Config> {
7575
}
7676
}
7777
} else {
78-
frame_support::debug::error!(
79-
target: "xcm",
78+
log::error!(
79+
target: "runtime::ump-sink",
8080
"Failed to decode versioned XCM from upward message.",
8181
);
8282
}

runtime/polkadot/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build = "build.rs"
88
[dependencies]
99
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"] }
1010
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
11-
log = { version = "0.4.13", optional = true }
11+
log = { version = "0.4.14", default-features = false }
1212
rustc-hex = { version = "2.1.0", default-features = false }
1313
serde = { version = "1.0.123", default-features = false }
1414
serde_derive = { version = "1.0.117", optional = true }
@@ -139,7 +139,7 @@ std = [
139139
"sp-version/std",
140140
"serde_derive",
141141
"serde/std",
142-
"log",
142+
"log/std",
143143
"pallet-babe/std",
144144
"babe-primitives/std",
145145
"sp-session/std",
@@ -189,3 +189,10 @@ try-runtime = [
189189
# runtime without clashing with the runtime api exported functions
190190
# in WASM.
191191
disable-runtime-api = []
192+
193+
# A feature that should be enabled when the runtime should be build for on-chain
194+
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
195+
# to make it smaller like logging for example.
196+
on-chain-release-build = [
197+
"sp-api/disable-logging",
198+
]

runtime/polkadot/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use sp_version::NativeVersion;
5656
use sp_core::OpaqueMetadata;
5757
use sp_staking::SessionIndex;
5858
use frame_support::{
59-
parameter_types, construct_runtime, debug, RuntimeDebug,
59+
parameter_types, construct_runtime, RuntimeDebug,
6060
traits::{KeyOwnerProofSystem, Randomness, LockIdentifier, Filter},
6161
weights::Weight,
6262
};
@@ -742,7 +742,7 @@ impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for R
742742
claims::PrevalidateAttests::<Runtime>::new(),
743743
);
744744
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
745-
debug::warn!("Unable to create signed payload: {:?}", e);
745+
log::warn!("Unable to create signed payload: {:?}", e);
746746
}).ok()?;
747747
let signature = raw_payload.using_encoded(|payload| {
748748
C::sign(payload, public)
@@ -1314,7 +1314,6 @@ sp_api::impl_runtime_apis! {
13141314
#[cfg(feature = "try-runtime")]
13151315
impl frame_try_runtime::TryRuntime<Block> for Runtime {
13161316
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
1317-
frame_support::debug::RuntimeLogger::init();
13181317
let weight = Executive::try_runtime_upgrade()?;
13191318
Ok((weight, BlockWeights::get().max_block))
13201319
}

0 commit comments

Comments
 (0)