lnwire: channels are now identified by outpoint

This commit modifies most of the wire messages to uniquely identify any
*active* channels by their funding output. This allows the wire
protocol to support funding transactions which open several channels in
parallel.

Any pending channels created by partial completion of the funding
workflow are to be identified by a uint64 initialized by both sides as
follows: the initiator of the connection starts from 0, while the
listening node starts from (1 << 63). These pending channel identifiers
are expected to be monotonically increasing with each new funding
workflow between two nodes. This identifier is volatile w.r.t to each
connection initiation.
This commit is contained in:
Olaoluwa Osuntokun
2016-06-20 21:55:07 -07:00
parent 7b7d572984
commit 6c7880ef76
25 changed files with 236 additions and 202 deletions

View File

@@ -3,6 +3,8 @@ package lnwire
import (
"fmt"
"io"
"github.com/roasbeef/btcd/wire"
)
// HTLCAddRequest is the message sent by Alice to Bob when she wishes to add an
@@ -13,9 +15,9 @@ import (
// A subsequent CommitSignature message will move the pending HTLC to the newly
// created commitment transaction, marking them as "staged".
type HTLCAddRequest struct {
// ChannelID is the particular active channel that this HTLCAddRequest
// ChannelPoint is the particular active channel that this HTLCAddRequest
// is binded to.
ChannelID uint64
ChannelPoint *wire.OutPoint
// Expiry is the number of blocks after which this HTLC should expire.
// It is the receiver's duty to ensure that the outgoing HTLC has a
@@ -72,14 +74,14 @@ var _ Message = (*HTLCAddRequest)(nil)
//
// This is part of the lnwire.Message interface.
func (c *HTLCAddRequest) Decode(r io.Reader, pver uint32) error {
// ChannelID(8)
// ChannelPoint(8)
// Expiry(4)
// Amount(4)
// ContractType(1)
// RedemptionHashes (numOfHashes * 20 + numOfHashes)
// OnionBlog
err := readElements(r,
&c.ChannelID,
&c.ChannelPoint,
&c.Expiry,
&c.Amount,
&c.ContractType,
@@ -99,7 +101,7 @@ func (c *HTLCAddRequest) Decode(r io.Reader, pver uint32) error {
// This is part of the lnwire.Message interface.
func (c *HTLCAddRequest) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.ChannelPoint,
c.Expiry,
c.Amount,
c.ContractType,
@@ -156,7 +158,7 @@ func (c *HTLCAddRequest) String() string {
}
return fmt.Sprintf("\n--- Begin HTLCAddRequest ---\n") +
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
fmt.Sprintf("ChannelPoint:\t%d\n", c.ChannelPoint) +
fmt.Sprintf("Expiry:\t\t%d\n", c.Expiry) +
fmt.Sprintf("Amount\t\t%d\n", c.Amount) +
fmt.Sprintf("ContractType:\t%d (%b)\n", c.ContractType, c.ContractType) +