mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
2536195be0
* Change forkchoice API doubly-linked-tree changes * protoarray changes * blockchain tests * rebase and fix conflicts * More blockchain fixes * blockchain test fixes * doubly linked tree changes again * protoarray changes v2 * blockchain packages v2 * Radek's review * Fix on batch processing * Terence's review * fill in at start * Revert "fill in at start" This reverts commit 8c11db063a02a59df8e0ac6d0af0c8923921dc76. * wrap error message * fill in before mutating the state * wrap nil node errors * handle unknown optimistic status on init sync * rename insert function * prune on batches only after forkchoice insertion Co-authored-by: terencechain <terence@prysmaticlabs.com>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package doublylinkedtree
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
|
)
|
|
|
|
func (s *Store) setUnrealizedJustifiedEpoch(root [32]byte, epoch types.Epoch) error {
|
|
s.nodesLock.Lock()
|
|
defer s.nodesLock.Unlock()
|
|
|
|
node, ok := s.nodeByRoot[root]
|
|
if !ok || node == nil {
|
|
return errors.Wrap(ErrNilNode, "could not set unrealized justified epoch")
|
|
}
|
|
if epoch < node.unrealizedJustifiedEpoch {
|
|
return errInvalidUnrealizedJustifiedEpoch
|
|
}
|
|
node.unrealizedJustifiedEpoch = epoch
|
|
return nil
|
|
}
|
|
|
|
func (s *Store) setUnrealizedFinalizedEpoch(root [32]byte, epoch types.Epoch) error {
|
|
s.nodesLock.Lock()
|
|
defer s.nodesLock.Unlock()
|
|
|
|
node, ok := s.nodeByRoot[root]
|
|
if !ok || node == nil {
|
|
return errors.Wrap(ErrNilNode, "could not set unrealized finalized epoch")
|
|
}
|
|
if epoch < node.unrealizedFinalizedEpoch {
|
|
return errInvalidUnrealizedFinalizedEpoch
|
|
}
|
|
node.unrealizedFinalizedEpoch = epoch
|
|
return nil
|
|
}
|
|
|
|
// UpdateUnrealizedCheckpoints "realizes" the unrealized justified and finalized
|
|
// epochs stored within nodes. It should be called at the beginning of each
|
|
// epoch
|
|
func (f *ForkChoice) UpdateUnrealizedCheckpoints() {
|
|
f.store.nodesLock.Lock()
|
|
defer f.store.nodesLock.Unlock()
|
|
for _, node := range f.store.nodeByRoot {
|
|
node.justifiedEpoch = node.unrealizedJustifiedEpoch
|
|
node.finalizedEpoch = node.unrealizedFinalizedEpoch
|
|
if node.justifiedEpoch > f.store.justifiedEpoch {
|
|
f.store.justifiedEpoch = node.justifiedEpoch
|
|
}
|
|
if node.finalizedEpoch > f.store.finalizedEpoch {
|
|
f.store.finalizedEpoch = node.finalizedEpoch
|
|
}
|
|
}
|
|
}
|