mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
channeldb: update channel closing methods to respect new on-disk structure
This commit is contained in:
parent
385818307b
commit
06e6649da5
1 changed files with 25 additions and 18 deletions
|
@ -406,24 +406,19 @@ func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, erro
|
|||
}
|
||||
|
||||
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)
|
||||
chanSummary, err := deserializeCloseChannelSummary(summaryReader)
|
||||
if err != nil {
|
||||
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)
|
||||
return nil
|
||||
})
|
||||
|
@ -452,16 +447,28 @@ func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error {
|
|||
return err
|
||||
}
|
||||
|
||||
chanSummary := closedChanBucket.Get(chanID)
|
||||
if chanSummary == nil {
|
||||
chanSummaryBytes := closedChanBucket.Get(chanID)
|
||||
if chanSummaryBytes == nil {
|
||||
return fmt.Errorf("no closed channel by that chanID found")
|
||||
}
|
||||
|
||||
newSummary := make([]byte, len(chanSummary))
|
||||
copy(newSummary[:], chanSummary[:])
|
||||
newSummary[0] = 0x00
|
||||
chanSummaryReader := bytes.NewReader(chanSummaryBytes)
|
||||
chanSummary, err := deserializeCloseChannelSummary(
|
||||
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())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue