Skip to content

Commit

Permalink
Revert "avoid redundant root computations"
Browse files Browse the repository at this point in the history
This reverts commit f11692e.
  • Loading branch information
nkryuchkov committed Oct 30, 2024
1 parent f468409 commit bb91514
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 46 deletions.
30 changes: 12 additions & 18 deletions operator/validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ type controller struct {
// nonCommittees is a cache of initialized committeeObserver instances
committeesObservers *ttlcache.Cache[spectypes.MessageID, *committeeObserver]
committeesObserversMutex sync.Mutex
beaconVoteHashRoots *ttlcache.Cache[phase0.Root, struct{}]
attesterRoots *ttlcache.Cache[phase0.Root, struct{}]
syncCommRoots *ttlcache.Cache[phase0.Root, struct{}]
domainCache *validator.DomainCache
Expand Down Expand Up @@ -328,9 +327,6 @@ func NewController(logger *zap.Logger, options ControllerOptions) Controller {
committeesObservers: ttlcache.New(
ttlcache.WithTTL[spectypes.MessageID, *committeeObserver](cacheTTL),
),
beaconVoteHashRoots: ttlcache.New(
ttlcache.WithTTL[phase0.Root, struct{}](cacheTTL),
),
attesterRoots: ttlcache.New(
ttlcache.WithTTL[phase0.Root, struct{}](cacheTTL),
),
Expand All @@ -350,7 +346,6 @@ func NewController(logger *zap.Logger, options ControllerOptions) Controller {
// Start automatic expired item deletion in nonCommitteeValidators.
go ctrl.committeesObservers.Start()
// Delete old root and domain entries.
go ctrl.beaconVoteHashRoots.Start()
go ctrl.attesterRoots.Start()
go ctrl.syncCommRoots.Start()
go ctrl.domainCache.Start()
Expand Down Expand Up @@ -467,19 +462,18 @@ func (c *controller) handleWorkerMessages(msg network.DecodedSSVMessage) error {
item := c.getNonCommitteeValidators(ssvMsg.GetID())
if item == nil {
committeeObserverOptions := validator.CommitteeObserverOptions{
Logger: c.logger,
NetworkConfig: c.networkConfig,
ValidatorStore: c.validatorStore,
Network: c.validatorOptions.Network,
Storage: c.validatorOptions.Storage,
FullNode: c.validatorOptions.FullNode,
Operator: c.validatorOptions.Operator,
OperatorSigner: c.validatorOptions.OperatorSigner,
NewDecidedHandler: c.validatorOptions.NewDecidedHandler,
BeaconVoteHashRoots: c.beaconVoteHashRoots,
AttesterRoots: c.attesterRoots,
SyncCommRoots: c.syncCommRoots,
DomainCache: c.domainCache,
Logger: c.logger,
NetworkConfig: c.networkConfig,
ValidatorStore: c.validatorStore,
Network: c.validatorOptions.Network,
Storage: c.validatorOptions.Storage,
FullNode: c.validatorOptions.FullNode,
Operator: c.validatorOptions.Operator,
OperatorSigner: c.validatorOptions.OperatorSigner,
NewDecidedHandler: c.validatorOptions.NewDecidedHandler,
AttesterRoots: c.attesterRoots,
SyncCommRoots: c.syncCommRoots,
DomainCache: c.domainCache,
}
ncv = &committeeObserver{
CommitteeObserver: validator.NewCommitteeObserver(convert.MessageID(ssvMsg.MsgID), committeeObserverOptions),
Expand Down
40 changes: 12 additions & 28 deletions protocol/v2/ssv/validator/non_committee_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,25 @@ type CommitteeObserver struct {
qbftController *qbftcontroller.Controller
ValidatorStore registrystorage.ValidatorStore
newDecidedHandler qbftcontroller.NewDecidedHandler
beaconVoteHashRoots *ttlcache.Cache[phase0.Root, struct{}]
attesterRoots *ttlcache.Cache[phase0.Root, struct{}]
syncCommRoots *ttlcache.Cache[phase0.Root, struct{}]
domainCache *DomainCache
postConsensusContainer map[phase0.ValidatorIndex]*ssv.PartialSigContainer
}

type CommitteeObserverOptions struct {
FullNode bool
Logger *zap.Logger
NetworkConfig networkconfig.NetworkConfig
Network specqbft.Network
Storage *storage.QBFTStores
Operator *spectypes.CommitteeMember
OperatorSigner ssvtypes.OperatorSigner
NewDecidedHandler qbftctrl.NewDecidedHandler
ValidatorStore registrystorage.ValidatorStore
BeaconVoteHashRoots *ttlcache.Cache[phase0.Root, struct{}]
AttesterRoots *ttlcache.Cache[phase0.Root, struct{}]
SyncCommRoots *ttlcache.Cache[phase0.Root, struct{}]
DomainCache *DomainCache
FullNode bool
Logger *zap.Logger
NetworkConfig networkconfig.NetworkConfig
Network specqbft.Network
Storage *storage.QBFTStores
Operator *spectypes.CommitteeMember
OperatorSigner ssvtypes.OperatorSigner
NewDecidedHandler qbftctrl.NewDecidedHandler
ValidatorStore registrystorage.ValidatorStore
AttesterRoots *ttlcache.Cache[phase0.Root, struct{}]
SyncCommRoots *ttlcache.Cache[phase0.Root, struct{}]
DomainCache *DomainCache
}

func NewCommitteeObserver(identifier convert.MessageID, opts CommitteeObserverOptions) *CommitteeObserver {
Expand All @@ -85,7 +83,6 @@ func NewCommitteeObserver(identifier convert.MessageID, opts CommitteeObserverOp
beaconNetwork: opts.NetworkConfig.Beacon,
ValidatorStore: opts.ValidatorStore,
newDecidedHandler: opts.NewDecidedHandler,
beaconVoteHashRoots: opts.BeaconVoteHashRoots,
attesterRoots: opts.AttesterRoots,
syncCommRoots: opts.SyncCommRoots,
domainCache: opts.DomainCache,
Expand Down Expand Up @@ -346,16 +343,6 @@ func (ncv *CommitteeObserver) OnProposalMsg(msg *queue.SSVMessage) error {
ncv.logger.Fatal("unreachable: OnProposalMsg must be called only on qbft messages")
}

beaconVoteRoot, err := beaconVote.HashTreeRoot()
if err != nil {
return err
}

// skip computation if the beacon vote root is already cached
if ncv.beaconVoteHashRoots.Get(beaconVoteRoot) != nil {
return nil
}

epoch := ncv.beaconNetwork.EstimatedEpochAtSlot(phase0.Slot(qbftMsg.Height))

if err := ncv.saveAttesterRoots(epoch, beaconVote, qbftMsg); err != nil {
Expand All @@ -366,9 +353,6 @@ func (ncv *CommitteeObserver) OnProposalMsg(msg *queue.SSVMessage) error {
return err
}

// cache the beacon vote hash tree root to avoid redundant computations
ncv.beaconVoteHashRoots.Set(beaconVoteRoot, struct{}{}, ttlcache.DefaultTTL)

return nil
}

Expand Down

0 comments on commit bb91514

Please sign in to comment.