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:
parent
54b3541707
commit
c3b2854428
@ -344,7 +344,7 @@ func (d *Discovery) networkHandler() {
|
||||
func(p *channeldb.ChannelEdgePolicy) error {
|
||||
c := &lnwire.ChannelUpdateAnnouncement{
|
||||
Signature: d.fakeSig,
|
||||
ChannelID: lnwire.NewChanIDFromInt(p.ChannelID),
|
||||
ShortChannelID: lnwire.NewShortChanIDFromInt(p.ChannelID),
|
||||
Timestamp: uint32(p.LastUpdate.Unix()),
|
||||
Flags: p.Flags,
|
||||
TimeLockDelta: p.TimeLockDelta,
|
||||
@ -403,7 +403,7 @@ func (d *Discovery) networkHandler() {
|
||||
// may want to batch this request to be broadcast to immediate peers during the
|
||||
// next announcement epoch.
|
||||
func (d *Discovery) processNetworkAnnouncement(aMsg *networkMsg) bool {
|
||||
isPremature := func(chanID *lnwire.ChannelID) bool {
|
||||
isPremature := func(chanID *lnwire.ShortChannelID) bool {
|
||||
return chanID.BlockHeight > d.bestHeight
|
||||
}
|
||||
|
||||
@ -438,11 +438,11 @@ func (d *Discovery) processNetworkAnnouncement(aMsg *networkMsg) bool {
|
||||
// If the advertised inclusionary block is beyond our knowledge
|
||||
// of the chain tip, then we'll put the announcement in limbo
|
||||
// to be fully verified once we advance forward in the chain.
|
||||
if isPremature(&msg.ChannelID) {
|
||||
blockHeight := msg.ChannelID.BlockHeight
|
||||
if isPremature(&msg.ShortChannelID) {
|
||||
blockHeight := msg.ShortChannelID.BlockHeight
|
||||
log.Infof("Announcement for chan_id=(%v), is "+
|
||||
"premature: advertises height %v, only height "+
|
||||
"%v is known", msg.ChannelID, msg.ChannelID.BlockHeight,
|
||||
"%v is known", msg.ShortChannelID, msg.ShortChannelID.BlockHeight,
|
||||
d.bestHeight)
|
||||
|
||||
d.prematureAnnouncements[blockHeight] = append(
|
||||
@ -458,18 +458,18 @@ func (d *Discovery) processNetworkAnnouncement(aMsg *networkMsg) bool {
|
||||
}
|
||||
|
||||
proof = &channeldb.ChannelAuthProof{
|
||||
NodeSig1: msg.FirstNodeSig,
|
||||
NodeSig2: msg.SecondNodeSig,
|
||||
BitcoinSig1: msg.FirstBitcoinSig,
|
||||
BitcoinSig2: msg.SecondBitcoinSig,
|
||||
NodeSig1: msg.NodeSig1,
|
||||
NodeSig2: msg.NodeSig2,
|
||||
BitcoinSig1: msg.BitcoinSig1,
|
||||
BitcoinSig2: msg.BitcoinSig2,
|
||||
}
|
||||
|
||||
edge := &channeldb.ChannelEdgeInfo{
|
||||
ChannelID: msg.ChannelID.ToUint64(),
|
||||
NodeKey1: msg.FirstNodeID,
|
||||
NodeKey2: msg.SecondNodeID,
|
||||
BitcoinKey1: msg.FirstBitcoinKey,
|
||||
BitcoinKey2: msg.SecondBitcoinKey,
|
||||
ChannelID: msg.ShortChannelID.ToUint64(),
|
||||
NodeKey1: msg.NodeID1,
|
||||
NodeKey2: msg.NodeID2,
|
||||
BitcoinKey1: msg.BitcoinKey1,
|
||||
BitcoinKey2: msg.BitcoinKey2,
|
||||
AuthProof: proof,
|
||||
}
|
||||
|
||||
@ -487,13 +487,13 @@ func (d *Discovery) processNetworkAnnouncement(aMsg *networkMsg) bool {
|
||||
// that the directional information for an already known channel has
|
||||
// been updated.
|
||||
case *lnwire.ChannelUpdateAnnouncement:
|
||||
chanID := msg.ChannelID.ToUint64()
|
||||
chanID := msg.ShortChannelID.ToUint64()
|
||||
|
||||
// If the advertised inclusionary block is beyond our knowledge
|
||||
// of the chain tip, then we'll put the announcement in limbo
|
||||
// to be fully verified once we advance forward in the chain.
|
||||
if isPremature(&msg.ChannelID) {
|
||||
blockHeight := msg.ChannelID.BlockHeight
|
||||
if isPremature(&msg.ShortChannelID) {
|
||||
blockHeight := msg.ShortChannelID.BlockHeight
|
||||
log.Infof("Update announcement for chan_id=(%v), is "+
|
||||
"premature: advertises height %v, only height "+
|
||||
"%v is known", chanID, blockHeight,
|
||||
@ -578,7 +578,7 @@ func (d *Discovery) synchronize(syncReq *syncRequest) error {
|
||||
if err := d.cfg.Router.ForEachChannel(func(chanInfo *channeldb.ChannelEdgeInfo,
|
||||
e1, e2 *channeldb.ChannelEdgePolicy) error {
|
||||
|
||||
chanID := lnwire.NewChanIDFromInt(chanInfo.ChannelID)
|
||||
chanID := lnwire.NewShortChanIDFromInt(chanInfo.ChannelID)
|
||||
|
||||
// First, using the parameters of the channel, along with the
|
||||
// channel authentication proof, we'll create re-create the
|
||||
@ -586,15 +586,15 @@ func (d *Discovery) synchronize(syncReq *syncRequest) error {
|
||||
// TODO(andrew.shvv) skip if proof is nil
|
||||
authProof := chanInfo.AuthProof
|
||||
chanAnn := &lnwire.ChannelAnnouncement{
|
||||
FirstNodeSig: authProof.NodeSig1,
|
||||
SecondNodeSig: authProof.NodeSig2,
|
||||
ChannelID: chanID,
|
||||
FirstBitcoinSig: authProof.BitcoinSig1,
|
||||
SecondBitcoinSig: authProof.BitcoinSig2,
|
||||
FirstNodeID: chanInfo.NodeKey1,
|
||||
SecondNodeID: chanInfo.NodeKey2,
|
||||
FirstBitcoinKey: chanInfo.BitcoinKey1,
|
||||
SecondBitcoinKey: chanInfo.BitcoinKey2,
|
||||
NodeSig1: authProof.NodeSig1,
|
||||
NodeSig2: authProof.NodeSig2,
|
||||
ShortChannelID: chanID,
|
||||
BitcoinSig1: authProof.BitcoinSig1,
|
||||
BitcoinSig2: authProof.BitcoinSig2,
|
||||
NodeID1: chanInfo.NodeKey1,
|
||||
NodeID2: chanInfo.NodeKey2,
|
||||
BitcoinKey1: chanInfo.BitcoinKey1,
|
||||
BitcoinKey2: chanInfo.BitcoinKey2,
|
||||
}
|
||||
announceMessages = append(announceMessages, chanAnn)
|
||||
|
||||
@ -604,7 +604,7 @@ func (d *Discovery) synchronize(syncReq *syncRequest) error {
|
||||
if e1 != nil {
|
||||
announceMessages = append(announceMessages, &lnwire.ChannelUpdateAnnouncement{
|
||||
Signature: d.fakeSig,
|
||||
ChannelID: chanID,
|
||||
ShortChannelID: chanID,
|
||||
Timestamp: uint32(e1.LastUpdate.Unix()),
|
||||
Flags: 0,
|
||||
TimeLockDelta: e1.TimeLockDelta,
|
||||
@ -616,7 +616,7 @@ func (d *Discovery) synchronize(syncReq *syncRequest) error {
|
||||
if e2 != nil {
|
||||
announceMessages = append(announceMessages, &lnwire.ChannelUpdateAnnouncement{
|
||||
Signature: d.fakeSig,
|
||||
ChannelID: chanID,
|
||||
ShortChannelID: chanID,
|
||||
Timestamp: uint32(e2.LastUpdate.Unix()),
|
||||
Flags: 1,
|
||||
TimeLockDelta: e2.TimeLockDelta,
|
||||
|
@ -175,7 +175,7 @@ func createNodeAnnouncement() (*lnwire.NodeAnnouncement,
|
||||
func createUpdateAnnouncement(blockHeight uint32) *lnwire.ChannelUpdateAnnouncement {
|
||||
return &lnwire.ChannelUpdateAnnouncement{
|
||||
Signature: testSig,
|
||||
ChannelID: lnwire.ChannelID{
|
||||
ShortChannelID: lnwire.ShortChannelID{
|
||||
BlockHeight: blockHeight,
|
||||
},
|
||||
Timestamp: uint32(prand.Int31()),
|
||||
@ -188,14 +188,14 @@ func createUpdateAnnouncement(blockHeight uint32) *lnwire.ChannelUpdateAnnouncem
|
||||
|
||||
func createChannelAnnouncement(blockHeight uint32) *lnwire.ChannelAnnouncement {
|
||||
// Our fake channel will be "confirmed" at height 101.
|
||||
chanID := lnwire.ChannelID{
|
||||
chanID := lnwire.ShortChannelID{
|
||||
BlockHeight: blockHeight,
|
||||
TxIndex: 0,
|
||||
TxPosition: 0,
|
||||
}
|
||||
|
||||
return &lnwire.ChannelAnnouncement{
|
||||
ChannelID: chanID,
|
||||
ShortChannelID: chanID,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -954,7 +954,7 @@ func (f *fundingManager) waitForFundingConfirmation(
|
||||
// construct the compact chainID which is used on the network to unique
|
||||
// identify channels.
|
||||
// TODO(roasbeef): remove after spec change, no more chanID's!!!
|
||||
chanID := lnwire.ChannelID{
|
||||
chanID := lnwire.ShortChannelID{
|
||||
BlockHeight: confDetails.BlockHeight,
|
||||
TxIndex: confDetails.TxIndex,
|
||||
TxPosition: uint16(fundingPoint.Index),
|
||||
@ -1025,14 +1025,14 @@ type chanAnnouncement struct {
|
||||
// authenticated only by us and contains our directional routing policy for the
|
||||
// channel.
|
||||
func newChanAnnouncement(localIdentity, remotePub *btcec.PublicKey,
|
||||
channel *lnwallet.LightningChannel, chanID lnwire.ChannelID,
|
||||
channel *lnwallet.LightningChannel, chanID lnwire.ShortChannelID,
|
||||
localProof, remoteProof *channelProof) *chanAnnouncement {
|
||||
|
||||
// The unconditional section of the announcement is the ChannelID
|
||||
// itself which compactly encodes the location of the funding output
|
||||
// within the blockchain.
|
||||
chanAnn := &lnwire.ChannelAnnouncement{
|
||||
ChannelID: chanID,
|
||||
ShortChannelID: chanID,
|
||||
}
|
||||
|
||||
// The chanFlags field indicates which directed edge of the channel is
|
||||
@ -1048,27 +1048,27 @@ func newChanAnnouncement(localIdentity, remotePub *btcec.PublicKey,
|
||||
selfBytes := localIdentity.SerializeCompressed()
|
||||
remoteBytes := remotePub.SerializeCompressed()
|
||||
if bytes.Compare(selfBytes, remoteBytes) == -1 {
|
||||
chanAnn.FirstNodeID = localIdentity
|
||||
chanAnn.SecondNodeID = remotePub
|
||||
chanAnn.FirstNodeSig = localProof.nodeSig
|
||||
chanAnn.SecondNodeSig = remoteProof.nodeSig
|
||||
chanAnn.FirstBitcoinSig = localProof.nodeSig
|
||||
chanAnn.SecondBitcoinSig = remoteProof.nodeSig
|
||||
chanAnn.FirstBitcoinKey = channel.LocalFundingKey
|
||||
chanAnn.SecondBitcoinKey = channel.RemoteFundingKey
|
||||
chanAnn.NodeID1 = localIdentity
|
||||
chanAnn.NodeID2 = remotePub
|
||||
chanAnn.NodeSig1 = localProof.nodeSig
|
||||
chanAnn.NodeSig2 = remoteProof.nodeSig
|
||||
chanAnn.BitcoinSig1 = localProof.nodeSig
|
||||
chanAnn.BitcoinSig2 = remoteProof.nodeSig
|
||||
chanAnn.BitcoinKey1 = channel.LocalFundingKey
|
||||
chanAnn.BitcoinKey2 = channel.RemoteFundingKey
|
||||
|
||||
// If we're the first node then update the chanFlags to
|
||||
// indicate the "direction" of the update.
|
||||
chanFlags = 0
|
||||
} else {
|
||||
chanAnn.FirstNodeID = remotePub
|
||||
chanAnn.SecondNodeID = localIdentity
|
||||
chanAnn.FirstNodeSig = remoteProof.nodeSig
|
||||
chanAnn.SecondNodeSig = localProof.nodeSig
|
||||
chanAnn.FirstBitcoinSig = remoteProof.nodeSig
|
||||
chanAnn.SecondBitcoinSig = localProof.nodeSig
|
||||
chanAnn.FirstBitcoinKey = channel.RemoteFundingKey
|
||||
chanAnn.SecondBitcoinKey = channel.LocalFundingKey
|
||||
chanAnn.NodeID1 = remotePub
|
||||
chanAnn.NodeID2 = localIdentity
|
||||
chanAnn.NodeSig1 = remoteProof.nodeSig
|
||||
chanAnn.NodeSig2 = localProof.nodeSig
|
||||
chanAnn.BitcoinSig1 = remoteProof.nodeSig
|
||||
chanAnn.BitcoinSig2 = localProof.nodeSig
|
||||
chanAnn.BitcoinKey1 = channel.RemoteFundingKey
|
||||
chanAnn.BitcoinKey2 = channel.LocalFundingKey
|
||||
|
||||
// If we're the second node then update the chanFlags to
|
||||
// indicate the "direction" of the update.
|
||||
@ -1078,7 +1078,7 @@ func newChanAnnouncement(localIdentity, remotePub *btcec.PublicKey,
|
||||
// TODO(roasbeef): add real sig, populate proper FeeSchema
|
||||
chanUpdateAnn := &lnwire.ChannelUpdateAnnouncement{
|
||||
Signature: localProof.nodeSig,
|
||||
ChannelID: chanID,
|
||||
ShortChannelID: chanID,
|
||||
Timestamp: uint32(time.Now().Unix()),
|
||||
Flags: chanFlags,
|
||||
TimeLockDelta: 1,
|
||||
@ -1099,7 +1099,7 @@ func newChanAnnouncement(localIdentity, remotePub *btcec.PublicKey,
|
||||
// announcements are then send to the channel router to handle broadcasting to
|
||||
// the network during its next trickle.
|
||||
func (f *fundingManager) announceChannel(idKey, remoteIDKey *btcec.PublicKey,
|
||||
channel *lnwallet.LightningChannel, chanID lnwire.ChannelID, localProof,
|
||||
channel *lnwallet.LightningChannel, chanID lnwire.ShortChannelID, localProof,
|
||||
remoteProof *channelProof) {
|
||||
|
||||
// TODO(roasbeef): need a Signer.SignMessage method to finalize
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
8
peer.go
8
peer.go
@ -536,10 +536,10 @@ func (p *peer) logWireMessage(msg lnwire.Message, read bool) {
|
||||
case *lnwire.NodeAnnouncement:
|
||||
m.NodeID.Curve = nil
|
||||
case *lnwire.ChannelAnnouncement:
|
||||
m.FirstNodeID.Curve = nil
|
||||
m.SecondNodeID.Curve = nil
|
||||
m.FirstBitcoinKey.Curve = nil
|
||||
m.SecondBitcoinKey.Curve = nil
|
||||
m.NodeID1.Curve = nil
|
||||
m.NodeID2.Curve = nil
|
||||
m.BitcoinKey1.Curve = nil
|
||||
m.BitcoinKey2.Curve = nil
|
||||
case *lnwire.SingleFundingComplete:
|
||||
m.RevocationKey.Curve = nil
|
||||
case *lnwire.SingleFundingRequest:
|
||||
|
@ -75,7 +75,7 @@ func createTestNode() (*channeldb.LightningNode, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func randEdgePolicy(chanID lnwire.ChannelID,
|
||||
func randEdgePolicy(chanID lnwire.ShortChannelID,
|
||||
node *channeldb.LightningNode) *channeldb.ChannelEdgePolicy {
|
||||
|
||||
return &channeldb.ChannelEdgePolicy{
|
||||
@ -90,7 +90,7 @@ func randEdgePolicy(chanID lnwire.ChannelID,
|
||||
}
|
||||
|
||||
func randChannelEdge(ctx *testCtx, chanValue btcutil.Amount,
|
||||
fundingHeight uint32) (*wire.MsgTx, wire.OutPoint, lnwire.ChannelID) {
|
||||
fundingHeight uint32) (*wire.MsgTx, wire.OutPoint, lnwire.ShortChannelID) {
|
||||
|
||||
fundingTx := wire.NewMsgTx(2)
|
||||
fundingTx.TxOut = append(fundingTx.TxOut, &wire.TxOut{
|
||||
@ -105,7 +105,7 @@ func randChannelEdge(ctx *testCtx, chanValue btcutil.Amount,
|
||||
ctx.chain.addUtxo(chanUtxo, chanValue)
|
||||
|
||||
// Our fake channel will be "confirmed" at height 101.
|
||||
chanID := lnwire.ChannelID{
|
||||
chanID := lnwire.ShortChannelID{
|
||||
BlockHeight: fundingHeight,
|
||||
TxIndex: 0,
|
||||
TxPosition: 0,
|
||||
|
@ -547,7 +547,7 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
||||
// Before we can add the channel to the channel graph, we need
|
||||
// to obtain the full funding outpoint that's encoded within
|
||||
// the channel ID.
|
||||
channelID := lnwire.NewChanIDFromInt(msg.ChannelID)
|
||||
channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||
fundingPoint, err := r.fetchChanPoint(&channelID)
|
||||
if err != nil {
|
||||
return errors.Errorf("unable to fetch chan point for "+
|
||||
@ -580,7 +580,7 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
||||
fundingPoint, msg.ChannelID)
|
||||
|
||||
case *channeldb.ChannelEdgePolicy:
|
||||
channelID := lnwire.NewChanIDFromInt(msg.ChannelID)
|
||||
channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||
edge1Timestamp, edge2Timestamp, _, err := r.cfg.Graph.HasChannelEdge(msg.ChannelID)
|
||||
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
|
||||
return errors.Errorf("unable to check for edge "+
|
||||
@ -658,7 +658,7 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
||||
|
||||
// fetchChanPoint retrieves the original outpoint which is encoded within the
|
||||
// channelID.
|
||||
func (r *ChannelRouter) fetchChanPoint(chanID *lnwire.ChannelID) (*wire.OutPoint, error) {
|
||||
func (r *ChannelRouter) fetchChanPoint(chanID *lnwire.ShortChannelID) (*wire.OutPoint, error) {
|
||||
// First fetch the block hash by the block number encoded, then use
|
||||
// that hash to fetch the block itself.
|
||||
blockNum := int64(chanID.BlockHeight)
|
||||
|
Loading…
Reference in New Issue
Block a user