mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
channeldb: persist channel Memo field and read it when fetching
We add a Memo field to the OpenChannel DB struct. We also persist it using a tlv record. We then pass the Memo value from the InitFundingReserveMsg when creating a new reservation for the channel. Finally, we also read Memo field when fetching channel from DB.
This commit is contained in:
parent
db44924c5a
commit
396a4cb6c4
@ -220,6 +220,10 @@ const (
|
|||||||
// A tlv type definition used to serialize and deserialize the
|
// A tlv type definition used to serialize and deserialize the
|
||||||
// confirmed ShortChannelID for a zero-conf channel.
|
// confirmed ShortChannelID for a zero-conf channel.
|
||||||
realScidType tlv.Type = 4
|
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
|
// 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.
|
// default ShortChannelID. This is only set for zero-conf channels.
|
||||||
confirmedScid lnwire.ShortChannelID
|
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
|
// TODO(roasbeef): eww
|
||||||
Db *ChannelStateDB
|
Db *ChannelStateDB
|
||||||
|
|
||||||
@ -3642,6 +3650,7 @@ func putChanInfo(chanBucket kvdb.RwBucket, channel *OpenChannel) error {
|
|||||||
initialRemoteBalanceType, &remoteBalance,
|
initialRemoteBalanceType, &remoteBalance,
|
||||||
),
|
),
|
||||||
MakeScidRecord(realScidType, &channel.confirmedScid),
|
MakeScidRecord(realScidType, &channel.confirmedScid),
|
||||||
|
tlv.MakePrimitiveRecord(channelMemoType, &channel.Memo),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 (
|
var (
|
||||||
localBalance uint64
|
localBalance uint64
|
||||||
remoteBalance uint64
|
remoteBalance uint64
|
||||||
|
memo []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create the tlv stream.
|
// Create the tlv stream.
|
||||||
@ -3859,6 +3869,7 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
|
|||||||
initialRemoteBalanceType, &remoteBalance,
|
initialRemoteBalanceType, &remoteBalance,
|
||||||
),
|
),
|
||||||
MakeScidRecord(realScidType, &channel.confirmedScid),
|
MakeScidRecord(realScidType, &channel.confirmedScid),
|
||||||
|
tlv.MakePrimitiveRecord(channelMemoType, &memo),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -3872,6 +3883,11 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
|
|||||||
channel.InitialLocalBalance = lnwire.MilliSatoshi(localBalance)
|
channel.InitialLocalBalance = lnwire.MilliSatoshi(localBalance)
|
||||||
channel.InitialRemoteBalance = lnwire.MilliSatoshi(remoteBalance)
|
channel.InitialRemoteBalance = lnwire.MilliSatoshi(remoteBalance)
|
||||||
|
|
||||||
|
// Attach the memo field if non-empty.
|
||||||
|
if len(memo) > 0 {
|
||||||
|
channel.Memo = memo
|
||||||
|
}
|
||||||
|
|
||||||
channel.Packager = NewChannelPackager(channel.ShortChannelID)
|
channel.Packager = NewChannelPackager(channel.ShortChannelID)
|
||||||
|
|
||||||
// Finally, read the optional shutdown scripts.
|
// Finally, read the optional shutdown scripts.
|
||||||
|
@ -416,6 +416,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
|||||||
Db: wallet.Cfg.Database,
|
Db: wallet.Cfg.Database,
|
||||||
InitialLocalBalance: ourBalance,
|
InitialLocalBalance: ourBalance,
|
||||||
InitialRemoteBalance: theirBalance,
|
InitialRemoteBalance: theirBalance,
|
||||||
|
Memo: req.Memo,
|
||||||
},
|
},
|
||||||
pushMSat: req.PushMSat,
|
pushMSat: req.PushMSat,
|
||||||
pendingChanID: req.PendingChanID,
|
pendingChanID: req.PendingChanID,
|
||||||
|
Loading…
Reference in New Issue
Block a user