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

Refactor PartialSigContainer.HasSigner: avoid duplication code and rename #444

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions ssv/partial_sig_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@ func (ps *PartialSigContainer) AddSignature(sigMsg *types.PartialSignatureMessag
}
}

// Returns if container has signature for signer and signing root
func (ps *PartialSigContainer) HasSigner(validatorIndex phase0.ValidatorIndex, signer types.OperatorID, signingRoot [32]byte) bool {
if ps.Signatures[validatorIndex] == nil {
return false
}
if ps.Signatures[validatorIndex][rootHex(signingRoot)] == nil {
return false
}
return ps.Signatures[validatorIndex][rootHex(signingRoot)][signer] != nil
// HasSigner returns true if container has signature for signer and signing root, else it returns false
func (ps *PartialSigContainer) HasSignature(validatorIndex phase0.ValidatorIndex, signer types.OperatorID, signingRoot [32]byte) bool {
_, err := ps.GetSignature(validatorIndex, signer, signingRoot)
return err == nil
}

// Return signature for given root and signer
// GetSignature returns the signature for a given root and signer
func (ps *PartialSigContainer) GetSignature(validatorIndex phase0.ValidatorIndex, signer types.OperatorID, signingRoot [32]byte) (types.Signature, error) {
if ps.Signatures[validatorIndex] == nil {
return nil, errors.New("Dont have signature for the given validator index")
Expand Down
2 changes: 1 addition & 1 deletion ssv/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (b *BaseRunner) basePartialSigMsgProcessing(
prevQuorum := container.HasQuorum(msg.ValidatorIndex, msg.SigningRoot)

// Check if it has two signatures for the same signer
if container.HasSigner(msg.ValidatorIndex, msg.Signer, msg.SigningRoot) {
if container.HasSignature(msg.ValidatorIndex, msg.Signer, msg.SigningRoot) {
b.resolveDuplicateSignature(container, msg)
} else {
container.AddSignature(msg)
Expand Down