mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-03 23:03:37 +02:00
channeldb: update channel closing methods to respect new on-disk structure
This commit is contained in:
@@ -406,24 +406,19 @@ func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
return closeBucket.ForEach(func(chanID []byte, summaryBytes []byte) error {
|
return closeBucket.ForEach(func(chanID []byte, summaryBytes []byte) error {
|
||||||
// The first byte of the summary is a bool which
|
|
||||||
// indicates if this channel is pending closure, or has
|
|
||||||
// been fully closed.
|
|
||||||
isPending := summaryBytes[0]
|
|
||||||
|
|
||||||
// If the query specified to only include pending
|
|
||||||
// channels, then we'll skip any channels which aren't
|
|
||||||
// currently pending.
|
|
||||||
if pendingOnly && isPending != 0x01 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
summaryReader := bytes.NewReader(summaryBytes)
|
summaryReader := bytes.NewReader(summaryBytes)
|
||||||
chanSummary, err := deserializeCloseChannelSummary(summaryReader)
|
chanSummary, err := deserializeCloseChannelSummary(summaryReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the query specified to only include pending
|
||||||
|
// channels, then we'll skip any channels which aren't
|
||||||
|
// currently pending.
|
||||||
|
if !chanSummary.IsPending && pendingOnly {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
chanSummaries = append(chanSummaries, chanSummary)
|
chanSummaries = append(chanSummaries, chanSummary)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -452,16 +447,28 @@ func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
chanSummary := closedChanBucket.Get(chanID)
|
chanSummaryBytes := closedChanBucket.Get(chanID)
|
||||||
if chanSummary == nil {
|
if chanSummaryBytes == nil {
|
||||||
return fmt.Errorf("no closed channel by that chanID found")
|
return fmt.Errorf("no closed channel by that chanID found")
|
||||||
}
|
}
|
||||||
|
|
||||||
newSummary := make([]byte, len(chanSummary))
|
chanSummaryReader := bytes.NewReader(chanSummaryBytes)
|
||||||
copy(newSummary[:], chanSummary[:])
|
chanSummary, err := deserializeCloseChannelSummary(
|
||||||
newSummary[0] = 0x00
|
chanSummaryReader,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return closedChanBucket.Put(chanID, newSummary)
|
chanSummary.IsPending = false
|
||||||
|
|
||||||
|
var newSummary bytes.Buffer
|
||||||
|
err = serializeChannelCloseSummary(&newSummary, chanSummary)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return closedChanBucket.Put(chanID, newSummary.Bytes())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user