From 4c7af9f16d53dfb913fa491f8c54f3a41eca3637 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 16 Jun 2017 23:38:42 +0200 Subject: [PATCH] htlcswitch: eliminate HopID in favor of a [33]byte for compressed pub keys --- htlcswitch/circuit.go | 2 +- htlcswitch/interfaces.go | 9 ++------- htlcswitch/iterator.go | 23 ++--------------------- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/htlcswitch/circuit.go b/htlcswitch/circuit.go index 978050ea..624209c4 100644 --- a/htlcswitch/circuit.go +++ b/htlcswitch/circuit.go @@ -14,7 +14,7 @@ import ( // Currently, the payment hash is used to uniquely identify each circuit. type circuitKey [sha256.Size]byte -// String represent the circuit key in string format. +// String returns the string representation of the circuitKey. func (k *circuitKey) String() string { return hex.EncodeToString(k[:]) } diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index b32291d4..cbf36f96 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -1,8 +1,6 @@ package htlcswitch import ( - "crypto/sha256" - "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" @@ -83,15 +81,12 @@ type Peer interface { // SendMessage sends message to remote peer. SendMessage(lnwire.Message) error - // ID returns the lightning network peer id. - ID() [sha256.Size]byte - // WipeChannel removes the passed channel from all indexes associated // with the peer. WipeChannel(*lnwallet.LightningChannel) error - // PubKey returns the peer public key. - PubKey() []byte + // PubKey returns the serialize public key of the source peer. + PubKey() [33]byte // Disconnect disconnects with peer if we have error which we can't // properly handle. diff --git a/htlcswitch/iterator.go b/htlcswitch/iterator.go index f35e925c..7dd780da 100644 --- a/htlcswitch/iterator.go +++ b/htlcswitch/iterator.go @@ -1,34 +1,21 @@ package htlcswitch import ( - "bytes" - "encoding/hex" + "encoding/binary" "io" - "github.com/btcsuite/golangcrypto/ripemd160" "github.com/go-errors/errors" "github.com/lightningnetwork/lightning-onion" - "github.com/lightningnetwork/lnd/routing" - "github.com/roasbeef/btcd/btcec" + "github.com/lightningnetwork/lnd/lnwire" "github.com/roasbeef/btcutil" ) -// HopID represents the id which is used by propagation subsystem in order to -// identify lightning network node. -// TODO(andrew.shvv) remove after switching to the using channel id. -type HopID [ripemd160.Size]byte // NetworkHop indicates the blockchain network that is intended to be the next // hop for a forwarded HTLC. The existnce of this field within the // ForwardingInfo struct enables the ability for HTLC to cross chain-boundaries // at will. type NetworkHop uint8 -// NewHopID creates new instance of hop form node public key. -func NewHopID(pubKey []byte) HopID { - var routeID HopID - copy(routeID[:], btcutil.Hash160(pubKey)) - return routeID -} const ( // BitcoinHop denotes that an HTLC is to be forwarded along the Bitcoin // link with the specified short channel ID. @@ -39,9 +26,6 @@ const ( LitecoinHop ) -// String returns string representation of hop id. -func (h HopID) String() string { - return hex.EncodeToString(h[:]) // String returns the string representation of the target NetworkHop. func (c NetworkHop) String() string { switch c { @@ -54,9 +38,6 @@ func (c NetworkHop) String() string { } } -// IsEqual checks does the two hop ids are equal. -func (h HopID) IsEqual(h2 HopID) bool { - return bytes.Equal(h[:], h2[:]) var ( // exitHop is a special "hop" which denotes that an incoming HTLC is // meant to pay finally to the receiving node.