Skip to content

Commit 9a69512

Browse files
authored
feat: add logging to DIP components (#630)
Fixes KILTprotocol/ticket#3128. I introduced different new logging targets. For the deposit storage and relay store pallet, which are not technically part of the DIP protocol, the target is a standalone one. For the other things, meaning DIP pallets and DIP provider/consumer components, the log targets have the following structure: `"dip::<provider>|<consumer>::<type_name>"`. So filtering provider logs would require `RUST_LOG=dip::provider=info`, for instance. Most of the logs are `info` level, with some `error` where we return `Internal` errors or errors coalesced into a `u8` value, and a couple of `trace` for the less important stuff to show.
1 parent abc540d commit 9a69512

File tree

39 files changed

+482
-187
lines changed

39 files changed

+482
-187
lines changed

Cargo.lock

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

crates/kilt-dip-primitives/src/merkle_proofs/v0/dip_subject_state/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<
209209
ensure!(!signing_leaves_indices.is_empty(), Error::InvalidDidKeyRevealed);
210210

211211
let signing_leaves_indices_vector = signing_leaves_indices.try_into().map_err(|_| {
212-
log::error!("Should never fail to convert vector of signing leaf indices into BoundedVec.");
212+
log::error!(target: "dip::consumer::DipRevealedDetailsAndVerifiedDidSignatureFreshnessV0", "Failed to convert vector of signing leaf indices into BoundedVec<u8, {MAX_REVEALED_LEAVES_COUNT}>.");
213213
Error::Internal
214214
})?;
215215

crates/kilt-dip-primitives/src/merkle_proofs/v0/output_common.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,29 @@ impl<
9797
/// `Error::Internal` which, anyway, should never happen.
9898
pub fn get_signing_leaves(
9999
&self,
100-
) -> Result<impl Iterator<Item = &RevealedDidKey<KiltDidKeyId, KiltBlockNumber, KiltAccountId>>, Error> {
100+
) -> Result<impl Iterator<Item = &RevealedDidKey<KiltDidKeyId, KiltBlockNumber, KiltAccountId>>, Error>
101+
where
102+
KiltDidKeyId: Debug,
103+
KiltBlockNumber: Debug,
104+
KiltAccountId: Debug,
105+
KiltWeb3Name: Debug,
106+
KiltLinkableAccountId: Debug,
107+
{
108+
const LOG_TARGET: &str = "dip::consumer::DipOriginInfoV0";
101109
let leaves = self
102110
.signing_leaves_indices
103111
.iter()
104112
.map(|index| {
105113
let leaf = self.revealed_leaves.get(usize::saturated_from(*index)).ok_or_else(|| {
106-
log::error!("Should never fail to retrieve the signing leaf at index {:#?}.", index);
114+
log::error!(
115+
target: LOG_TARGET,
116+
"Failed to retrieve the signing leaf at index {:#?}.",
117+
index
118+
);
107119
Error::Internal
108120
})?;
109121
let RevealedDidMerkleProofLeaf::DidKey(did_key) = leaf else {
110-
log::error!("Should never fail to convert the signing leaf to a DID Key leaf.");
122+
log::error!(target: LOG_TARGET, "Failed to convert the signing leaf {:#?} to a DID Key leaf.", leaf);
111123
return Err(Error::Internal);
112124
};
113125
Ok(did_key)

crates/kilt-dip-primitives/src/merkle_proofs/v0/provider_state/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl<
176176
ProviderHeader: Decode + HeaderT<Hash = OutputOf<RelayHasher>, Number = KiltBlockNumber>,
177177
{
178178
let provider_head_storage_key = calculate_parachain_head_storage_key(provider_para_id);
179+
log::trace!(target: "dip::consumer::ParachainDipDidProofV0", "Calculated storage key for para ID {:#?} = {:#?}", provider_para_id, provider_head_storage_key);
179180
// TODO: Figure out why RPC call returns 2 bytes in front which we don't need
180181
//This could be the reason (and the solution): https://substrate.stackexchange.com/a/1891/1795
181182
let provider_header = verify_storage_value_proof_with_decoder::<_, RelayHasher, ProviderHeader>(
@@ -323,6 +324,7 @@ impl<
323324
{
324325
let dip_commitment_storage_key =
325326
calculate_dip_identity_commitment_storage_key_for_runtime::<ProviderRuntime>(subject, 0);
327+
log::trace!(target: "dip::consumer::DipDidProofWithVerifiedStateRootV0", "Calculated storage key for subject {:#?} = {:#?}", subject, dip_commitment_storage_key);
326328
let dip_commitment = verify_storage_value_proof::<_, ParachainHasher, IdentityCommitmentOf<ProviderRuntime>>(
327329
&dip_commitment_storage_key,
328330
self.state_root,
@@ -466,10 +468,11 @@ impl<
466468
self.dip_proof.blinded.as_slice(),
467469
proof_leaves_key_value_pairs.as_slice(),
468470
)
471+
// Can't log since the result returned by `verify_trie_proof` implements `Debug` only with `std`.
469472
.map_err(|_| Error::InvalidDidMerkleProof)?;
470473

471474
let revealed_leaves = BoundedVec::try_from(self.dip_proof.revealed).map_err(|_| {
472-
log::error!("Should not fail to construct BoundedVec since bounds were checked before.");
475+
log::error!(target: "dip::consumer::DipDidProofWithVerifiedSubjectCommitmentV0", "Failed to construct BoundedVec<u8, {MAX_REVEALED_LEAVES_COUNT}>.");
473476
Error::Internal
474477
})?;
475478

crates/kilt-dip-primitives/src/state_proofs/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,17 @@ where
7676
MerkleHasher: Hash,
7777
OutputOf<MerkleHasher>: Ord,
7878
{
79+
const LOG_TARGET: &str = "dip::consumer::verify_storage_value_proof_with_decoder";
7980
let storage_proof = StorageProof::new(state_proof);
8081
let mut revealed_leaves = read_proof_check::<MerkleHasher, _>(state_root, storage_proof, [storage_key].iter())
81-
.map_err(|_| MerkleProofError::InvalidProof)?;
82+
.map_err(|e| {
83+
log::info!(
84+
target: LOG_TARGET,
85+
"Failed verification of storage proof with error {:#?}",
86+
e
87+
);
88+
MerkleProofError::InvalidProof
89+
})?;
8290

8391
debug_assert!(
8492
revealed_leaves.len() == 1usize,

crates/kilt-dip-primitives/src/verifier/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
// If you feel like getting in touch with us, you can do so at [email protected]
1818

19+
use sp_std::fmt::Debug;
20+
21+
#[derive(Debug)]
1922
#[repr(u8)]
2023
pub(crate) enum DipProofComponentTooLargeError {
2124
ParachainHeadProofTooManyLeaves = 0,

crates/kilt-dip-primitives/src/verifier/parachain/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ impl<
188188
KiltRuntime::IdentityCommitmentGenerator:
189189
IdentityCommitmentGenerator<KiltRuntime, Output = RelaychainRuntime::Hash>,
190190
SignedExtra: GetWithoutArg,
191-
SignedExtra::Result: Encode,
191+
SignedExtra::Result: Encode + Debug,
192192
DidCallVerifier: DipCallOriginFilter<
193193
RuntimeCallOf<ConsumerRuntime>,
194194
OriginInfo = Vec<RevealedDidKey<KeyIdOf<KiltRuntime>, BlockNumberFor<KiltRuntime>, KiltRuntime::AccountId>>,
195195
>,
196-
DidCallVerifier::Error: Into<u8>,
196+
DidCallVerifier::Error: Into<u8> + Debug,
197197
{
198198
type Error = DipParachainStateProofVerifierError<DidCallVerifier::Error>;
199199
type Proof = VersionedDipParachainStateProof<

0 commit comments

Comments
 (0)