2022-03-09 03:05:51 +00:00
|
|
|
package doublylinkedtree
|
|
|
|
|
|
|
|
import (
|
2023-02-18 10:37:03 +00:00
|
|
|
"fmt"
|
2022-03-09 03:05:51 +00:00
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
2022-03-09 03:05:51 +00:00
|
|
|
)
|
|
|
|
|
2023-02-18 10:37:03 +00:00
|
|
|
// applyProposerBoostScore applies the current proposer boost scores to the
|
2023-03-02 12:10:52 +00:00
|
|
|
// relevant nodes.
|
2023-02-18 10:37:03 +00: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 03:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-18 10:37:03 +00: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 03:05:51 +00:00
|
|
|
}
|
2023-02-18 10:37:03 +00: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 03:05:51 +00:00
|
|
|
}
|