mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-02 18:02:29 +02:00
lnwallet+link: move marking channel states to link
Instead of marking the database state when processing the channel reestablishment message, we wait for the result of this processing to arrive in the link, and mark it accordingly in the database here. We do this move the logic determining whether we should force close the channel or not, and what state to mark it in the DB, to the same place, as these need to be consistent.
This commit is contained in:
@@ -897,7 +897,7 @@ func (l *channelLink) htlcManager() {
|
||||
if err != nil {
|
||||
log.Warnf("Error when syncing channel states: %v", err)
|
||||
|
||||
_, localDataLoss :=
|
||||
errDataLoss, localDataLoss :=
|
||||
err.(*lnwallet.ErrCommitSyncLocalDataLoss)
|
||||
|
||||
switch {
|
||||
@@ -922,6 +922,12 @@ func (l *channelLink) htlcManager() {
|
||||
// what they sent us before.
|
||||
// TODO(halseth): ban peer?
|
||||
case err == lnwallet.ErrInvalidLocalUnrevokedCommitPoint:
|
||||
err = l.channel.MarkBorked()
|
||||
if err != nil {
|
||||
log.Errorf("Unable to mark channel "+
|
||||
"borked: %v", err)
|
||||
}
|
||||
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrSyncError,
|
||||
@@ -935,13 +941,18 @@ func (l *channelLink) htlcManager() {
|
||||
// We have lost state and cannot safely force close the
|
||||
// channel. Fail the channel and wait for the remote to
|
||||
// hopefully force close it. The remote has sent us its
|
||||
// latest unrevoked commitment point, that we stored in
|
||||
// the database, that we can use to retrieve the funds
|
||||
// when the remote closes the channel.
|
||||
// TODO(halseth): mark this, such that we prevent
|
||||
// channel from being force closed by the user or
|
||||
// contractcourt etc.
|
||||
// latest unrevoked commitment point, and we'll store
|
||||
// it in the database, such that we can attempt to
|
||||
// recover the funds if the remote force closes the
|
||||
// channel.
|
||||
case localDataLoss:
|
||||
err := l.channel.MarkDataLoss(
|
||||
errDataLoss.CommitPoint,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to mark channel "+
|
||||
"data loss: %v", err)
|
||||
}
|
||||
|
||||
// We determined the commit chains were not possible to
|
||||
// sync. We cautiously fail the channel, but don't
|
||||
@@ -949,6 +960,10 @@ func (l *channelLink) htlcManager() {
|
||||
// TODO(halseth): can we safely force close in any
|
||||
// cases where this error is returned?
|
||||
case err == lnwallet.ErrCannotSyncCommitChains:
|
||||
if err := l.channel.MarkBorked(); err != nil {
|
||||
log.Errorf("Unable to mark channel "+
|
||||
"borked: %v", err)
|
||||
}
|
||||
|
||||
// Other, unspecified error.
|
||||
default:
|
||||
|
Reference in New Issue
Block a user