breacharbiter: mark channel as fully closed upon detection of unilateral close

This commit modifies the breachArbiter to properly mark a channel as
_fully_ closed once the transaction which force closed the channel has
been confirmed within the chain.
This commit is contained in:
Olaoluwa Osuntokun 2017-05-04 16:08:56 -07:00
parent 4f758eb549
commit 27329ed9db
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -92,7 +92,7 @@ func (b *breachArbiter) Start() error {
// it to watch for channel breaches.
activeChannels, err := b.db.FetchAllChannels()
if err != nil && err != channeldb.ErrNoActiveChannels {
brarLog.Errorf("unable to fetch active channels")
brarLog.Errorf("unable to fetch active channels: %v", err)
return err
}
@ -109,7 +109,8 @@ func (b *breachArbiter) Start() error {
channel, err := lnwallet.NewLightningChannel(nil, b.notifier,
chanState)
if err != nil {
brarLog.Errorf("unable to load channel from disk")
brarLog.Errorf("unable to load channel from "+
"disk: %v", err)
return err
}
@ -360,6 +361,30 @@ func (b *breachArbiter) breachObserver(contract *lnwallet.LightningChannel,
contract.Stop()
return
// The channel has been closed by a normal means: force closing with
// the latest commitment transaction.
case closeInfo := <-contract.UnilateralClose:
// Launch a goroutine to cancel out this contract within the
// breachArbiter's main goroutine.
go func() {
b.settledContracts <- chanPoint
}()
// Next, we'll launch a goroutine to wait until the closing
// transaction has been confirmed so we can mark the contract
// as resolved in the database.
//
// TODO(roasbeef): also notify utxoNursery, might've had
// outbound HTLC's in flight
go waitForChanToClose(b.notifier, nil, chanPoint, closeInfo.SpenderTxHash, func() {
brarLog.Infof("Force closed ChannelPoint(%v) is "+
"fully closed, updating DB", chanPoint)
if err := b.db.MarkChanFullyClosed(chanPoint); err != nil {
brarLog.Errorf("unable to mark chan as closed: %v", err)
}
})
// A read from this channel indicates that a channel breach has been
// detected! So we notify the main coordination goroutine with the
// information needed to bring the counterparty to justice.