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

feat(dot/parachain): implement validate candidate from exhaustive #4036

Merged
merged 31 commits into from
Jul 10, 2024

Conversation

edwardmack
Copy link
Member

Changes

This PR introduces code for candidate validation subsystem to validate candidates when all data validation data is provided. As described in Implementation Plan this PR implements:

  • Defining structure for ValidateFromExhaustive message
  • Implements function performBasicChecks to confirm parameters are present and checks collator signature.
  • Instantiates validation host.
  • makes call to validate block of validation host to check the validation parameters and returns validation results message to caller.

Create tests to check for candidate validation exceptions based on possible errors generated by validate block function and reviewing code from polkadot test code

Tests

 go test github.com/ChainSafe/gossamer/dot/parachain/candidate-validation -v

Issues

closes: #3547 and #3995

Copy link
Contributor

@axaysagathiya axaysagathiya left a comment

Choose a reason for hiding this comment

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

the function returns the wrong struct.

dot/parachain/candidate-validation/messages.go Outdated Show resolved Hide resolved
dot/parachain/candidate-validation/candidate_validation.go Outdated Show resolved Hide resolved
dot/parachain/candidate-validation/candidate_validation.go Outdated Show resolved Hide resolved
dot/parachain/candidate-validation/candidate_validation.go Outdated Show resolved Hide resolved
@axaysagathiya
Copy link
Contributor

We don't need to Encode or decode ValidationResultMessage, so we don't need to create VDT.

I have already commented above on how to use this struct.

Validation results can be either Valid or Invalid.

If the result is Invalid,
    set the IsValid field of ValidationResultMessage to false.
    also store the reason for invalidity in the Err field of ValidationResultMessage.

If the result is Valid,
    set the IsValid field of ValidationResultMessage to true.
    set the values of the CandidateCommitments and PersistedValidationData fields of ValidationResultMessage.

Reference from rust: https://github.com/paritytech/polkadot-sdk/blob/7ca0d65f19497ac1c3c7ad6315f1a0acb2ca32f8/polkadot/node/primitives/src/lib.rs#L346-L353

Let's schedule a meeting and work on this together if you are confused.

@edwardmack
Copy link
Member Author

We don't need to Encode or decode ValidationResultMessage, so we don't need to create VDT.

I've removed the usage VDT for this type (and renamed it back to ValidationResult)

Copy link
Contributor

@kishansagathiya kishansagathiya left a comment

Choose a reason for hiding this comment

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

epic! 🎉

dot/parachain/candidate-validation/messages.go Outdated Show resolved Hide resolved
dot/parachain/candidate-validation/messages.go Outdated Show resolved Hide resolved
dot/parachain/candidate-validation/messages.go Outdated Show resolved Hide resolved
dot/parachain/types/types.go Outdated Show resolved Hide resolved
@axaysagathiya
Copy link
Contributor

axaysagathiya commented Jul 3, 2024

It seems you have missed implementing this.

@edwardmack
Copy link
Member Author

It seems you have missed implementing this.

Good point, I've implemented this now.

Copy link
Contributor

@axaysagathiya axaysagathiya left a comment

Choose a reason for hiding this comment

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

How do you plan to handle these errors?

You have returned all the errors, but Rust doesn't consider them all errors. Two are considered errors, and others are reasons for invalidity.

Copy link
Contributor

@timwu20 timwu20 left a comment

Choose a reason for hiding this comment

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

Great work Ed!

@edwardmack
Copy link
Member Author

How do you plan to handle these errors?

You have returned all the errors, but Rust doesn't consider them all errors. Two are considered errors, and others are reasons for invalidity.

The ValidateBlock function that creates these errors will be refactored when the PVF host is implemented, so we can parse the errors that are generated by that when it's implemented.

@axaysagathiya
Copy link
Contributor

How do you plan to handle these errors?
You have returned all the errors, but Rust doesn't consider them all errors. Two are considered errors, and others are reasons for invalidity.

The ValidateBlock function that creates these errors will be refactored when the PVF host is implemented, so we can parse the errors generated by that function when it's implemented.

If we are not checking that the error is an actual error or reason for invalidity, it's not the correct implementation.
Can we add a to-do comment where errors should be filtered out?

Context:
Reason for invalidity: When a candidate is Invalid, we store the reason in the validationResult struct and don't consider it an error.

@kishansagathiya How should we handle errors here?

@kishansagathiya
Copy link
Contributor

kishansagathiya commented Jul 9, 2024

If we are not checking that the error is an actual error or reason for invalidity, it's not the correct implementation.
Can we add a to-do comment where errors should be filtered out?

@edwardmack
Me and @axaysagathiya sat down to figure this out how to approach this. @edwardmack I agree with you that we could do this as a separate task.

So, currently (I am including this PR), eventhough we have Reason for Invalidity (

type ReasonForInvalidity byte
) we never use it.
I would think that ValidateBlock (
func (in *Instance) ValidateBlock(params ValidationParameters) (
) should return a reason for invalidity in validation result. Right now it doesn't since ValidationResult struct (
type ValidationResult struct {
) does not have any field in it for reason for invality or any sort of error.

Let's make sure that ValidateBlock is implemented as expected. Let's have a decent number of tests for it. And differentiate between ReasonForInvalidity and errors occurred in executing ValidateBlock or any other internal error.

Have created an issue to track this task

@edwardmack edwardmack merged commit 4235bd9 into feat/parachain Jul 10, 2024
22 checks passed
@edwardmack edwardmack deleted the ed/feat/candidate_validation_exhaustive branch July 10, 2024 14:32
kishansagathiya pushed a commit that referenced this pull request Jul 15, 2024
)

Co-authored-by: Timothy Wu <tim.wu@chainsafe.io>
kishansagathiya pushed a commit that referenced this pull request Jul 15, 2024
)

Co-authored-by: Timothy Wu <tim.wu@chainsafe.io>
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.

5 participants