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.
This commit is contained in:
eugene committed 2022-07-07 17:10:28 -04:00
1 parent 59fea192b7
commit 13c15e8038
12 files changed
+2406 -298

No files matched your search

+38 -1
View File
@@ -69,6 +69,36 @@ type dustHandler interface {
getDustClosure() dustClosure
}
// 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
}
// ChannelUpdateHandler is an interface that provides methods that allow
// sending lnwire.Message to the underlying link as well as querying state.
type ChannelUpdateHandler interface {
@@ -138,6 +168,13 @@ type ChannelLink interface {
// Embed the dustHandler interface.
dustHandler
// Embed the scidAliasHandler interface.
scidAliasHandler
// IsUnadvertised returns true if the underlying channel is
// unadvertised.
IsUnadvertised() bool
// ChannelPoint returns the channel outpoint for the channel link.
ChannelPoint() *wire.OutPoint
@@ -165,7 +202,7 @@ type ChannelLink interface {
CheckHtlcForward(payHash [32]byte, incomingAmt lnwire.MilliSatoshi,
amtToForward lnwire.MilliSatoshi,
incomingTimeout, outgoingTimeout uint32,
heightNow uint32) *LinkError
heightNow uint32, scid lnwire.ShortChannelID) *LinkError
// CheckHtlcTransit should return a nil error if the passed HTLC details
// satisfy the current channel policy. Otherwise, a LinkError with a