2017-05-01 18:58:08 +02:00
|
|
|
package htlcswitch
|
|
|
|
|
|
|
|
import (
|
2018-10-30 10:36:27 +01:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2017-05-03 16:02:22 +02:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
2022-11-18 12:15:22 +01:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
2019-02-20 12:11:15 +01:00
|
|
|
"github.com/lightningnetwork/lnd/invoices"
|
2018-06-08 05:10:26 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnpeer"
|
2019-01-15 11:31:22 +01:00
|
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
2019-06-14 02:27:55 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
2021-09-28 17:43:51 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
2017-05-01 18:58:08 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2020-06-24 12:03:00 +02:00
|
|
|
"github.com/lightningnetwork/lnd/record"
|
2017-05-01 18:58:08 +02:00
|
|
|
)
|
|
|
|
|
2017-05-03 16:02:22 +02:00
|
|
|
// InvoiceDatabase is an interface which represents the persistent subsystem
|
|
|
|
// which may search, lookup and settle invoices.
|
|
|
|
type InvoiceDatabase interface {
|
2018-02-07 04:13:07 +01:00
|
|
|
// LookupInvoice attempts to look up an invoice according to its 32
|
2019-08-20 14:54:39 +02:00
|
|
|
// byte payment hash.
|
|
|
|
LookupInvoice(lntypes.Hash) (channeldb.Invoice, error)
|
2017-05-03 16:02:22 +02:00
|
|
|
|
2019-02-20 12:11:15 +01:00
|
|
|
// NotifyExitHopHtlc attempts to mark an invoice as settled. If the
|
|
|
|
// invoice is a debug invoice, then this method is a noop as debug
|
|
|
|
// invoices are never fully settled. The return value describes how the
|
2019-02-11 12:01:05 +01:00
|
|
|
// htlc should be resolved. If the htlc cannot be resolved immediately,
|
2019-07-31 06:52:17 +02:00
|
|
|
// the resolution is sent on the passed in hodlChan later. The eob
|
|
|
|
// field passes the entire onion hop payload into the invoice registry
|
|
|
|
// for decoding purposes.
|
2019-02-11 12:01:05 +01:00
|
|
|
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
|
2019-04-16 12:11:20 +02:00
|
|
|
expiry uint32, currentHeight int32,
|
2022-11-18 12:15:22 +01:00
|
|
|
circuitKey models.CircuitKey, hodlChan chan<- interface{},
|
2020-02-06 18:35:10 +01:00
|
|
|
payload invoices.Payload) (invoices.HtlcResolution, error)
|
2019-01-11 11:19:16 +01:00
|
|
|
|
|
|
|
// CancelInvoice attempts to cancel the invoice corresponding to the
|
|
|
|
// passed payment hash.
|
|
|
|
CancelInvoice(payHash lntypes.Hash) error
|
2019-02-11 12:01:05 +01:00
|
|
|
|
|
|
|
// SettleHodlInvoice settles a hold invoice.
|
|
|
|
SettleHodlInvoice(preimage lntypes.Preimage) error
|
|
|
|
|
2019-12-20 11:25:07 +01:00
|
|
|
// HodlUnsubscribeAll unsubscribes from all htlc resolutions.
|
2019-02-11 12:01:05 +01:00
|
|
|
HodlUnsubscribeAll(subscriber chan<- interface{})
|
2017-05-03 16:02:22 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 20:59:15 +02:00
|
|
|
// packetHandler is an interface used exclusively by the Switch to handle
|
|
|
|
// htlcPacket and pass them to the link implementation.
|
|
|
|
type packetHandler interface {
|
|
|
|
// handleSwitchPacket handles the switch packets. These packets might
|
|
|
|
// be forwarded to us from another channel link in case the htlc
|
|
|
|
// update came from another peer or if the update was created by user
|
|
|
|
// initially.
|
|
|
|
//
|
|
|
|
// NOTE: This function should block as little as possible.
|
|
|
|
handleSwitchPacket(*htlcPacket) error
|
|
|
|
}
|
|
|
|
|
2021-09-28 17:43:51 +02:00
|
|
|
// dustHandler is an interface used exclusively by the Switch to evaluate
|
|
|
|
// whether a link has too much dust exposure.
|
|
|
|
type dustHandler interface {
|
|
|
|
// getDustSum returns the dust sum on either the local or remote
|
|
|
|
// commitment.
|
|
|
|
getDustSum(remote bool) lnwire.MilliSatoshi
|
|
|
|
|
|
|
|
// getFeeRate returns the current channel feerate.
|
|
|
|
getFeeRate() chainfee.SatPerKWeight
|
|
|
|
|
|
|
|
// getDustClosure returns a closure that can evaluate whether a passed
|
|
|
|
// HTLC is dust.
|
|
|
|
getDustClosure() dustClosure
|
|
|
|
}
|
|
|
|
|
server+htlcswitch: prevent privacy leaks, allow alias routing
This intent of this change is to prevent privacy leaks when routing
with aliases and also to allow routing when using an alias. The
aliases are our aliases.
Introduces are two maps:
* aliasToReal:
This is an N->1 mapping for a channel. The keys are the set of
aliases and the value is the confirmed, on-chain SCID.
* baseIndex:
This is also an N->1 mapping for a channel. The keys are the set
of aliases and the value is the "base" SCID (whatever is in the
OpenChannel.ShortChannelID field). There is also a base->base
mapping, so not all keys are aliases.
The above maps are populated when a link is added to the switch and
when the channel has confirmed on-chain. The maps are not removed
from if the link is removed, but this is fine since forwarding won't
occur.
* getLinkByMapping
This function is introduced to adhere to the spec requirements that
using the confirmed SCID of a private, scid-alias-feature-bit
channel does not work. Lnd implements a stricter version of the spec
and disallows this behavior if the feature-bit was negotiated, rather
than just the channel type. The old, privacy-leak behavior is
preserved.
The spec also requires that if we must fail back an HTLC, the
ChannelUpdate must use the SCID of whatever was in the onion, to avoid
a privacy leak. This is also done by passing in the relevant SCID to
the mailbox and link. Lnd will also cancel back on the "incoming" side
if the InterceptableSwitch was used or if the link failed to decrypt
the onion. In this case, we are cautious and replace the SCID if an
alias exists.
2022-04-04 22:44:51 +02:00
|
|
|
// scidAliasHandler is an interface that the ChannelLink implements so it can
|
|
|
|
// properly handle option_scid_alias channels.
|
|
|
|
type scidAliasHandler interface {
|
|
|
|
// attachFailAliasUpdate allows the link to properly fail incoming
|
|
|
|
// HTLCs on option_scid_alias channels.
|
|
|
|
attachFailAliasUpdate(failClosure func(
|
|
|
|
sid lnwire.ShortChannelID,
|
|
|
|
incoming bool) *lnwire.ChannelUpdate)
|
|
|
|
|
|
|
|
// getAliases fetches the link's underlying aliases. This is used by
|
|
|
|
// the Switch to determine whether to forward an HTLC and where to
|
|
|
|
// forward an HTLC.
|
|
|
|
getAliases() []lnwire.ShortChannelID
|
|
|
|
|
|
|
|
// isZeroConf returns whether or not the underlying channel is a
|
|
|
|
// zero-conf channel.
|
|
|
|
isZeroConf() bool
|
|
|
|
|
|
|
|
// negotiatedAliasFeature returns whether the option-scid-alias feature
|
|
|
|
// bit was negotiated.
|
|
|
|
negotiatedAliasFeature() bool
|
|
|
|
|
|
|
|
// confirmedScid returns the confirmed SCID for a zero-conf channel.
|
|
|
|
confirmedScid() lnwire.ShortChannelID
|
|
|
|
|
|
|
|
// zeroConfConfirmed returns whether or not the zero-conf channel has
|
|
|
|
// confirmed.
|
|
|
|
zeroConfConfirmed() bool
|
|
|
|
}
|
|
|
|
|
2021-08-03 21:06:26 +02:00
|
|
|
// ChannelUpdateHandler is an interface that provides methods that allow
|
|
|
|
// sending lnwire.Message to the underlying link as well as querying state.
|
|
|
|
type ChannelUpdateHandler interface {
|
|
|
|
// HandleChannelUpdate handles the htlc requests as settle/add/fail
|
|
|
|
// which sent to us from remote peer we have a channel with.
|
|
|
|
//
|
|
|
|
// NOTE: This function MUST be non-blocking (or block as little as
|
|
|
|
// possible).
|
|
|
|
HandleChannelUpdate(lnwire.Message)
|
|
|
|
|
|
|
|
// ChanID returns the channel ID for the channel link. The channel ID
|
|
|
|
// is a more compact representation of a channel's full outpoint.
|
|
|
|
ChanID() lnwire.ChannelID
|
|
|
|
|
|
|
|
// Bandwidth returns the amount of milli-satoshis which current link
|
|
|
|
// might pass through channel link. The value returned from this method
|
|
|
|
// represents the up to date available flow through the channel. This
|
|
|
|
// takes into account any forwarded but un-cleared HTLC's, and any
|
|
|
|
// HTLC's which have been set to the over flow queue.
|
|
|
|
Bandwidth() lnwire.MilliSatoshi
|
|
|
|
|
|
|
|
// EligibleToForward returns a bool indicating if the channel is able
|
|
|
|
// to actively accept requests to forward HTLC's. A channel may be
|
|
|
|
// active, but not able to forward HTLC's if it hasn't yet finalized
|
|
|
|
// the pre-channel operation protocol with the remote peer. The switch
|
|
|
|
// will use this function in forwarding decisions accordingly.
|
|
|
|
EligibleToForward() bool
|
|
|
|
|
|
|
|
// MayAddOutgoingHtlc returns an error if we may not add an outgoing
|
2021-10-19 09:37:47 +02:00
|
|
|
// htlc to the channel, taking the amount of the htlc to add as a
|
|
|
|
// parameter.
|
|
|
|
MayAddOutgoingHtlc(lnwire.MilliSatoshi) error
|
2021-08-10 22:59:17 +02:00
|
|
|
|
|
|
|
// ShutdownIfChannelClean shuts the link down if the channel state is
|
|
|
|
// clean. This can be used with dynamic commitment negotiation or coop
|
|
|
|
// close negotiation which require a clean channel state.
|
|
|
|
ShutdownIfChannelClean() error
|
2021-08-03 21:06:26 +02:00
|
|
|
}
|
|
|
|
|
2017-06-16 23:32:41 +02:00
|
|
|
// ChannelLink is an interface which represents the subsystem for managing the
|
|
|
|
// incoming htlc requests, applying the changes to the channel, and also
|
2017-05-01 18:58:08 +02:00
|
|
|
// propagating/forwarding it to htlc switch.
|
|
|
|
//
|
2022-08-22 20:58:42 +02:00
|
|
|
// abstraction level
|
|
|
|
// ^
|
|
|
|
// |
|
|
|
|
// | - - - - - - - - - - - - Lightning - - - - - - - - - - - - -
|
|
|
|
// |
|
|
|
|
// | (Switch) (Switch) (Switch)
|
|
|
|
// | Alice <-- channel link --> Bob <-- channel link --> Carol
|
|
|
|
// |
|
|
|
|
// | - - - - - - - - - - - - - TCP - - - - - - - - - - - - - - -
|
|
|
|
// |
|
|
|
|
// | (Peer) (Peer) (Peer)
|
|
|
|
// | Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
|
|
|
|
// |
|
2017-05-01 18:58:08 +02:00
|
|
|
type ChannelLink interface {
|
2017-11-10 23:48:23 +01:00
|
|
|
// TODO(roasbeef): modify interface to embed mail boxes?
|
|
|
|
|
2021-08-03 20:59:15 +02:00
|
|
|
// Embed the packetHandler interface.
|
|
|
|
packetHandler
|
2020-04-13 17:29:52 +02:00
|
|
|
|
2021-08-03 21:06:26 +02:00
|
|
|
// Embed the ChannelUpdateHandler interface.
|
|
|
|
ChannelUpdateHandler
|
2017-05-01 18:58:08 +02:00
|
|
|
|
2021-09-28 17:43:51 +02:00
|
|
|
// Embed the dustHandler interface.
|
|
|
|
dustHandler
|
|
|
|
|
server+htlcswitch: prevent privacy leaks, allow alias routing
This intent of this change is to prevent privacy leaks when routing
with aliases and also to allow routing when using an alias. The
aliases are our aliases.
Introduces are two maps:
* aliasToReal:
This is an N->1 mapping for a channel. The keys are the set of
aliases and the value is the confirmed, on-chain SCID.
* baseIndex:
This is also an N->1 mapping for a channel. The keys are the set
of aliases and the value is the "base" SCID (whatever is in the
OpenChannel.ShortChannelID field). There is also a base->base
mapping, so not all keys are aliases.
The above maps are populated when a link is added to the switch and
when the channel has confirmed on-chain. The maps are not removed
from if the link is removed, but this is fine since forwarding won't
occur.
* getLinkByMapping
This function is introduced to adhere to the spec requirements that
using the confirmed SCID of a private, scid-alias-feature-bit
channel does not work. Lnd implements a stricter version of the spec
and disallows this behavior if the feature-bit was negotiated, rather
than just the channel type. The old, privacy-leak behavior is
preserved.
The spec also requires that if we must fail back an HTLC, the
ChannelUpdate must use the SCID of whatever was in the onion, to avoid
a privacy leak. This is also done by passing in the relevant SCID to
the mailbox and link. Lnd will also cancel back on the "incoming" side
if the InterceptableSwitch was used or if the link failed to decrypt
the onion. In this case, we are cautious and replace the SCID if an
alias exists.
2022-04-04 22:44:51 +02:00
|
|
|
// Embed the scidAliasHandler interface.
|
|
|
|
scidAliasHandler
|
|
|
|
|
|
|
|
// IsUnadvertised returns true if the underlying channel is
|
|
|
|
// unadvertised.
|
|
|
|
IsUnadvertised() bool
|
|
|
|
|
2018-10-30 10:36:27 +01:00
|
|
|
// ChannelPoint returns the channel outpoint for the channel link.
|
|
|
|
ChannelPoint() *wire.OutPoint
|
|
|
|
|
2017-06-16 23:32:41 +02:00
|
|
|
// ShortChanID returns the short channel ID for the channel link. The
|
|
|
|
// short channel ID encodes the exact location in the main chain that
|
|
|
|
// the original funding output can be found.
|
|
|
|
ShortChanID() lnwire.ShortChannelID
|
2017-06-17 00:01:00 +02:00
|
|
|
|
2018-02-04 03:14:09 +01:00
|
|
|
// UpdateShortChanID updates the short channel ID for a link. This may
|
|
|
|
// be required in the event that a link is created before the short
|
|
|
|
// chan ID for it is known, or a re-org occurs, and the funding
|
2018-02-07 09:30:09 +01:00
|
|
|
// transaction changes location within the chain.
|
2018-05-02 01:29:24 +02:00
|
|
|
UpdateShortChanID() (lnwire.ShortChannelID, error)
|
2018-02-04 03:14:09 +01:00
|
|
|
|
2017-06-17 00:01:00 +02:00
|
|
|
// UpdateForwardingPolicy updates the forwarding policy for the target
|
|
|
|
// ChannelLink. Once updated, the link will use the new forwarding
|
|
|
|
// policy to govern if it an incoming HTLC should be forwarded or not.
|
|
|
|
UpdateForwardingPolicy(ForwardingPolicy)
|
|
|
|
|
2019-09-27 16:21:34 +02:00
|
|
|
// CheckHtlcForward should return a nil error if the passed HTLC details
|
|
|
|
// satisfy the current forwarding policy fo the target link. Otherwise,
|
2020-01-14 14:07:42 +01:00
|
|
|
// a LinkError with a valid protocol failure message should be returned
|
|
|
|
// in order to signal to the source of the HTLC, the policy consistency
|
|
|
|
// issue.
|
2019-09-27 16:21:34 +02:00
|
|
|
CheckHtlcForward(payHash [32]byte, incomingAmt lnwire.MilliSatoshi,
|
2018-06-26 05:15:46 +02:00
|
|
|
amtToForward lnwire.MilliSatoshi,
|
|
|
|
incomingTimeout, outgoingTimeout uint32,
|
server+htlcswitch: prevent privacy leaks, allow alias routing
This intent of this change is to prevent privacy leaks when routing
with aliases and also to allow routing when using an alias. The
aliases are our aliases.
Introduces are two maps:
* aliasToReal:
This is an N->1 mapping for a channel. The keys are the set of
aliases and the value is the confirmed, on-chain SCID.
* baseIndex:
This is also an N->1 mapping for a channel. The keys are the set
of aliases and the value is the "base" SCID (whatever is in the
OpenChannel.ShortChannelID field). There is also a base->base
mapping, so not all keys are aliases.
The above maps are populated when a link is added to the switch and
when the channel has confirmed on-chain. The maps are not removed
from if the link is removed, but this is fine since forwarding won't
occur.
* getLinkByMapping
This function is introduced to adhere to the spec requirements that
using the confirmed SCID of a private, scid-alias-feature-bit
channel does not work. Lnd implements a stricter version of the spec
and disallows this behavior if the feature-bit was negotiated, rather
than just the channel type. The old, privacy-leak behavior is
preserved.
The spec also requires that if we must fail back an HTLC, the
ChannelUpdate must use the SCID of whatever was in the onion, to avoid
a privacy leak. This is also done by passing in the relevant SCID to
the mailbox and link. Lnd will also cancel back on the "incoming" side
if the InterceptableSwitch was used or if the link failed to decrypt
the onion. In this case, we are cautious and replace the SCID if an
alias exists.
2022-04-04 22:44:51 +02:00
|
|
|
heightNow uint32, scid lnwire.ShortChannelID) *LinkError
|
htlcswitch: perform fee related checks at forwarding time
In this commit, we fix a very old, lingering bug within the link. When
accepting an HTLC we are meant to validate the fee against the
constraints of the *outgoing* link. This is due to the fact that we're
offering a payment transit service on our outgoing link. Before this
commit, we would use the policies of the *incoming* link. This would at
times lead to odd routing errors as we would go to route, get an error
update and then route again, repeating the process.
With this commit, we'll properly use the incoming link for timelock
related constraints, and the outgoing link for fee related constraints.
We do this by introducing a new HtlcSatisfiesPolicy method in the link.
This method should return a non-nil error if the link can carry the HTLC
as it satisfies its current forwarding policy. We'll use this method now
at *forwarding* time to ensure that we only forward to links that
actually accept the policy. This fixes a number of bugs that existed
before that could result in a link accepting an HTLC that actually
violated its policy. In the case that the policy is violated for *all*
links, we take care to return the error returned by the *target* link so
the caller can update their sending accordingly.
In this commit, we also remove the prior linkControl channel in the
channelLink. Instead, of sending a message to update the internal link
policy, we'll use a mutex in place. This simplifies the code, and also
adds some necessary refactoring in anticipation of the next follow up
commit.
2018-04-04 04:51:40 +02:00
|
|
|
|
2019-09-27 16:21:34 +02:00
|
|
|
// CheckHtlcTransit should return a nil error if the passed HTLC details
|
2020-01-14 14:07:42 +01:00
|
|
|
// satisfy the current channel policy. Otherwise, a LinkError with a
|
|
|
|
// valid protocol failure message should be returned in order to signal
|
|
|
|
// the violation. This call is intended to be used for locally initiated
|
|
|
|
// payments for which there is no corresponding incoming htlc.
|
2019-09-27 16:21:34 +02:00
|
|
|
CheckHtlcTransit(payHash [32]byte, amt lnwire.MilliSatoshi,
|
2020-01-14 14:07:42 +01:00
|
|
|
timeout uint32, heightNow uint32) *LinkError
|
2019-04-19 11:11:16 +02:00
|
|
|
|
2017-05-01 18:58:08 +02:00
|
|
|
// Stats return the statistics of channel link. Number of updates,
|
2017-08-22 08:36:43 +02:00
|
|
|
// total sent/received milli-satoshis.
|
|
|
|
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
2017-05-01 18:58:08 +02:00
|
|
|
|
2017-06-16 23:32:41 +02:00
|
|
|
// Peer returns the representation of remote peer with which we have
|
|
|
|
// the channel link opened.
|
2018-06-08 05:10:26 +02:00
|
|
|
Peer() lnpeer.Peer
|
2017-05-01 18:58:08 +02:00
|
|
|
|
2018-01-16 21:55:41 +01:00
|
|
|
// AttachMailBox delivers an active MailBox to the link. The MailBox may
|
|
|
|
// have buffered messages.
|
|
|
|
AttachMailBox(MailBox)
|
|
|
|
|
2017-06-16 23:32:41 +02:00
|
|
|
// Start/Stop are used to initiate the start/stop of the channel link
|
|
|
|
// functioning.
|
2017-05-01 18:58:08 +02:00
|
|
|
Start() error
|
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2018-02-28 07:18:52 +01:00
|
|
|
// ForwardingLog is an interface that represents a time series database which
|
|
|
|
// keep track of all successfully completed payment circuits. Every few
|
|
|
|
// seconds, the switch will collate and flush out all the successful payment
|
|
|
|
// circuits during the last interval.
|
|
|
|
type ForwardingLog interface {
|
|
|
|
// AddForwardingEvents is a method that should write out the set of
|
|
|
|
// forwarding events in a batch to persistent storage. Outside
|
|
|
|
// sub-systems can then query the contents of the log for analysis,
|
|
|
|
// visualizations, etc.
|
|
|
|
AddForwardingEvents([]channeldb.ForwardingEvent) error
|
|
|
|
}
|
2019-06-14 02:27:55 +02:00
|
|
|
|
|
|
|
// TowerClient is the primary interface used by the daemon to backup pre-signed
|
|
|
|
// justice transactions to watchtowers.
|
|
|
|
type TowerClient interface {
|
|
|
|
// RegisterChannel persistently initializes any channel-dependent
|
|
|
|
// parameters within the client. This should be called during link
|
|
|
|
// startup to ensure that the client is able to support the link during
|
|
|
|
// operation.
|
|
|
|
RegisterChannel(lnwire.ChannelID) error
|
|
|
|
|
|
|
|
// BackupState initiates a request to back up a particular revoked
|
|
|
|
// state. If the method returns nil, the backup is guaranteed to be
|
|
|
|
// successful unless the tower is unavailable and client is force quit,
|
|
|
|
// or the justice transaction would create dust outputs when trying to
|
2019-08-08 04:49:59 +02:00
|
|
|
// abide by the negotiated policy. If the channel we're trying to back
|
|
|
|
// up doesn't have a tweak for the remote party's output, then
|
|
|
|
// isTweakless should be true.
|
2020-11-26 00:04:12 +01:00
|
|
|
BackupState(*lnwire.ChannelID, *lnwallet.BreachRetribution,
|
|
|
|
channeldb.ChannelType) error
|
2019-06-14 02:27:55 +02:00
|
|
|
}
|
2020-02-19 16:34:47 +01:00
|
|
|
|
2020-05-19 11:56:58 +02:00
|
|
|
// InterceptableHtlcForwarder is the interface to set the interceptor
|
|
|
|
// implementation that intercepts htlc forwards.
|
|
|
|
type InterceptableHtlcForwarder interface {
|
|
|
|
// SetInterceptor sets a ForwardInterceptor.
|
|
|
|
SetInterceptor(interceptor ForwardInterceptor)
|
2022-02-07 08:53:10 +01:00
|
|
|
|
|
|
|
// Resolve resolves an intercepted packet.
|
|
|
|
Resolve(res *FwdResolution) error
|
2020-05-19 11:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ForwardInterceptor is a function that is invoked from the switch for every
|
|
|
|
// incoming htlc that is intended to be forwarded. It is passed with the
|
|
|
|
// InterceptedForward that contains the information about the packet and a way
|
|
|
|
// to resolve it manually later in case it is held.
|
|
|
|
// The return value indicates if this handler will take control of this forward
|
|
|
|
// and resolve it later or let the switch execute its default behavior.
|
2022-02-07 08:53:10 +01:00
|
|
|
type ForwardInterceptor func(InterceptedPacket) error
|
2020-05-19 11:56:58 +02:00
|
|
|
|
2020-06-23 16:19:41 +02:00
|
|
|
// InterceptedPacket contains the relevant information for the interceptor about
|
|
|
|
// an htlc.
|
|
|
|
type InterceptedPacket struct {
|
|
|
|
// IncomingCircuit contains the incoming channel and htlc id of the
|
|
|
|
// packet.
|
2022-11-18 12:15:22 +01:00
|
|
|
IncomingCircuit models.CircuitKey
|
2020-06-23 16:19:41 +02:00
|
|
|
|
2020-06-23 16:22:00 +02:00
|
|
|
// OutgoingChanID is the destination channel for this packet.
|
|
|
|
OutgoingChanID lnwire.ShortChannelID
|
|
|
|
|
2020-06-23 16:19:41 +02:00
|
|
|
// Hash is the payment hash of the htlc.
|
|
|
|
Hash lntypes.Hash
|
|
|
|
|
|
|
|
// OutgoingExpiry is the absolute block height at which the outgoing
|
|
|
|
// htlc expires.
|
|
|
|
OutgoingExpiry uint32
|
|
|
|
|
|
|
|
// OutgoingAmount is the amount to forward.
|
|
|
|
OutgoingAmount lnwire.MilliSatoshi
|
2020-06-23 16:22:00 +02:00
|
|
|
|
|
|
|
// IncomingExpiry is the absolute block height at which the incoming
|
|
|
|
// htlc expires.
|
|
|
|
IncomingExpiry uint32
|
|
|
|
|
|
|
|
// IncomingAmount is the amount of the accepted htlc.
|
|
|
|
IncomingAmount lnwire.MilliSatoshi
|
2020-06-24 12:03:00 +02:00
|
|
|
|
|
|
|
// CustomRecords are user-defined records in the custom type range that
|
|
|
|
// were included in the payload.
|
|
|
|
CustomRecords record.CustomSet
|
2020-06-25 18:43:47 +02:00
|
|
|
|
|
|
|
// OnionBlob is the onion packet for the next hop
|
|
|
|
OnionBlob [lnwire.OnionPacketSize]byte
|
2022-08-15 17:28:19 +02:00
|
|
|
|
|
|
|
// AutoFailHeight is the block height at which this intercept will be
|
|
|
|
// failed back automatically.
|
|
|
|
AutoFailHeight int32
|
2020-06-23 16:19:41 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 11:56:58 +02:00
|
|
|
// InterceptedForward is passed to the ForwardInterceptor for every forwarded
|
|
|
|
// htlc. It contains all the information about the packet which accordingly
|
|
|
|
// the interceptor decides if to hold or not.
|
|
|
|
// In addition this interface allows a later resolution by calling either
|
|
|
|
// Resume, Settle or Fail.
|
|
|
|
type InterceptedForward interface {
|
|
|
|
// Packet returns the intercepted packet.
|
2020-06-23 16:19:41 +02:00
|
|
|
Packet() InterceptedPacket
|
2020-05-19 11:56:58 +02:00
|
|
|
|
|
|
|
// Resume notifies the intention to resume an existing hold forward. This
|
|
|
|
// basically means the caller wants to resume with the default behavior for
|
|
|
|
// this htlc which usually means forward it.
|
|
|
|
Resume() error
|
|
|
|
|
|
|
|
// Settle notifies the intention to settle an existing hold
|
|
|
|
// forward with a given preimage.
|
|
|
|
Settle(lntypes.Preimage) error
|
|
|
|
|
2022-01-18 15:17:05 +01:00
|
|
|
// Fail notifies the intention to fail an existing hold forward with an
|
|
|
|
// encrypted failure reason.
|
|
|
|
Fail(reason []byte) error
|
|
|
|
|
|
|
|
// FailWithCode notifies the intention to fail an existing hold forward
|
|
|
|
// with the specified failure code.
|
|
|
|
FailWithCode(code lnwire.FailCode) error
|
2020-05-19 11:56:58 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 16:34:47 +01:00
|
|
|
// htlcNotifier is an interface which represents the input side of the
|
|
|
|
// HtlcNotifier which htlc events are piped through. This interface is intended
|
|
|
|
// to allow for mocking of the htlcNotifier in tests, so is unexported because
|
|
|
|
// it is not needed outside of the htlcSwitch package.
|
|
|
|
type htlcNotifier interface {
|
|
|
|
// NotifyForwardingEvent notifies the HtlcNotifier than a htlc has been
|
|
|
|
// forwarded.
|
|
|
|
NotifyForwardingEvent(key HtlcKey, info HtlcInfo,
|
|
|
|
eventType HtlcEventType)
|
|
|
|
|
|
|
|
// NotifyIncomingLinkFailEvent notifies that a htlc has failed on our
|
|
|
|
// incoming link. It takes an isReceive bool to differentiate between
|
|
|
|
// our node's receives and forwards.
|
|
|
|
NotifyLinkFailEvent(key HtlcKey, info HtlcInfo,
|
|
|
|
eventType HtlcEventType, linkErr *LinkError, incoming bool)
|
|
|
|
|
|
|
|
// NotifyForwardingFailEvent notifies the HtlcNotifier that a htlc we
|
|
|
|
// forwarded has failed down the line.
|
|
|
|
NotifyForwardingFailEvent(key HtlcKey, eventType HtlcEventType)
|
|
|
|
|
|
|
|
// NotifySettleEvent notifies the HtlcNotifier that a htlc that we
|
|
|
|
// committed to as part of a forward or a receive to our node has been
|
|
|
|
// settled.
|
2021-06-15 21:01:24 +02:00
|
|
|
NotifySettleEvent(key HtlcKey, preimage lntypes.Preimage,
|
|
|
|
eventType HtlcEventType)
|
2022-08-29 13:28:17 +02:00
|
|
|
|
|
|
|
// NotifyFinalHtlcEvent notifies the HtlcNotifier that the final outcome
|
|
|
|
// for an htlc has been determined.
|
2022-11-18 12:15:22 +01:00
|
|
|
NotifyFinalHtlcEvent(key models.CircuitKey,
|
2022-08-29 13:28:17 +02:00
|
|
|
info channeldb.FinalHtlcInfo)
|
2020-02-19 16:34:47 +01:00
|
|
|
}
|