Skip to content

Parachain loop metrics#1484

Merged
svyatonik merged 4 commits intomasterfrom
parachain-loop-metrics
Jun 29, 2022
Merged

Parachain loop metrics#1484
svyatonik merged 4 commits intomasterfrom
parachain-loop-metrics

Conversation

@svyatonik
Copy link
Copy Markdown
Contributor

closes #1481

Two metrics are provided: best parachain head numbers at the source relay chain and at the target chain.

@svyatonik svyatonik merged commit 1d04752 into master Jun 29, 2022
@svyatonik svyatonik deleted the parachain-loop-metrics branch June 29, 2022 12:58
Copy link
Copy Markdown
Collaborator

@serban300 serban300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! I just left a few comments. I would be happy to address them if they make sense.

Comment on lines +119 to +122
let para_hash_at_source = match self.on_chain_parachain_header(at_block, para_id).await? {
Some(parachain_header) => {
let mut parachain_head = ParaHashAtSource::Some(parachain_header.hash());
para_header_number_at_source = Some(*parachain_header.number());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: para_hash_at_source and parachain_head seem to be almost the same variable. I think we can delete one of them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but they have different scopes. Feel free to change the code if you think your version is better, though :)

.client
.storage_value::<ParaHead>(imported_para_head_key, Some(at_block.1))
.await?
.and_then(|h| match HeaderOf::<P::SourceParachain>::decode(&mut &h.0[..]) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would it make sense to add a helper function similar to storage_value for double-encoded storage values instead of doing the decoding here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind - feel free to add :)

head_hash: ParaHash,
) -> StorageKey {
bp_runtime::storage_double_map_final_key::<Blake2_128Concat, Twox64Concat>(
bp_runtime::storage_double_map_final_key::<Blake2_128Concat, Blake2_128Concat>(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with storage values, but considering these fixes, I was wondering if we could use a safer approach here. I'm thinking of the following issues:

  1. As seen here, we can use different hashers for the storage key vs the StorageDoubleMap that is defined in the pallet. This seems to be covered by unit tests however.
  2. We can use different types when we decode the value. For example here the correct ones would be ParaId, ParaHash, but we might by mistake use something else when decoding. Not sure if this is covered by unit tests.

So I was wondering if we could use a safer approach to cover these issues. Maybe define a new structure to hold all these hashers and types and use if both when defining the StorageDoubleMap and when computing the key and reading the value. A scaled-down version of StorageDoubleMap maybe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a good idea. I'm not sure, though that you'll able to do that - all storage delarations are handled by procedural macro and it may happen that you can't specify e,g, MyMap::Hasher there. But you can try to experiment of course :)

let imported_para_header = self
.client
.storage_value::<ParaHead>(imported_para_head_key, Some(at_block.1))
.await?
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more thing. await? returns the error directly, if any, while if HeaderOf::<P::SourceParachain>::decode() returns an error, we also log a message. Is this desired? Or should we log a message in both error cases ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to make a new method for double-encoded storage values, then let's log it here, where we know what the storage value actually mean and where we may log the meaningful error.

Ideally (imo) we'll need to migrate to some crate that would allow us to propagate error with context and log it once at the upper level (inside the relay loop). But that's not a part of your follow-up PR of course :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will log the error here, but I was wondering if we should log an error both when storage_value() returns an Err and when decode returns an Err. Or should we keep the await? and log an error only when decode() returns an Err ?

The idea with having a new method for double-encoded storage value is not going very well so far. I think I might have to give it up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will log the error here, but I was wondering if we should log an error both when storage_value() returns an Err and when decode returns an Err. Or should we keep the await? and log an error only when decode() returns an Err ?

Imo more detailing logging = better :) The fact that logging occurs at the one branch only is probably the outcome of some bug that I've met. In the end the error is logged at the top level anyway, but this additional trace adds some context. So I'd add the second logging call here.

@serban300 serban300 mentioned this pull request Jul 27, 2022
@serban300
Copy link
Copy Markdown
Collaborator

The comments have been addressed in #1521 . Marking this PR as reviewed.

wuminzhe pushed a commit to darwinia-network/darwinia-messages-substrate that referenced this pull request Aug 8, 2022
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
* parachain loop metrics

* some fixes

* mini refactoring

* add tests
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
* parachain loop metrics

* some fixes

* mini refactoring

* add tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide metrics from parachains relay

2 participants