diff --git a/channeldb/channel.go b/channeldb/channel.go index b2bfb3013..dc0bf0058 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -220,6 +220,10 @@ const ( // A tlv type definition used to serialize and deserialize the // confirmed ShortChannelID for a zero-conf channel. realScidType tlv.Type = 4 + + // A tlv type definition used to serialize and deserialize the + // Memo for the channel channel. + channelMemoType tlv.Type = 5 ) // indexStatus is an enum-like type that describes what state the @@ -818,6 +822,10 @@ type OpenChannel struct { // default ShortChannelID. This is only set for zero-conf channels. confirmedScid lnwire.ShortChannelID + // Memo is any arbitrary information we wish to store locally about the + // channel that will be useful to our future selves. + Memo []byte + // TODO(roasbeef): eww Db *ChannelStateDB @@ -3642,6 +3650,7 @@ func putChanInfo(chanBucket kvdb.RwBucket, channel *OpenChannel) error { initialRemoteBalanceType, &remoteBalance, ), MakeScidRecord(realScidType, &channel.confirmedScid), + tlv.MakePrimitiveRecord(channelMemoType, &channel.Memo), ) if err != nil { return err @@ -3839,10 +3848,11 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error { } } - // Create balance fields in uint64. + // Create balance fields in uint64, and Memo field as byte slice. var ( localBalance uint64 remoteBalance uint64 + memo []byte ) // Create the tlv stream. @@ -3859,6 +3869,7 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error { initialRemoteBalanceType, &remoteBalance, ), MakeScidRecord(realScidType, &channel.confirmedScid), + tlv.MakePrimitiveRecord(channelMemoType, &memo), ) if err != nil { return err @@ -3872,6 +3883,11 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error { channel.InitialLocalBalance = lnwire.MilliSatoshi(localBalance) channel.InitialRemoteBalance = lnwire.MilliSatoshi(remoteBalance) + // Attach the memo field if non-empty. + if len(memo) > 0 { + channel.Memo = memo + } + channel.Packager = NewChannelPackager(channel.ShortChannelID) // Finally, read the optional shutdown scripts. diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 90a1201cf..916184c6b 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -416,6 +416,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, Db: wallet.Cfg.Database, InitialLocalBalance: ourBalance, InitialRemoteBalance: theirBalance, + Memo: req.Memo, }, pushMSat: req.PushMSat, pendingChanID: req.PendingChanID,