channeldb: persist numConfsRequired in OpenChannel.

When a pending channel is persisted and then reloaded upon system startup
it's necessary to also persist the number of confirmations that will be required
before the pending channel can be opened.
This commit is contained in:
bryanvu 2017-01-23 17:15:14 -08:00 committed by Olaoluwa Osuntokun
parent 0dd6cb99c1
commit 59763ebc7e
3 changed files with 21 additions and 0 deletions

@ -214,6 +214,11 @@ type OpenChannel struct {
// funding transaction.
FundingWitnessScript []byte
// NumConfsRequired is the number of confirmations a channel's funding
// transaction must have received in order to be considered available for
// normal transactional use.
NumConfsRequired uint16
// LocalCsvDelay is the delay to be used in outputs paying to us within
// the commitment transaction. This value is to be always expressed in
// terms of relative blocks.
@ -1456,6 +1461,11 @@ func putChanFundingInfo(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error
return err
}
byteOrder.PutUint16(scratch[:2], uint16(channel.NumConfsRequired))
if _, err := b.Write(scratch[:2]); err != nil {
return err
}
return nodeChanBucket.Put(fundTxnKey, b.Bytes())
}
@ -1529,6 +1539,11 @@ func fetchChanFundingInfo(nodeChanBucket *bolt.Bucket, channel *OpenChannel) err
}
channel.ChanType = ChannelType(chanType[0])
if _, err := infoBytes.Read(scratch[:2]); err != nil {
return err
}
channel.NumConfsRequired = byteOrder.Uint16(scratch[:2])
return nil
}

@ -158,6 +158,7 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
OurMultiSigKey: privKey.PubKey(),
TheirMultiSigKey: privKey.PubKey(),
FundingWitnessScript: script,
NumConfsRequired: 4,
TheirCurrentRevocation: privKey.PubKey(),
TheirCurrentRevocationHash: key,
OurDeliveryScript: script,
@ -307,6 +308,10 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
if state.TotalSatoshisReceived != newState.TotalSatoshisReceived {
t.Fatal("satoshis received doesn't match")
}
if state.NumConfsRequired != newState.NumConfsRequired {
t.Fatalf("num confs required doesn't match: %v, vs. %v",
state.NumConfsRequired, newState.NumConfsRequired)
}
if state.CreationTime.Unix() != newState.CreationTime.Unix() {
t.Fatal("creation time doesn't match")

@ -541,6 +541,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
reservation.nodeAddr = req.nodeAddr
reservation.ourContribution.CsvDelay = req.csvDelay
reservation.partialState.NumConfsRequired = req.numConfs
reservation.partialState.IdentityPub = req.nodeID
reservation.partialState.LocalCsvDelay = req.csvDelay
reservation.partialState.OurDustLimit = req.ourDustLimit