lnwire: converge discovery part of messages with specification
Change the name of fields of messages which are belong to the discovery subsystem in a such way so they were the same with the names that are defined in the specification.
This commit is contained in:
1 parent
54b3541707
commit
c3b2854428
19 files changed
+163
-165
No files matched your search
@@ -23,7 +23,7 @@ type AnnounceSignatures struct {
|
||||
// as the block height, the next 3 bytes indicating the transaction
|
||||
// index within the block, and the least significant two bytes
|
||||
// indicating the output index which pays to the channel.
|
||||
ShortChannelID ChannelID
|
||||
ShortChannelID ShortChannelID
|
||||
|
||||
// NodeSignature is the signature which contains the signed announce
|
||||
// channel message, by this signature we proof that we posses of the
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func TestAnnounceSignatureEncodeDecode(t *testing.T) {
|
||||
ac := &AnnounceSignatures{
|
||||
ChannelID: *outpoint1,
|
||||
ShortChannelID: NewChanIDFromInt(1),
|
||||
ShortChannelID: NewShortChanIDFromInt(1),
|
||||
NodeSignature: someSig,
|
||||
BitcoinSignature: someSig,
|
||||
}
|
||||
|
||||
@@ -15,28 +15,28 @@ type ChannelAnnouncement struct {
|
||||
// references between node's channel and node. Requiring both nodes
|
||||
// to sign indicates they are both willing to route other payments via
|
||||
// this node.
|
||||
FirstNodeSig *btcec.Signature
|
||||
SecondNodeSig *btcec.Signature
|
||||
|
||||
// ChannelID is the unique description of the funding transaction.
|
||||
ChannelID ChannelID
|
||||
NodeSig1 *btcec.Signature
|
||||
NodeSig2 *btcec.Signature
|
||||
|
||||
// This signatures are used by nodes in order to create cross
|
||||
// references between node's channel and node. Requiring the bitcoin
|
||||
// signatures proves they control the channel.
|
||||
FirstBitcoinSig *btcec.Signature
|
||||
SecondBitcoinSig *btcec.Signature
|
||||
BitcoinSig1 *btcec.Signature
|
||||
BitcoinSig2 *btcec.Signature
|
||||
|
||||
// ShortChannelID is the unique description of the funding transaction.
|
||||
ShortChannelID ShortChannelID
|
||||
|
||||
// The public keys of the two nodes who are operating the channel, such
|
||||
// that is FirstNodeID the numerically-lesser of the two DER encoded
|
||||
// keys (ascending numerical order).
|
||||
FirstNodeID *btcec.PublicKey
|
||||
SecondNodeID *btcec.PublicKey
|
||||
// that is NodeID1 the numerically-lesser than NodeID2 (ascending
|
||||
// numerical order).
|
||||
NodeID1 *btcec.PublicKey
|
||||
NodeID2 *btcec.PublicKey
|
||||
|
||||
// Public keys which corresponds to the keys which was declared in
|
||||
// multisig funding transaction output.
|
||||
FirstBitcoinKey *btcec.PublicKey
|
||||
SecondBitcoinKey *btcec.PublicKey
|
||||
BitcoinKey1 *btcec.PublicKey
|
||||
BitcoinKey2 *btcec.PublicKey
|
||||
}
|
||||
|
||||
// A compile time check to ensure ChannelAnnouncement implements the
|
||||
@@ -57,15 +57,15 @@ func (a *ChannelAnnouncement) Validate() error {
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
return readElements(r,
|
||||
&a.FirstNodeSig,
|
||||
&a.SecondNodeSig,
|
||||
&a.ChannelID,
|
||||
&a.FirstBitcoinSig,
|
||||
&a.SecondBitcoinSig,
|
||||
&a.FirstNodeID,
|
||||
&a.SecondNodeID,
|
||||
&a.FirstBitcoinKey,
|
||||
&a.SecondBitcoinKey,
|
||||
&a.NodeSig1,
|
||||
&a.NodeSig2,
|
||||
&a.ShortChannelID,
|
||||
&a.BitcoinSig1,
|
||||
&a.BitcoinSig2,
|
||||
&a.NodeID1,
|
||||
&a.NodeID2,
|
||||
&a.BitcoinKey1,
|
||||
&a.BitcoinKey2,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -75,15 +75,15 @@ func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (a *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
return writeElements(w,
|
||||
a.FirstNodeSig,
|
||||
a.SecondNodeSig,
|
||||
a.ChannelID,
|
||||
a.FirstBitcoinSig,
|
||||
a.SecondBitcoinSig,
|
||||
a.FirstNodeID,
|
||||
a.SecondNodeID,
|
||||
a.FirstBitcoinKey,
|
||||
a.SecondBitcoinKey,
|
||||
a.NodeSig1,
|
||||
a.NodeSig2,
|
||||
a.ShortChannelID,
|
||||
a.BitcoinSig1,
|
||||
a.BitcoinSig2,
|
||||
a.NodeID1,
|
||||
a.NodeID2,
|
||||
a.BitcoinKey1,
|
||||
a.BitcoinKey2,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (a *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (a *ChannelAnnouncement) Command() uint32 {
|
||||
return CmdChannelAnnoucmentMessage
|
||||
return CmdChannelAnnouncement
|
||||
}
|
||||
|
||||
// MaxPayloadLength returns the maximum allowed payload size for this message
|
||||
@@ -102,31 +102,31 @@ func (a *ChannelAnnouncement) Command() uint32 {
|
||||
func (a *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
var length uint32
|
||||
|
||||
// FirstNodeSig - 64 bytes
|
||||
// NodeSig1 - 64 bytes
|
||||
length += 64
|
||||
|
||||
// SecondNodeSig - 64 bytes
|
||||
// NodeSig2 - 64 bytes
|
||||
length += 64
|
||||
|
||||
// ChannelID - 8 bytes
|
||||
// ShortChannelID - 8 bytes
|
||||
length += 8
|
||||
|
||||
// FirstBitcoinSig - 64 bytes
|
||||
// BitcoinSig1 - 64 bytes
|
||||
length += 64
|
||||
|
||||
// SecondBitcoinSig - 64 bytes
|
||||
// BitcoinSig2 - 64 bytes
|
||||
length += 64
|
||||
|
||||
// FirstNodeID - 33 bytes
|
||||
// NodeID1 - 33 bytes
|
||||
length += 33
|
||||
|
||||
// SecondNodeID - 33 bytes
|
||||
// NodeID2 - 33 bytes
|
||||
length += 33
|
||||
|
||||
// FirstBitcoinKey - 33 bytes
|
||||
// BitcoinKey1 - 33 bytes
|
||||
length += 33
|
||||
|
||||
// SecondBitcoinKey - 33 bytes
|
||||
// BitcoinKey2 - 33 bytes
|
||||
length += 33
|
||||
|
||||
return length
|
||||
@@ -138,13 +138,11 @@ func (a *ChannelAnnouncement) DataToSign() ([]byte, error) {
|
||||
// We should not include the signatures itself.
|
||||
var w bytes.Buffer
|
||||
err := writeElements(&w,
|
||||
a.ChannelID,
|
||||
a.FirstBitcoinSig,
|
||||
a.SecondBitcoinSig,
|
||||
a.FirstNodeID,
|
||||
a.SecondNodeID,
|
||||
a.FirstBitcoinKey,
|
||||
a.SecondBitcoinKey,
|
||||
a.ShortChannelID,
|
||||
a.NodeID1,
|
||||
a.NodeID2,
|
||||
a.BitcoinKey1,
|
||||
a.BitcoinKey2,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -11,15 +11,15 @@ import (
|
||||
|
||||
func TestChannelAnnoucementEncodeDecode(t *testing.T) {
|
||||
ca := &ChannelAnnouncement{
|
||||
FirstNodeSig: someSig,
|
||||
SecondNodeSig: someSig,
|
||||
ChannelID: someChannelID,
|
||||
FirstBitcoinSig: someSig,
|
||||
SecondBitcoinSig: someSig,
|
||||
FirstNodeID: pubKey,
|
||||
SecondNodeID: pubKey,
|
||||
FirstBitcoinKey: pubKey,
|
||||
SecondBitcoinKey: pubKey,
|
||||
NodeSig1: someSig,
|
||||
NodeSig2: someSig,
|
||||
ShortChannelID: someChannelID,
|
||||
BitcoinSig1: someSig,
|
||||
BitcoinSig2: someSig,
|
||||
NodeID1: pubKey,
|
||||
NodeID2: pubKey,
|
||||
BitcoinKey1: pubKey,
|
||||
BitcoinKey2: pubKey,
|
||||
}
|
||||
|
||||
// Next encode the CA message into an empty bytes buffer.
|
||||
@@ -65,23 +65,23 @@ func TestChannelAnnoucementValidation(t *testing.T) {
|
||||
secondBitcoinSig, _ := secondBitcoinPrivKey.Sign(hash)
|
||||
|
||||
ca := &ChannelAnnouncement{
|
||||
ChannelID: someChannelID,
|
||||
FirstBitcoinSig: firstBitcoinSig,
|
||||
SecondBitcoinSig: secondBitcoinSig,
|
||||
FirstNodeID: firstNodePubKey,
|
||||
SecondNodeID: secondNodePubKey,
|
||||
FirstBitcoinKey: firstBitcoinPubKey,
|
||||
SecondBitcoinKey: secondBitcoinPubKey,
|
||||
ShortChannelID: someChannelID,
|
||||
BitcoinSig1: firstBitcoinSig,
|
||||
BitcoinSig2: secondBitcoinSig,
|
||||
NodeID1: firstNodePubKey,
|
||||
NodeID2: secondNodePubKey,
|
||||
BitcoinKey1: firstBitcoinPubKey,
|
||||
BitcoinKey2: secondBitcoinPubKey,
|
||||
}
|
||||
|
||||
dataToSign, _ := ca.DataToSign()
|
||||
hash = chainhash.DoubleHashB(dataToSign)
|
||||
|
||||
firstNodeSign, _ := firstNodePrivKey.Sign(hash)
|
||||
ca.FirstNodeSig = firstNodeSign
|
||||
ca.NodeSig1 = firstNodeSign
|
||||
|
||||
secondNodeSign, _ := secondNodePrivKey.Sign(hash)
|
||||
ca.SecondNodeSig = secondNodeSign
|
||||
ca.NodeSig2 = secondNodeSign
|
||||
|
||||
if err := ca.Validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
+10
-10
@@ -1,8 +1,8 @@
|
||||
package lnwire
|
||||
|
||||
// ChannelID represent the set of data which is needed to retrieve all
|
||||
// ShortChannelID represent the set of data which is needed to retrieve all
|
||||
// necessary data to validate the channel existence.
|
||||
type ChannelID struct {
|
||||
type ShortChannelID struct {
|
||||
// BlockHeight is the height of the block where funding transaction
|
||||
// located.
|
||||
//
|
||||
@@ -18,21 +18,21 @@ type ChannelID struct {
|
||||
TxPosition uint16
|
||||
}
|
||||
|
||||
// NewChanIDFromInt returns a new ChannelID which is the decoded version of the
|
||||
// compact channel ID encoded within the uint64. The format of the compact
|
||||
// channel ID is as follows: 3 bytes for the block height, 3 bytes for the
|
||||
// transaction index, and 2 bytes for the output index.
|
||||
func NewChanIDFromInt(chanID uint64) ChannelID {
|
||||
return ChannelID{
|
||||
// NewShortChanIDFromInt returns a new ShortChannelID which is the decoded
|
||||
// version of the compact channel ID encoded within the uint64. The format of
|
||||
// the compact channel ID is as follows: 3 bytes for the block height, 3 bytes
|
||||
// for the transaction index, and 2 bytes for the output index.
|
||||
func NewShortChanIDFromInt(chanID uint64) ShortChannelID {
|
||||
return ShortChannelID{
|
||||
BlockHeight: uint32(chanID >> 40),
|
||||
TxIndex: uint32(chanID>>16) & 0xFFFFFF,
|
||||
TxPosition: uint16(chanID),
|
||||
}
|
||||
}
|
||||
|
||||
// ToUint64 converts the ChannelID into a compact format encoded within a
|
||||
// ToUint64 converts the ShortChannelID into a compact format encoded within a
|
||||
// uint64 (8 bytes).
|
||||
func (c *ChannelID) ToUint64() uint64 {
|
||||
func (c *ShortChannelID) ToUint64() uint64 {
|
||||
// TODO(roasbeef): explicit error on overflow?
|
||||
return ((uint64(c.BlockHeight) << 40) | (uint64(c.TxIndex) << 16) |
|
||||
(uint64(c.TxPosition)))
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestChannelIDEncoding(t *testing.T) {
|
||||
var testCases = []ChannelID{
|
||||
var testCases = []ShortChannelID{
|
||||
{
|
||||
BlockHeight: (1 << 24) - 1,
|
||||
TxIndex: (1 << 24) - 1,
|
||||
@@ -29,7 +29,7 @@ func TestChannelIDEncoding(t *testing.T) {
|
||||
for _, testCase := range testCases {
|
||||
chanInt := testCase.ToUint64()
|
||||
|
||||
newChanID := NewChanIDFromInt(chanInt)
|
||||
newChanID := NewShortChanIDFromInt(chanInt)
|
||||
|
||||
if !reflect.DeepEqual(testCase, newChanID) {
|
||||
t.Fatalf("chan ID's don't match: expected %v got %v",
|
||||
|
||||
@@ -17,8 +17,8 @@ type ChannelUpdateAnnouncement struct {
|
||||
// ownership of node id.
|
||||
Signature *btcec.Signature
|
||||
|
||||
// ChannelID is the unique description of the funding transaction.
|
||||
ChannelID ChannelID
|
||||
// ShortChannelID is the unique description of the funding transaction.
|
||||
ShortChannelID ShortChannelID
|
||||
|
||||
// Timestamp allows ordering in the case of multiple announcements.
|
||||
// We should ignore the message if timestamp is not greater than
|
||||
@@ -74,7 +74,7 @@ func (a *ChannelUpdateAnnouncement) Validate() error {
|
||||
func (a *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
return readElements(r,
|
||||
&a.Signature,
|
||||
&a.ChannelID,
|
||||
&a.ShortChannelID,
|
||||
&a.Timestamp,
|
||||
&a.Flags,
|
||||
&a.TimeLockDelta,
|
||||
@@ -91,7 +91,7 @@ func (a *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
|
||||
func (a *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
return writeElements(w,
|
||||
a.Signature,
|
||||
a.ChannelID,
|
||||
a.ShortChannelID,
|
||||
a.Timestamp,
|
||||
a.Flags,
|
||||
a.TimeLockDelta,
|
||||
@@ -106,7 +106,7 @@ func (a *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (a *ChannelUpdateAnnouncement) Command() uint32 {
|
||||
return CmdChannelUpdateAnnoucmentMessage
|
||||
return CmdChannelUpdateAnnouncement
|
||||
}
|
||||
|
||||
// MaxPayloadLength returns the maximum allowed payload size for this message
|
||||
@@ -119,7 +119,7 @@ func (a *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
||||
// Signature - 64 bytes
|
||||
length += 64
|
||||
|
||||
// ChannelID - 8 bytes
|
||||
// ShortChannelID - 8 bytes
|
||||
length += 8
|
||||
|
||||
// Timestamp - 4 bytes
|
||||
@@ -150,7 +150,7 @@ func (a *ChannelUpdateAnnouncement) DataToSign() ([]byte, error) {
|
||||
// We should not include the signatures itself.
|
||||
var w bytes.Buffer
|
||||
err := writeElements(&w,
|
||||
a.ChannelID,
|
||||
a.ShortChannelID,
|
||||
a.Timestamp,
|
||||
a.Flags,
|
||||
a.TimeLockDelta,
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func TestChannelUpdateAnnouncementEncodeDecode(t *testing.T) {
|
||||
cua := &ChannelUpdateAnnouncement{
|
||||
Signature: someSig,
|
||||
ChannelID: someChannelID,
|
||||
ShortChannelID: someChannelID,
|
||||
Timestamp: maxUint32,
|
||||
Flags: maxUint16,
|
||||
TimeLockDelta: maxUint16,
|
||||
|
||||
@@ -21,7 +21,7 @@ type FundingLocked struct {
|
||||
|
||||
// ChannelId serves to uniquely identify the channel created by the
|
||||
// current channel funding workflow.
|
||||
ChannelID ChannelID
|
||||
ChannelID ShortChannelID
|
||||
|
||||
// NextPerCommitmentPoint is the secret that can be used to revoke
|
||||
// the next commitment transaction for the channel.
|
||||
@@ -30,7 +30,7 @@ type FundingLocked struct {
|
||||
|
||||
// NewFundingLocked creates a new FundingLocked message, populating it with
|
||||
// the necessary IDs and revocation secret..
|
||||
func NewFundingLocked(op wire.OutPoint, cid ChannelID,
|
||||
func NewFundingLocked(op wire.OutPoint, cid ShortChannelID,
|
||||
npcp *btcec.PublicKey) *FundingLocked {
|
||||
return &FundingLocked{
|
||||
ChannelOutpoint: op,
|
||||
|
||||
+3
-3
@@ -270,7 +270,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case ChannelID:
|
||||
case ShortChannelID:
|
||||
// Check that field fit in 3 bytes and write the blockHeight
|
||||
if e.BlockHeight > ((1 << 24) - 1) {
|
||||
return errors.New("block height should fit in 3 bytes")
|
||||
@@ -596,7 +596,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *ChannelID:
|
||||
case *ShortChannelID:
|
||||
var blockHeight [4]byte
|
||||
if _, err = io.ReadFull(r, blockHeight[1:]); err != nil {
|
||||
return err
|
||||
@@ -612,7 +612,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
*e = ChannelID{
|
||||
*e = ShortChannelID{
|
||||
BlockHeight: binary.BigEndian.Uint32(blockHeight[:]),
|
||||
TxIndex: binary.BigEndian.Uint32(txIndex[:]),
|
||||
TxPosition: binary.BigEndian.Uint16(txPosition[:]),
|
||||
|
||||
@@ -64,7 +64,7 @@ var (
|
||||
maxUint24 uint32 = (1 << 24) - 1
|
||||
maxUint16 uint16 = (1 << 16) - 1
|
||||
|
||||
someChannelID = ChannelID{
|
||||
someChannelID = ShortChannelID{
|
||||
BlockHeight: maxUint24,
|
||||
TxIndex: maxUint24,
|
||||
TxPosition: maxUint16,
|
||||
|
||||
+7
-7
@@ -52,10 +52,10 @@ const (
|
||||
CmdErrorGeneric = uint32(4000)
|
||||
|
||||
// Commands for discovery service.
|
||||
CmdChannelAnnoucmentMessage = uint32(5000)
|
||||
CmdChannelUpdateAnnoucmentMessage = uint32(5010)
|
||||
CmdNodeAnnoucmentMessage = uint32(5020)
|
||||
CmdAnnounceSignatures = uint32(5030)
|
||||
CmdChannelAnnouncement = uint32(5000)
|
||||
CmdChannelUpdateAnnouncement = uint32(5010)
|
||||
CmdNodeAnnouncement = uint32(5020)
|
||||
CmdAnnounceSignatures = uint32(5030)
|
||||
|
||||
// Commands for connection keep-alive.
|
||||
CmdPing = uint32(6000)
|
||||
@@ -121,11 +121,11 @@ func makeEmptyMessage(command uint32) (Message, error) {
|
||||
msg = &RevokeAndAck{}
|
||||
case CmdErrorGeneric:
|
||||
msg = &ErrorGeneric{}
|
||||
case CmdChannelAnnoucmentMessage:
|
||||
case CmdChannelAnnouncement:
|
||||
msg = &ChannelAnnouncement{}
|
||||
case CmdChannelUpdateAnnoucmentMessage:
|
||||
case CmdChannelUpdateAnnouncement:
|
||||
msg = &ChannelUpdateAnnouncement{}
|
||||
case CmdNodeAnnoucmentMessage:
|
||||
case CmdNodeAnnouncement:
|
||||
msg = &NodeAnnouncement{}
|
||||
case CmdPing:
|
||||
msg = &Ping{}
|
||||
|
||||
@@ -154,7 +154,7 @@ func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (a *NodeAnnouncement) Command() uint32 {
|
||||
return CmdNodeAnnoucmentMessage
|
||||
return CmdNodeAnnouncement
|
||||
}
|
||||
|
||||
// MaxPayloadLength returns the maximum allowed payload size for this message
|
||||
|
||||
Reference in new issue
Block a user