htlcswitch/hop: move hop.Exit and hop.Source to hop pkg
This commit is contained in:
parent
fc0e4be4d8
commit
378e0558c5
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -311,7 +312,7 @@ func (cm *circuitMap) restoreMemState() error {
|
|||||||
// documented case of stray keystones emerges for
|
// documented case of stray keystones emerges for
|
||||||
// forwarded payments, this check should be removed, but
|
// forwarded payments, this check should be removed, but
|
||||||
// with extreme caution.
|
// with extreme caution.
|
||||||
if strayKeystone.OutKey.ChanID != sourceHop {
|
if strayKeystone.OutKey.ChanID != hop.Source {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,9 +397,9 @@ func (cm *circuitMap) trimAllOpenCircuits() error {
|
|||||||
|
|
||||||
// First, skip any channels that have not been assigned their
|
// First, skip any channels that have not been assigned their
|
||||||
// final channel identifier, otherwise we would try to trim
|
// final channel identifier, otherwise we would try to trim
|
||||||
// htlcs belonging to the all-zero, sourceHop ID.
|
// htlcs belonging to the all-zero, hop.Source ID.
|
||||||
chanID := activeChannel.ShortChanID()
|
chanID := activeChannel.ShortChanID()
|
||||||
if chanID == sourceHop {
|
if chanID == hop.Source {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
htlcswitch/hop/type.go
Normal file
13
htlcswitch/hop/type.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package hop
|
||||||
|
|
||||||
|
import "github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Exit is a special "hop" denoting that an incoming HTLC is meant to
|
||||||
|
// pay finally to the receiving node.
|
||||||
|
Exit lnwire.ShortChannelID
|
||||||
|
|
||||||
|
// Source is a sentinel "hop" denoting that an incoming HTLC is
|
||||||
|
// initiated by our own switch.
|
||||||
|
Source lnwire.ShortChannelID
|
||||||
|
)
|
@ -14,16 +14,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// exitHop is a special "hop" which denotes that an incoming HTLC is
|
|
||||||
// meant to pay finally to the receiving node.
|
|
||||||
exitHop lnwire.ShortChannelID
|
|
||||||
|
|
||||||
// sourceHop is a sentinel value denoting that an incoming HTLC is
|
|
||||||
// initiated by our own switch.
|
|
||||||
sourceHop lnwire.ShortChannelID
|
|
||||||
)
|
|
||||||
|
|
||||||
// HopIterator is an interface that abstracts away the routing information
|
// HopIterator is an interface that abstracts away the routing information
|
||||||
// included in HTLC's which includes the entirety of the payment path of an
|
// included in HTLC's which includes the entirety of the payment path of an
|
||||||
// HTLC. This interface provides two basic method which carry out: how to
|
// HTLC. This interface provides two basic method which carry out: how to
|
||||||
@ -109,7 +99,7 @@ func (r *sphinxHopIterator) ForwardingInstructions() (
|
|||||||
|
|
||||||
switch r.processedPacket.Action {
|
switch r.processedPacket.Action {
|
||||||
case sphinx.ExitNode:
|
case sphinx.ExitNode:
|
||||||
nextHop = exitHop
|
nextHop = hop.Exit
|
||||||
case sphinx.MoreHops:
|
case sphinx.MoreHops:
|
||||||
s := binary.BigEndian.Uint64(fwdInst.NextAddress[:])
|
s := binary.BigEndian.Uint64(fwdInst.NextAddress[:])
|
||||||
nextHop = lnwire.NewShortChanIDFromInt(s)
|
nextHop = lnwire.NewShortChanIDFromInt(s)
|
||||||
|
@ -437,8 +437,8 @@ func (l *channelLink) Start() error {
|
|||||||
// off point, since all indexes below that are committed. This action
|
// off point, since all indexes below that are committed. This action
|
||||||
// is only performed if the link's final short channel ID has been
|
// is only performed if the link's final short channel ID has been
|
||||||
// assigned, otherwise we would try to trim the htlcs belonging to the
|
// assigned, otherwise we would try to trim the htlcs belonging to the
|
||||||
// all-zero, sourceHop ID.
|
// all-zero, hop.Source ID.
|
||||||
if l.ShortChanID() != sourceHop {
|
if l.ShortChanID() != hop.Source {
|
||||||
localHtlcIndex, err := l.channel.NextLocalHtlcIndex()
|
localHtlcIndex, err := l.channel.NextLocalHtlcIndex()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve next local "+
|
return fmt.Errorf("unable to retrieve next local "+
|
||||||
@ -536,7 +536,7 @@ func (l *channelLink) WaitForShutdown() {
|
|||||||
// the all-zero source ID, meaning that the channel has had its ID finalized.
|
// the all-zero source ID, meaning that the channel has had its ID finalized.
|
||||||
func (l *channelLink) EligibleToForward() bool {
|
func (l *channelLink) EligibleToForward() bool {
|
||||||
return l.channel.RemoteNextRevocation() != nil &&
|
return l.channel.RemoteNextRevocation() != nil &&
|
||||||
l.ShortChanID() != sourceHop
|
l.ShortChanID() != hop.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
// sampleNetworkFee samples the current fee rate on the network to get into the
|
// sampleNetworkFee samples the current fee rate on the network to get into the
|
||||||
@ -962,7 +962,7 @@ func (l *channelLink) htlcManager() {
|
|||||||
// only attempt to resolve packages if our short chan id indicates that
|
// only attempt to resolve packages if our short chan id indicates that
|
||||||
// the channel is not pending, otherwise we should have no htlcs to
|
// the channel is not pending, otherwise we should have no htlcs to
|
||||||
// reforward.
|
// reforward.
|
||||||
if l.ShortChanID() != sourceHop {
|
if l.ShortChanID() != hop.Source {
|
||||||
if err := l.resolveFwdPkgs(); err != nil {
|
if err := l.resolveFwdPkgs(); err != nil {
|
||||||
l.fail(LinkFailureError{code: ErrInternalError},
|
l.fail(LinkFailureError{code: ErrInternalError},
|
||||||
"unable to resolve fwd pkgs: %v", err)
|
"unable to resolve fwd pkgs: %v", err)
|
||||||
@ -2076,7 +2076,7 @@ func (l *channelLink) UpdateShortChanID() (lnwire.ShortChannelID, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
l.errorf("unable to refresh short_chan_id for chan_id=%v: %v",
|
l.errorf("unable to refresh short_chan_id for chan_id=%v: %v",
|
||||||
chanID, err)
|
chanID, err)
|
||||||
return sourceHop, err
|
return hop.Source, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sid := l.channel.ShortChanID()
|
sid := l.channel.ShortChanID()
|
||||||
@ -2675,7 +2675,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch fwdInfo.NextHop {
|
switch fwdInfo.NextHop {
|
||||||
case exitHop:
|
case hop.Exit:
|
||||||
updated, err := l.processExitHop(
|
updated, err := l.processExitHop(
|
||||||
pd, obfuscator, fwdInfo, heightNow,
|
pd, obfuscator, fwdInfo, heightNow,
|
||||||
chanIterator.ExtraOnionBlob(),
|
chanIterator.ExtraOnionBlob(),
|
||||||
|
@ -1937,7 +1937,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
}
|
}
|
||||||
addPkt := htlcPacket{
|
addPkt := htlcPacket{
|
||||||
htlc: htlc,
|
htlc: htlc,
|
||||||
incomingChanID: sourceHop,
|
incomingChanID: hop.Source,
|
||||||
incomingHTLCID: 0,
|
incomingHTLCID: 0,
|
||||||
obfuscator: NewMockObfuscator(),
|
obfuscator: NewMockObfuscator(),
|
||||||
}
|
}
|
||||||
@ -2017,7 +2017,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
}
|
}
|
||||||
addPkt = htlcPacket{
|
addPkt = htlcPacket{
|
||||||
htlc: htlc,
|
htlc: htlc,
|
||||||
incomingChanID: sourceHop,
|
incomingChanID: hop.Source,
|
||||||
incomingHTLCID: 1,
|
incomingHTLCID: 1,
|
||||||
obfuscator: NewMockObfuscator(),
|
obfuscator: NewMockObfuscator(),
|
||||||
}
|
}
|
||||||
@ -2535,7 +2535,7 @@ func genAddsAndCircuits(numHtlcs int, htlc *lnwire.UpdateAddHTLC) (
|
|||||||
for i := 0; i < numHtlcs; i++ {
|
for i := 0; i < numHtlcs; i++ {
|
||||||
addPkt := htlcPacket{
|
addPkt := htlcPacket{
|
||||||
htlc: htlc,
|
htlc: htlc,
|
||||||
incomingChanID: sourceHop,
|
incomingChanID: hop.Source,
|
||||||
incomingHTLCID: uint64(i),
|
incomingHTLCID: uint64(i),
|
||||||
obfuscator: NewMockObfuscator(),
|
obfuscator: NewMockObfuscator(),
|
||||||
}
|
}
|
||||||
@ -4311,7 +4311,7 @@ func generateHtlcAndInvoice(t *testing.T,
|
|||||||
hops := []hop.ForwardingInfo{
|
hops := []hop.ForwardingInfo{
|
||||||
{
|
{
|
||||||
Network: hop.BitcoinNetwork,
|
Network: hop.BitcoinNetwork,
|
||||||
NextHop: exitHop,
|
NextHop: hop.Exit,
|
||||||
AmountToForward: htlcAmt,
|
AmountToForward: htlcAmt,
|
||||||
OutgoingCTLV: uint32(htlcExpiry),
|
OutgoingCTLV: uint32(htlcExpiry),
|
||||||
},
|
},
|
||||||
|
@ -16,6 +16,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/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -354,7 +355,7 @@ func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash,
|
|||||||
nChan <-chan *networkResult
|
nChan <-chan *networkResult
|
||||||
err error
|
err error
|
||||||
outKey = CircuitKey{
|
outKey = CircuitKey{
|
||||||
ChanID: sourceHop,
|
ChanID: hop.Source,
|
||||||
HtlcID: paymentID,
|
HtlcID: paymentID,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -428,7 +429,7 @@ func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, paymentID uint64,
|
|||||||
// this stage it means that packet haven't left boundaries of our
|
// this stage it means that packet haven't left boundaries of our
|
||||||
// system and something wrong happened.
|
// system and something wrong happened.
|
||||||
packet := &htlcPacket{
|
packet := &htlcPacket{
|
||||||
incomingChanID: sourceHop,
|
incomingChanID: hop.Source,
|
||||||
incomingHTLCID: paymentID,
|
incomingHTLCID: paymentID,
|
||||||
outgoingChanID: firstHop,
|
outgoingChanID: firstHop,
|
||||||
htlc: htlc,
|
htlc: htlc,
|
||||||
@ -513,7 +514,7 @@ func (s *Switch) forward(packet *htlcPacket) error {
|
|||||||
return ErrDuplicateAdd
|
return ErrDuplicateAdd
|
||||||
|
|
||||||
case len(actions.Fails) == 1:
|
case len(actions.Fails) == 1:
|
||||||
if packet.incomingChanID == sourceHop {
|
if packet.incomingChanID == hop.Source {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1031,14 +1032,14 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
case *lnwire.UpdateAddHTLC:
|
case *lnwire.UpdateAddHTLC:
|
||||||
// Check if the node is set to reject all onward HTLCs and also make
|
// Check if the node is set to reject all onward HTLCs and also make
|
||||||
// sure that HTLC is not from the source node.
|
// sure that HTLC is not from the source node.
|
||||||
if s.cfg.RejectHTLC && packet.incomingChanID != sourceHop {
|
if s.cfg.RejectHTLC && packet.incomingChanID != hop.Source {
|
||||||
failure := &lnwire.FailChannelDisabled{}
|
failure := &lnwire.FailChannelDisabled{}
|
||||||
addErr := fmt.Errorf("unable to forward any htlcs")
|
addErr := fmt.Errorf("unable to forward any htlcs")
|
||||||
|
|
||||||
return s.failAddPacket(packet, failure, addErr)
|
return s.failAddPacket(packet, failure, addErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if packet.incomingChanID == sourceHop {
|
if packet.incomingChanID == hop.Source {
|
||||||
// A blank incomingChanID indicates that this is
|
// A blank incomingChanID indicates that this is
|
||||||
// a pending user-initiated payment.
|
// a pending user-initiated payment.
|
||||||
return s.handleLocalDispatch(packet)
|
return s.handleLocalDispatch(packet)
|
||||||
@ -1080,7 +1081,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
|
|
||||||
// If the link doesn't yet have a source chan ID, then
|
// If the link doesn't yet have a source chan ID, then
|
||||||
// we'll skip it as well.
|
// we'll skip it as well.
|
||||||
case link.ShortChanID() == sourceHop:
|
case link.ShortChanID() == hop.Source:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1222,7 +1223,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): only do this once link actually
|
// TODO(roasbeef): only do this once link actually
|
||||||
// fully settles?
|
// fully settles?
|
||||||
localHTLC := packet.incomingChanID == sourceHop
|
localHTLC := packet.incomingChanID == hop.Source
|
||||||
if !localHTLC {
|
if !localHTLC {
|
||||||
s.fwdEventMtx.Lock()
|
s.fwdEventMtx.Lock()
|
||||||
s.pendingFwdingEvents = append(
|
s.pendingFwdingEvents = append(
|
||||||
@ -1241,7 +1242,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
|
|
||||||
// A blank IncomingChanID in a circuit indicates that it is a pending
|
// A blank IncomingChanID in a circuit indicates that it is a pending
|
||||||
// user-initiated payment.
|
// user-initiated payment.
|
||||||
if packet.incomingChanID == sourceHop {
|
if packet.incomingChanID == hop.Source {
|
||||||
return s.handleLocalDispatch(packet)
|
return s.handleLocalDispatch(packet)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1798,7 +1799,7 @@ func (s *Switch) reforwardResponses() error {
|
|||||||
shortChanID := openChannel.ShortChanID()
|
shortChanID := openChannel.ShortChanID()
|
||||||
|
|
||||||
// Locally-initiated payments never need reforwarding.
|
// Locally-initiated payments never need reforwarding.
|
||||||
if shortChanID == sourceHop {
|
if shortChanID == hop.Source {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1994,7 +1995,7 @@ func (s *Switch) AddLink(link ChannelLink) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shortChanID := link.ShortChanID()
|
shortChanID := link.ShortChanID()
|
||||||
if shortChanID == sourceHop {
|
if shortChanID == hop.Source {
|
||||||
log.Infof("Adding pending link chan_id=%v, short_chan_id=%v",
|
log.Infof("Adding pending link chan_id=%v, short_chan_id=%v",
|
||||||
chanID, shortChanID)
|
chanID, shortChanID)
|
||||||
|
|
||||||
@ -2157,7 +2158,7 @@ func (s *Switch) UpdateShortChanID(chanID lnwire.ChannelID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reject any blank short channel ids.
|
// Reject any blank short channel ids.
|
||||||
if shortChanID == sourceHop {
|
if shortChanID == hop.Source {
|
||||||
return fmt.Errorf("refusing trivial short_chan_id for chan_id=%v"+
|
return fmt.Errorf("refusing trivial short_chan_id for chan_id=%v"+
|
||||||
"live link", chanID)
|
"live link", chanID)
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32,
|
|||||||
for i := len(path) - 1; i >= 0; i-- {
|
for i := len(path) - 1; i >= 0; i-- {
|
||||||
// If this is the last hop, then the next hop is the special
|
// If this is the last hop, then the next hop is the special
|
||||||
// "exit node". Otherwise, we look to the "prior" hop.
|
// "exit node". Otherwise, we look to the "prior" hop.
|
||||||
nextHop := exitHop
|
nextHop := hop.Exit
|
||||||
if i != len(path)-1 {
|
if i != len(path)-1 {
|
||||||
nextHop = path[i+1].channel.ShortChanID()
|
nextHop = path[i+1].channel.ShortChanID()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user