mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
chainntnfs: modify all historical rescans to scan backwards
In this commit, we modify all existing historical rescans for ChainNotifier backends to scan backwards rather than forwards. If we know that a transaction has been confirmed, or outpoint spent, the it's likely that the event has recently transpired assuming we've been offline for a short period of time. Therefore, if we scan backwards rather than forwards, then we can save potentially hundreds or thousands of block fetches if the event recently happened close to the tip of the chain. We bound this search at the genesis block, to ensure we don't underflow the uint32 used throughout the package in the main loop.
This commit is contained in:
parent
712fc3ebed
commit
28eb8474f4
@ -521,7 +521,7 @@ func (b *BitcoindNotifier) confDetailsManually(txid *chainhash.Hash,
|
|||||||
|
|
||||||
// Begin scanning blocks at every height to determine where the
|
// Begin scanning blocks at every height to determine where the
|
||||||
// transaction was included in.
|
// transaction was included in.
|
||||||
for height := heightHint; height <= currentHeight; height++ {
|
for height := currentHeight; height >= heightHint && height > 0; height-- {
|
||||||
// Ensure we haven't been requested to shut down before
|
// Ensure we haven't been requested to shut down before
|
||||||
// processing the next height.
|
// processing the next height.
|
||||||
select {
|
select {
|
||||||
@ -749,7 +749,7 @@ func (b *BitcoindNotifier) dispatchSpendDetailsManually(
|
|||||||
|
|
||||||
// Begin scanning blocks at every height to determine if the outpoint
|
// Begin scanning blocks at every height to determine if the outpoint
|
||||||
// was spent.
|
// was spent.
|
||||||
for height := startHeight; height <= endHeight; height++ {
|
for height := endHeight; height >= startHeight && height > 0; height-- {
|
||||||
// Ensure we haven't been requested to shut down before
|
// Ensure we haven't been requested to shut down before
|
||||||
// processing the next height.
|
// processing the next height.
|
||||||
select {
|
select {
|
||||||
|
@ -572,7 +572,7 @@ func (b *BtcdNotifier) confDetailsManually(txid *chainhash.Hash, startHeight,
|
|||||||
|
|
||||||
// Begin scanning blocks at every height to determine where the
|
// Begin scanning blocks at every height to determine where the
|
||||||
// transaction was included in.
|
// transaction was included in.
|
||||||
for height := startHeight; height <= endHeight; height++ {
|
for height := endHeight; height >= startHeight && height > 0; height-- {
|
||||||
// Ensure we haven't been requested to shut down before
|
// Ensure we haven't been requested to shut down before
|
||||||
// processing the next height.
|
// processing the next height.
|
||||||
select {
|
select {
|
||||||
|
@ -467,7 +467,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
|
|
||||||
// Starting from the height hint, we'll walk forwards in the chain to
|
// Starting from the height hint, we'll walk forwards in the chain to
|
||||||
// see if this transaction has already been confirmed.
|
// see if this transaction has already been confirmed.
|
||||||
for scanHeight := startHeight; scanHeight <= endHeight; scanHeight++ {
|
for scanHeight := endHeight; scanHeight >= startHeight && scanHeight > 0; scanHeight-- {
|
||||||
// Ensure we haven't been requested to shut down before
|
// Ensure we haven't been requested to shut down before
|
||||||
// processing the next height.
|
// processing the next height.
|
||||||
select {
|
select {
|
||||||
|
Loading…
Reference in New Issue
Block a user