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

fix(CommitteeObserver): post consensus mem leak #1859

Open
wants to merge 4 commits into
base: stage
Choose a base branch
from
Open
Changes from 3 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
28 changes: 24 additions & 4 deletions protocol/v2/ssv/validator/non_committee_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/ssvlabs/ssv/utils/casts"
)

const postConsensusContainerCapacity = 34
nkryuchkov marked this conversation as resolved.
Show resolved Hide resolved

type CommitteeObserver struct {
logger *zap.Logger
Storage *storage.QBFTStores
Expand All @@ -41,7 +43,7 @@ type CommitteeObserver struct {
attesterRoots *ttlcache.Cache[phase0.Root, struct{}]
syncCommRoots *ttlcache.Cache[phase0.Root, struct{}]
domainCache *DomainCache
postConsensusContainer map[phase0.ValidatorIndex]*ssv.PartialSigContainer
postConsensusContainer map[phase0.Slot]map[phase0.ValidatorIndex]*ssv.PartialSigContainer
}

type CommitteeObserverOptions struct {
Expand Down Expand Up @@ -82,7 +84,7 @@ func NewCommitteeObserver(identifier convert.MessageID, opts CommitteeObserverOp
attesterRoots: opts.AttesterRoots,
syncCommRoots: opts.SyncCommRoots,
domainCache: opts.DomainCache,
postConsensusContainer: make(map[phase0.ValidatorIndex]*ssv.PartialSigContainer),
postConsensusContainer: make(map[phase0.Slot]map[phase0.ValidatorIndex]*ssv.PartialSigContainer, postConsensusContainerCapacity),
}
}

Expand Down Expand Up @@ -220,15 +222,22 @@ func (ncv *CommitteeObserver) processMessage(
) (map[validatorIndexAndRoot][]spectypes.OperatorID, error) {
quorums := make(map[validatorIndexAndRoot][]spectypes.OperatorID)

currentSlot := signedMsg.Slot
slotValidators, exist := ncv.postConsensusContainer[currentSlot]
if !exist {
slotValidators = make(map[phase0.ValidatorIndex]*ssv.PartialSigContainer)
ncv.postConsensusContainer[signedMsg.Slot] = slotValidators
}

for _, msg := range signedMsg.Messages {
validator, exists := ncv.ValidatorStore.ValidatorByIndex(msg.ValidatorIndex)
if !exists {
return nil, fmt.Errorf("could not find share for validator with index %d", msg.ValidatorIndex)
}
container, ok := ncv.postConsensusContainer[msg.ValidatorIndex]
container, ok := slotValidators[msg.ValidatorIndex]
if !ok {
container = ssv.NewPartialSigContainer(validator.Quorum())
ncv.postConsensusContainer[msg.ValidatorIndex] = container
slotValidators[msg.ValidatorIndex] = container
}
if container.HasSignature(msg.ValidatorIndex, msg.Signer, msg.SigningRoot) {
ncv.resolveDuplicateSignature(container, msg, validator)
Expand All @@ -250,6 +259,17 @@ func (ncv *CommitteeObserver) processMessage(
}
}
}

// Remove older slots container
if len(ncv.postConsensusContainer) >= postConsensusContainerCapacity {
thresholdSlot := currentSlot - postConsensusContainerCapacity
for slot := range ncv.postConsensusContainer {
if slot < thresholdSlot {
delete(ncv.postConsensusContainer, slot)
}
}
}

return quorums, nil
}

Expand Down
Loading