diff --git a/channeldb/channel.go b/channeldb/channel.go index 6c8664a8..2df4fcb8 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -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 } diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index fe937647..b7893bba 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -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") diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 892503d5..81e970ee 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -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