2022-12-06 17:35:56 +00:00
|
|
|
# nimbus-eth1
|
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
|
2023-02-14 23:38:33 +00:00
|
|
|
{.push raises: [].}
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/tables,
|
|
|
|
eth/[common, trie/nibbles],
|
|
|
|
stew/results,
|
|
|
|
../../range_desc,
|
2023-03-22 20:11:49 +00:00
|
|
|
"."/[hexary_desc, hexary_error, hexary_nodes_helper, hexary_paths]
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc branchNibbleMin(node: XNodeObj|RNodeRef; minInx: int8): int8 =
|
|
|
|
## Find the least index for an argument branch `node` link with index
|
|
|
|
## greater or equal the argument `nibble`.
|
|
|
|
if node.kind == Branch:
|
|
|
|
for n in minInx .. 15:
|
|
|
|
if not node.bLink[n].isZeroLink:
|
|
|
|
return n
|
|
|
|
-1
|
|
|
|
|
|
|
|
proc branchNibbleMax(node: XNodeObj|RNodeRef; maxInx: int8): int8 =
|
|
|
|
## Find the greatest index for an argument branch `node` link with index
|
|
|
|
## less or equal the argument `nibble`.
|
|
|
|
if node.kind == Branch:
|
|
|
|
for n in maxInx.countDown 0:
|
|
|
|
if not node.bLink[n].isZeroLink:
|
|
|
|
return n
|
|
|
|
-1
|
|
|
|
|
|
|
|
# --------------------
|
|
|
|
|
2022-12-06 17:35:56 +00:00
|
|
|
proc `<=`(a, b: NibblesSeq): bool =
|
|
|
|
## Compare nibbles, different lengths are padded to the right with zeros
|
|
|
|
let abMin = min(a.len, b.len)
|
|
|
|
for n in 0 ..< abMin:
|
|
|
|
if a[n] < b[n]:
|
|
|
|
return true
|
|
|
|
if b[n] < a[n]:
|
|
|
|
return false
|
|
|
|
# otherwise a[n] == b[n]
|
|
|
|
|
|
|
|
# Assuming zero for missing entries
|
|
|
|
if b.len < a.len:
|
|
|
|
for n in abMin + 1 ..< a.len:
|
|
|
|
if 0 < a[n]:
|
|
|
|
return false
|
|
|
|
true
|
|
|
|
|
|
|
|
proc `<`(a, b: NibblesSeq): bool =
|
|
|
|
not (b <= a)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc complete(
|
|
|
|
path: RPath|XPath; # Partially expanded path
|
|
|
|
key: RepairKey|NodeKey|Blob; # Start key
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
pathLenMax: int; # Beware of loops (if any)
|
|
|
|
doLeast: static[bool]; # Direction: *least* or *most*
|
|
|
|
): auto
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
## Extend path using least or last nodes without recursion.
|
|
|
|
var uPath = typeof(path)(root: path.root, path: path.path)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
let firstNode = key.getNode(db)
|
|
|
|
if firstNode.isErr:
|
|
|
|
return Result[typeof(path),HexaryError].err(firstNode.error)
|
2022-12-06 17:35:56 +00:00
|
|
|
var
|
|
|
|
key = key
|
2023-03-17 14:46:50 +00:00
|
|
|
node = firstNode.value
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
while uPath.path.len < pathLenMax:
|
2022-12-06 17:35:56 +00:00
|
|
|
case node.kind:
|
|
|
|
of Leaf:
|
2023-03-17 14:46:50 +00:00
|
|
|
uPath.path.add typeof(path.path[0])(key: key, node: node, nibble: -1)
|
|
|
|
return ok(uPath) # done
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
of Extension:
|
2023-03-17 14:46:50 +00:00
|
|
|
let newKey = node.eLink
|
|
|
|
if not newkey.isZeroLink:
|
|
|
|
let newNode = newKey.getNode(db)
|
|
|
|
if newNode.isOK:
|
|
|
|
uPath.path.add typeof(path.path[0])(key: key, node: node, nibble: -1)
|
|
|
|
key = newKey
|
|
|
|
node = newNode.value
|
|
|
|
continue
|
|
|
|
return err(NearbyExtensionError) # Oops, no way
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
of Branch:
|
2023-03-17 14:46:50 +00:00
|
|
|
let n = block:
|
|
|
|
when doLeast:
|
|
|
|
node.branchNibbleMin 0
|
|
|
|
else:
|
|
|
|
node.branchNibbleMax 15
|
|
|
|
if 0 <= n:
|
|
|
|
let
|
|
|
|
newKey = node.bLink[n]
|
|
|
|
newNode = newKey.getNode(db)
|
|
|
|
if newNode.isOK:
|
|
|
|
uPath.path.add typeof(path.path[0])(key: key, node: node, nibble: n)
|
|
|
|
key = newKey
|
|
|
|
node = newNode.value
|
|
|
|
continue
|
|
|
|
return err(NearbyBranchError) # Oops, no way
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
err(NearbyNestingTooDeep)
|
|
|
|
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc zeroAdjust(
|
|
|
|
path: XPath|RPath; # Partially expanded path
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
doLeast: static[bool]; # Direction: *least* or *most*
|
|
|
|
): auto
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
## Adjust empty argument path to the first node entry to the right. Ths
|
|
|
|
## applies is the argument path `path` is before the first entry in the
|
|
|
|
## database. The result is a path which is aligned with the first entry.
|
|
|
|
proc accept(p: typeof(path); pfx: NibblesSeq): bool =
|
|
|
|
when doLeast:
|
|
|
|
p.tail <= pfx
|
2022-12-06 17:35:56 +00:00
|
|
|
else:
|
2023-03-17 14:46:50 +00:00
|
|
|
pfx <= p.tail
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc branchNibble(w: typeof(path.path[0].node); n: int8): int8 =
|
|
|
|
when doLeast:
|
|
|
|
w.branchNibbleMin n
|
|
|
|
else:
|
|
|
|
w.branchNibbleMax n
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
if path.path.len == 0:
|
|
|
|
let root = path.root.getNode(db)
|
|
|
|
if root.isOk:
|
|
|
|
block fail:
|
|
|
|
var pfx: NibblesSeq
|
|
|
|
case root.value.kind:
|
|
|
|
of Branch:
|
|
|
|
# Find first non-dangling link and assign it
|
|
|
|
if path.tail.len == 0:
|
|
|
|
break fail
|
|
|
|
let n = root.value.branchNibble path.tail[0].int8
|
|
|
|
if n < 0:
|
|
|
|
break fail
|
|
|
|
pfx = @[n.byte].initNibbleRange.slice(1)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
of Extension:
|
|
|
|
let ePfx = root.value.ePfx
|
|
|
|
# Must be followed by a branch node
|
|
|
|
if path.tail.len < 2 or not path.accept(ePfx):
|
|
|
|
break fail
|
|
|
|
let node = root.value.eLink.getNode(db)
|
|
|
|
if node.isErr:
|
|
|
|
break fail
|
|
|
|
let n = node.value.branchNibble path.tail[1].int8
|
|
|
|
if n < 0:
|
|
|
|
break fail
|
|
|
|
pfx = ePfx & @[n.byte].initNibbleRange.slice(1)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
of Leaf:
|
|
|
|
pfx = root.value.lPfx
|
|
|
|
if not path.accept(pfx):
|
|
|
|
break fail
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
return pfx.padPartialPath(0).hexaryPath(path.root, db)
|
|
|
|
path
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc finalise(
|
|
|
|
path: XPath|RPath; # Partially expanded path
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
): auto
|
2023-02-14 23:38:33 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2023-03-17 14:46:50 +00:00
|
|
|
## Handle some pathological cases after main processing failed
|
|
|
|
if path.path.len == 0:
|
|
|
|
return Result[typeof(path),HexaryError].err(NearbyEmptyPath)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
# Pathological cases
|
|
|
|
# * finalise right: nfffff.. for n < f or
|
|
|
|
# * finalise left: n00000.. for 0 < n
|
|
|
|
if path.path[0].node.kind == Branch or
|
|
|
|
(1 < path.path.len and path.path[1].node.kind == Branch):
|
|
|
|
return err(NearbyFailed) # no more nodes
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
err(NearbyUnexpectedNode) # error
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc nearbyNext(
|
|
|
|
path: RPath|XPath; # Partially expanded path
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
doLeast: static[bool]; # Direction: *least* or *most*
|
|
|
|
pathLenMax = 64; # Beware of loops (if any)
|
|
|
|
): auto
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
## Unified implementation of `hexaryNearbyRight()` and `hexaryNearbyLeft()`.
|
|
|
|
proc accept(nibble: int8): bool =
|
|
|
|
## Accept `nibble` unless on boundaty dependent on `doLeast`
|
|
|
|
when doLeast:
|
|
|
|
nibble < 15
|
2022-12-06 17:35:56 +00:00
|
|
|
else:
|
2023-03-17 14:46:50 +00:00
|
|
|
0 < nibble
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc accept(p: typeof(path); pfx: NibblesSeq): bool =
|
|
|
|
when doLeast:
|
|
|
|
p.tail <= pfx
|
|
|
|
else:
|
|
|
|
pfx <= p.tail
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc branchNibbleNext(w: typeof(path.path[0].node); n: int8): int8 =
|
|
|
|
when doLeast:
|
|
|
|
w.branchNibbleMin(n + 1)
|
|
|
|
else:
|
|
|
|
w.branchNibbleMax(n - 1)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
# Some easy cases
|
2023-03-17 14:46:50 +00:00
|
|
|
var path = path.zeroAdjust(db, doLeast)
|
2022-12-06 17:35:56 +00:00
|
|
|
if path.path.len == 0:
|
2023-03-17 14:46:50 +00:00
|
|
|
return Result[typeof(path),HexaryError].err(NearbyEmptyPath) # error
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-01-30 17:50:58 +00:00
|
|
|
var
|
2023-03-17 14:46:50 +00:00
|
|
|
uPath = path
|
2023-01-30 17:50:58 +00:00
|
|
|
start = true
|
2023-03-17 14:46:50 +00:00
|
|
|
while 0 < uPath.path.len:
|
|
|
|
let top = uPath.path[^1]
|
2023-01-30 17:50:58 +00:00
|
|
|
case top.node.kind:
|
|
|
|
of Leaf:
|
2023-03-17 14:46:50 +00:00
|
|
|
return ok(uPath)
|
2023-01-30 17:50:58 +00:00
|
|
|
of Branch:
|
2023-03-17 14:46:50 +00:00
|
|
|
if top.nibble < 0 or uPath.tail.len == 0:
|
2023-01-30 17:50:58 +00:00
|
|
|
return err(NearbyUnexpectedNode)
|
|
|
|
of Extension:
|
2023-03-17 14:46:50 +00:00
|
|
|
uPath.tail = top.node.ePfx & uPath.tail
|
|
|
|
uPath.path.setLen(uPath.path.len - 1)
|
2023-01-30 17:50:58 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
var
|
|
|
|
step = top
|
|
|
|
let
|
2023-03-17 14:46:50 +00:00
|
|
|
uPathLen = uPath.path.len # in case of backtracking
|
|
|
|
uPathTail = uPath.tail # in case of backtracking
|
2023-01-30 17:50:58 +00:00
|
|
|
|
|
|
|
# Look ahead checking next node
|
|
|
|
if start:
|
2023-03-17 14:46:50 +00:00
|
|
|
let
|
|
|
|
topLink = top.node.bLink[top.nibble]
|
|
|
|
nextNode = block:
|
|
|
|
if topLink.isZeroLink:
|
|
|
|
return err(NearbyDanglingLink) # error
|
|
|
|
let rc = topLink.getNode(db)
|
|
|
|
if rc.isErr:
|
|
|
|
return err(rc.error) # error
|
|
|
|
rc.value
|
2023-01-30 17:50:58 +00:00
|
|
|
|
2023-03-10 17:10:30 +00:00
|
|
|
case nextNode.kind
|
|
|
|
of Leaf:
|
2023-03-17 14:46:50 +00:00
|
|
|
if uPath.accept(nextNode.lPfx):
|
|
|
|
return uPath.complete(topLink, db, pathLenMax, doLeast)
|
2023-03-10 17:10:30 +00:00
|
|
|
of Extension:
|
2023-03-17 14:46:50 +00:00
|
|
|
if uPath.accept(nextNode.ePfx):
|
|
|
|
return uPath.complete(topLink, db, pathLenMax, doLeast)
|
2023-03-10 17:10:30 +00:00
|
|
|
of Branch:
|
2023-03-17 14:46:50 +00:00
|
|
|
let nextNibble = uPath.tail[0].int8
|
|
|
|
if start and accept(nextNibble):
|
2023-01-30 17:50:58 +00:00
|
|
|
# Step down and complete with a branch link on the child node
|
2023-03-17 14:46:50 +00:00
|
|
|
step = typeof(path.path[0])(
|
2023-01-30 17:50:58 +00:00
|
|
|
key: topLink,
|
|
|
|
node: nextNode,
|
|
|
|
nibble: nextNibble)
|
2023-03-17 14:46:50 +00:00
|
|
|
uPath.path &= step
|
2023-01-30 17:50:58 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
# Find the next item to the right/left of the current top entry
|
|
|
|
let n = step.node.branchNibbleNext step.nibble
|
|
|
|
if 0 <= n:
|
|
|
|
uPath.path[^1].nibble = n
|
|
|
|
return uPath.complete(step.node.bLink[n], db, pathLenMax, doLeast)
|
2023-01-30 17:50:58 +00:00
|
|
|
|
|
|
|
if start:
|
|
|
|
# Retry without look ahead
|
|
|
|
start = false
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
# Restore `uPath` (pop temporary extra step)
|
|
|
|
if uPathLen < uPath.path.len:
|
|
|
|
uPath.path.setLen(uPathLen)
|
|
|
|
uPath.tail = uPathTail
|
2023-01-30 17:50:58 +00:00
|
|
|
else:
|
|
|
|
# Pop current `Branch` node on top and append nibble to `tail`
|
2023-03-17 14:46:50 +00:00
|
|
|
uPath.tail = @[top.nibble.byte].initNibbleRange.slice(1) & uPath.tail
|
|
|
|
uPath.path.setLen(uPath.path.len - 1)
|
2023-01-30 17:50:58 +00:00
|
|
|
# End while
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
# Handle some pathological cases
|
|
|
|
return path.finalise(db)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc nearbyNext(
|
|
|
|
baseTag: NodeTag; # Some node
|
|
|
|
rootKey: NodeKey; # State root
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
doLeast: static[bool]; # Direction: *least* or *most*
|
|
|
|
pathLenMax = 64; # Beware of loops (if any)
|
|
|
|
): Result[NodeTag,HexaryError]
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
## Variant of `nearbyNext()`, convenience wrapper
|
|
|
|
let rc = baseTag.hexaryPath(rootKey, db).nearbyNext(db, doLeast)
|
|
|
|
if rc.isErr:
|
|
|
|
return err(rc.error)
|
2023-01-30 17:50:58 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
let path = rc.value
|
|
|
|
if 0 < path.path.len and path.path[^1].node.kind == Leaf:
|
|
|
|
let nibbles = path.getNibbles
|
|
|
|
if nibbles.len == 64:
|
|
|
|
return ok(nibbles.getBytes.convertTo(NodeTag))
|
2023-01-30 17:50:58 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
err(NearbyLeafExpected)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions, moving and right boundary proof
|
|
|
|
# ------------------------------------------------------------------------------
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc hexaryNearbyRight*(
|
|
|
|
path: RPath|XPath; # Partially expanded path
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
): auto
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
## Extends the maximally extended argument nodes `path` to the right (i.e.
|
|
|
|
## with non-decreasing path value). This is similar to the
|
|
|
|
## `hexary_path.next()` function, only that this algorithm does not
|
|
|
|
## backtrack if there are dangling links in between and rather returns
|
|
|
|
## an error.
|
|
|
|
##
|
|
|
|
## This code is intended to be used for verifying a left-bound proof to
|
|
|
|
## verify that there is no leaf node *right* of a boundary path value.
|
|
|
|
path.nearbyNext(db, doLeast=true)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
proc hexaryNearbyRight*(
|
|
|
|
baseTag: NodeTag; # Some node
|
|
|
|
rootKey: NodeKey; # State root
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
): Result[NodeTag,HexaryError]
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
## Variant of `hexaryNearbyRight()` working with `NodeTag` arguments rather
|
|
|
|
## than `RPath` or `XPath` ones.
|
|
|
|
baseTag.nearbyNext(rootKey, db, doLeast=true)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
proc hexaryNearbyRightMissing*(
|
2023-03-17 14:46:50 +00:00
|
|
|
path: RPath|XPath; # Partially expanded path
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
): Result[bool,HexaryError]
|
|
|
|
{.gcsafe, raises: [KeyError].} =
|
2022-12-06 17:35:56 +00:00
|
|
|
## Returns `true` if the maximally extended argument nodes `path` is the
|
|
|
|
## rightmost on the hexary trie database. It verifies that there is no more
|
|
|
|
## leaf entry to the right of the argument `path`.
|
|
|
|
##
|
|
|
|
## This code is intended be used for verifying a left-bound proof.
|
2023-03-17 14:46:50 +00:00
|
|
|
if path.path.len == 0:
|
|
|
|
return err(NearbyEmptyPath)
|
|
|
|
if 0 < path.tail.len:
|
|
|
|
return err(NearbyPathTail)
|
|
|
|
|
|
|
|
let top = path.path[^1]
|
|
|
|
if top.node.kind != Branch or top.nibble < 0:
|
|
|
|
return err(NearbyBranchError)
|
|
|
|
|
|
|
|
let nextNode = block:
|
|
|
|
let topLink = top.node.bLink[top.nibble]
|
|
|
|
if topLink.isZeroLink:
|
|
|
|
return err(NearbyDanglingLink) # error
|
|
|
|
let rc = topLink.getNode(db)
|
|
|
|
if rc.isErr:
|
|
|
|
return err(rc.error) # error
|
|
|
|
rc.value
|
2022-12-06 17:35:56 +00:00
|
|
|
|
2023-03-17 14:46:50 +00:00
|
|
|
case nextNode.kind
|
|
|
|
of Leaf:
|
|
|
|
return ok(nextNode.lPfx < path.tail)
|
|
|
|
of Extension:
|
|
|
|
return ok(nextNode.ePfx < path.tail)
|
|
|
|
of Branch:
|
|
|
|
return ok(nextNode.branchNibbleMin(path.tail[0].int8) < 0)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc hexaryNearbyLeft*(
|
2023-03-17 14:46:50 +00:00
|
|
|
path: RPath|XPath; # Partially expanded path
|
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
|
|
|
): auto
|
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2022-12-06 17:35:56 +00:00
|
|
|
## Similar to `hexaryNearbyRight()`.
|
|
|
|
##
|
2022-12-24 09:54:18 +00:00
|
|
|
## This code is intended to be used for verifying a right-bound proof to
|
|
|
|
## verify that there is no leaf node *left* to a boundary path value.
|
2023-03-17 14:46:50 +00:00
|
|
|
path.nearbyNext(db, doLeast=false)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
proc hexaryNearbyLeft*(
|
2023-01-30 17:50:58 +00:00
|
|
|
baseTag: NodeTag; # Some node
|
|
|
|
rootKey: NodeKey; # State root
|
2023-02-14 23:38:33 +00:00
|
|
|
db: HexaryTreeDbRef|HexaryGetFn; # Database abstraction
|
2022-12-06 17:35:56 +00:00
|
|
|
): Result[NodeTag,HexaryError]
|
2023-03-17 14:46:50 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2022-12-06 17:35:56 +00:00
|
|
|
## Similar to `hexaryNearbyRight()` for `NodeKey` arguments.
|
2023-03-17 14:46:50 +00:00
|
|
|
baseTag.nearbyNext(rootKey, db, doLeast=false)
|
2022-12-06 17:35:56 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|