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:
Olaoluwa Osuntokun 2017-11-06 16:09:02 -08:00
parent ccf94e9457
commit 9294358b5b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 12 additions and 9 deletions

View File

@ -273,14 +273,10 @@ func (r *ChannelRouter) Start() error {
r.newBlocks = r.cfg.ChainView.FilteredBlocks()
r.staleBlocks = r.cfg.ChainView.DisconnectedBlocks()
// 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
}
// Once we've concluded our manual block pruning, we'll constrcut and
// Before we perform our manual block pruning, we'll construct and
// 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()
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
return err
@ -291,6 +287,12 @@ func (r *ChannelRouter) Start() error {
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)
go r.networkHandler()
@ -371,7 +373,7 @@ func (r *ChannelRouter) syncGraphWithChain() error {
log.Infof("channel graph is stale. Disconnecting block %v "+
"(hash=%v)", pruneHeight, pruneHash)
// Prune the graph for every channel that was opened at height
// >= pruneHeigth.
// >= pruneHeight.
_, err := r.cfg.Graph.DisconnectBlockAtHeight(pruneHeight)
if err != nil {
return err
@ -431,7 +433,8 @@ func (r *ChannelRouter) syncGraphWithChain() error {
// With the spent outputs gathered, attempt to prune the
// channel graph, also passing in the hash+height of the block
// 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)
if err != nil {
return err