From 83d2112e8b189fb229193d9d3b88f58dcf83c87f Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 30 Aug 2019 14:05:53 -0700 Subject: [PATCH] htlcswitch/hop: move NetworkHop to hop.Network --- htlcswitch/hop/network.go | 28 ++++++++++++++++++++++++++++ htlcswitch/iterator.go | 33 +++------------------------------ htlcswitch/link_test.go | 3 ++- htlcswitch/mock.go | 3 ++- htlcswitch/test_utils.go | 3 ++- 5 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 htlcswitch/hop/network.go diff --git a/htlcswitch/hop/network.go b/htlcswitch/hop/network.go new file mode 100644 index 00000000..6f121642 --- /dev/null +++ b/htlcswitch/hop/network.go @@ -0,0 +1,28 @@ +package hop + +// Network indicates the blockchain network that is intended to be the next hop +// for a forwarded HTLC. The existence of this field within the ForwardingInfo +// struct enables the ability for HTLC to cross chain-boundaries at will. +type Network uint8 + +const ( + // BitcoinNetwork denotes that an HTLC is to be forwarded along the + // Bitcoin link with the specified short channel ID. + BitcoinNetwork Network = iota + + // LitecoinNetwork denotes that an HTLC is to be forwarded along the + // Litecoin link with the specified short channel ID. + LitecoinNetwork +) + +// String returns the string representation of the target Network. +func (c Network) String() string { + switch c { + case BitcoinNetwork: + return "Bitcoin" + case LitecoinNetwork: + return "Litecoin" + default: + return "Kekcoin" + } +} diff --git a/htlcswitch/iterator.go b/htlcswitch/iterator.go index f201129e..66869d52 100644 --- a/htlcswitch/iterator.go +++ b/htlcswitch/iterator.go @@ -8,39 +8,12 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/lightningnetwork/lightning-onion" + "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/tlv" ) -// NetworkHop indicates the blockchain network that is intended to be the next -// hop for a forwarded HTLC. The existence of this field within the -// ForwardingInfo struct enables the ability for HTLC to cross chain-boundaries -// at will. -type NetworkHop uint8 - -const ( - // BitcoinHop denotes that an HTLC is to be forwarded along the Bitcoin - // link with the specified short channel ID. - BitcoinHop NetworkHop = iota - - // LitecoinHop denotes that an HTLC is to be forwarded along the - // Litecoin link with the specified short channel ID. - LitecoinHop -) - -// String returns the string representation of the target NetworkHop. -func (c NetworkHop) String() string { - switch c { - case BitcoinHop: - return "Bitcoin" - case LitecoinHop: - return "Litecoin" - default: - return "Kekcoin" - } -} - var ( // exitHop is a special "hop" which denotes that an incoming HTLC is // meant to pay finally to the receiving node. @@ -59,7 +32,7 @@ var ( type ForwardingInfo struct { // Network is the target blockchain network that the HTLC will travel // over next. - Network NetworkHop + Network hop.Network // NextHop is the channel ID of the next hop. The received HTLC should // be forwarded to this particular channel in order to continue the @@ -199,7 +172,7 @@ func (r *sphinxHopIterator) ForwardingInstructions() (ForwardingInfo, error) { } return ForwardingInfo{ - Network: BitcoinHop, + Network: hop.BitcoinNetwork, NextHop: nextHop, AmountToForward: lnwire.MilliSatoshi(amt), OutgoingCTLV: cltv, diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 3c337c16..d05e4754 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -26,6 +26,7 @@ import ( "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/htlcswitch/hodl" + "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lntypes" @@ -4309,7 +4310,7 @@ func generateHtlcAndInvoice(t *testing.T, htlcExpiry := testStartingHeight + testInvoiceCltvExpiry hops := []ForwardingInfo{ { - Network: BitcoinHop, + Network: hop.BitcoinNetwork, NextHop: exitHop, AmountToForward: htlcAmt, OutgoingCTLV: uint32(htlcExpiry), diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 34651b5e..2256ca54 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -23,6 +23,7 @@ import ( "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/contractcourt" + "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lnpeer" @@ -485,7 +486,7 @@ func (f *ForwardingInfo) decode(r io.Reader) error { if _, err := r.Read(net[:]); err != nil { return err } - f.Network = NetworkHop(net[0]) + f.Network = hop.Network(net[0]) if err := binary.Read(r, binary.BigEndian, &f.NextHop); err != nil { return err diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 50a73a23..02ddedbc 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -25,6 +25,7 @@ import ( "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/contractcourt" + "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnpeer" @@ -680,7 +681,7 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32, } hops[i] = ForwardingInfo{ - Network: BitcoinHop, + Network: hop.BitcoinNetwork, NextHop: nextHop, AmountToForward: amount, OutgoingCTLV: timeLock,