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

Drop duplicated value check call #367

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MatheusFranco99
Copy link
Contributor

@MatheusFranco99 MatheusFranco99 commented Mar 1, 2024

Drop duplicated value check call as pointed by #325.

The tests for starting an instance with empty value, nil value and invalid value were dropped since the instance doesn't perform a value check anymore.

These tests can't be replicated into Runner tests because the input value for starting an instance is defined internally and not by an external argument.

Closes #325.

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski Should we add a check inside StartNewInstance just to check if the value is not empty?

@GalRogozinski
Copy link
Contributor

@MatheusFranco99
for your question... shouldn't this check be on decided?

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski
What do you mean by "on decided"? Once the instance decides?
Btw, should this PR be into main or dev?

@GalRogozinski
Copy link
Contributor

@MatheusFranco99
Sorry was being super unclear.
I meant that the check you offered should be on decide() the function that calls StartNewInstance

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski
Oh yeah, I agree

@MatheusFranco99
Copy link
Contributor Author

Actually, thinking about it again, we would have something like:

func (b *BaseRunner) decide(runner Runner, input *types.ConsensusData) error {
	byts, err := input.Encode()
	if err != nil {
		return errors.Wrap(err, "could not encode ConsensusData")
	}
        // New check
	if len(byts) == 0 {
		return errors.Wrap(err, "...")
	}

	if err := runner.GetValCheckF()(byts); err != nil {
		return errors.Wrap(err, "input data invalid")
	}
	// ...

But runner.GetValCheckF should already cover it. What do you think?

@GalRogozinski
Copy link
Contributor

@MatheusFranco99
For example on BeaconVoteValueCheckF I don't see an empty check. I see we do a Decode that I am not sure will fail (maybe it returns empty struct, unclear from the code and spec should be clear). It will of course fail but with some other error message.

You have a point though, that it is nice that this will be inside the value check. But this probably means that you need to add the check in each function.

From a SW engineer perspective I would make a base function wrapper that does checks that should happen across all value checks and then calls an internal ValueCheck function. But I don't know how readable it is for spec.

So for spec I would either use your snippet or add the empty check in each valueCheckF. You can choose. The first one won't translate the check to the postconsensus stage, but this is fine since we should never have consensus on an empty value.

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Just a question: we are still covered test wise for empty values?

@@ -50,7 +50,7 @@ func (b *BaseRunner) ValidatePostConsensusMsg(runner Runner, psigMsgs *types.Par
}

// TODO https://github.com/ssvlabs/ssv-spec/issues/142 need to fix with this issue solution instead.
if b.State.DecidedValue == nil || len(b.State.DecidedValue) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski
It seems so according to the test: postconsensus.InvalidDecidedValue

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.

Optimization Proposal: Eliminate Duplicate Validation Check to Improve Consensus Time
2 participants