Commit Graph

13348 Commits

Author SHA1 Message Date
eugene
0ba67015da
rpcserver+invoicesrpc: alias-aware AddInvoice,AddHoldInvoice rpc
AddInvoice,AddHoldInvoice now issue invoices that include our
peer's aliases. Some extra sanity checks are included to ensure we
don't leak our confirmed SCID for a private channel.
2022-07-07 17:10:29 -04:00
eugene
1aa9626606
server+funding: allow scid-alias, zero-conf chantypes, scid-alias
feature-bit channels

This allows opening zero-conf chan-type, scid-alias chan-type, and
scid-alias feature-bit channels. scid-alias chan-type channels are
required to be private. Two paths are available for opening a zero-conf
channel:

* explicit chan-type negotiation
* LDK carve-out where chan-types are not used, LND is on the
  receiving end, and a ChannelAcceptor is used to enable zero-conf

When a zero-conf channel is negotiated, the funding manager:
* sends a FundingLocked with an alias
* waits for a FundingLocked from the remote peer
* calls addToRouterGraph to persist the channel using our alias in
  the graph. The peer's alias is used to send them a ChannelUpdate.
* wait for six confirmations. If public, the alias edge in the
  graph is deleted and replaced (not atomically) with the confirmed
  edge. Our policy is also read-and-replaced, but the counterparty's
  policy won't exist until they send it to us.

When a scid-alias-feature channel is negotiated, the funding manager:
* sends a FundingLocked with an alias:
* calls addToRouterGraph, sends ChannelUpdate with the confirmed SCID
  since it exists.
* when six confirmations occurs, the edge is deleted and re-inserted
  since the peer may have sent us an alias ChannelUpdate that we are
  storing in the graph.

Since it is possible for a user to toggle the scid-alias-feature-bit
to on while channels exist in the funding manager, care has been taken
to ensure that an alias is ALWAYS sent in the funding_locked message
if this happens.
2022-07-07 17:10:28 -04:00
eugene
13c15e8038
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-07-07 17:10:28 -04:00
eugene
59fea192b7
server+routing: pass isAlias to router
This allows the router to determine what is and isn't an alias from
lnd's definition of an alias. Any ChannelAnnouncement that has an
alias ShortChannelID field is not verified on-chain. To prevent a
DoS vector from existing, the gossiper ensures that only the local
lnd node can send its ChannelAnnouncements to the router with an
alias ShortChannelID.
2022-07-07 17:10:28 -04:00
eugene
01f28ba540
server+discovery: alias-handling in gossiper
An OptionalMsgField has been added that allows outside subsystems
to provide a short channel id we should insert into a ChannelUpdate
that we then sign and send to our peer.

When the gossiper receives a ChannelUpdate, it will query the
alias manager by the passed-in FindBaseByAlias function to determine
if the short channel id in the ChannelUpdate points to a known
channel. If this lookup returns an error, we'll fallback to using
the original id in the ChannelUpdate when querying the router.
The lookup and potential fallback must occur in order to properly
lock the multimutex, query the correct router channels, and rate
limit the correct short channel id. An unfortunate side effect of
receiving ChannelUpdates from our peer that reference on of our
aliases rather than the real SCID is that we must store this policy.
Yet it is not broadcast-able. Care has been taken to ensure the
gossiper does not broadcast *any* ChannelUpdate with an alias SCID.

The cachedNetworkMsg uses the new processedNetworkMsg struct. This
is necessary so that delete-and-reinsert in the funding manager
doesn't process a ChannelUpdate twice and end up in a deadlock since
the err chan is no longer being used.
2022-07-07 17:10:28 -04:00
eugene
15b871de36
aliasmgr: new data store containing our, peer's aliases
This introduces the a store for managing all things alias-related.

There are two maps:

* baseToSet:
  This stores the "base" short channel id as the key. The value is
  the set of all aliases issued for this channel. The "base" SCID is
  whatever is stored in the OpenChannel's ShortChannelID member. For
  everything other than zero-conf channels, this is the confirmed SCID.
  For zero-conf channels, this is the very first alias assigned. This is
  used mostly by the Switch to retrieve a set of aliases and determine
  if it is safe to forward.

* aliasToBase:
  This stores the reverse mapping of baseToSet. Each key is an alias
  SCID and the value is the "base" SCID. This is exclusively used by
  the gossiper to determine if an alias in a ChannelUpdate our peer
  sends actually references a channel we know of.

The functions make use of the above two maps:

* AddLocalAlias:
  This persists the {alias, base} pair in the database. The baseToSet
  map is populated. The aliasToBase is optionally populated depending on
  where this function is called from. Upgrade cases, where the
  scid-alias feature bit is toggled and channels already exist, will
  not persist to the gossip map. This is mainly to simplify the tangle
  of logic that would otherwise occur.

* GetAliases:
  This fetches the set of aliases by using the passed-in base SCID. This
  is used in the Switch and other places where the alias set is needed.

* FindBaseSCID:
  This fetches the base given an alias. This is used in the gossiper to
  determine validity of a peer's ChannelUpdate that contains an alias.

* DeleteSixConfs:
  This removes the aliasToBase map entry for the given "base". This is
  used when the gossiper mappings are no longer needed, i.e. when the
  channel has six confirmations and is public.

* PutPeerAlias:
  Stores the peer's alias.

* GetPeerAlias:
  Fetches the peer's alias.

* RequestAlias:
  Generates an alias for us in the range 16000000:0:0 and
  16250000:16777215:65535
2022-07-07 17:10:27 -04:00
eugene
21c83b0744
lnwallet: extend Reservation with alias chan-type, feature-bit flags
This extends the Reservation arguments to include whether a pending
channel open has negotiated the zero-conf channel type, the scid-alias
channel type, and/or the scid-alias feature bit. The result of those
negotiates are stored in the OpenChannel's ChanType. The arguments to
NewChannelReservation have also been simplified.
2022-07-07 17:10:27 -04:00
eugene
c9f5912601
channeldb: BigSize migration, store zero-conf, scid-alias bits
This introduces a BigSize migration that is used to expand the width
of the ChannelStatus and ChannelType fields. Three channel "types"
are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit.
ScidAliasChanBit denotes that the scid-alias channel type was
negotiated for the channel. ScidAliasFeatureBit denotes that the
scid-alias feature bit was negotiated during the *lifetime* of the
channel. Several helper functions on the OpenChannel struct are
exposed to aid callers from different packages.

The RefreshShortChanID has been renamed to Refresh.

A new function BroadcastHeight is used to guard access to the
mutable FundingBroadcastHeight member. This prevents data races.
2022-07-07 17:10:27 -04:00
eugene
3ff8eb899c
lnwire: add alias to FundingLocked in TLV
This adds an optional short channel id field to the FundingLocked
message that is sent/received as a TLV segment inside the
ExtraOpaqueData field.
2022-07-07 17:10:27 -04:00
eugene
a493caf3c0
server+lncfg: protocol flag to enable scid-alias, zero-conf feature bits
This allows the zero-conf and scid-alias feature bits to be toggled
using the config. The feature bits are off by default to protect users
from accidentally incurring the risk of a zero-conf channel.
2022-07-07 17:10:26 -04:00
eugene
a6c62eb71e
lnwire+feature: new zero-conf, scid-alias feature bit + chantypes
This defines the zero-conf feature bit, the scid-alias feature bit,
the zero-conf channel type, and the scid-alias channel type. It also
defines the dependency "tree" that exists for the feature bits.

The scid-alias feature bit signals that the node requires an alias
short channel id to be sent in funding_locked. The scid-alias channel
type requires that the channel is private, in addition to some other
forwarding-related privacy measures.
2022-07-07 17:10:24 -04:00
Olaoluwa Osuntokun
dc35f78ebc
Merge pull request #6509 from Roasbeef/macaroons-rks
macaroons: futher abstract NewService from root key store impl
2022-07-06 19:00:49 -07:00
Olaoluwa Osuntokun
e073b1d343
macaroons: futher abstract NewService from root key store impl
In this commit, we modify the `macaroons.NewService` consturctor to
accept the main interface rather than the raw DB. This allows us to use
other backends other than bolt or the kvdb interface to store the
macaroon root keys.

We also create a new ExtendedRootKeyStore interface that implements some
of the more advanced features we use such as macaroon encryption and
password rotation.
2022-07-06 18:59:50 -07:00
Oliver Gugger
947639bb60
Merge pull request #6705 from hieblmi/chan-point-for-updatechanstatus
lncli: chan_point option for updatechanstatus
2022-07-06 17:34:38 +02:00
Slyghtning
86f1bc7db0 lncli: chan_point option for updatechanstatus 2022-07-06 10:19:12 -04:00
Oliver Gugger
738241d5fa
Merge pull request #6681 from guggero/editor-helpers
Add settings files for most common editors
2022-07-06 13:35:28 +02:00
Oliver Gugger
b9d8c701eb
Merge pull request #6659 from ErikEk/trivial-typo
typo: trivial
2022-07-06 13:34:19 +02:00
Oliver Gugger
2b9787b43a
docs: add release notes 2022-07-06 13:33:02 +02:00
Oliver Gugger
37578a6b6d
routing: fix formatting
This commit fixes a formatting issue in the router. The commit is in
this PR to demonstrate how the .editorconfig settings also affect the
way GitHub displays the code diff.
2022-07-06 13:33:02 +02:00
Oliver Gugger
f268786a87
docs: extract formatting rules 2022-07-06 13:33:02 +02:00
Oliver Gugger
2681c02afd
.editorconfig: add editor settings for most editors
This should automatically set the tab size to 8 spaces and add a visual
guide (ruler) at 80 characters in GoLand, GitHub and a few other
editors.
2022-07-06 13:33:02 +02:00
Oliver Gugger
d20140e393
.vscode: add editor settings for VS Code 2022-07-06 10:25:19 +02:00
Oliver Gugger
ed2a126541
Merge pull request #6698 from hieblmi/fix-batchopenchannel-help-text
Fix batchopenchannel help text
2022-07-05 21:05:55 +02:00
Oliver Gugger
341fde723b
Merge pull request #6636 from tvolk131/migrate_assert_to_require
Migrate assert.NoError to require.NoError
2022-07-05 19:16:41 +02:00
Tommy Volk
820e3c2422 gitrelease-notes: update release notes for 0.15.1 2022-07-05 16:41:08 +00:00
Tommy Volk
834756c53c multi: migrate assert.NoError to require.NoError 2022-07-05 16:41:08 +00:00
Oliver Gugger
4cb68e4de3
Merge pull request #6588 from C-Otto/peer-logging
peer: add pubkey to log messages
2022-07-05 09:36:26 +02:00
Slyghtning
abcd1dc4ed lncli: Fix batchopenchannel help text [skip ci] 2022-07-04 11:10:31 -04:00
Oliver Gugger
8970e309dc
Merge pull request #6438 from tvolk131/delete_failed_payments
Delete failed payment attempts for successfully settled payments
2022-07-04 10:27:34 +02:00
Tommy Volk
714f8a8142 gitrelease-notes: update release notes for 0.15.1 2022-07-03 21:04:34 +00:00
Tommy Volk
2dd11ed249 channeldb+routing: htlcs are pruned on settle 2022-07-03 21:04:34 +00:00
Tommy Volk
8291e8a170 multi: add keep-failed-payment-attempts flag 2022-07-03 21:04:27 +00:00
ErikEk
6146b8d644 trivial typo[skip ci] 2022-07-01 11:21:46 +02:00
Oliver Gugger
e6277986fd
Merge pull request #6685 from guggero/release-notes-fix
Release notes: Move 0.15.1 item, remove duplicate headings, fix formatting
2022-07-01 10:05:23 +02:00
Oliver Gugger
9656994c3b
docs: fix formatting and phrasing [skip ci] 2022-07-01 10:04:08 +02:00
Oliver Gugger
120fbc6758
docs: remove duplicate headings 2022-07-01 10:03:41 +02:00
Oliver Gugger
8e5ff6d1a6
docs: move 0.15.1 release notes item 2022-07-01 10:01:55 +02:00
Olaoluwa Osuntokun
98ab9e3057
Merge pull request #6642 from Crypt-iQ/linkstopidx
htlcswitch: add linkStopIndex to cleanly shutdown ChannelLink
2022-06-30 17:01:07 -07:00
Olaoluwa Osuntokun
7b56b67f34
Merge pull request #6546 from carlaKC/bolts-950-warningmessage
lnwire/peer: add ability to read + log peer warning messages
2022-06-30 16:56:20 -07:00
eugene
0cbf0e6208
release-notes: update for 0.15.1 2022-06-30 15:02:58 -04:00
eugene
407184ac51
htlcswitch: add linkStopIndex to cleanly shutdown ChannelLink
With this, extra calls to RemoveLink will wait for the link to
fully stop. This is accomplished by a map that stores a single stop
channel that callers to RemoveLink will listen on. This map is not
consulted when the Switch is shutting down and calls Stop on each
individual link. Though that could be added in the future, it is
not necessary.
2022-06-30 15:02:57 -04:00
Oliver Gugger
3af42eede9
Merge pull request #6687 from guggero/sign-psbt-np2wkh
walletrpc: Fix SignPsbt for NP2WKH inputs
2022-06-30 12:18:12 +02:00
Oliver Gugger
719fd584f9
docs: add release notes 2022-06-30 10:27:39 +02:00
Oliver Gugger
bb3cec6b12
itest: add test for FundPsbt->SignPsbt|FinalizePsbt flow 2022-06-30 10:27:39 +02:00
Oliver Gugger
63ec849605
lnwallet: fix bug in SignPsbt with np2wkh addresses
Fixes #6626.
If either of the two fields FinalScriptSig or FinalScriptWitness is set
on an input of a PSBT then that results in most of the fields of that
input not to be serialized in the packet anymore, since the input is
considered to be complete.
But because a signer isn't supposed to set any of the Final* fields,
this was wrong from the beginning. Only the finalizer will set those
fields.
2022-06-30 10:27:39 +02:00
Oliver Gugger
9d339f0fe2
Merge pull request #6680 from guggero/compute-input-script
Taproot: Fix p2tr support in `ComputeInputScript`
2022-06-30 10:11:11 +02:00
Olaoluwa Osuntokun
b96203a0eb
Merge pull request #6655 from Crypt-iQ/disconnectpeerfix
server.go: replace call to removePeer with Disconnect in DisconnectPeer
2022-06-29 18:40:45 -07:00
eugene
ff39f1e5ea
release-notes: update for 0.15.1 2022-06-29 13:50:03 -04:00
eugene
a7f5b89cf3
itest: update switch delivery tests with more robust reconnect logic 2022-06-29 13:50:03 -04:00
eugene
f7681cb51d
server.go: replace call to removePeer with Disconnect in DisconnectPeer
Without this, calls to DisconnectPeer would bypass the
peerTerminationWatcher and allow subsequent connect requests to
go through before the peer's links were fully shut down. This could
lead to force closes.
2022-06-29 13:50:00 -04:00