Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix primary_parent_hash and add domain_parent_hash in invalid state transition proof #1291

Merged

Conversation

liuchengxu
Copy link
Contributor

@liuchengxu liuchengxu commented Mar 24, 2023

There are two commits in this PR, the code changes are not a lot, but they are kind of tricky, let me know if the following context is still confusing.

Code contributor checklist:

…erating the invalid state transition proof

The main point of this commit is to fix a bug that the legacy `parent_hash`
in `InvalidStateTransitionProof` was incorrectly initialized as the domain
parent hash, which should be the parent hash of the parent block(used to
retrieve the domain runtime code from the primary chain using the
primary chain runtime api).

We didn't catch it earlier because it was
manually set to the _right_ hash in the test by accident which is essentially
caused the gap between the test and production environment. I hope it
won't happen again when we add tests closer to the production code with
the new testing framework.

This commit also makes it more explicit by renaming `parent_hash` to `primary_parent_hash`.
Copy link
Member

@NingLin-P NingLin-P left a comment

Choose a reason for hiding this comment

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

Make sense!

let parent_hash = T::Hash::decode(&mut fraud_proof.parent_hash.encode().as_slice())
.map_err(|_| FraudProofError::WrongHashType)?;
let primary_parent_hash =
T::Hash::decode(&mut fraud_proof.primary_parent_hash.encode().as_slice())
Copy link
Member

Choose a reason for hiding this comment

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

Another lesson learned is that encoding/decoding erases types and can easily cause problems. We should consider adding to/from bounds and ensure that types are compatible statically even if we can't name them explicitly due to use of generics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although I'm not super happy about adding the from/to bounds due to several reasons, I agree on the benefits gained from the compiler. We had a TODO, but haven't fixed it and applied the rule everythere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retrieve state transition data for InitializeBlock
3 participants