routing: no backend call to fetch best block
This commit is contained in:
parent
8af00ab0cf
commit
cdddaaca75
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
@ -480,6 +481,7 @@ func (r *ChannelRouter) Start() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
r.bestHeight = uint32(bestHeight)
|
||||||
|
|
||||||
// If the graph has never been pruned, or hasn't fully been created yet,
|
// If the graph has never been pruned, or hasn't fully been created yet,
|
||||||
// then we don't treat this as an explicit error.
|
// then we don't treat this as an explicit error.
|
||||||
@ -556,7 +558,7 @@ func (r *ChannelRouter) Start() error {
|
|||||||
// Before we begin normal operation of the router, we first need
|
// Before we begin normal operation of the router, we first need
|
||||||
// to synchronize the channel graph to the latest state of the
|
// to synchronize the channel graph to the latest state of the
|
||||||
// UTXO set.
|
// UTXO set.
|
||||||
if err := r.syncGraphWithChain(); err != nil {
|
if err := r.syncGraphWithChain(bestHash, bestHeight); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,15 +667,11 @@ func (r *ChannelRouter) Stop() error {
|
|||||||
// the latest UTXO set state. This process involves pruning from the channel
|
// the latest UTXO set state. This process involves pruning from the channel
|
||||||
// graph any channels which have been closed by spending their funding output
|
// graph any channels which have been closed by spending their funding output
|
||||||
// since we've been down.
|
// since we've been down.
|
||||||
func (r *ChannelRouter) syncGraphWithChain() error {
|
func (r *ChannelRouter) syncGraphWithChain(bestHash *chainhash.Hash,
|
||||||
|
bestHeight int32) error {
|
||||||
|
|
||||||
// First, we'll need to check to see if we're already in sync with the
|
// First, we'll need to check to see if we're already in sync with the
|
||||||
// latest state of the UTXO set.
|
// latest state of the UTXO set.
|
||||||
bestHash, bestHeight, err := r.cfg.Chain.GetBestBlock()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
r.bestHeight = uint32(bestHeight)
|
|
||||||
|
|
||||||
pruneHash, pruneHeight, err := r.cfg.Graph.PruneTip()
|
pruneHash, pruneHeight, err := r.cfg.Graph.PruneTip()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
@ -2015,10 +2013,7 @@ func (r *ChannelRouter) sendPayment(
|
|||||||
|
|
||||||
// We'll also fetch the current block height so we can properly
|
// We'll also fetch the current block height so we can properly
|
||||||
// calculate the required HTLC time locks within the route.
|
// calculate the required HTLC time locks within the route.
|
||||||
_, currentHeight, err := r.cfg.Chain.GetBestBlock()
|
currentHeight := int32(atomic.LoadUint32(&r.bestHeight))
|
||||||
if err != nil {
|
|
||||||
return [32]byte{}, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now set up a paymentLifecycle struct with these params, such that we
|
// Now set up a paymentLifecycle struct with these params, such that we
|
||||||
// can resume the payment from the current state.
|
// can resume the payment from the current state.
|
||||||
|
Loading…
Reference in New Issue
Block a user