mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 18:10:48 +02:00
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:
@ -92,7 +92,7 @@ func (b *breachArbiter) Start() error {
|
|||||||
// it to watch for channel breaches.
|
// it to watch for channel breaches.
|
||||||
activeChannels, err := b.db.FetchAllChannels()
|
activeChannels, err := b.db.FetchAllChannels()
|
||||||
if err != nil && err != channeldb.ErrNoActiveChannels {
|
if err != nil && err != channeldb.ErrNoActiveChannels {
|
||||||
brarLog.Errorf("unable to fetch active channels")
|
brarLog.Errorf("unable to fetch active channels: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,8 @@ func (b *breachArbiter) Start() error {
|
|||||||
channel, err := lnwallet.NewLightningChannel(nil, b.notifier,
|
channel, err := lnwallet.NewLightningChannel(nil, b.notifier,
|
||||||
chanState)
|
chanState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
brarLog.Errorf("unable to load channel from disk")
|
brarLog.Errorf("unable to load channel from "+
|
||||||
|
"disk: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +361,30 @@ func (b *breachArbiter) breachObserver(contract *lnwallet.LightningChannel,
|
|||||||
contract.Stop()
|
contract.Stop()
|
||||||
return
|
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
|
// A read from this channel indicates that a channel breach has been
|
||||||
// detected! So we notify the main coordination goroutine with the
|
// detected! So we notify the main coordination goroutine with the
|
||||||
// information needed to bring the counterparty to justice.
|
// information needed to bring the counterparty to justice.
|
||||||
|
Reference in New Issue
Block a user