channeldb: when fetching/inserting commits check for ChanStatusRestored

If the ChanStatusRestored flag is set, then we don't need to write or
read the set of commits for a channel as they won't exist. This will be
the case when we restore a channel from an SCB.
This commit is contained in:
Olaoluwa Osuntokun 2018-12-09 19:31:34 -08:00
parent c656788b0b
commit fa30af0475
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2

@ -972,7 +972,9 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *ChannelCommitment) error {
// With the proper bucket fetched, we'll now write toe latest // With the proper bucket fetched, we'll now write toe latest
// commitment state to dis for the target party. // commitment state to dis for the target party.
err = putChanCommitment(chanBucket, newCommitment, true) err = putChanCommitment(
chanBucket, newCommitment, true,
)
if err != nil { if err != nil {
return fmt.Errorf("unable to store chan "+ return fmt.Errorf("unable to store chan "+
"revocations: %v", err) "revocations: %v", err)
@ -1540,7 +1542,9 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg) error {
if err != nil { if err != nil {
return err return err
} }
err = putChanCommitment(chanBucket, &newCommit.Commitment, false) err = putChanCommitment(
chanBucket, &newCommit.Commitment, false,
)
if err != nil { if err != nil {
return err return err
} }
@ -2353,12 +2357,22 @@ func putChanCommitment(chanBucket *bbolt.Bucket, c *ChannelCommitment,
} }
func putChanCommitments(chanBucket *bbolt.Bucket, channel *OpenChannel) error { func putChanCommitments(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
err := putChanCommitment(chanBucket, &channel.LocalCommitment, true) // If this is a restored channel, then we don't have any commitments to
// write.
if channel.hasChanStatus(ChanStatusRestored) {
return nil
}
err := putChanCommitment(
chanBucket, &channel.LocalCommitment, true,
)
if err != nil { if err != nil {
return err return err
} }
return putChanCommitment(chanBucket, &channel.RemoteCommitment, false) return putChanCommitment(
chanBucket, &channel.RemoteCommitment, false,
)
} }
func putChanRevocationState(chanBucket *bbolt.Bucket, channel *OpenChannel) error { func putChanRevocationState(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
@ -2473,6 +2487,12 @@ func fetchChanCommitment(chanBucket *bbolt.Bucket, local bool) (ChannelCommitmen
func fetchChanCommitments(chanBucket *bbolt.Bucket, channel *OpenChannel) error { func fetchChanCommitments(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
var err error var err error
// If this is a restored channel, then we don't have any commitments to
// read.
if channel.hasChanStatus(ChanStatusRestored) {
return nil
}
channel.LocalCommitment, err = fetchChanCommitment(chanBucket, true) channel.LocalCommitment, err = fetchChanCommitment(chanBucket, true)
if err != nil { if err != nil {
return err return err