-
Notifications
You must be signed in to change notification settings - Fork 24
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
Message Validation #491
base: dev
Are you sure you want to change the base?
Message Validation #491
Conversation
* Filter shares for slot `CommitteeRunner` based on validators that have duty for that slot. * Filter duty and create share map according to owned validators * Add test: start duty with no shares for duty's validators * Add test: happy flow for committee with fraction of duty's validators * Generate JSON tests * Apply suggestions --------- Co-authored-by: MatheusFranco99 <[email protected]>
* Update go1.20 to go1.22 * Update go.sum with mod tidy
* Update dependencies * Fix lint issue * Generate JSON tests to trigger actions * Update fastssz * Generate JSON tests and align ssz error * Revert go-eth2-client version change * Revert fastssz upgrade * Generate SSZ and JSON tests
* Solve potential file inclusion via variable * Fix file permission (0644 to 0600) * Add nosec comment for PRNG (pseudo-random number generator) used for testing * Fix lint issue on nil check in []byte type * Update permission from 0444 to 0600 * Update 0444 to 0400
* Remove nolint comment and export timeout variables * Drop unnecessary nolint * Add comment * Fix lint issue
* Add share length validation in runner construction * Align to error handling in runners constructions * Add validation to committee runner * Add runner construction tests * Refactor runner construction in testingutil to deal with creation errors * Generate JSON tests * Fix lint issue * Fix comments
* Remove redundant validation * Align error string
* Sort signers in decided message * Add test for sorted signers in decided msg * Generate JSON tests * Fix lint issue
* Stop processing consensus messages after instance is decided * Align error in qbft tests * Align errors in ssv tests * Generate JSON tests * Fix lint issue
* Remove leftover err check * Align argument variable name to type
Maybe p2p/SPEC.md needs some update at line 268-283 about Basic Validation |
@alan-ssvlabs Indeed. Thanks! |
In the |
@GalRogozinski @alan-ssvlabs Moved the msg estimation code to a go file and added some tests. |
Fixes #453 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good!
Just a few comments
// Expected number of messages per duty step | ||
|
||
func consensusMessages(n int) int { | ||
return 1 + n + n + 2 // 1 Proposal + n Prepares + n Commits + 2 Decideds (average) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the average of 2 decides depends on n
, no?
func (test *MessageRateTest) Run(t *testing.T) { | ||
for _, testCase := range test.TestCases { | ||
|
||
// Build the list of committees | ||
committees := make([]*messagerate.Committee, 0) | ||
for _, committeesWithValidators := range testCase.CommitteesConfig { | ||
committees = append(committees, testingutils.TestingDisjointCommittees(committeesWithValidators.NumCommittees, committeesWithValidators.NumValidators)...) | ||
} | ||
|
||
// Check result | ||
expectedValue := testCase.ExpectedMessageRate | ||
result := messagerate.EstimateMessageRateForTopic(committees) | ||
require.InDelta(t, expectedValue, result, allowedError) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking whether those tests are spectests?
The point of spec tests is to make sure the spec didn't break and for nodes to test spec alignment.
Are those tests doing anything like this? You wrote that this was added since the documentation referenced the message rate.
Still... I think this belongs to the research repository where we do simulations
|
||
// Protocol configuration for the MessageValidator | ||
type Config interface { | ||
ProposerForHeightAndRound(height qbft.Height, round qbft.Round) types.OperatorID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to know the committeeLength?
Usually for a single function we declare a function type.
What you did here works as well but maybe we should be consistent.
I would simply add a function to validator.go
and add in a comment that its output is defined by the QBFT leader selection function for clarity
type DutyFetcher interface { | ||
HasProposerDuty(validatorIndex phase0.ValidatorIndex, slot phase0.Slot) bool | ||
HasSyncCommitteeContributionDuty(validatorIndex phase0.ValidatorIndex, slot phase0.Slot) bool | ||
HasSyncCommitteeDuty(validatorIndex phase0.ValidatorIndex, slot phase0.Slot) bool | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like something that would be as part of our BeaconNode
interface
ExistingValidator(validatorPK types.ValidatorPK) bool | ||
ActiveValidator(validatorPK types.ValidatorPK) bool | ||
ValidatorLiquidated(validatorPK types.ValidatorPK) bool | ||
ExistingCommitteeID(committeeID types.CommitteeID) bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those methods we query the contract right?
And for the others we don't, right? So maybe should be 2 interfaces?
I also think we should add comments for interfaces methods, especially ones we only implement as test methods
@@ -39,6 +39,7 @@ func LateCommit() tests.SpecTest { | |||
ControllerPostState: sc.ExpectedState, | |||
}, | |||
}, | |||
ExpectedError: "not processing consensus message since instance is already decided", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come all these messages were added?
// Sort the OperatorIDs and Signatures in the SignedSSVMessage | ||
|
||
pairs := make([]struct { | ||
OpID types.OperatorID | ||
Sig types.Signature | ||
}, len(ret.OperatorIDs)) | ||
|
||
for i, id := range ret.OperatorIDs { | ||
pairs[i] = struct { | ||
OpID types.OperatorID | ||
Sig types.Signature | ||
}{OpID: id, Sig: ret.Signatures[i]} | ||
} | ||
|
||
// Sort the slice of pairs | ||
sort.Slice(pairs, func(i, j int) bool { | ||
return pairs[i].OpID < pairs[j].OpID | ||
}) | ||
|
||
// Extract the sorted IDs and Signatures back into separate slices | ||
for i, pair := range pairs { | ||
ret.OperatorIDs[i] = pair.OpID | ||
ret.Signatures[i] = pair.Sig | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qbft changes because of message validation?
) (Runner, error) { | ||
|
||
if len(share) != 1 { | ||
return nil, errors.New("must have one share") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has nothing to do with the PR right?
b5bd1d3
to
bf0ff16
Compare
Overview
This PR updates the message validation module.
It adds a
MessageValidator
structure that implements theValidatorForTopic
function, as defined by the libp2p framework.Its main validation function starts a chain of validation checks for the pub-sub, syntax, semantics, QBFT and duty logic rules.
Documentation and message rate estimation
The PR also updates the message validation and scoring documentation in
p2p/SPEC.md
andp2p/SCORING.md
. The go code for the message rate estimation is added (along with tests) since this estimation is referenced by the scoring documentation.Tests
This PR also adds tests for each implemented rule, as can be seen in the following list.
PubSub
Syntax validation
ssz
decodingssz
encoding errors.General semantics validation
Consensus semantics validation
Consensus QBFT logic validation
Consensus duty logic validation
Partial signature semantics validation
ssz
encoding errorsPartial signature duty logic validation
General duty logic validation
Wrong signature
Valid