Ori Newman a436b30ebf
[NOD-1417] Implement reachability (#964)
* [NOD-1417] Implement reachability

* [NOD-1417] Rename package name

* [NOD-1417] Add UpdateReindexRoot to interface api

* [NOD-1417] Remove redundant type

* [NOD-1417] Rename reachabilityTreeManager/reachabilityTree to reachabilityManager

* [NOD-1417] Fix typo

* [NOD-1417] Remove redundant copyright message

* [NOD-1417] Fix comment
2020-10-28 12:19:50 +02:00

31 lines
1018 B
Go

package reachabilitymanager
import (
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
)
// IsDAGAncestorOf returns true if blockHashA is an ancestor of
// blockHashB in the DAG.
//
// Note: this method will return true if blockHashA == blockHashB
// The complexity of this method is O(log(|this.futureCoveringTreeNodeSet|))
func (rt *reachabilityManager) IsDAGAncestorOf(blockHashA, blockHashB *externalapi.DomainHash) (bool, error) {
// Check if this node is a reachability tree ancestor of the
// other node
isReachabilityTreeAncestor, err := rt.IsReachabilityTreeAncestorOf(blockHashA, blockHashB)
if err != nil {
return false, err
}
if isReachabilityTreeAncestor {
return true, nil
}
// Otherwise, use previously registered future blocks to complete the
// reachability test
return rt.futureCoveringSetHasAncestorOf(blockHashA, blockHashB)
}
func (rt *reachabilityManager) UpdateReindexRoot(selectedTip *externalapi.DomainHash) error {
return rt.updateReindexRoot(selectedTip)
}