Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Refactor check_validation_outputs #4727

Merged
merged 9 commits into from
Jan 28, 2022
Merged

Conversation

Lldenaurois
Copy link
Contributor

A particular check that ensures the backed_candidate's persisted validation hash matches the expected hash (fetched via the util function fn make_persisted_validation_data) was not included the fn verify_backed_candidate function and was present higher in the call-stack instead.

However, this logic needs to be called in the fn create_inherent_inner function but was incorrectly ommitted from this inner function. In order to reconcile this discrepancy we must move the persisted validation hash verification into the fn verify_backed_candidate function, which ensures this logic is called in both fn process_candidates and fn create_inherent_inner as desired.

@Lldenaurois Lldenaurois added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. labels Jan 16, 2022
.verify_backed_candidate(parent_hash, candidate_idx, backed_candidate)
.is_err()
//
// NOTE: this is the only place where we check the relay-parent.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is true in my branch but not here

@drahnr
Copy link
Contributor

drahnr commented Jan 19, 2022

@rphmeier is there a particular reason we are discarding all other candidates too just rather than discarding the one with an invalid parachain? We could as well just continue there. Another Q, we do the same filtering as the block producer, so I don't see a particular reason for the special handling and introducing Result<Result<_>>.

@rphmeier
Copy link
Contributor

rphmeier commented Jan 21, 2022

@drahnr

is there a particular reason we are discarding all other candidates too just rather than discarding the one with an invalid parachain?

We have 2 places with use of check_validation_outputs. The first is in inclusion and is logic that runs on-chain. The second is in filtering and runs off-chain.

In inclusion, it has always been the case to not silently ignore invalid backed candidates, and this PR simply continues that behavior. The logic of process_backed_candidates, as far as I can see, is exactly the same as before.

From my reading of this PR, the usage in filtering is as a predicate in sanitize_backed_candidates and so should only skip candidates that fail the predicate.

Another Q, we do the same filtering as the block producer, so I don't see a particular reason for the special handling and introducing Result<Result<_>>

The Result<Result<_>> is not particularly relevant in filtering but is used on-chain process_candidates to preserve the behavior that a failure in constructing the PersistedValidationData in process_candidates leads to the silent ignoring of all candidates. This is an internal error code path which should really never be hit (as the comment above it explains) and the changes here preserve previous behavior.

I hope this is helpful / sane.

@drahnr drahnr added this to the v0.9.16 milestone Jan 26, 2022
@@ -725,7 +726,7 @@ impl<T: Config> Pallet<T> {
// That way we avoid possible duplicate checks while assuring all
// backed candidates fine to pass on.
check_ctx
.verify_backed_candidate(parent_hash, candidate_idx, backed_candidate)
.verify_backed_candidate(parent_hash, parent_storage_root, candidate_idx, backed_candidate)
Copy link
Contributor

@drahnr drahnr Jan 26, 2022

Choose a reason for hiding this comment

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

I don't think this is correct, we'd want to filter out all of them, not only the outer error. Missing a para chain header is also a good enough reason to drop the candidate iiuc

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having a hard time connecting your comment to the code here. Can you explain in more detail?

Copy link
Contributor

Choose a reason for hiding this comment

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

We are now only considering the outer error of the nested result, I'd argue that an error of the inner result type is also a good enough reason to discard the backed candidate iiuc. This can be deferred to a follow up PR, since as you correctly stated, behavior does not change compared to current master

Copy link
Contributor

@rphmeier rphmeier Jan 28, 2022

Choose a reason for hiding this comment

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

I'd argue that an error of the inner result type is also a good enough reason to discard the backed candidate iiuc

Ok, fair. We should probably discard all backed candidates when encountering this error. It means something is seriously wrong and governance will probably need to step in. The on-chain logic is to ignore all the candidates anyway for the same reasons.

Copy link
Member

@eskimor eskimor Jan 28, 2022

Choose a reason for hiding this comment

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

I assume we can change that in the next release/new PR.

@drahnr
Copy link
Contributor

drahnr commented Jan 26, 2022

I agree that fn process_candidates has the same behavior as before, yet it's not really in-line with what we want to do. Further discussions to be had about this, the change LGTM, besides one minor thing I just added.

@drahnr drahnr modified the milestones: v0.9.16, v0.9.17 Jan 26, 2022
ordian and others added 3 commits January 27, 2022 19:47
* master:
  Fix incomplete sorting. (#4795)
  Companion for better way to resolve `Phase::Emergency` via governance #10663 (#4757)
  Refactor and fix usage of `get_session_index()` and `get_session_info_by_index()` (#4735)
  `relay chain selection` and `dispute-coordinator` fixes and improvements (#4752)
  Fix tests (#4787)
  log concluded disputes (#4785)
  availability-distribution: look for leaf ancestors within the same session (#4596)
  Companion for Use proper bounded vector type for nominations #10601 (#4709)
  Fix release profile (#4778)
  [ci] remove publish-s3-release (#4779)
  Companion for substrate#10632 (#4689)
  [ci] pipeline chores (#4775)
  New changelog scripts (#4491)
@eskimor eskimor merged commit e3985d4 into master Jan 28, 2022
@eskimor eskimor deleted the refactor_check_validation_outputs branch January 28, 2022 10:21
chevdor pushed a commit that referenced this pull request Jan 28, 2022
…4801)

* Move PersistedValidationData check into

* Address feedback

* Remove incorrect comment

* Update runtime/parachains/src/inclusion/mod.rs

* fmt

* Add logging

Co-authored-by: Robert Habermeier <[email protected]>
Co-authored-by: Andronik <[email protected]>
@chevdor chevdor mentioned this pull request Jan 28, 2022
chevdor added a commit that referenced this pull request Jan 28, 2022
* Update deps

* Fix release profile (#4778)

* Add codeden-units=1

ref #4311

* opt-level to 3

* Fix opt-level

* Refactor apt-level into the release profile

fix #4780

* wrong if-case - backport of #4798 into v0.9.16 (#4800)

* fixup

* fmt

* fix tests

* Rk fix sorting 0.9.16 (#4806)

* Fix incomplete sorting.

* fmt.

* Better test.

* Update runtime/parachains/src/disputes.rs

Co-authored-by: Bastian Köcher <[email protected]>

* cargo fmt

Co-authored-by: Bastian Köcher <[email protected]>

* Refactor check validation outputs - Backport of #4727 into v0.9.16 (#4801)

* Move PersistedValidationData check into

* Address feedback

* Remove incorrect comment

* Update runtime/parachains/src/inclusion/mod.rs

* fmt

* Add logging

Co-authored-by: Robert Habermeier <[email protected]>
Co-authored-by: Andronik <[email protected]>

Co-authored-by: Bernhard Schuster <[email protected]>
Co-authored-by: Robert Klotzner <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Lldenaurois <[email protected]>
Co-authored-by: Robert Habermeier <[email protected]>
Co-authored-by: Andronik <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants