routing: ensure access to r.bestHeight is thread-safe

This commit is contained in:
Olaoluwa Osuntokun 2017-12-05 17:40:40 -08:00
parent c5049125f8
commit ffd6b65ec1
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 5 additions and 3 deletions

View File

@ -565,7 +565,7 @@ func (r *ChannelRouter) networkHandler() {
// Since this block is stale, we update our best height
// to the previous block.
blockHeight := uint32(chainUpdate.Height)
r.bestHeight = blockHeight - 1
atomic.StoreUint32(&r.bestHeight, blockHeight-1)
// Update the channel graph to reflect that this block
// was disconnected.
@ -596,7 +596,7 @@ func (r *ChannelRouter) networkHandler() {
// Once a new block arrives, we update our running
// track of the height of the chain tip.
blockHeight := uint32(chainUpdate.Height)
r.bestHeight = blockHeight
atomic.StoreUint32(&r.bestHeight, blockHeight)
log.Infof("Pruning channel graph using block %v (height=%v)",
chainUpdate.Hash, blockHeight)
@ -919,7 +919,9 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
// FilteredChainView so we are notified if/when this channel is
// closed.
filterUpdate := []wire.OutPoint{*fundingPoint}
err = r.cfg.ChainView.UpdateFilter(filterUpdate, r.bestHeight)
err = r.cfg.ChainView.UpdateFilter(
filterUpdate, atomic.LoadUint32(&r.bestHeight),
)
if err != nil {
return errors.Errorf("unable to update chain "+
"view: %v", err)