diff --git a/full-node/src/run/consensus_service.rs b/full-node/src/run/consensus_service.rs index a2b0c4f81..40f683f16 100644 --- a/full-node/src/run/consensus_service.rs +++ b/full-node/src/run/consensus_service.rs @@ -693,6 +693,7 @@ impl SyncBackground { parent_runtime, block_body_capacity: 0, // TODO: could be set to the size of the tx pool top_trie_root_calculation_cache: None, // TODO: pretty important for performances + max_log_level: 0, }) }; diff --git a/lib/src/author/build.rs b/lib/src/author/build.rs index 5c376e2b8..432cb89f7 100644 --- a/lib/src/author/build.rs +++ b/lib/src/author/build.rs @@ -229,6 +229,7 @@ impl AuthoringStart { }) } }, + max_log_level: config.max_log_level, }); let inherent_data = inherents::InherentData { @@ -275,6 +276,14 @@ pub struct AuthoringStartConfig<'a> { /// Capacity to reserve for the number of extrinsics. Should be higher than the approximate /// number of extrinsics that are going to be applied. pub block_body_capacity: usize, + + /// Maximum log level of the runtime. + /// + /// > **Note**: This value is opaque from the point of the view of the client, and the runtime + /// > is free to interpret it the way it wants. However, usually values are: `0` for + /// > "off", `1` for "error", `2` for "warn", `3` for "info", `4` for "debug", + /// > and `5` for "trace". + pub max_log_level: u32, } /// More transactions can be added. diff --git a/lib/src/author/runtime.rs b/lib/src/author/runtime.rs index d3f53aac5..034332e55 100644 --- a/lib/src/author/runtime.rs +++ b/lib/src/author/runtime.rs @@ -91,6 +91,14 @@ pub struct Config<'a> { /// Capacity to reserve for the number of extrinsics. Should be higher than the approximate /// number of extrinsics that are going to be applied. pub block_body_capacity: usize, + + /// Maximum log level of the runtime. + /// + /// > **Note**: This value is opaque from the point of the view of the client, and the runtime + /// > is free to interpret it the way it wants. However, usually values are: `0` for + /// > "off", `1` for "error", `2` for "warn", `3` for "info", `4` for "debug", + /// > and `5` for "trace". + pub max_log_level: u32, } /// Extra configuration depending on the consensus algorithm. @@ -185,6 +193,7 @@ pub fn build_block(config: Config) -> BlockBuild { top_trie_root_calculation_cache: config.top_trie_root_calculation_cache, storage_top_trie_changes: Default::default(), offchain_storage_changes: Default::default(), + max_log_level: config.max_log_level, }); let vm = match init_result { @@ -196,6 +205,7 @@ pub fn build_block(config: Config) -> BlockBuild { stage: Stage::InitializeBlock, block_body: Vec::with_capacity(config.block_body_capacity), logs: String::new(), + max_log_level: config.max_log_level, }; BlockBuild::from_inner(vm, shared) @@ -322,6 +332,7 @@ impl BlockBuild { ), storage_top_trie_changes: success.storage_top_trie_changes, offchain_storage_changes: success.offchain_storage_changes, + max_log_level: shared.max_log_level, }); inner = Inner::Runtime(match init_result { @@ -447,6 +458,8 @@ struct Shared { block_body: Vec>, /// Concatenation of all logs produced by the multiple calls. logs: String, + /// Value provided by [`Config::max_log_level`]. + max_log_level: u32, } /// The block building process is separated into multiple stages. @@ -515,6 +528,7 @@ impl InherentExtrinsics { top_trie_root_calculation_cache: Some(self.top_trie_root_calculation_cache), storage_top_trie_changes: self.storage_top_trie_changes, offchain_storage_changes: self.offchain_storage_changes, + max_log_level: self.shared.max_log_level, }); let vm = match init_result { @@ -548,6 +562,7 @@ impl ApplyExtrinsic { top_trie_root_calculation_cache: Some(self.top_trie_root_calculation_cache), storage_top_trie_changes: self.storage_top_trie_changes, offchain_storage_changes: self.offchain_storage_changes, + max_log_level: self.shared.max_log_level, }); self.shared.stage = Stage::ApplyExtrinsic(extrinsic); @@ -571,6 +586,7 @@ impl ApplyExtrinsic { top_trie_root_calculation_cache: Some(self.top_trie_root_calculation_cache), storage_top_trie_changes: self.storage_top_trie_changes, offchain_storage_changes: self.offchain_storage_changes, + max_log_level: self.shared.max_log_level, }); let vm = match init_result { diff --git a/lib/src/author/runtime/tests.rs b/lib/src/author/runtime/tests.rs index 47bb0401a..7e5014836 100644 --- a/lib/src/author/runtime/tests.rs +++ b/lib/src/author/runtime/tests.rs @@ -41,6 +41,7 @@ fn block_building_works() { slot_number: 1234u64, }), top_trie_root_calculation_cache: None, + max_log_level: 0, }); loop { diff --git a/lib/src/chain/blocks_tree/verify.rs b/lib/src/chain/blocks_tree/verify.rs index e036e1102..ae115a8fd 100644 --- a/lib/src/chain/blocks_tree/verify.rs +++ b/lib/src/chain/blocks_tree/verify.rs @@ -809,6 +809,7 @@ impl BodyVerifyRuntimeRequired { parent_block_header: parent_block_header.into(), block_body, top_trie_root_calculation_cache, + max_log_level: 0, }); self.context.with_body_verify(process) diff --git a/lib/src/chain/chain_information/build.rs b/lib/src/chain/chain_information/build.rs index 054a4e0a0..f22da7e8f 100644 --- a/lib/src/chain/chain_information/build.rs +++ b/lib/src/chain/chain_information/build.rs @@ -391,6 +391,7 @@ impl ChainInformationBuild { function_to_call: call.function_name(), parameter: call.parameter_vectored(), virtual_machine: inner.virtual_machine.take().unwrap(), + max_log_level: 0, }); let vm = match vm_start_result { diff --git a/lib/src/executor/read_only_runtime_host.rs b/lib/src/executor/read_only_runtime_host.rs index 2d7390779..ca0d8cc29 100644 --- a/lib/src/executor/read_only_runtime_host.rs +++ b/lib/src/executor/read_only_runtime_host.rs @@ -35,6 +35,14 @@ pub struct Config<'a, TParams> { /// Parameter of the call, as an iterator of bytes. The concatenation of bytes forms the /// actual input. pub parameter: TParams, + + /// Maximum log level of the runtime. + /// + /// > **Note**: This value is opaque from the point of the view of the client, and the runtime + /// > is free to interpret it the way it wants. However, usually values are: `0` for + /// > "off", `1` for "error", `2` for "warn", `3` for "info", `4` for "debug", + /// > and `5` for "trace". + pub max_log_level: u32, } /// Start running the WebAssembly virtual machine. @@ -47,6 +55,7 @@ pub fn run( .run_vectored(config.function_to_call, config.parameter)? .into(), logs: String::new(), + max_log_level: config.max_log_level, } .run()) } @@ -339,6 +348,8 @@ struct Inner { vm: host::HostVm, /// Concatenation of all the log messages generated by the runtime. logs: String, + /// Value provided by [`Config::max_log_level`]. + max_log_level: u32, } impl Inner { @@ -436,8 +447,7 @@ impl Inner { } host::HostVm::GetMaxLogLevel(resume) => { - // TODO: make configurable? - self.vm = resume.resume(0); // Off + self.vm = resume.resume(self.max_log_level); } host::HostVm::LogEmit(req) => { diff --git a/lib/src/executor/runtime_host.rs b/lib/src/executor/runtime_host.rs index 4a25bcead..f99e2f93d 100644 --- a/lib/src/executor/runtime_host.rs +++ b/lib/src/executor/runtime_host.rs @@ -72,6 +72,14 @@ pub struct Config<'a, TParams> { /// Initial state of [`Success::offchain_storage_changes`]. The changes made during this /// execution will be pushed over the value in this field. pub offchain_storage_changes: storage_diff::StorageDiff, + + /// Maximum log level of the runtime. + /// + /// > **Note**: This value is opaque from the point of the view of the client, and the runtime + /// > is free to interpret it the way it wants. However, usually values are: `0` for + /// > "off", `1` for "error", `2` for "warn", `3` for "info", `4` for "debug", + /// > and `5` for "trace". + pub max_log_level: u32, } /// Start running the WebAssembly virtual machine. @@ -99,6 +107,7 @@ pub fn run( ), root_calculation: None, logs: String::new(), + max_log_level: config.max_log_level, } .run()) } @@ -631,6 +640,9 @@ struct Inner { /// Concatenation of all the log messages generated by the runtime. logs: String, + + /// Value provided by [`Config::max_log_level`]. + max_log_level: u32, } impl Inner { @@ -917,8 +929,7 @@ impl Inner { } host::HostVm::GetMaxLogLevel(resume) => { - // TODO: make configurable? - self.vm = resume.resume(0); // Off + self.vm = resume.resume(self.max_log_level); } host::HostVm::LogEmit(req) => { diff --git a/lib/src/transactions/validate.rs b/lib/src/transactions/validate.rs index 2e9d721ef..b2b6bc475 100644 --- a/lib/src/transactions/validate.rs +++ b/lib/src/transactions/validate.rs @@ -48,6 +48,14 @@ pub struct Config<'a, TTx> { /// This information is passed to the runtime, which might perform some additional /// verifications if the source isn't trusted. pub source: TransactionSource, + + /// Maximum log level of the runtime. + /// + /// > **Note**: This value is opaque from the point of the view of the client, and the runtime + /// > is free to interpret it the way it wants. However, usually values are: `0` for + /// > "off", `1` for "error", `2` for "warn", `3` for "info", `4` for "debug", + /// > and `5` for "trace". + pub max_log_level: u32, } /// Source of the transaction. @@ -327,6 +335,7 @@ pub fn validate_transaction( top_trie_root_calculation_cache: None, storage_top_trie_changes: storage_diff::StorageDiff::empty(), offchain_storage_changes: storage_diff::StorageDiff::empty(), + max_log_level: config.max_log_level, }); // Information used later, after `Core_initialize_block` is done. @@ -363,6 +372,7 @@ pub fn validate_transaction( top_trie_root_calculation_cache: None, storage_top_trie_changes: storage_diff::StorageDiff::empty(), offchain_storage_changes: storage_diff::StorageDiff::empty(), + max_log_level: config.max_log_level, }); match vm { @@ -454,6 +464,7 @@ impl Query { top_trie_root_calculation_cache: Some( success.top_trie_root_calculation_cache, ), + max_log_level: 0, }); match vm { diff --git a/lib/src/verify/header_body.rs b/lib/src/verify/header_body.rs index 1ff311aeb..9f43cf924 100644 --- a/lib/src/verify/header_body.rs +++ b/lib/src/verify/header_body.rs @@ -70,6 +70,14 @@ pub struct Config<'a, TBody> { /// Optional cache corresponding to the storage trie root hash calculation of the parent /// block. pub top_trie_root_calculation_cache: Option, + + /// Maximum log level of the runtime. + /// + /// > **Note**: This value is opaque from the point of the view of the client, and the runtime + /// > is free to interpret it the way it wants. However, usually values are: `0` for + /// > "off", `1` for "error", `2` for "warn", `3` for "info", `4` for "debug", + /// > and `5` for "trace". + pub max_log_level: u32, } /// Extra items of [`Config`] that are dependant on the consensus engine of the chain. @@ -364,6 +372,7 @@ pub fn verify( top_trie_root_calculation_cache: config.top_trie_root_calculation_cache, storage_top_trie_changes: Default::default(), offchain_storage_changes: Default::default(), + max_log_level: config.max_log_level, }); match vm { @@ -443,6 +452,7 @@ impl VerifyInner { ), storage_top_trie_changes: success.storage_top_trie_changes, offchain_storage_changes: success.offchain_storage_changes, + max_log_level: 0, }); match vm { diff --git a/light-base/src/json_rpc_service.rs b/light-base/src/json_rpc_service.rs index 96d347a8f..35c560599 100644 --- a/light-base/src/json_rpc_service.rs +++ b/light-base/src/json_rpc_service.rs @@ -1606,6 +1606,7 @@ impl Background { top_trie_root_calculation_cache: None, storage_top_trie_changes: Default::default(), offchain_storage_changes: Default::default(), + max_log_level: 0, }) { Ok(vm) => vm, Err((err, prototype)) => { diff --git a/light-base/src/json_rpc_service/chain_head.rs b/light-base/src/json_rpc_service/chain_head.rs index d554e674d..f049b2c84 100644 --- a/light-base/src/json_rpc_service/chain_head.rs +++ b/light-base/src/json_rpc_service/chain_head.rs @@ -194,6 +194,7 @@ impl Background { top_trie_root_calculation_cache: None, offchain_storage_changes: Default::default(), storage_top_trie_changes: Default::default(), + max_log_level: 0, }) { Err((error, prototype)) => { runtime_call_lock.unlock(prototype); diff --git a/light-base/src/sync_service/parachain.rs b/light-base/src/sync_service/parachain.rs index 92c017b68..a788a1e76 100644 --- a/light-base/src/sync_service/parachain.rs +++ b/light-base/src/sync_service/parachain.rs @@ -1127,6 +1127,7 @@ async fn parahead( parachain_id, para::OccupiedCoreAssumption::TimedOut, ), + max_log_level: 0, }) { Ok(vm) => vm, Err((err, prototype)) => { diff --git a/light-base/src/transactions_service.rs b/light-base/src/transactions_service.rs index 3c8369e1f..a3fc84aeb 100644 --- a/light-base/src/transactions_service.rs +++ b/light-base/src/transactions_service.rs @@ -1165,6 +1165,7 @@ async fn validate_transaction( block_number_bytes: relay_chain_sync.block_number_bytes(), scale_encoded_transaction: iter::once(scale_encoded_transaction), source, + max_log_level: 0, }); loop {