routing: populate the chain filter before calling syncGraphWithChain
In this commit we fix an existing bug within the ChannelRouter. Before this commit, we would sync our graph prune state, *then* update the cain filter. This is incorrect as the blocks we manually pruned may have included channel closing transactions. As a result, we would miss the pruning of a set of channels, and assume that they were still active. In this commit, we fix this by reversing the order: we first update the chain filter and THEN sync the channel graph.
This commit is contained in:
parent
ccf94e9457
commit
9294358b5b
@ -273,14 +273,10 @@ func (r *ChannelRouter) Start() error {
|
|||||||
r.newBlocks = r.cfg.ChainView.FilteredBlocks()
|
r.newBlocks = r.cfg.ChainView.FilteredBlocks()
|
||||||
r.staleBlocks = r.cfg.ChainView.DisconnectedBlocks()
|
r.staleBlocks = r.cfg.ChainView.DisconnectedBlocks()
|
||||||
|
|
||||||
// Before we begin normal operation of the router, we first need to
|
// Before we perform our manual block pruning, we'll construct and
|
||||||
// synchronize the channel graph to the latest state of the UTXO set.
|
|
||||||
if err := r.syncGraphWithChain(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once we've concluded our manual block pruning, we'll constrcut and
|
|
||||||
// apply a fresh chain filter to the active FilteredChainView instance.
|
// apply a fresh chain filter to the active FilteredChainView instance.
|
||||||
|
// We do this before, as otherwise we may miss on-chain events as the
|
||||||
|
// filter hasn't properly been applied.
|
||||||
channelView, err := r.cfg.Graph.ChannelView()
|
channelView, err := r.cfg.Graph.ChannelView()
|
||||||
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
|
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
|
||||||
return err
|
return err
|
||||||
@ -291,6 +287,12 @@ func (r *ChannelRouter) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Before we begin normal operation of the router, we first need to
|
||||||
|
// synchronize the channel graph to the latest state of the UTXO set.
|
||||||
|
if err := r.syncGraphWithChain(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
r.wg.Add(1)
|
r.wg.Add(1)
|
||||||
go r.networkHandler()
|
go r.networkHandler()
|
||||||
|
|
||||||
@ -371,7 +373,7 @@ func (r *ChannelRouter) syncGraphWithChain() error {
|
|||||||
log.Infof("channel graph is stale. Disconnecting block %v "+
|
log.Infof("channel graph is stale. Disconnecting block %v "+
|
||||||
"(hash=%v)", pruneHeight, pruneHash)
|
"(hash=%v)", pruneHeight, pruneHash)
|
||||||
// Prune the graph for every channel that was opened at height
|
// Prune the graph for every channel that was opened at height
|
||||||
// >= pruneHeigth.
|
// >= pruneHeight.
|
||||||
_, err := r.cfg.Graph.DisconnectBlockAtHeight(pruneHeight)
|
_, err := r.cfg.Graph.DisconnectBlockAtHeight(pruneHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -431,7 +433,8 @@ func (r *ChannelRouter) syncGraphWithChain() error {
|
|||||||
// With the spent outputs gathered, attempt to prune the
|
// With the spent outputs gathered, attempt to prune the
|
||||||
// channel graph, also passing in the hash+height of the block
|
// channel graph, also passing in the hash+height of the block
|
||||||
// being pruned so the prune tip can be updated.
|
// being pruned so the prune tip can be updated.
|
||||||
closedChans, err := r.cfg.Graph.PruneGraph(spentOutputs, nextHash,
|
closedChans, err := r.cfg.Graph.PruneGraph(spentOutputs,
|
||||||
|
nextHash,
|
||||||
nextHeight)
|
nextHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user