mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package doublylinkedtree
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
)
|
|
|
|
// applyProposerBoostScore applies the current proposer boost scores to the
|
|
// relevant nodes.
|
|
func (f *ForkChoice) applyProposerBoostScore() error {
|
|
s := f.store
|
|
proposerScore := big.NewInt(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.Sub(previousNode.balance, new(big.Int).SetUint64(s.previousProposerBoostScore))
|
|
}
|
|
}
|
|
|
|
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 = new(big.Int).Mul(s.committeeWeight, new(big.Int).SetUint64(params.BeaconConfig().ProposerScoreBoost))
|
|
proposerScore.Div(proposerScore, big.NewInt(100))
|
|
currentNode.balance.Add(currentNode.balance, proposerScore)
|
|
}
|
|
}
|
|
s.previousProposerBoostRoot = s.proposerBoostRoot
|
|
s.previousProposerBoostScore = proposerScore.Uint64()
|
|
return nil
|
|
}
|
|
|
|
// ProposerBoost of fork choice store.
|
|
func (s *Store) proposerBoost() [fieldparams.RootLength]byte {
|
|
return s.proposerBoostRoot
|
|
}
|