From ed76e2c96275a4da44662e63541eae4bb24ffb02 Mon Sep 17 00:00:00 2001 From: Mike Zak Date: Sun, 28 Apr 2019 11:53:48 +0300 Subject: [PATCH] [NOD-143] SelectedAncestor now returns the first chain block under height if there's no chain block with exact hight --- blockdag/blocknode.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/blockdag/blocknode.go b/blockdag/blocknode.go index 46f021860..b7b022fdb 100644 --- a/blockdag/blocknode.go +++ b/blockdag/blocknode.go @@ -198,6 +198,9 @@ func (node *blockNode) Header() *wire.BlockHeader { // the selected chain backwards from this node. The returned block will be nil when a // height is requested that is after the height of the passed node or is less than zero. // +// When there's no chain-block of the requested height, the block with the highest height +// that is lower than requested height would be returned. +// // This function is safe for concurrent access. func (node *blockNode) SelectedAncestor(height int32) *blockNode { if height < 0 || height > node.height { @@ -205,7 +208,7 @@ func (node *blockNode) SelectedAncestor(height int32) *blockNode { } n := node - for ; n != nil && n.height != height; n = n.selectedParent { + for ; n != nil && n.height > height; n = n.selectedParent { // Intentionally left blank }