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