[NOD-1487] Implement dagtopology's IsAncestorOfAny and IsInSelectedParentChainOf (#971)

* [NOD-1487] Implement dagtopology's IsAncestorOfAny and IsInSelectedParentChainOf

* [NOD-1487] Fix IsInSelectedParentChainOf to use reachabilityTree
This commit is contained in:
Ori Newman 2020-10-27 08:46:30 -07:00 committed by GitHub
parent 03790ad8a2
commit ed6d8243ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -13,7 +13,4 @@ type DAGTopologyManager interface {
IsDescendantOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error)
IsAncestorOfAny(blockHash *externalapi.DomainHash, potentialDescendants []*externalapi.DomainHash) (bool, error)
IsInSelectedParentChainOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error)
Tips() ([]*externalapi.DomainHash, error)
AddTip(tipHash *externalapi.DomainHash) error
}

View File

@ -75,12 +75,23 @@ func (dtm *dagTopologyManager) IsDescendantOf(blockHashA *externalapi.DomainHash
// IsAncestorOfAny returns true if `blockHash` is an ancestor of at least one of `potentialDescendants`
func (dtm *dagTopologyManager) IsAncestorOfAny(blockHash *externalapi.DomainHash, potentialDescendants []*externalapi.DomainHash) (bool, error) {
panic("unimplemented")
for _, potentialDescendant := range potentialDescendants {
isAncestorOf, err := dtm.IsAncestorOf(blockHash, potentialDescendant)
if err != nil {
return false, err
}
if isAncestorOf {
return true, nil
}
}
return false, nil
}
// IsInSelectedParentChainOf returns true if blockHashA is in the selected parent chain of blockHashB
func (dtm *dagTopologyManager) IsInSelectedParentChainOf(blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) {
panic("unimplemented")
return dtm.reachabilityTree.IsReachabilityTreeAncestorOf(blockHashA, blockHashB)
}
func isHashInSlice(hash *externalapi.DomainHash, hashes []*externalapi.DomainHash) bool {
@ -91,13 +102,3 @@ func isHashInSlice(hash *externalapi.DomainHash, hashes []*externalapi.DomainHas
}
return false
}
// Tips returns the current DAG tips
func (dtm *dagTopologyManager) Tips() ([]*externalapi.DomainHash, error) {
panic("implement me")
}
// AddTip adds the given tip to the current DAG tips
func (dtm *dagTopologyManager) AddTip(tipHash *externalapi.DomainHash) error {
panic("implement me")
}