mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
* Compiling main beacon-chain binary
* Add feature flag
* passing protoarray tests
* passing nodetree tests
* passing blockchain package tests
* passing rpc tests
* go fmt
* re-export forkchoice store from blockchain package
* remove duplicated import
* remove unused var
* add nodetree rpc method
* remove slot from IsOptimisticForRoot
* release lock in IsOptimistic
* change package name
* Revert "change package name"
This reverts commit 679112f9ef.
* rename package
* Update doc
* Fix span names
* Terence + Raul review
* remove go:build flags
* add errors dep
* spec tests
* fix call to IsOptimisticForRoot
* fix test
* Fix conflict
* change name of function
* remove ctx from store.head
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package doublylinkedtree
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// removeNode removes the node with the given root and all of its children
|
|
// from the Fork Choice Store.
|
|
func (s *Store) removeNode(ctx context.Context, root [32]byte) error {
|
|
s.nodesLock.Lock()
|
|
defer s.nodesLock.Unlock()
|
|
|
|
node, ok := s.nodeByRoot[root]
|
|
if !ok || node == nil {
|
|
return errNilNode
|
|
}
|
|
if !node.optimistic || node.parent == nil {
|
|
return errInvalidOptimisticStatus
|
|
}
|
|
children := node.parent.children
|
|
if len(children) == 1 {
|
|
node.parent.children = []*Node{}
|
|
} else {
|
|
for i, n := range children {
|
|
if n == node {
|
|
if i != len(children)-1 {
|
|
children[i] = children[len(children)-1]
|
|
}
|
|
node.parent.children = children[:len(children)-2]
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return s.removeNodeAndChildren(ctx, node)
|
|
}
|
|
|
|
// removeNodeAndChildren removes `node` and all of its descendant from the Store
|
|
func (s *Store) removeNodeAndChildren(ctx context.Context, node *Node) error {
|
|
for _, child := range node.children {
|
|
if ctx.Err() != nil {
|
|
return ctx.Err()
|
|
}
|
|
if err := s.removeNodeAndChildren(ctx, child); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
delete(s.nodeByRoot, node.root)
|
|
return nil
|
|
}
|