htlcswitch/hop: move NetworkHop to hop.Network

This commit is contained in:
Conner Fromknecht 2019-08-30 14:05:53 -07:00
parent 866867a4b0
commit 83d2112e8b
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
5 changed files with 37 additions and 33 deletions

28
htlcswitch/hop/network.go Normal file

@ -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"
}
}

@ -8,39 +8,12 @@ import (
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/tlv" "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 ( var (
// exitHop is a special "hop" which denotes that an incoming HTLC is // exitHop is a special "hop" which denotes that an incoming HTLC is
// meant to pay finally to the receiving node. // meant to pay finally to the receiving node.
@ -59,7 +32,7 @@ var (
type ForwardingInfo struct { type ForwardingInfo struct {
// Network is the target blockchain network that the HTLC will travel // Network is the target blockchain network that the HTLC will travel
// over next. // over next.
Network NetworkHop Network hop.Network
// NextHop is the channel ID of the next hop. The received HTLC should // NextHop is the channel ID of the next hop. The received HTLC should
// be forwarded to this particular channel in order to continue the // be forwarded to this particular channel in order to continue the
@ -199,7 +172,7 @@ func (r *sphinxHopIterator) ForwardingInstructions() (ForwardingInfo, error) {
} }
return ForwardingInfo{ return ForwardingInfo{
Network: BitcoinHop, Network: hop.BitcoinNetwork,
NextHop: nextHop, NextHop: nextHop,
AmountToForward: lnwire.MilliSatoshi(amt), AmountToForward: lnwire.MilliSatoshi(amt),
OutgoingCTLV: cltv, OutgoingCTLV: cltv,

@ -26,6 +26,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/htlcswitch/hodl" "github.com/lightningnetwork/lnd/htlcswitch/hodl"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnpeer"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
@ -4309,7 +4310,7 @@ func generateHtlcAndInvoice(t *testing.T,
htlcExpiry := testStartingHeight + testInvoiceCltvExpiry htlcExpiry := testStartingHeight + testInvoiceCltvExpiry
hops := []ForwardingInfo{ hops := []ForwardingInfo{
{ {
Network: BitcoinHop, Network: hop.BitcoinNetwork,
NextHop: exitHop, NextHop: exitHop,
AmountToForward: htlcAmt, AmountToForward: htlcAmt,
OutgoingCTLV: uint32(htlcExpiry), OutgoingCTLV: uint32(htlcExpiry),

@ -23,6 +23,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnpeer"
@ -485,7 +486,7 @@ func (f *ForwardingInfo) decode(r io.Reader) error {
if _, err := r.Read(net[:]); err != nil { if _, err := r.Read(net[:]); err != nil {
return err return err
} }
f.Network = NetworkHop(net[0]) f.Network = hop.Network(net[0])
if err := binary.Read(r, binary.BigEndian, &f.NextHop); err != nil { if err := binary.Read(r, binary.BigEndian, &f.NextHop); err != nil {
return err return err

@ -25,6 +25,7 @@ import (
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnpeer"
@ -680,7 +681,7 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32,
} }
hops[i] = ForwardingInfo{ hops[i] = ForwardingInfo{
Network: BitcoinHop, Network: hop.BitcoinNetwork,
NextHop: nextHop, NextHop: nextHop,
AmountToForward: amount, AmountToForward: amount,
OutgoingCTLV: timeLock, OutgoingCTLV: timeLock,