Skip to content

Commit

Permalink
make runtime maximum log level configurable (paritytech#276)
Browse files Browse the repository at this point in the history
* make runtime maximum log level configurable

* fix

* make log_level enum

* Revert "make log_level enum"

This reverts commit 3d07ae980ffb83ee851229915eda1e86b7be211a.

* propagate runtime log_level

* apply suggestions

* typo

* more configs

* default max_log_level

* Wrap comments

---------

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
  • Loading branch information
ermalkaleci and tomaka authored Mar 14, 2023
1 parent c25201e commit eb4058a
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions full-node/src/run/consensus_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
};

Expand Down
9 changes: 9 additions & 0 deletions lib/src/author/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl AuthoringStart {
})
}
},
max_log_level: config.max_log_level,
});

let inherent_data = inherents::InherentData {
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions lib/src/author/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -447,6 +458,8 @@ struct Shared {
block_body: Vec<Vec<u8>>,
/// 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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/src/author/runtime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn block_building_works() {
slot_number: 1234u64,
}),
top_trie_root_calculation_cache: None,
max_log_level: 0,
});

loop {
Expand Down
1 change: 1 addition & 0 deletions lib/src/chain/blocks_tree/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ impl<T> BodyVerifyRuntimeRequired<T> {
parent_block_header: parent_block_header.into(),
block_body,
top_trie_root_calculation_cache,
max_log_level: 0,
});

self.context.with_body_verify(process)
Expand Down
1 change: 1 addition & 0 deletions lib/src/chain/chain_information/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions lib/src/executor/read_only_runtime_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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())
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down
15 changes: 13 additions & 2 deletions lib/src/executor/runtime_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -99,6 +107,7 @@ pub fn run(
),
root_calculation: None,
logs: String::new(),
max_log_level: config.max_log_level,
}
.run())
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down
11 changes: 11 additions & 0 deletions lib/src/transactions/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -454,6 +464,7 @@ impl Query {
top_trie_root_calculation_cache: Some(
success.top_trie_root_calculation_cache,
),
max_log_level: 0,
});

match vm {
Expand Down
10 changes: 10 additions & 0 deletions lib/src/verify/header_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<calculate_root::CalculationCache>,

/// 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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions light-base/src/json_rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ impl<TPlat: Platform> Background<TPlat> {
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)) => {
Expand Down
1 change: 1 addition & 0 deletions light-base/src/json_rpc_service/chain_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl<TPlat: Platform> Background<TPlat> {
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);
Expand Down
1 change: 1 addition & 0 deletions light-base/src/sync_service/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ async fn parahead<TPlat: Platform>(
parachain_id,
para::OccupiedCoreAssumption::TimedOut,
),
max_log_level: 0,
}) {
Ok(vm) => vm,
Err((err, prototype)) => {
Expand Down
1 change: 1 addition & 0 deletions light-base/src/transactions_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ async fn validate_transaction<TPlat: Platform>(
block_number_bytes: relay_chain_sync.block_number_bytes(),
scale_encoded_transaction: iter::once(scale_encoded_transaction),
source,
max_log_level: 0,
});

loop {
Expand Down

0 comments on commit eb4058a

Please sign in to comment.