Skip to content

Commit

Permalink
channeldb: add ChannelFlags to OpenChannel struct
Browse files Browse the repository at this point in the history
This commit adds the ChannelFlags field, of type
lnwire.FundingFlags, to the OpenChannel struct,
including serialization for database storage.
This is done to preserve the flags that were
sent during channel opening, currently used
to determine whether a channel should be made
public or not after opening.
  • Loading branch information
halseth authored and Roasbeef committed Dec 18, 2017
1 parent 17d1d5d commit 48e2221
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ type OpenChannel struct {
// for normal transactional use.
NumConfsRequired uint16

// ChannelFlags holds the flags that were sent as part of the
// open_channel message.
ChannelFlags lnwire.FundingFlag

// IdentityPub is the identity public key of the remote node this
// channel has been established with.
IdentityPub *btcec.PublicKey
Expand Down Expand Up @@ -1442,8 +1446,8 @@ func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
channel.ShortChanID, channel.IsPending, channel.IsInitiator,
channel.FundingBroadcastHeight, channel.NumConfsRequired,
channel.IdentityPub, channel.Capacity, channel.TotalMSatSent,
channel.TotalMSatReceived,
channel.ChannelFlags, channel.IdentityPub, channel.Capacity,
channel.TotalMSatSent, channel.TotalMSatReceived,
); err != nil {
return err
}
Expand Down Expand Up @@ -1542,8 +1546,8 @@ func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
&channel.ShortChanID, &channel.IsPending, &channel.IsInitiator,
&channel.FundingBroadcastHeight, &channel.NumConfsRequired,
&channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent,
&channel.TotalMSatReceived,
&channel.ChannelFlags, &channel.IdentityPub, &channel.Capacity,
&channel.TotalMSatSent, &channel.TotalMSatReceived,
); err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions channeldb/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func writeElement(w io.Writer, element interface{}) error {
if err := binary.Write(w, byteOrder, e); err != nil {
return err
}
case lnwire.FundingFlag:
if err := binary.Write(w, byteOrder, e); err != nil {
return err
}

default:
return fmt.Errorf("Unknown type in writeElement: %T", e)
Expand Down Expand Up @@ -287,6 +291,10 @@ func readElement(r io.Reader, element interface{}) error {
if err := binary.Read(r, byteOrder, e); err != nil {
return err
}
case *lnwire.FundingFlag:
if err := binary.Read(r, byteOrder, e); err != nil {
return err
}

default:
return fmt.Errorf("Unknown type in readElement: %T", e)
Expand Down

0 comments on commit 48e2221

Please sign in to comment.