From 9f0228b21c99093851b7167761549a865798b5c6 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 7 May 2021 19:11:19 +0200 Subject: [PATCH] router: add SyncedHeight() method The router subsystem has its own goroutine that receives chain updates and then does its (quite time consuming) work on each new block. To make it possible to find out what block the router currently is synced to, we export its internal best height through a new method. --- routing/router.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/routing/router.go b/routing/router.go index 76d1291d..aab8e7d6 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2479,6 +2479,13 @@ func (r *ChannelRouter) CurrentBlockHeight() (uint32, error) { return uint32(height), err } +// SyncedHeight returns the block height to which the router subsystem currently +// is synced to. This can differ from the above chain height if the goroutine +// responsible for processing the blocks isn't yet up to speed. +func (r *ChannelRouter) SyncedHeight() uint32 { + return atomic.LoadUint32(&r.bestHeight) +} + // GetChannelByID return the channel by the channel id. // // NOTE: This method is part of the ChannelGraphSource interface.