2022-03-09 00:05:51 -03:00
|
|
|
package doublylinkedtree
|
|
|
|
|
|
|
|
import (
|
2023-02-18 07:37:03 -03:00
|
|
|
"fmt"
|
2022-03-09 00:05:51 -03:00
|
|
|
|
2024-02-14 21:46:47 -08:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
2022-03-09 00:05:51 -03:00
|
|
|
)
|
|
|
|
|
2023-02-18 07:37:03 -03:00
|
|
|
// applyProposerBoostScore applies the current proposer boost scores to the
|
2023-03-02 09:10:52 -03:00
|
|
|
// relevant nodes.
|
2023-02-18 07:37:03 -03:00
|
|
|
func (f *ForkChoice) applyProposerBoostScore() error {
|
|
|
|
s := f.store
|
|
|
|
proposerScore := uint64(0)
|
|
|
|
if s.previousProposerBoostRoot != params.BeaconConfig().ZeroHash {
|
|
|
|
previousNode, ok := s.nodeByRoot[s.previousProposerBoostRoot]
|
|
|
|
if !ok || previousNode == nil {
|
|
|
|
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid prev root %#x", s.previousProposerBoostRoot))
|
|
|
|
} else {
|
|
|
|
previousNode.balance -= s.previousProposerBoostScore
|
2022-03-09 00:05:51 -03:00
|
|
|
}
|
|
|
|
}
|
2023-02-18 07:37:03 -03:00
|
|
|
|
|
|
|
if s.proposerBoostRoot != params.BeaconConfig().ZeroHash {
|
|
|
|
currentNode, ok := s.nodeByRoot[s.proposerBoostRoot]
|
|
|
|
if !ok || currentNode == nil {
|
|
|
|
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid current root %#x", s.proposerBoostRoot))
|
|
|
|
} else {
|
|
|
|
proposerScore = (s.committeeWeight * params.BeaconConfig().ProposerScoreBoost) / 100
|
|
|
|
currentNode.balance += proposerScore
|
|
|
|
}
|
2022-03-09 00:05:51 -03:00
|
|
|
}
|
2023-02-18 07:37:03 -03:00
|
|
|
s.previousProposerBoostRoot = s.proposerBoostRoot
|
|
|
|
s.previousProposerBoostScore = proposerScore
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProposerBoost of fork choice store.
|
|
|
|
func (s *Store) proposerBoost() [fieldparams.RootLength]byte {
|
|
|
|
return s.proposerBoostRoot
|
2022-03-09 00:05:51 -03:00
|
|
|
}
|