channeldb: BigSize migration, store zero-conf, scid-alias bits

This introduces a BigSize migration that is used to expand the width
of the ChannelStatus and ChannelType fields. Three channel "types"
are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit.
ScidAliasChanBit denotes that the scid-alias channel type was
negotiated for the channel. ScidAliasFeatureBit denotes that the
scid-alias feature bit was negotiated during the *lifetime* of the
channel. Several helper functions on the OpenChannel struct are
exposed to aid callers from different packages.

The RefreshShortChanID has been renamed to Refresh.

A new function BroadcastHeight is used to guard access to the
mutable FundingBroadcastHeight member. This prevents data races.
This commit is contained in:
eugene committed 2022-07-07 17:10:27 -04:00
1 parent 3ff8eb899c
commit c9f5912601
13 files changed
+503 -28

No files matched your search

+15 -4
View File
@@ -14,6 +14,7 @@ import (
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/shachain"
"github.com/lightningnetwork/lnd/tlv"
)
// writeOutpoint writes an outpoint to the passed writer using the minimal
@@ -85,7 +86,8 @@ func WriteElement(w io.Writer, element interface{}) error {
return binary.Write(w, byteOrder, false)
case ChannelType:
if err := binary.Write(w, byteOrder, e); err != nil {
var buf [8]byte
if err := tlv.WriteVarInt(w, uint64(e), &buf); err != nil {
return err
}
@@ -194,7 +196,8 @@ func WriteElement(w io.Writer, element interface{}) error {
}
case ChannelStatus:
if err := binary.Write(w, byteOrder, e); err != nil {
var buf [8]byte
if err := tlv.WriteVarInt(w, uint64(e), &buf); err != nil {
return err
}
@@ -270,10 +273,14 @@ func ReadElement(r io.Reader, element interface{}) error {
}
case *ChannelType:
if err := binary.Read(r, byteOrder, e); err != nil {
var buf [8]byte
ctype, err := tlv.ReadVarInt(r, &buf)
if err != nil {
return err
}
*e = ChannelType(ctype)
case *chainhash.Hash:
if _, err := io.ReadFull(r, e[:]); err != nil {
return err
@@ -419,10 +426,14 @@ func ReadElement(r io.Reader, element interface{}) error {
*e = msg
case *ChannelStatus:
if err := binary.Read(r, byteOrder, e); err != nil {
var buf [8]byte
status, err := tlv.ReadVarInt(r, &buf)
if err != nil {
return err
}
*e = ChannelStatus(status)
case *ClosureType:
if err := binary.Read(r, byteOrder, e); err != nil {
return err