lnwire: replace ChannelPoint with ChannelID, use new PendingChanID
This commit is contained in:
parent
8147151fbf
commit
c06894a2e6
@ -1804,7 +1804,7 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck, err
|
|||||||
// ACK'd index within the log to right at this set of pending changes.
|
// ACK'd index within the log to right at this set of pending changes.
|
||||||
lc.remoteUpdateLog.ackTransition()
|
lc.remoteUpdateLog.ackTransition()
|
||||||
|
|
||||||
revocationMsg.ChannelPoint = *lc.channelState.ChanID
|
revocationMsg.ChanID = lnwire.NewChanIDFromOutPoint(lc.channelState.ChanID)
|
||||||
return revocationMsg, nil
|
return revocationMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1954,7 +1954,7 @@ func (lc *LightningChannel) ExtendRevocationWindow() (*lnwire.RevokeAndAck, erro
|
|||||||
// InitialRevocationWindow
|
// InitialRevocationWindow
|
||||||
|
|
||||||
revMsg := &lnwire.RevokeAndAck{}
|
revMsg := &lnwire.RevokeAndAck{}
|
||||||
revMsg.ChannelPoint = *lc.channelState.ChanID
|
revMsg.ChanID = lnwire.NewChanIDFromOutPoint(lc.channelState.ChanID)
|
||||||
|
|
||||||
nextHeight := lc.revocationWindowEdge + 1
|
nextHeight := lc.revocationWindowEdge + 1
|
||||||
revocation, err := lc.channelState.RevocationProducer.AtIndex(nextHeight)
|
revocation, err := lc.channelState.RevocationProducer.AtIndex(nextHeight)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AnnounceSignatures this is a direct message between two endpoints of a
|
// AnnounceSignatures this is a direct message between two endpoints of a
|
||||||
@ -16,7 +15,7 @@ type AnnounceSignatures struct {
|
|||||||
// Channel id is better for users and debugging and short channel id is
|
// Channel id is better for users and debugging and short channel id is
|
||||||
// used for quick test on existence of the particular utxo inside the
|
// used for quick test on existence of the particular utxo inside the
|
||||||
// block chain, because it contains information about block.
|
// block chain, because it contains information about block.
|
||||||
ChannelID wire.OutPoint
|
ChannelID ChannelID
|
||||||
|
|
||||||
// ShortChannelID is the unique description of the funding
|
// ShortChannelID is the unique description of the funding
|
||||||
// transaction. It is constructed with the most significant 3 bytes
|
// transaction. It is constructed with the most significant 3 bytes
|
||||||
|
@ -13,7 +13,7 @@ func TestChannelAnnoucementEncodeDecode(t *testing.T) {
|
|||||||
ca := &ChannelAnnouncement{
|
ca := &ChannelAnnouncement{
|
||||||
NodeSig1: someSig,
|
NodeSig1: someSig,
|
||||||
NodeSig2: someSig,
|
NodeSig2: someSig,
|
||||||
ShortChannelID: someChannelID,
|
ShortChannelID: someShortChannelID,
|
||||||
BitcoinSig1: someSig,
|
BitcoinSig1: someSig,
|
||||||
BitcoinSig2: someSig,
|
BitcoinSig2: someSig,
|
||||||
NodeID1: pubKey,
|
NodeID1: pubKey,
|
||||||
@ -65,7 +65,7 @@ func TestChannelAnnoucementValidation(t *testing.T) {
|
|||||||
secondBitcoinSig, _ := secondBitcoinPrivKey.Sign(hash)
|
secondBitcoinSig, _ := secondBitcoinPrivKey.Sign(hash)
|
||||||
|
|
||||||
ca := &ChannelAnnouncement{
|
ca := &ChannelAnnouncement{
|
||||||
ShortChannelID: someChannelID,
|
ShortChannelID: someShortChannelID,
|
||||||
BitcoinSig1: firstBitcoinSig,
|
BitcoinSig1: firstBitcoinSig,
|
||||||
BitcoinSig2: secondBitcoinSig,
|
BitcoinSig2: secondBitcoinSig,
|
||||||
NodeID1: firstNodePubKey,
|
NodeID1: firstNodePubKey,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
func TestChannelUpdateAnnouncementEncodeDecode(t *testing.T) {
|
func TestChannelUpdateAnnouncementEncodeDecode(t *testing.T) {
|
||||||
cua := &ChannelUpdateAnnouncement{
|
cua := &ChannelUpdateAnnouncement{
|
||||||
Signature: someSig,
|
Signature: someSig,
|
||||||
ShortChannelID: someChannelID,
|
ShortChannelID: someShortChannelID,
|
||||||
Timestamp: maxUint32,
|
Timestamp: maxUint32,
|
||||||
Flags: maxUint16,
|
Flags: maxUint16,
|
||||||
TimeLockDelta: maxUint16,
|
TimeLockDelta: maxUint16,
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
|
|
||||||
"io"
|
"io"
|
||||||
@ -21,8 +20,8 @@ import (
|
|||||||
// both sides are able to arrive at an identical closure transaction as they
|
// both sides are able to arrive at an identical closure transaction as they
|
||||||
// know the order of the inputs/outputs.
|
// know the order of the inputs/outputs.
|
||||||
type CloseRequest struct {
|
type CloseRequest struct {
|
||||||
// ChannelPoint serves to identify which channel is to be closed.
|
// ChanID serves to identify which channel is to be closed.
|
||||||
ChannelPoint wire.OutPoint
|
ChanID ChannelID
|
||||||
|
|
||||||
// RequesterCloseSig is the signature of the requester for the fully
|
// RequesterCloseSig is the signature of the requester for the fully
|
||||||
// assembled closing transaction.
|
// assembled closing transaction.
|
||||||
@ -36,10 +35,10 @@ type CloseRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCloseRequest creates a new CloseRequest.
|
// NewCloseRequest creates a new CloseRequest.
|
||||||
func NewCloseRequest(cp wire.OutPoint, sig *btcec.Signature) *CloseRequest {
|
func NewCloseRequest(cid ChannelID, sig *btcec.Signature) *CloseRequest {
|
||||||
// TODO(roasbeef): update once fees aren't hardcoded
|
// TODO(roasbeef): update once fees aren't hardcoded
|
||||||
return &CloseRequest{
|
return &CloseRequest{
|
||||||
ChannelPoint: cp,
|
ChanID: cid,
|
||||||
RequesterCloseSig: sig,
|
RequesterCloseSig: sig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,12 +52,8 @@ var _ Message = (*CloseRequest)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *CloseRequest) Decode(r io.Reader, pver uint32) error {
|
func (c *CloseRequest) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelPoint (8)
|
|
||||||
// RequesterCloseSig (73)
|
|
||||||
// First byte length then sig
|
|
||||||
// Fee (8)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelPoint,
|
&c.ChanID,
|
||||||
&c.RequesterCloseSig,
|
&c.RequesterCloseSig,
|
||||||
&c.Fee)
|
&c.Fee)
|
||||||
}
|
}
|
||||||
@ -68,11 +63,8 @@ func (c *CloseRequest) Decode(r io.Reader, pver uint32) error {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *CloseRequest) Encode(w io.Writer, pver uint32) error {
|
func (c *CloseRequest) Encode(w io.Writer, pver uint32) error {
|
||||||
// ChannelID
|
|
||||||
// RequesterCloseSig
|
|
||||||
// Fee
|
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelPoint,
|
c.ChanID,
|
||||||
c.RequesterCloseSig,
|
c.RequesterCloseSig,
|
||||||
c.Fee)
|
c.Fee)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommitSig is sent by either side to stage any pending HTLC's in the
|
// CommitSig is sent by either side to stage any pending HTLC's in the
|
||||||
@ -15,9 +14,9 @@ import (
|
|||||||
// order to batch add several HTLC's with a single signature covering all
|
// order to batch add several HTLC's with a single signature covering all
|
||||||
// implicitly accepted HTLC's.
|
// implicitly accepted HTLC's.
|
||||||
type CommitSig struct {
|
type CommitSig struct {
|
||||||
// ChannelPoint uniquely identifies to which currently active channel
|
// ChanID uniquely identifies to which currently active channel this
|
||||||
// this CommitSig applies to.
|
// CommitSig applies to.
|
||||||
ChannelPoint wire.OutPoint
|
ChanID ChannelID
|
||||||
|
|
||||||
// CommitSig is Alice's signature for Bob's new commitment transaction.
|
// CommitSig is Alice's signature for Bob's new commitment transaction.
|
||||||
// Alice is able to send this signature without requesting any
|
// Alice is able to send this signature without requesting any
|
||||||
@ -44,10 +43,8 @@ var _ Message = (*CommitSig)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
|
func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelPoint(8)
|
|
||||||
// RequesterCommitSig(73max+2)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelPoint,
|
&c.ChanID,
|
||||||
&c.CommitSig,
|
&c.CommitSig,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -58,7 +55,7 @@ func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *CommitSig) Encode(w io.Writer, pver uint32) error {
|
func (c *CommitSig) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelPoint,
|
c.ChanID,
|
||||||
c.CommitSig,
|
c.CommitSig,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -76,8 +73,8 @@ func (c *CommitSig) Command() uint32 {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *CommitSig) MaxPayloadLength(uint32) uint32 {
|
func (c *CommitSig) MaxPayloadLength(uint32) uint32 {
|
||||||
// 36 + 73
|
// 32 + 64
|
||||||
return 109
|
return 96
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs any necessary sanity checks to ensure all fields present
|
// Validate performs any necessary sanity checks to ensure all fields present
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
func TestCommitSigEncodeDecode(t *testing.T) {
|
func TestCommitSigEncodeDecode(t *testing.T) {
|
||||||
commitSignature := &CommitSig{
|
commitSignature := &CommitSig{
|
||||||
ChannelPoint: *outpoint1,
|
ChanID: ChannelID(revHash),
|
||||||
CommitSig: commitSig,
|
CommitSig: commitSig,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next encode the CS message into an empty bytes buffer.
|
// Next encode the CS message into an empty bytes buffer.
|
||||||
|
@ -5,53 +5,44 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FundingLocked is the message that both parties to a new channel creation
|
// FundingLocked is the message that both parties to a new channel creation
|
||||||
// send once they have observed the funding transaction being confirmed on
|
// send once they have observed the funding transaction being confirmed on the
|
||||||
// the blockchain. FundingLocked contains the signatures necessary for the
|
// blockchain. FundingLocked contains the signatures necessary for the channel
|
||||||
// channel participants to advertise the existence of the channel to the
|
// participants to advertise the existence of the channel to the rest of the
|
||||||
// rest of the network.
|
// network.
|
||||||
type FundingLocked struct {
|
type FundingLocked struct {
|
||||||
// ChannelOutpoint is the outpoint of the channel's funding
|
// ChanID is the outpoint of the channel's funding transaction. This
|
||||||
// transaction. This can be used to query for the channel in the
|
// can be used to query for the channel in the database.
|
||||||
// database.
|
ChanID ChannelID
|
||||||
ChannelOutpoint wire.OutPoint
|
|
||||||
|
|
||||||
// ChannelId serves to uniquely identify the channel created by the
|
// NextPerCommitmentPoint is the secret that can be used to revoke the
|
||||||
// current channel funding workflow.
|
// next commitment transaction for the channel.
|
||||||
ChannelID ShortChannelID
|
|
||||||
|
|
||||||
// NextPerCommitmentPoint is the secret that can be used to revoke
|
|
||||||
// the next commitment transaction for the channel.
|
|
||||||
NextPerCommitmentPoint *btcec.PublicKey
|
NextPerCommitmentPoint *btcec.PublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFundingLocked creates a new FundingLocked message, populating it with
|
// NewFundingLocked creates a new FundingLocked message, populating it with the
|
||||||
// the necessary IDs and revocation secret..
|
// necessary IDs and revocation secret.
|
||||||
func NewFundingLocked(op wire.OutPoint, cid ShortChannelID,
|
func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *FundingLocked {
|
||||||
npcp *btcec.PublicKey) *FundingLocked {
|
|
||||||
return &FundingLocked{
|
return &FundingLocked{
|
||||||
ChannelOutpoint: op,
|
ChanID: cid,
|
||||||
ChannelID: cid,
|
|
||||||
NextPerCommitmentPoint: npcp,
|
NextPerCommitmentPoint: npcp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compile time check to ensure FundingLocked implements the
|
// A compile time check to ensure FundingLocked implements the lnwire.Message
|
||||||
// lnwire.Message interface.
|
// interface.
|
||||||
var _ Message = (*FundingLocked)(nil)
|
var _ Message = (*FundingLocked)(nil)
|
||||||
|
|
||||||
// Decode deserializes the serialized FundingLocked message stored in the passed
|
// Decode deserializes the serialized FundingLocked message stored in the
|
||||||
// io.Reader into the target FundingLocked using the deserialization
|
// passed io.Reader into the target FundingLocked using the deserialization
|
||||||
// rules defined by the passed protocol version.
|
// rules defined by the passed protocol version.
|
||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *FundingLocked) Decode(r io.Reader, pver uint32) error {
|
func (c *FundingLocked) Decode(r io.Reader, pver uint32) error {
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelOutpoint,
|
&c.ChanID,
|
||||||
&c.ChannelID,
|
|
||||||
&c.NextPerCommitmentPoint)
|
&c.NextPerCommitmentPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +53,7 @@ func (c *FundingLocked) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *FundingLocked) Encode(w io.Writer, pver uint32) error {
|
func (c *FundingLocked) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelOutpoint,
|
c.ChanID,
|
||||||
c.ChannelID,
|
|
||||||
c.NextPerCommitmentPoint)
|
c.NextPerCommitmentPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,15 +73,13 @@ func (c *FundingLocked) Command() uint32 {
|
|||||||
func (c *FundingLocked) MaxPayloadLength(uint32) uint32 {
|
func (c *FundingLocked) MaxPayloadLength(uint32) uint32 {
|
||||||
var length uint32
|
var length uint32
|
||||||
|
|
||||||
// ChannelOutpoint - 36 bytes
|
// ChanID - 32 bytes
|
||||||
length += 36
|
length += 32
|
||||||
|
|
||||||
// ChannelID - 8 bytes
|
|
||||||
length += 8
|
|
||||||
|
|
||||||
// NextPerCommitmentPoint - 33 bytes
|
// NextPerCommitmentPoint - 33 bytes
|
||||||
length += 33
|
length += 33
|
||||||
|
|
||||||
|
// 65 bytes
|
||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestFundingLockedWire(t *testing.T) {
|
func TestFundingLockedWire(t *testing.T) {
|
||||||
// First create a new FundingLocked message.
|
// First create a new FundingLocked message.
|
||||||
fl := NewFundingLocked(*outpoint1, someChannelID, pubKey)
|
fl := NewFundingLocked(ChannelID(revHash), pubKey)
|
||||||
|
|
||||||
// Next encode the FundingLocked message into an empty bytes buffer.
|
// Next encode the FundingLocked message into an empty bytes buffer.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
@ -250,26 +250,29 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case wire.OutPoint:
|
case wire.OutPoint:
|
||||||
// TODO(roasbeef): consolidate with above
|
|
||||||
// First write out the previous txid.
|
|
||||||
var h [32]byte
|
var h [32]byte
|
||||||
copy(h[:], e.Hash[:])
|
copy(h[:], e.Hash[:])
|
||||||
if _, err := w.Write(h[:]); err != nil {
|
if _, err := w.Write(h[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then the exact index of this output.
|
var idx [2]byte
|
||||||
var idx [4]byte
|
binary.BigEndian.PutUint16(idx[:], uint16(e.Index))
|
||||||
binary.BigEndian.PutUint32(idx[:], e.Index)
|
|
||||||
if _, err := w.Write(idx[:]); err != nil {
|
if _, err := w.Write(idx[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO(roasbeef): *MsgTx
|
|
||||||
case int64, float64:
|
case int64, float64:
|
||||||
err := binary.Write(w, binary.BigEndian, e)
|
err := binary.Write(w, binary.BigEndian, e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ChannelID:
|
||||||
|
if _, err := w.Write(e[:]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
case ShortChannelID:
|
case ShortChannelID:
|
||||||
// Check that field fit in 3 bytes and write the blockHeight
|
// Check that field fit in 3 bytes and write the blockHeight
|
||||||
if e.BlockHeight > ((1 << 24) - 1) {
|
if e.BlockHeight > ((1 << 24) - 1) {
|
||||||
@ -573,7 +576,6 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
(*e).PreviousOutPoint.Index = binary.BigEndian.Uint32(idxBytes[:])
|
(*e).PreviousOutPoint.Index = binary.BigEndian.Uint32(idxBytes[:])
|
||||||
return nil
|
return nil
|
||||||
case *wire.OutPoint:
|
case *wire.OutPoint:
|
||||||
// TODO(roasbeef): consolidate with above
|
|
||||||
var h [32]byte
|
var h [32]byte
|
||||||
if _, err = io.ReadFull(r, h[:]); err != nil {
|
if _, err = io.ReadFull(r, h[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -582,20 +584,29 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Index
|
|
||||||
var idxBytes [4]byte
|
var idxBytes [2]byte
|
||||||
_, err = io.ReadFull(r, idxBytes[:])
|
_, err = io.ReadFull(r, idxBytes[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
index := binary.BigEndian.Uint32(idxBytes[:])
|
index := binary.BigEndian.Uint16(idxBytes[:])
|
||||||
|
|
||||||
*e = wire.OutPoint{Hash: *hash, Index: index}
|
*e = wire.OutPoint{
|
||||||
|
Hash: *hash,
|
||||||
|
Index: uint32(index),
|
||||||
|
}
|
||||||
case *int64, *float64:
|
case *int64, *float64:
|
||||||
err := binary.Read(r, binary.BigEndian, e)
|
err := binary.Read(r, binary.BigEndian, e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case *ChannelID:
|
||||||
|
if _, err := io.ReadFull(r, e[:]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
case *ShortChannelID:
|
case *ShortChannelID:
|
||||||
var blockHeight [4]byte
|
var blockHeight [4]byte
|
||||||
if _, err = io.ReadFull(r, blockHeight[1:]); err != nil {
|
if _, err = io.ReadFull(r, blockHeight[1:]); err != nil {
|
||||||
|
@ -64,7 +64,7 @@ var (
|
|||||||
maxUint24 uint32 = (1 << 24) - 1
|
maxUint24 uint32 = (1 << 24) - 1
|
||||||
maxUint16 uint16 = (1 << 16) - 1
|
maxUint16 uint16 = (1 << 16) - 1
|
||||||
|
|
||||||
someChannelID = ShortChannelID{
|
someShortChannelID = ShortChannelID{
|
||||||
BlockHeight: maxUint24,
|
BlockHeight: maxUint24,
|
||||||
TxIndex: maxUint24,
|
TxIndex: maxUint24,
|
||||||
TxPosition: maxUint16,
|
TxPosition: maxUint16,
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RevokeAndAck is sent by either side once a CommitSig message has been
|
// RevokeAndAck is sent by either side once a CommitSig message has been
|
||||||
@ -17,9 +16,9 @@ import (
|
|||||||
// Alice to send the next CommitSig message modifying Bob's commitment
|
// Alice to send the next CommitSig message modifying Bob's commitment
|
||||||
// transaction without first asking for a revocation hash initially.
|
// transaction without first asking for a revocation hash initially.
|
||||||
type RevokeAndAck struct {
|
type RevokeAndAck struct {
|
||||||
// ChannelPoint uniquely identifies to which currently active channel
|
// ChanID uniquely identifies to which currently active channel this
|
||||||
// this RevokeAndAck applies to.
|
// RevokeAndAck applies to.
|
||||||
ChannelPoint wire.OutPoint
|
ChanID ChannelID
|
||||||
|
|
||||||
// Revocation is the preimage to the revocation hash of the now prior
|
// Revocation is the preimage to the revocation hash of the now prior
|
||||||
// commitment transaction.
|
// commitment transaction.
|
||||||
@ -58,12 +57,8 @@ var _ Message = (*RevokeAndAck)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
|
func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelPoint (8)
|
|
||||||
// Revocation (32)
|
|
||||||
// NextRevocationKey (33)
|
|
||||||
// NextRevocationHash (32)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelPoint,
|
&c.ChanID,
|
||||||
c.Revocation[:],
|
c.Revocation[:],
|
||||||
&c.NextRevocationKey,
|
&c.NextRevocationKey,
|
||||||
c.NextRevocationHash[:],
|
c.NextRevocationHash[:],
|
||||||
@ -76,7 +71,7 @@ func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error {
|
func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelPoint,
|
c.ChanID,
|
||||||
c.Revocation[:],
|
c.Revocation[:],
|
||||||
c.NextRevocationKey,
|
c.NextRevocationKey,
|
||||||
c.NextRevocationHash[:],
|
c.NextRevocationHash[:],
|
||||||
@ -96,8 +91,8 @@ func (c *RevokeAndAck) Command() uint32 {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *RevokeAndAck) MaxPayloadLength(uint32) uint32 {
|
func (c *RevokeAndAck) MaxPayloadLength(uint32) uint32 {
|
||||||
// 36 + 32 + 33 + 32
|
// 32 + 32 + 33 + 32
|
||||||
return 133
|
return 129
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs any necessary sanity checks to ensure all fields present
|
// Validate performs any necessary sanity checks to ensure all fields present
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestRevokeAndAckEncodeDecode(t *testing.T) {
|
func TestRevokeAndAckEncodeDecode(t *testing.T) {
|
||||||
cr := &RevokeAndAck{
|
cr := &RevokeAndAck{
|
||||||
ChannelPoint: *outpoint1,
|
ChanID: ChannelID(revHash),
|
||||||
Revocation: revHash,
|
Revocation: revHash,
|
||||||
NextRevocationKey: pubKey,
|
NextRevocationKey: pubKey,
|
||||||
NextRevocationHash: revHash,
|
NextRevocationHash: revHash,
|
||||||
|
@ -15,10 +15,9 @@ import (
|
|||||||
// required for him to generate a signature for Alice's version of the
|
// required for him to generate a signature for Alice's version of the
|
||||||
// commitment transaction.
|
// commitment transaction.
|
||||||
type SingleFundingComplete struct {
|
type SingleFundingComplete struct {
|
||||||
// ChannelID serves to uniquely identify the future channel created by
|
// PendingChannelID serves to uniquely identify the future channel
|
||||||
// the initiated single funder workflow.
|
// created by the initiated single funder workflow.
|
||||||
// TODO(roasbeef): change all to PendingChannelID, document schema
|
PendingChannelID [32]byte
|
||||||
ChannelID uint64
|
|
||||||
|
|
||||||
// FundingOutPoint is the outpoint (txid:index) of the funding
|
// FundingOutPoint is the outpoint (txid:index) of the funding
|
||||||
// transaction. With this value, Bob will be able to generate a
|
// transaction. With this value, Bob will be able to generate a
|
||||||
@ -46,12 +45,12 @@ type SingleFundingComplete struct {
|
|||||||
|
|
||||||
// NewSingleFundingComplete creates, and returns a new empty
|
// NewSingleFundingComplete creates, and returns a new empty
|
||||||
// SingleFundingResponse.
|
// SingleFundingResponse.
|
||||||
func NewSingleFundingComplete(chanID uint64, fundingPoint wire.OutPoint,
|
func NewSingleFundingComplete(pChanID [32]byte, fundingPoint wire.OutPoint,
|
||||||
commitSig *btcec.Signature, revokeKey *btcec.PublicKey,
|
commitSig *btcec.Signature, revokeKey *btcec.PublicKey,
|
||||||
obsfucator [6]byte) *SingleFundingComplete {
|
obsfucator [6]byte) *SingleFundingComplete {
|
||||||
|
|
||||||
return &SingleFundingComplete{
|
return &SingleFundingComplete{
|
||||||
ChannelID: chanID,
|
PendingChannelID: pChanID,
|
||||||
FundingOutPoint: fundingPoint,
|
FundingOutPoint: fundingPoint,
|
||||||
CommitSignature: commitSig,
|
CommitSignature: commitSig,
|
||||||
RevocationKey: revokeKey,
|
RevocationKey: revokeKey,
|
||||||
@ -65,12 +64,8 @@ func NewSingleFundingComplete(chanID uint64, fundingPoint wire.OutPoint,
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error {
|
func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelID (8)
|
|
||||||
// FundingOutPoint (36)
|
|
||||||
// CommitmentSignature (73)
|
|
||||||
// RevocationKey (33)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&s.ChannelID,
|
s.PendingChannelID[:],
|
||||||
&s.FundingOutPoint,
|
&s.FundingOutPoint,
|
||||||
&s.CommitSignature,
|
&s.CommitSignature,
|
||||||
&s.RevocationKey,
|
&s.RevocationKey,
|
||||||
@ -83,12 +78,8 @@ func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (s *SingleFundingComplete) Encode(w io.Writer, pver uint32) error {
|
func (s *SingleFundingComplete) Encode(w io.Writer, pver uint32) error {
|
||||||
// ChannelID (8)
|
|
||||||
// FundingOutPoint (36)
|
|
||||||
// Commitment Signature (73)
|
|
||||||
// RevocationKey (33)
|
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
s.ChannelID,
|
s.PendingChannelID[:],
|
||||||
s.FundingOutPoint,
|
s.FundingOutPoint,
|
||||||
s.CommitSignature,
|
s.CommitSignature,
|
||||||
s.RevocationKey,
|
s.RevocationKey,
|
||||||
@ -105,12 +96,12 @@ func (s *SingleFundingComplete) Command() uint32 {
|
|||||||
|
|
||||||
// MaxPayloadLength returns the maximum allowed payload length for a
|
// MaxPayloadLength returns the maximum allowed payload length for a
|
||||||
// SingleFundingComplete. This is calculated by summing the max length of all
|
// SingleFundingComplete. This is calculated by summing the max length of all
|
||||||
// the fields within a SingleFundingComplete. Therefore, the final breakdown
|
// the fields within a SingleFundingComplete.
|
||||||
// is: 8 + 36 + 33 + 73 + 4 = 154
|
|
||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (s *SingleFundingComplete) MaxPayloadLength(uint32) uint32 {
|
func (s *SingleFundingComplete) MaxPayloadLength(uint32) uint32 {
|
||||||
return 154
|
// 32 + 36 + 64 + 33 + 6
|
||||||
|
return 171
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate examines each populated field within the SingleFundingComplete for
|
// Validate examines each populated field within the SingleFundingComplete for
|
||||||
|
@ -11,7 +11,7 @@ func TestSingleFundingCompleteWire(t *testing.T) {
|
|||||||
copy(obsfucator[:], bytes.Repeat([]byte("k"), 6))
|
copy(obsfucator[:], bytes.Repeat([]byte("k"), 6))
|
||||||
|
|
||||||
// First create a new SFC message.
|
// First create a new SFC message.
|
||||||
sfc := NewSingleFundingComplete(22, *outpoint1, commitSig1, pubKey,
|
sfc := NewSingleFundingComplete(revHash, *outpoint1, commitSig1, pubKey,
|
||||||
obsfucator)
|
obsfucator)
|
||||||
|
|
||||||
// Next encode the SFC message into an empty bytes buffer.
|
// Next encode the SFC message into an empty bytes buffer.
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
// to provide the responder with an SPV proof of funding transaction inclusion
|
// to provide the responder with an SPV proof of funding transaction inclusion
|
||||||
// after a sufficient number of confirmations.
|
// after a sufficient number of confirmations.
|
||||||
type SingleFundingRequest struct {
|
type SingleFundingRequest struct {
|
||||||
// ChannelID serves to uniquely identify the future channel created by
|
// PendingChannelID serves to uniquely identify the future channel
|
||||||
// the initiated single funder workflow.
|
// created by the initiated single funder workflow.
|
||||||
ChannelID uint64
|
PendingChannelID [32]byte
|
||||||
|
|
||||||
// ChannelType represents the type of channel this request would like
|
// ChannelType represents the type of channel this request would like
|
||||||
// to open. At this point, the only supported channels are type 0
|
// to open. At this point, the only supported channels are type 0
|
||||||
@ -84,14 +84,14 @@ type SingleFundingRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSingleFundingRequest creates, and returns a new empty SingleFundingRequest.
|
// NewSingleFundingRequest creates, and returns a new empty SingleFundingRequest.
|
||||||
func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
|
func NewSingleFundingRequest(chanID [32]byte, chanType uint8, coinType uint64,
|
||||||
fee btcutil.Amount, amt btcutil.Amount, delay uint32, ck,
|
fee btcutil.Amount, amt btcutil.Amount, delay uint32, ck,
|
||||||
cdp *btcec.PublicKey, deliveryScript PkScript,
|
cdp *btcec.PublicKey, deliveryScript PkScript,
|
||||||
dustLimit btcutil.Amount, pushSat btcutil.Amount,
|
dustLimit btcutil.Amount, pushSat btcutil.Amount,
|
||||||
confDepth uint32) *SingleFundingRequest {
|
confDepth uint32) *SingleFundingRequest {
|
||||||
|
|
||||||
return &SingleFundingRequest{
|
return &SingleFundingRequest{
|
||||||
ChannelID: chanID,
|
PendingChannelID: chanID,
|
||||||
ChannelType: chanType,
|
ChannelType: chanType,
|
||||||
CoinType: coinType,
|
CoinType: coinType,
|
||||||
FeePerKb: fee,
|
FeePerKb: fee,
|
||||||
@ -113,7 +113,7 @@ func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
|
func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelID,
|
c.PendingChannelID[:],
|
||||||
&c.ChannelType,
|
&c.ChannelType,
|
||||||
&c.CoinType,
|
&c.CoinType,
|
||||||
&c.FeePerKb,
|
&c.FeePerKb,
|
||||||
@ -134,7 +134,7 @@ func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error {
|
func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelID,
|
c.PendingChannelID[:],
|
||||||
c.ChannelType,
|
c.ChannelType,
|
||||||
c.CoinType,
|
c.CoinType,
|
||||||
c.FeePerKb,
|
c.FeePerKb,
|
||||||
@ -165,8 +165,8 @@ func (c *SingleFundingRequest) Command() uint32 {
|
|||||||
func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 {
|
func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 {
|
||||||
var length uint32
|
var length uint32
|
||||||
|
|
||||||
// ChannelID - 8 bytes
|
// PendingChannelID - 32 bytes
|
||||||
length += 8
|
length += 32
|
||||||
|
|
||||||
// ChannelType - 1 byte
|
// ChannelType - 1 byte
|
||||||
length++
|
length++
|
||||||
@ -224,17 +224,6 @@ func (c *SingleFundingRequest) Validate() error {
|
|||||||
" CSV delay")
|
" CSV delay")
|
||||||
}
|
}
|
||||||
|
|
||||||
// The channel derivation point must be non-nil, and have an odd
|
|
||||||
// y-coordinate.
|
|
||||||
if c.ChannelDerivationPoint == nil {
|
|
||||||
return fmt.Errorf("the channel derivation point must be " +
|
|
||||||
"non-nil")
|
|
||||||
}
|
|
||||||
//if c.ChannelDerivationPoint.Y.Bit(0) != 1 {
|
|
||||||
//return fmt.Errorf("The channel derivation point must have an odd " +
|
|
||||||
//"y-coordinate")
|
|
||||||
//}
|
|
||||||
|
|
||||||
// The delivery pkScript must be amongst the supported script
|
// The delivery pkScript must be amongst the supported script
|
||||||
// templates.
|
// templates.
|
||||||
if !isValidPkScript(c.DeliveryPkScript) {
|
if !isValidPkScript(c.DeliveryPkScript) {
|
||||||
|
@ -10,7 +10,7 @@ func TestSingleFundingRequestWire(t *testing.T) {
|
|||||||
// First create a new SFR message.
|
// First create a new SFR message.
|
||||||
cdp := pubKey
|
cdp := pubKey
|
||||||
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
|
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
|
||||||
sfr := NewSingleFundingRequest(20, 21, 22, 23, 5, 5, cdp, cdp,
|
sfr := NewSingleFundingRequest(revHash, 21, 22, 23, 5, 5, cdp, cdp,
|
||||||
delivery, 540, 10000, 6)
|
delivery, 540, 10000, 6)
|
||||||
|
|
||||||
// Next encode the SFR message into an empty bytes buffer.
|
// Next encode the SFR message into an empty bytes buffer.
|
||||||
|
@ -10,12 +10,12 @@ import (
|
|||||||
|
|
||||||
// SingleFundingResponse is the message Bob sends to Alice after she initiates
|
// SingleFundingResponse is the message Bob sends to Alice after she initiates
|
||||||
// the single funder channel workflow via a SingleFundingRequest message. Once
|
// the single funder channel workflow via a SingleFundingRequest message. Once
|
||||||
// Alice receives Bob's reponse, then she has all the items neccessary to
|
// Alice receives Bob's response, then she has all the items necessary to
|
||||||
// construct the funding transaction, and both commitment transactions.
|
// construct the funding transaction, and both commitment transactions.
|
||||||
type SingleFundingResponse struct {
|
type SingleFundingResponse struct {
|
||||||
// ChannelID serves to uniquely identify the future channel created by
|
// PendingChannelID serves to uniquely identify the future channel
|
||||||
// the initiated single funder workflow.
|
// created by the initiated single funder workflow.
|
||||||
ChannelID uint64
|
PendingChannelID [32]byte
|
||||||
|
|
||||||
// ChannelDerivationPoint is an secp256k1 point which will be used to
|
// ChannelDerivationPoint is an secp256k1 point which will be used to
|
||||||
// derive the public key the responder will use for the half of the
|
// derive the public key the responder will use for the half of the
|
||||||
@ -60,12 +60,12 @@ type SingleFundingResponse struct {
|
|||||||
|
|
||||||
// NewSingleFundingResponse creates, and returns a new empty
|
// NewSingleFundingResponse creates, and returns a new empty
|
||||||
// SingleFundingResponse.
|
// SingleFundingResponse.
|
||||||
func NewSingleFundingResponse(chanID uint64, rk, ck, cdp *btcec.PublicKey,
|
func NewSingleFundingResponse(chanID [32]byte, rk, ck, cdp *btcec.PublicKey,
|
||||||
delay uint32, deliveryScript PkScript,
|
delay uint32, deliveryScript PkScript,
|
||||||
dustLimit btcutil.Amount, confDepth uint32) *SingleFundingResponse {
|
dustLimit btcutil.Amount, confDepth uint32) *SingleFundingResponse {
|
||||||
|
|
||||||
return &SingleFundingResponse{
|
return &SingleFundingResponse{
|
||||||
ChannelID: chanID,
|
PendingChannelID: chanID,
|
||||||
ChannelDerivationPoint: cdp,
|
ChannelDerivationPoint: cdp,
|
||||||
CommitmentKey: ck,
|
CommitmentKey: ck,
|
||||||
RevocationKey: rk,
|
RevocationKey: rk,
|
||||||
@ -86,16 +86,8 @@ var _ Message = (*SingleFundingResponse)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error {
|
func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelID (8)
|
|
||||||
// ChannelDerivationPoint (33)
|
|
||||||
// CommitmentKey (33)
|
|
||||||
// RevocationKey (33)
|
|
||||||
// CsvDelay (4)
|
|
||||||
// DeliveryPkScript (final delivery)
|
|
||||||
// DustLimit (8)
|
|
||||||
// ConfirmationDepth (4)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelID,
|
c.PendingChannelID[:],
|
||||||
&c.ChannelDerivationPoint,
|
&c.ChannelDerivationPoint,
|
||||||
&c.CommitmentKey,
|
&c.CommitmentKey,
|
||||||
&c.RevocationKey,
|
&c.RevocationKey,
|
||||||
@ -112,7 +104,7 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error {
|
func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelID,
|
c.PendingChannelID[:],
|
||||||
c.ChannelDerivationPoint,
|
c.ChannelDerivationPoint,
|
||||||
c.CommitmentKey,
|
c.CommitmentKey,
|
||||||
c.RevocationKey,
|
c.RevocationKey,
|
||||||
@ -139,8 +131,8 @@ func (c *SingleFundingResponse) Command() uint32 {
|
|||||||
func (c *SingleFundingResponse) MaxPayloadLength(uint32) uint32 {
|
func (c *SingleFundingResponse) MaxPayloadLength(uint32) uint32 {
|
||||||
var length uint32
|
var length uint32
|
||||||
|
|
||||||
// ChannelID - 8 bytes
|
// PendingChannelID - 32 bytes
|
||||||
length += 8
|
length += 32
|
||||||
|
|
||||||
// ChannelDerivationPoint - 33 bytes
|
// ChannelDerivationPoint - 33 bytes
|
||||||
length += 33
|
length += 33
|
||||||
@ -177,10 +169,6 @@ func (c *SingleFundingResponse) Validate() error {
|
|||||||
if c.ChannelDerivationPoint == nil {
|
if c.ChannelDerivationPoint == nil {
|
||||||
return fmt.Errorf("The channel derivation point must be non-nil")
|
return fmt.Errorf("The channel derivation point must be non-nil")
|
||||||
}
|
}
|
||||||
//if c.ChannelDerivationPoint.Y.Bit(0) != 1 {
|
|
||||||
// return fmt.Errorf("The channel derivation point must have an odd " +
|
|
||||||
// "y-coordinate")
|
|
||||||
//}
|
|
||||||
|
|
||||||
// The delivery pkScript must be amongst the supported script
|
// The delivery pkScript must be amongst the supported script
|
||||||
// templates.
|
// templates.
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
func TestSingleFundingResponseWire(t *testing.T) {
|
func TestSingleFundingResponseWire(t *testing.T) {
|
||||||
// First create a new SFR message.
|
// First create a new SFR message.
|
||||||
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
|
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
|
||||||
sfr := NewSingleFundingResponse(22, pubKey, pubKey, pubKey, 5,
|
sfr := NewSingleFundingResponse(revHash, pubKey, pubKey, pubKey, 5,
|
||||||
delivery, 540, 4)
|
delivery, 540, 4)
|
||||||
|
|
||||||
// Next encode the SFR message into an empty bytes buffer.
|
// Next encode the SFR message into an empty bytes buffer.
|
||||||
|
@ -12,9 +12,9 @@ import (
|
|||||||
// message is received and processed by Alice, she is free to broadcast the
|
// message is received and processed by Alice, she is free to broadcast the
|
||||||
// funding transaction.
|
// funding transaction.
|
||||||
type SingleFundingSignComplete struct {
|
type SingleFundingSignComplete struct {
|
||||||
// ChannelID serves to uniquely identify the future channel created by
|
// PendingChannelID serves to uniquely identify the future channel
|
||||||
// the initiated single funder workflow.
|
// created by the initiated single funder workflow.
|
||||||
ChannelID uint64
|
PendingChannelID [32]byte
|
||||||
|
|
||||||
// CommitSignature is Bobs's signature for Alice's version of the
|
// CommitSignature is Bobs's signature for Alice's version of the
|
||||||
// commitment transaction.
|
// commitment transaction.
|
||||||
@ -23,12 +23,12 @@ type SingleFundingSignComplete struct {
|
|||||||
|
|
||||||
// NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete
|
// NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete
|
||||||
// message.
|
// message.
|
||||||
func NewSingleFundingSignComplete(chanID uint64,
|
func NewSingleFundingSignComplete(chanID [32]byte,
|
||||||
sig *btcec.Signature) *SingleFundingSignComplete {
|
sig *btcec.Signature) *SingleFundingSignComplete {
|
||||||
|
|
||||||
return &SingleFundingSignComplete{
|
return &SingleFundingSignComplete{
|
||||||
ChannelID: chanID,
|
PendingChannelID: chanID,
|
||||||
CommitSignature: sig,
|
CommitSignature: sig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,10 +38,8 @@ func NewSingleFundingSignComplete(chanID uint64,
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelID (8)
|
|
||||||
// CommitmentSignature (73)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelID,
|
c.PendingChannelID[:],
|
||||||
&c.CommitSignature)
|
&c.CommitSignature)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +50,7 @@ func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelID,
|
c.PendingChannelID[:],
|
||||||
c.CommitSignature)
|
c.CommitSignature)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,13 +63,13 @@ func (c *SingleFundingSignComplete) Command() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MaxPayloadLength returns the maximum allowed payload length for a
|
// MaxPayloadLength returns the maximum allowed payload length for a
|
||||||
// SingleFundingSignComplete. This is calculated by summing the max length of all
|
// SingleFundingSignComplete. This is calculated by summing the max length of
|
||||||
// the fields within a SingleFundingSignComplete. The final breakdown
|
// all the fields within a SingleFundingSignComplete.
|
||||||
// is: 8 + 73 = 81
|
|
||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
||||||
return 81
|
// 32 + 64
|
||||||
|
return 96
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate examines each populated field within the SingleFundingSignComplete
|
// Validate examines each populated field within the SingleFundingSignComplete
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
func TestSingleFundingSignCompleteWire(t *testing.T) {
|
func TestSingleFundingSignCompleteWire(t *testing.T) {
|
||||||
// First create a new SFSC message.
|
// First create a new SFSC message.
|
||||||
sfsc := NewSingleFundingSignComplete(
|
sfsc := NewSingleFundingSignComplete(
|
||||||
22,
|
revHash,
|
||||||
&btcec.Signature{
|
&btcec.Signature{
|
||||||
R: new(big.Int).SetInt64(9),
|
R: new(big.Int).SetInt64(9),
|
||||||
S: new(big.Int).SetInt64(11),
|
S: new(big.Int).SetInt64(11),
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,9 +19,9 @@ const OnionPacketSize = 1254
|
|||||||
// CommitSig message will move the pending HTLC to the newly created commitment
|
// CommitSig message will move the pending HTLC to the newly created commitment
|
||||||
// transaction, marking them as "staged".
|
// transaction, marking them as "staged".
|
||||||
type UpdateAddHTLC struct {
|
type UpdateAddHTLC struct {
|
||||||
// ChannelPoint is the particular active channel that this
|
// ChanID is the particular active channel that this
|
||||||
// UpdateAddHTLC is binded to.
|
// UpdateAddHTLC is binded to.
|
||||||
ChannelPoint wire.OutPoint
|
ChanID ChannelID
|
||||||
|
|
||||||
// ID is the identification server for this HTLC. This value is
|
// ID is the identification server for this HTLC. This value is
|
||||||
// explicitly included as it allows nodes to survive single-sided
|
// explicitly included as it allows nodes to survive single-sided
|
||||||
@ -70,14 +69,8 @@ var _ Message = (*UpdateAddHTLC)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
|
func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelPoint(8)
|
|
||||||
// ID(4)
|
|
||||||
// Expiry(4)
|
|
||||||
// Amount(8)
|
|
||||||
// PaymentHash(32)
|
|
||||||
// OnionBlob(1254)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelPoint,
|
&c.ChanID,
|
||||||
&c.ID,
|
&c.ID,
|
||||||
&c.Expiry,
|
&c.Expiry,
|
||||||
&c.Amount,
|
&c.Amount,
|
||||||
@ -92,7 +85,7 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error {
|
func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelPoint,
|
c.ChanID,
|
||||||
c.ID,
|
c.ID,
|
||||||
c.Expiry,
|
c.Expiry,
|
||||||
c.Amount,
|
c.Amount,
|
||||||
@ -114,8 +107,8 @@ func (c *UpdateAddHTLC) Command() uint32 {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateAddHTLC) MaxPayloadLength(uint32) uint32 {
|
func (c *UpdateAddHTLC) MaxPayloadLength(uint32) uint32 {
|
||||||
// 1342
|
// 1338
|
||||||
return 36 + 8 + 4 + 8 + 32 + 1254
|
return 32 + 8 + 4 + 8 + 32 + 1254
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs any necessary sanity checks to ensure all fields present
|
// Validate performs any necessary sanity checks to ensure all fields present
|
||||||
@ -128,6 +121,7 @@ func (c *UpdateAddHTLC) Validate() error {
|
|||||||
// negative payments. Maybe for some wallets, but not this one!
|
// negative payments. Maybe for some wallets, but not this one!
|
||||||
return fmt.Errorf("amount paid cannot be negative")
|
return fmt.Errorf("amount paid cannot be negative")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're good!
|
// We're good!
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ import (
|
|||||||
func TestUpdateAddHTLCEncodeDecode(t *testing.T) {
|
func TestUpdateAddHTLCEncodeDecode(t *testing.T) {
|
||||||
// First create a new UPAH message.
|
// First create a new UPAH message.
|
||||||
addReq := &UpdateAddHTLC{
|
addReq := &UpdateAddHTLC{
|
||||||
ChannelPoint: *outpoint1,
|
ChanID: ChannelID(revHash),
|
||||||
ID: 99,
|
ID: 99,
|
||||||
Expiry: uint32(144),
|
Expiry: uint32(144),
|
||||||
Amount: btcutil.Amount(123456000),
|
Amount: btcutil.Amount(123456000),
|
||||||
PaymentHash: revHash,
|
PaymentHash: revHash,
|
||||||
}
|
}
|
||||||
copy(addReq.OnionBlob[:], bytes.Repeat([]byte{23}, OnionPacketSize))
|
copy(addReq.OnionBlob[:], bytes.Repeat([]byte{23}, OnionPacketSize))
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package lnwire
|
package lnwire
|
||||||
|
|
||||||
import (
|
import "io"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FailCode specifies the precise reason that an upstream HTLC was cancelled.
|
// FailCode specifies the precise reason that an upstream HTLC was cancelled.
|
||||||
// Each UpdateFailHTLC message carries a FailCode which is to be passed back
|
// Each UpdateFailHTLC message carries a FailCode which is to be passed back
|
||||||
@ -82,8 +78,8 @@ type OpaqueReason []byte
|
|||||||
// the route to fully undo the HTLC.
|
// the route to fully undo the HTLC.
|
||||||
type UpdateFailHTLC struct {
|
type UpdateFailHTLC struct {
|
||||||
// ChannelPoint is the particular active channel that this
|
// ChannelPoint is the particular active channel that this
|
||||||
// UpdateFailHTLC is binded to.
|
// UpdateFailHTLC is bound to.
|
||||||
ChannelPoint wire.OutPoint
|
ChanID ChannelID
|
||||||
|
|
||||||
// ID references which HTLC on the remote node's commitment transaction
|
// ID references which HTLC on the remote node's commitment transaction
|
||||||
// has timed out.
|
// has timed out.
|
||||||
@ -105,11 +101,8 @@ var _ Message = (*UpdateFailHTLC)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
|
func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelPoint(8)
|
|
||||||
// HTLCKey(8)
|
|
||||||
// Reason(??)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelPoint,
|
&c.ChanID,
|
||||||
&c.ID,
|
&c.ID,
|
||||||
&c.Reason,
|
&c.Reason,
|
||||||
)
|
)
|
||||||
@ -121,7 +114,7 @@ func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error {
|
func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelPoint,
|
c.ChanID,
|
||||||
c.ID,
|
c.ID,
|
||||||
c.Reason,
|
c.Reason,
|
||||||
)
|
)
|
||||||
@ -140,8 +133,8 @@ func (c *UpdateFailHTLC) Command() uint32 {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateFailHTLC) MaxPayloadLength(uint32) uint32 {
|
func (c *UpdateFailHTLC) MaxPayloadLength(uint32) uint32 {
|
||||||
// 36 + 8 + 154
|
// 32 + 8 + 154
|
||||||
return 198
|
return 194
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs any necessary sanity checks to ensure all fields present
|
// Validate performs any necessary sanity checks to ensure all fields present
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
func TestUpdateFailHTLC(t *testing.T) {
|
func TestUpdateFailHTLC(t *testing.T) {
|
||||||
// First create a new UFH message.
|
// First create a new UFH message.
|
||||||
cancelMsg := &UpdateFailHTLC{
|
cancelMsg := &UpdateFailHTLC{
|
||||||
ChannelPoint: *outpoint1,
|
ChanID: ChannelID(revHash),
|
||||||
ID: 22,
|
ID: 22,
|
||||||
}
|
}
|
||||||
cancelMsg.Reason = []byte{byte(UnknownDestination)}
|
cancelMsg.Reason = []byte{byte(UnknownDestination)}
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package lnwire
|
package lnwire
|
||||||
|
|
||||||
import (
|
import "io"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UpdateFufillHTLC is sent by Alice to Bob when she wishes to settle a
|
// UpdateFufillHTLC is sent by Alice to Bob when she wishes to settle a
|
||||||
// particular HTLC referenced by its HTLCKey within a specific active channel
|
// particular HTLC referenced by its HTLCKey within a specific active channel
|
||||||
@ -12,9 +8,9 @@ import (
|
|||||||
// Alice to "lock-in" the removal of the specified HTLC, possible containing a
|
// Alice to "lock-in" the removal of the specified HTLC, possible containing a
|
||||||
// batch signature covering several settled HTLC's.
|
// batch signature covering several settled HTLC's.
|
||||||
type UpdateFufillHTLC struct {
|
type UpdateFufillHTLC struct {
|
||||||
// ChannelPoint references an active channel which holds the HTLC to be
|
// ChanID references an active channel which holds the HTLC to be
|
||||||
// settled.
|
// settled.
|
||||||
ChannelPoint wire.OutPoint
|
ChanID ChannelID
|
||||||
|
|
||||||
// ID denotes the exact HTLC stage within the receiving node's
|
// ID denotes the exact HTLC stage within the receiving node's
|
||||||
// commitment transaction to be removed.
|
// commitment transaction to be removed.
|
||||||
@ -26,11 +22,11 @@ type UpdateFufillHTLC struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewUpdateFufillHTLC returns a new empty UpdateFufillHTLC.
|
// NewUpdateFufillHTLC returns a new empty UpdateFufillHTLC.
|
||||||
func NewUpdateFufillHTLC(chanPoint wire.OutPoint, id uint64,
|
func NewUpdateFufillHTLC(chanID ChannelID, id uint64,
|
||||||
preimage [32]byte) *UpdateFufillHTLC {
|
preimage [32]byte) *UpdateFufillHTLC {
|
||||||
|
|
||||||
return &UpdateFufillHTLC{
|
return &UpdateFufillHTLC{
|
||||||
ChannelPoint: chanPoint,
|
ChanID: chanID,
|
||||||
ID: id,
|
ID: id,
|
||||||
PaymentPreimage: preimage,
|
PaymentPreimage: preimage,
|
||||||
}
|
}
|
||||||
@ -45,11 +41,8 @@ var _ Message = (*UpdateFufillHTLC)(nil)
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error {
|
func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error {
|
||||||
// ChannelPoint(8)
|
|
||||||
// ID(8)
|
|
||||||
// PaymentPreimage(32)
|
|
||||||
return readElements(r,
|
return readElements(r,
|
||||||
&c.ChannelPoint,
|
&c.ChanID,
|
||||||
&c.ID,
|
&c.ID,
|
||||||
c.PaymentPreimage[:],
|
c.PaymentPreimage[:],
|
||||||
)
|
)
|
||||||
@ -61,7 +54,7 @@ func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error {
|
|||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error {
|
func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
c.ChannelPoint,
|
c.ChanID,
|
||||||
c.ID,
|
c.ID,
|
||||||
c.PaymentPreimage[:],
|
c.PaymentPreimage[:],
|
||||||
)
|
)
|
||||||
@ -80,8 +73,8 @@ func (c *UpdateFufillHTLC) Command() uint32 {
|
|||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *UpdateFufillHTLC) MaxPayloadLength(uint32) uint32 {
|
func (c *UpdateFufillHTLC) MaxPayloadLength(uint32) uint32 {
|
||||||
// 36 + 8 + (32 * 15)
|
// 32 + 8 + 32
|
||||||
return 524
|
return 72
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs any necessary sanity checks to ensure all fields present
|
// Validate performs any necessary sanity checks to ensure all fields present
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestUpdateFufillHTLCEncodeDecode(t *testing.T) {
|
func TestUpdateFufillHTLCEncodeDecode(t *testing.T) {
|
||||||
// First create a new HTLCSR message.
|
// First create a new HTLCSR message.
|
||||||
settleReq := NewUpdateFufillHTLC(*outpoint1, 23, revHash)
|
settleReq := NewUpdateFufillHTLC(ChannelID(revHash), 23, revHash)
|
||||||
|
|
||||||
// Next encode the HTLCSR message into an empty bytes buffer.
|
// Next encode the HTLCSR message into an empty bytes buffer.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
Loading…
Reference in New Issue
Block a user