mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +00:00
Improve state related logs to use a more uniform format (#9452)
* Improve `state` related logs to use a more uniform format The logging before wasn't that uniform and not that great to read/parse. Now we are using a uniform format for all the logs. Besides these changes, there are some minor changes around the code that calls the state machine. * Make CI happy * Use HexDisplay for `ext_id`
This commit is contained in:
@@ -206,7 +206,7 @@ where
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "Get",
|
||||
ext_id = self.id,
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
key = %HexDisplay::from(&key),
|
||||
result = ?result.as_ref().map(HexDisplay::from),
|
||||
result_encoded = %HexDisplay::from(
|
||||
@@ -228,10 +228,12 @@ where
|
||||
.map(|x| x.map(|x| H::hash(x)))
|
||||
.unwrap_or_else(|| self.backend.storage_hash(key).expect(EXT_NOT_ALLOWED_TO_FAIL));
|
||||
|
||||
trace!(target: "state", "{:04x}: Hash {}={:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&key),
|
||||
result,
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "Hash",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
key = %HexDisplay::from(&key),
|
||||
?result,
|
||||
);
|
||||
result.map(|r| r.encode())
|
||||
}
|
||||
@@ -246,11 +248,13 @@ where
|
||||
self.backend.child_storage(child_info, key).expect(EXT_NOT_ALLOWED_TO_FAIL)
|
||||
});
|
||||
|
||||
trace!(target: "state", "{:04x}: GetChild({}) {}={:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&child_info.storage_key()),
|
||||
HexDisplay::from(&key),
|
||||
result.as_ref().map(HexDisplay::from)
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildGet",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&child_info.storage_key()),
|
||||
key = %HexDisplay::from(&key),
|
||||
result = ?result.as_ref().map(HexDisplay::from)
|
||||
);
|
||||
|
||||
result
|
||||
@@ -266,11 +270,13 @@ where
|
||||
self.backend.child_storage_hash(child_info, key).expect(EXT_NOT_ALLOWED_TO_FAIL)
|
||||
});
|
||||
|
||||
trace!(target: "state", "{:04x}: ChildHash({}) {}={:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&child_info.storage_key()),
|
||||
HexDisplay::from(&key),
|
||||
result,
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildHash",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&child_info.storage_key()),
|
||||
key = %HexDisplay::from(&key),
|
||||
?result,
|
||||
);
|
||||
|
||||
result.map(|r| r.encode())
|
||||
@@ -283,10 +289,12 @@ where
|
||||
_ => self.backend.exists_storage(key).expect(EXT_NOT_ALLOWED_TO_FAIL),
|
||||
};
|
||||
|
||||
trace!(target: "state", "{:04x}: Exists {}={:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&key),
|
||||
result,
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "Exists",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
key = %HexDisplay::from(&key),
|
||||
%result,
|
||||
);
|
||||
|
||||
result
|
||||
@@ -303,11 +311,13 @@ where
|
||||
.expect(EXT_NOT_ALLOWED_TO_FAIL),
|
||||
};
|
||||
|
||||
trace!(target: "state", "{:04x}: ChildExists({}) {}={:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&child_info.storage_key()),
|
||||
HexDisplay::from(&key),
|
||||
result,
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildExists",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&child_info.storage_key()),
|
||||
key = %HexDisplay::from(&key),
|
||||
%result,
|
||||
);
|
||||
result
|
||||
}
|
||||
@@ -402,7 +412,7 @@ where
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "Put",
|
||||
ext_id = self.id,
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
key = %HexDisplay::from(&key),
|
||||
value = ?value.as_ref().map(HexDisplay::from),
|
||||
value_encoded = %HexDisplay::from(
|
||||
@@ -423,11 +433,13 @@ where
|
||||
key: StorageKey,
|
||||
value: Option<StorageValue>,
|
||||
) {
|
||||
trace!(target: "state", "{:04x}: PutChild({}) {}={:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&child_info.storage_key()),
|
||||
HexDisplay::from(&key),
|
||||
value.as_ref().map(HexDisplay::from)
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildPut",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&child_info.storage_key()),
|
||||
key = %HexDisplay::from(&key),
|
||||
value = ?value.as_ref().map(HexDisplay::from),
|
||||
);
|
||||
let _guard = guard();
|
||||
|
||||
@@ -436,9 +448,11 @@ where
|
||||
}
|
||||
|
||||
fn kill_child_storage(&mut self, child_info: &ChildInfo, limit: Option<u32>) -> (bool, u32) {
|
||||
trace!(target: "state", "{:04x}: KillChild({})",
|
||||
self.id,
|
||||
HexDisplay::from(&child_info.storage_key()),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildKill",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&child_info.storage_key()),
|
||||
);
|
||||
let _guard = guard();
|
||||
self.mark_dirty();
|
||||
@@ -447,14 +461,19 @@ where
|
||||
}
|
||||
|
||||
fn clear_prefix(&mut self, prefix: &[u8], limit: Option<u32>) -> (bool, u32) {
|
||||
trace!(target: "state", "{:04x}: ClearPrefix {}",
|
||||
self.id,
|
||||
HexDisplay::from(&prefix),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ClearPrefix",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
prefix = %HexDisplay::from(&prefix),
|
||||
);
|
||||
let _guard = guard();
|
||||
|
||||
if sp_core::storage::well_known_keys::starts_with_child_storage_key(prefix) {
|
||||
warn!(target: "trie", "Refuse to directly clear prefix that is part or contains of child storage key");
|
||||
warn!(
|
||||
target: "trie",
|
||||
"Refuse to directly clear prefix that is part or contains of child storage key",
|
||||
);
|
||||
return (false, 0)
|
||||
}
|
||||
|
||||
@@ -469,10 +488,12 @@ where
|
||||
prefix: &[u8],
|
||||
limit: Option<u32>,
|
||||
) -> (bool, u32) {
|
||||
trace!(target: "state", "{:04x}: ClearChildPrefix({}) {}",
|
||||
self.id,
|
||||
HexDisplay::from(&child_info.storage_key()),
|
||||
HexDisplay::from(&prefix),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildClearPrefix",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&child_info.storage_key()),
|
||||
prefix = %HexDisplay::from(&prefix),
|
||||
);
|
||||
let _guard = guard();
|
||||
|
||||
@@ -482,10 +503,12 @@ where
|
||||
}
|
||||
|
||||
fn storage_append(&mut self, key: Vec<u8>, value: Vec<u8>) {
|
||||
trace!(target: "state", "{:04x}: Append {}={}",
|
||||
self.id,
|
||||
HexDisplay::from(&key),
|
||||
HexDisplay::from(&value),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "Append",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
key = %HexDisplay::from(&key),
|
||||
value = %HexDisplay::from(&value),
|
||||
);
|
||||
|
||||
let _guard = guard();
|
||||
@@ -501,15 +524,24 @@ where
|
||||
fn storage_root(&mut self) -> Vec<u8> {
|
||||
let _guard = guard();
|
||||
if let Some(ref root) = self.storage_transaction_cache.transaction_storage_root {
|
||||
trace!(target: "state", "{:04x}: Root(cached) {}",
|
||||
self.id,
|
||||
HexDisplay::from(&root.as_ref()),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "StorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = true,
|
||||
);
|
||||
return root.encode()
|
||||
}
|
||||
|
||||
let root = self.overlay.storage_root(self.backend, self.storage_transaction_cache);
|
||||
trace!(target: "state", "{:04x}: Root {}", self.id, HexDisplay::from(&root.as_ref()));
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "StorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = false,
|
||||
);
|
||||
root.encode()
|
||||
}
|
||||
|
||||
@@ -522,10 +554,13 @@ where
|
||||
.storage(prefixed_storage_key.as_slice())
|
||||
.and_then(|k| Decode::decode(&mut &k[..]).ok())
|
||||
.unwrap_or_else(|| empty_child_trie_root::<Layout<H>>());
|
||||
trace!(target: "state", "{:04x}: ChildRoot({})(cached) {}",
|
||||
self.id,
|
||||
HexDisplay::from(&storage_key),
|
||||
HexDisplay::from(&root.as_ref()),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildStorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&storage_key),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = true,
|
||||
);
|
||||
root.encode()
|
||||
} else {
|
||||
@@ -549,11 +584,15 @@ where
|
||||
self.overlay.set_storage(prefixed_storage_key.into_inner(), Some(root.clone()));
|
||||
}
|
||||
|
||||
trace!(target: "state", "{:04x}: ChildRoot({}) {}",
|
||||
self.id,
|
||||
HexDisplay::from(&storage_key.as_ref()),
|
||||
HexDisplay::from(&root.as_ref()),
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildStorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&storage_key.as_ref()),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = false,
|
||||
);
|
||||
|
||||
root
|
||||
} else {
|
||||
// empty overlay
|
||||
@@ -561,11 +600,16 @@ where
|
||||
.storage(prefixed_storage_key.as_slice())
|
||||
.and_then(|k| Decode::decode(&mut &k[..]).ok())
|
||||
.unwrap_or_else(|| empty_child_trie_root::<Layout<H>>());
|
||||
trace!(target: "state", "{:04x}: ChildRoot({})(no_change) {}",
|
||||
self.id,
|
||||
HexDisplay::from(&storage_key.as_ref()),
|
||||
HexDisplay::from(&root.as_ref()),
|
||||
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildStorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&storage_key.as_ref()),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = false,
|
||||
);
|
||||
|
||||
root.encode()
|
||||
}
|
||||
}
|
||||
@@ -574,12 +618,13 @@ where
|
||||
fn storage_index_transaction(&mut self, index: u32, hash: &[u8], size: u32) {
|
||||
trace!(
|
||||
target: "state",
|
||||
"{:04x}: IndexTransaction ({}): {}, {} bytes",
|
||||
self.id,
|
||||
index,
|
||||
HexDisplay::from(&hash),
|
||||
size,
|
||||
method = "IndexTransaction",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
%index,
|
||||
tx_hash = %HexDisplay::from(&hash),
|
||||
%size,
|
||||
);
|
||||
|
||||
self.overlay.add_transaction_index(IndexOperation::Insert {
|
||||
extrinsic: index,
|
||||
hash: hash.to_vec(),
|
||||
@@ -591,11 +636,12 @@ where
|
||||
fn storage_renew_transaction_index(&mut self, index: u32, hash: &[u8]) {
|
||||
trace!(
|
||||
target: "state",
|
||||
"{:04x}: RenewTransactionIndex ({}): {}",
|
||||
self.id,
|
||||
index,
|
||||
HexDisplay::from(&hash),
|
||||
method = "RenewTransactionIndex",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
%index,
|
||||
tx_hash = %HexDisplay::from(&hash),
|
||||
);
|
||||
|
||||
self.overlay
|
||||
.add_transaction_index(IndexOperation::Renew { extrinsic: index, hash: hash.to_vec() });
|
||||
}
|
||||
@@ -612,10 +658,11 @@ where
|
||||
{
|
||||
trace!(
|
||||
target: "state",
|
||||
"{:04x}: ChangesRoot({})(cached) {:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&parent_hash),
|
||||
root,
|
||||
method = "ChangesRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
parent_hash = %HexDisplay::from(&parent_hash),
|
||||
?root,
|
||||
cached = true,
|
||||
);
|
||||
|
||||
Ok(Some(root.encode()))
|
||||
@@ -626,8 +673,8 @@ where
|
||||
Decode::decode(&mut parent_hash).map_err(|e| {
|
||||
trace!(
|
||||
target: "state",
|
||||
"Failed to decode changes root parent hash: {}",
|
||||
e,
|
||||
error = %e,
|
||||
"Failed to decode changes root parent hash",
|
||||
)
|
||||
})?,
|
||||
true,
|
||||
@@ -636,10 +683,11 @@ where
|
||||
|
||||
trace!(
|
||||
target: "state",
|
||||
"{:04x}: ChangesRoot({}) {:?}",
|
||||
self.id,
|
||||
HexDisplay::from(&parent_hash),
|
||||
root,
|
||||
method = "ChangesRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
parent_hash = %HexDisplay::from(&parent_hash),
|
||||
?root,
|
||||
cached = false,
|
||||
);
|
||||
|
||||
root.map(|r| r.map(|o| o.encode()))
|
||||
|
||||
@@ -172,7 +172,6 @@ mod execution {
|
||||
use super::*;
|
||||
use codec::{Codec, Decode, Encode};
|
||||
use hash_db::Hasher;
|
||||
use log::{trace, warn};
|
||||
use sp_core::{
|
||||
hexdisplay::HexDisplay,
|
||||
storage::ChildInfo,
|
||||
@@ -181,6 +180,7 @@ mod execution {
|
||||
};
|
||||
use sp_externalities::Extensions;
|
||||
use std::{collections::HashMap, fmt, panic::UnwindSafe, result};
|
||||
use tracing::{trace, warn};
|
||||
|
||||
const PROOF_CLOSE_TRANSACTION: &str = "\
|
||||
Closing a transaction that was started in this function. Client initiated transactions
|
||||
@@ -305,6 +305,10 @@ mod execution {
|
||||
storage_transaction_cache: Option<&'a mut StorageTransactionCache<B::Transaction, H, N>>,
|
||||
runtime_code: &'a RuntimeCode<'a>,
|
||||
stats: StateMachineStats,
|
||||
/// The hash of the block the state machine will be executed on.
|
||||
///
|
||||
/// Used for logging.
|
||||
parent_hash: Option<H::Out>,
|
||||
}
|
||||
|
||||
impl<'a, B, H, N, Exec> Drop for StateMachine<'a, B, H, N, Exec>
|
||||
@@ -352,6 +356,7 @@ mod execution {
|
||||
storage_transaction_cache: None,
|
||||
runtime_code,
|
||||
stats: StateMachineStats::default(),
|
||||
parent_hash: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,6 +373,14 @@ mod execution {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the given `parent_hash` as the hash of the parent block.
|
||||
///
|
||||
/// This will be used for improved logging.
|
||||
pub fn set_parent_hash(mut self, parent_hash: H::Out) -> Self {
|
||||
self.parent_hash = Some(parent_hash);
|
||||
self
|
||||
}
|
||||
|
||||
/// Execute a call using the given state backend, overlayed changes, and call executor.
|
||||
///
|
||||
/// On an error, no prospective changes are written to the overlay.
|
||||
@@ -415,13 +428,15 @@ mod execution {
|
||||
Some(&mut self.extensions),
|
||||
);
|
||||
|
||||
let id = ext.id;
|
||||
let ext_id = ext.id;
|
||||
|
||||
trace!(
|
||||
target: "state", "{:04x}: Call {} at {:?}. Input={:?}",
|
||||
id,
|
||||
self.method,
|
||||
self.backend,
|
||||
HexDisplay::from(&self.call_data),
|
||||
target: "state",
|
||||
ext_id = %HexDisplay::from(&ext_id.to_le_bytes()),
|
||||
method = %self.method,
|
||||
parent_hash = %self.parent_hash.map(|h| format!("{:?}", h)).unwrap_or_else(|| String::from("None")),
|
||||
input = ?HexDisplay::from(&self.call_data),
|
||||
"Call",
|
||||
);
|
||||
|
||||
let (result, was_native) = self.exec.call(
|
||||
@@ -438,10 +453,11 @@ mod execution {
|
||||
.expect("Runtime is not able to call this function in the overlay; qed");
|
||||
|
||||
trace!(
|
||||
target: "state", "{:04x}: Return. Native={:?}, Result={:?}",
|
||||
id,
|
||||
was_native,
|
||||
result,
|
||||
target: "state",
|
||||
ext_id = %HexDisplay::from(&ext_id.to_le_bytes()),
|
||||
?was_native,
|
||||
?result,
|
||||
"Return",
|
||||
);
|
||||
|
||||
(result, was_native)
|
||||
@@ -554,7 +570,7 @@ mod execution {
|
||||
|
||||
/// Prove execution using the given state backend, overlayed changes, and call executor.
|
||||
pub fn prove_execution<B, H, N, Exec, Spawn>(
|
||||
mut backend: B,
|
||||
backend: &mut B,
|
||||
overlay: &mut OverlayedChanges,
|
||||
exec: &Exec,
|
||||
spawn_handle: Spawn,
|
||||
@@ -1137,10 +1153,10 @@ mod tests {
|
||||
};
|
||||
|
||||
// fetch execution proof from 'remote' full node
|
||||
let remote_backend = trie_backend::tests::test_trie();
|
||||
let mut remote_backend = trie_backend::tests::test_trie();
|
||||
let remote_root = remote_backend.storage_root(std::iter::empty()).0;
|
||||
let (remote_result, remote_proof) = prove_execution::<_, _, u64, _, _>(
|
||||
remote_backend,
|
||||
&mut remote_backend,
|
||||
&mut Default::default(),
|
||||
&executor,
|
||||
TaskExecutor::new(),
|
||||
|
||||
Reference in New Issue
Block a user