Commit Graph
100 Commits
Author SHA1 Message Date
Johan T. Halseth ad6673c21d lnd: close MacResponseChan when wallet is unlocked
After unification of the WalletUnlocker and RPC services on the same gRPC
server, the WalletUnlocker will no longer be shut down after the wallet
has been unlocked.

In case --no-macaroons was used, this lead to the caller getting stuck
after unlocking the wallet, since we would wait for a response on the
MacResponseChan. Earlier we would close the MacResponseChan always
when shutting down the WalletUnlocker, but this is no longer done.

To fix this we close this channel after the wallet is unlocked,
regardless of which combination of --no-macaroons and --noseedbackup
that is being used.
2021-03-16 14:47:02 +01:00
Johan T. Halseth fa4155c126 Merge pull request #5086 from halseth/mobile-graceful-exit
mobile: gracefully exit if lnd fails to start
2021-03-11 20:02:11 +01:00
Johan T. Halseth fd76b879a2 Merge pull request #4985 from halseth/walletunlocker-unify-jan21
[gRPC] WalletUnlocker and RPCServer unification
2021-03-11 14:00:00 +01:00
Johan T. Halseth 148f1be75f itest: add RPC errors to whitelist
Since we now log RPC errors as the first thing in our interceptor chain,
more benign errors bubble up. We add them to the whitelist.
2021-03-11 13:05:24 +01:00
Johan T. Halseth b2e0a7d684 rpcperms: export macaroon interceptor methods
Since we need access to these methods from external subservers in some
cases, we export them.
2021-03-11 13:05:24 +01:00
Johan T. Halseth 2877511fce rpcperms+lnd: gate RPC calls on RPC state
This commit makes us gate the calls to the RPC servers according to the
current RPC state. This ensures we won't try to call the RPC server
before it has been fully initialized, and that we won't call the
walletUnlocker after the wallet already has been unlocked.
2021-03-11 13:05:24 +01:00
Johan T. Halseth 0d7763fb96 walletunlocker: expose WalletExists 2021-03-11 13:05:24 +01:00
Johan T. Halseth 5e9e03858d lntest/node: call FetchNode info in wait.NoError after init
In case we call it before the RPC server is fully active.
2021-03-11 13:05:24 +01:00
Johan T. Halseth 4bbf5c4b6d rpcserver: use same grpc server for both services
This commit achieves what we have been building up to: running the
WalletUnlockerService and the LightningService on the same gRPC server
simultaneously!

To achieve this, we first create the RPC server in a "interface only"
way, only creating the struct and setting the dependencies we have
available before the wallet has been unlocked. After the wallet has been
unlocked and we have created all the subsystems we need, we add those to
the RPC server, and start the sub-servers.

This means that the WalletUnlockerService and the LightningService both
will be registered and available at all times on the gRPC server.
However, before the wallet has been unlocked, the LightningService
should not be used since the RPC server is not yet ready to handle the
calls. Similarly, after the wallet has been unlocked, the
WalletUnlockerService should not be used. This we will ensure in
following commits.
2021-03-11 13:05:24 +01:00
Johan T. Halseth 82fb22eda2 lnd+rpc: define external subserver config only once
We don't have to define the external subserver config more than once, so
it is not needed to be defined for every listener. Instead we move it to
the ListenerConfig.
2021-03-11 13:05:24 +01:00
Johan T. Halseth 73711941ad rpcperms: add macaroon whitelist
We extract common macaroon validating code into a method, and add a
method whitelist, for methods that won't need macaroons.

This give us explicit control over which methods don't require
macaroons, to avoid inadvertently adding RPCs that are unauthenticated.

For now this whitelist contains the WalletUnlocker methods, as the
wallet password is required to open the macaroon db.
2021-03-11 13:05:23 +01:00
Johan T. Halseth 3c81a5dd73 rpcperms: add RPC interceptor chain
This adds a new package rpcperms which houses the InterceptorChain
struct.  This is a central place where we'll craft interceptors to use
for the GRPC server, which includes macaroon enforcement.

This let us add the interceptor chain to the GRPC server before the
macaroon service is ready, allowing us to avoid tearing down the GRPC
server after the wallet has been unlocked.
2021-03-11 13:05:23 +01:00
Johan T. Halseth 4ea494e8c5 lnrpc: wrap subservers in GrpcHandler
In order to be able to register the subservers with the root grpc server
before we have all dependencies available, we wrap them in an
GrpcHandler struct. This struct will initially hold an empty reference
to the subservers, which allows us to register with the GRPC server, and
later populate and create the subserver instance.
2021-03-11 13:05:23 +01:00
Johan T. Halseth 8038e9f322 mobile: gracefully exit if lnd fails to start
Instead of killing the app, report an error back to the application.
2021-03-09 14:25:46 +01:00
Johan T. Halseth d30aae43e6 input/size: add txSize test
Similar to what we do for witnesses, check that the HTLC weight
constants check out.

They actually do not, since the spec is off by one. We ensure we agree
with the spec.
2021-03-05 10:58:42 +01:00
Johan T. Halseth 2bc37db61a lnwallet: export HTLC generating methods 2021-03-05 10:58:42 +01:00
Johan T. Halseth 3a3076397a input/size: fix comments for constants
We run a script that ensures the constant sizes listed is actually the
value of the constant.
2021-03-05 10:58:42 +01:00
Johan T. Halseth fe71c905e5 input/size: split constants into confirmed/non-confirmed
This to more easily track mismatches if constants and get more accurate
fee estimates for the two channel types.

The non-anchor weight estimates will now be smaller, this is okay since
these constants are only being used for fee estimation (and will now be
more accurate).
2021-03-05 10:58:42 +01:00
Johan T. Halseth 6842c0ba8c lnwire: convert the delivery addr in [Open+Accept]Channel to a TLV type in ExtraData
In this commit, we convert the delivery address in the open and accept
channel methods to be a TLV type. This works as an "empty" delivery
address is encoded using a two zero bytes (uint16 length zero), and a
tlv type of 0 is encoded in the same manner (byte for type, byte for
zero length). This change allows us to easily extend these messages in
the future, in a uniform manner.

When decoding the message we snip the bytes from the read TLV data.
Similarly, when encoding we concatenate the TLV record for the shutdown
script with the rest of the TLV data.
2021-02-24 17:40:08 +01:00
Johan T. Halseth 466c079bbe channeldb/migration21: add body and tests for migration 21
In this commit, we migrate all wire messages in the database from the
`legacy` to the `current` encoding.

This affects the way we write the `CommitDiff` and `LogUpdates` struct
to disk. We also need to migrate the network results bucket in the
switch as it includes a wire message without a length prefix.
2021-02-24 17:31:55 +01:00
Johan T. Halseth d4e90eae83 channeldb/migration21: add new serialization to package 'current'
We copy the new serialization togic to a new package 'current' and
export the methods we will need from the migration. This ensures that we
have isolation between the legacy and current serialization methods,
cleanly inidcating what type we are using during the migration.
2021-02-24 17:31:49 +01:00
Johan T. Halseth db66fef6cc channeldb+htlcswitch: write wire messages using length prefix
In this commit, we modify the way we write wire messages across the
entire database. We'll now ensure that we always write wire messages
with a length prefix. We update the `codec.go` file to always write a 2
byte length prefix, this affects the way we write the `CommitDiff` and
`LogUpdates` struct to disk, and the network results bucket in the
switch as it includes a wire message.
2021-02-24 17:15:27 +01:00
Johan T. Halseth 4133b4d04e channeldb/migration21: copy over legacy types+codec for migration21
The legacy encoding depends on the lnwire21 version of lnwire, so it will
let us change lnwire after the migration. To make sure it is separated
from the new encoding, we add it to a new package 'legacy'.

We also put common types in a new package 'common', which will house
types that won't change during the migration, and can be used by both
legacy and current serialization code.
2021-02-24 17:15:21 +01:00
Johan T. Halseth 90d36dbdd4 channeldb: rename Encode/Decode to serializeLogUpdate/deserializeLogUpdate
To more easily use different version of it post-/pre-migration, we
rename the method and make it take the LogUpdate as an argument.
2021-02-24 14:34:57 +01:00
Johan T. Halseth 7569cca19b channeldb/migration: copy current lnwire to migration dir
To avoid code changing underneath the static migrations, we copy the
lnwire dependency in its current form into the migration directory.

Ideally the migrations doesn't depend on any code that might change,
this takes us a step closer.
2021-02-24 14:34:57 +01:00
Johan T. Halseth db23e34f74 Merge pull request #3191 from halseth/deleteallpayments-failedonly
Add option for deleting failed-only payments.
2021-02-22 21:40:16 +01:00
Johan T. Halseth 59f41e518d channeldb: add failedHtlcsOnly option to DeletePayments 2021-02-22 12:50:25 +01:00
Johan T. Halseth 6eb42aec0a channeldb/payments: use only Read bucket when iterating 2021-02-22 12:50:25 +01:00
Johan T. Halseth 7e3738d773 rpcserver+channeldb: delete only failed payments if requested 2021-02-22 12:50:25 +01:00
Johan T. Halseth 0ef2ca06c1 lnrpc: add failed_payments_only and failed_htlcs_only option to DeleteAllPayments 2021-02-22 12:50:24 +01:00
Johan T. Halseth 82fe6f5f59 channeldb/payments_test: handle that dupe payments will always have StatusSuccess
Legacy duplicate payments would only be migrated over if they had
succeeded. Alter the test to reflect this.
2021-02-22 12:50:24 +01:00
Johan T. Halseth b52e872878 Merge pull request #4899 from halseth/ignore-local-ann-from-remote
[gossiper] Ignore received ChannelAnnouncements for own channels
2021-02-11 18:39:15 +01:00
Johan T. Halseth 926005aefa discovery/gossiper: ignore remote ChannelAnnouncement for own channel
To avoid learning about our own channel we have already closed and
removed from our graph, we ignore all ChannelAnns for channels we are
involved in.
2021-02-11 15:13:51 +01:00
Johan T. Halseth e8f7a11470 gossiper_test: split keys into self/remote
To make it more clear what is local and remote messages, we change to
use `selfKey` only for local messages.
2021-02-11 15:13:51 +01:00
Johan T. Halseth 4268bcc9f9 gossiper_test: combine local/remote chan ann
It will be the same announcement, no need to distinguish.
2021-02-11 15:13:51 +01:00
Johan T. Halseth f047c3517f discovery/gossiper: remove source pubkey from ProcessLocalAnnouncement params 2021-02-11 15:13:51 +01:00
Johan T. Halseth 69770f15e4 server: use nodeKeyECDH everywhere 2021-02-11 15:13:51 +01:00
Johan T. Halseth 06253e4dcc Merge pull request #5012 from halseth/rpc-check-fix
lnrpc: format protos
2021-02-11 15:13:20 +01:00
Johan T. Halseth 0227aaab1f lnrpc: format protos 2021-02-11 15:06:12 +01:00
Johan T. Halseth c9afc93151 discovery/gossiper: add local updates to graph immediately
Since the batch interval can potentially be long, adding local updates
to the graph could be slow. This would slow down operations like adding
our own channel update and announcements during the funding process, and
updating edge policies for local channels.

Now we instead check whether the update is remote or not, and only for
remote updates use the SchedulerOption to lazily add them to the graph.
2021-02-10 23:54:03 +01:00
Johan T. Halseth 7e34132c53 routing: let graph methods take scheduler option 2021-02-10 23:54:03 +01:00
Johan T. Halseth b5d6d7b4fd channeldb: add SchedulerOp arg to graph update methods 2021-02-10 23:54:03 +01:00
Johan T. Halseth e3b529939e batch: add option for executing requests immediately
We make the default non-lazy, and will make the incoming gossip requests
lazy.
2021-02-10 23:54:02 +01:00
Johan T. Halseth ef81217f7b Merge pull request #4993 from rockstardev/patch-1
fix: correct no-rest-tls parameter in error message
2021-02-08 13:47:55 +01:00
Johan T. Halseth ce01cdd7d6 Merge pull request #4981 from lightningnetwork/halseth-patch-1
docs: correct sign command
2021-02-04 19:20:40 +01:00
Johan T. Halseth b4d66662b9 docs: correct sign command 2021-02-04 10:05:37 +01:00
Johan T. Halseth 1a9fd09c01 Merge pull request #4978 from bhandras/addinvoice_crash
invoices+rpc: add missing channel graph to the AddInvoiceConfig
2021-02-03 11:46:14 +01:00
Johan T. Halseth 315f97ffd5 Merge pull request #4911 from guggero/docker-rpc-compile
lnrpc+mobile: use docker to compile/format protos
2021-02-01 13:42:42 +01:00
Johan T. Halseth 10a81e01e3 Merge pull request #2162 from halseth/make-goimports
[Makefile] Define `make imports`
2021-01-29 08:54:00 +01:00
Johan T. Halseth 991e077bf3 scripts: add halseth key to verify script 2021-01-27 10:43:32 +01:00
Johan T. Halseth 3485a7874f netann: ignore unknown channel updat on startup
Since the funding manager might be in process of adding the edge to the
graph, we ignore the error.
2021-01-26 15:33:45 +01:00
Johan T. Halseth 39f51b5568 Merge pull request #4926 from guggero/doc-code-blocks
docs: unify code block formatting
2021-01-22 09:39:02 +01:00
Johan T. Halseth 8c78f20ffa itest: add testAnchorReservedValue
We test that Alice as expected will not be allowed to spend her wallet
balance below the reserved amount.
2021-01-19 20:06:52 +01:00
Johan T. Halseth 422008e3c0 lnwallet+funding+rpcserver: check reserved value before
PublishTransaction

For a few manual send cases that can be initiated by the user, we check
the reserved value.
2021-01-19 20:06:52 +01:00
Johan T. Halseth 185ba77f8e sweep: allow specified outputs to sweep tx
We'll use this to attach an output for the value reserved for anchor
commitments fee bumping if the user requests a send_all transaction.
2021-01-19 10:53:45 +01:00
Johan T. Halseth eaf97418be lnwallet: check Reserved value on funding request 2021-01-19 10:53:45 +01:00
Johan T. Halseth 3cc31ae841 lnwallet: add CheckReservedValue 2021-01-19 10:53:45 +01:00
Johan T. Halseth 4a4e0c73f7 lnwallet/chanfunding: add Inputs/Outputs to assemblers
This will be used to try to estimate how much the funding transaction
will decrease our wallet balance.
2021-01-19 10:53:45 +01:00
Johan T. Halseth 01f31e436a itest: fix node names out of bounds
If the last channel fails, the indexing into nodeNames would panic. We
instead name the channels, such that the slices will be of the same
length.
2021-01-14 20:55:32 +01:00
Johan T. Halseth c86761f1b3 lncfg: make anchor commitments opt-in
This commit reverts the anchors-by-default change, and instead make
anchor commitments and opt-in option. The plan is to enable anchors by
default further down the line.
2021-01-14 09:09:42 +01:00
Johan T. Halseth cc0321d188 Merge pull request #4872 from Roasbeef/fix-tweakless-downgrade
peer: ensure consistent local+global feature bits when downgrading
2020-12-18 09:53:45 +01:00
Johan T. Halseth c3b20e34a7 monitoring: run go fmt 2020-12-18 09:04:44 +01:00
Johan T. Halseth 892635a93d make: run goimports during make fmt 2020-12-18 09:04:44 +01:00
Johan T. Halseth 6dfefe39ce make: exclude autogenerated files from go fmt 2020-12-18 09:04:44 +01:00
Johan T. Halseth 413ece2ccc itest: account for capped anchor commit fee rate in balance calc 2020-12-15 19:54:50 +01:00
Johan T. Halseth 99bbd992d2 sample config: add no-anchors and max-commit-fee-rate-anchors 2020-12-15 19:54:50 +01:00
Johan T. Halseth 0fd76e53b8 multi: cap anchors feerate at configurable maximum
This commit caps the update fee the initiator will send when the anchors
channel type is used. We do not limit anything on the receiver side.

10 sat/vbyte is the current default max fee rate we use. This should be
enough to ensure propagation before anchoring down the commitment
transaction.
2020-12-15 19:54:50 +01:00
Johan T. Halseth 64659e6156 protocol+rpctest: disable anchors by default for itests 2020-12-15 10:13:28 +01:00
Johan T. Halseth d69a1a616d sample config: add no-anchors 2020-12-15 10:13:27 +01:00
Johan T. Halseth c92c06400b config+protocol: enable anchor commitments (zero-fee HTLC ) by default 2020-12-15 10:13:25 +01:00
Johan T. Halseth 1923d40843 lnwallet+funding: enable AnchorsZeroFeeHtlcTx commit type if both nodes support
We assume the legacy anchor type is no longer advertised by us.
2020-12-15 10:13:18 +01:00
Johan T. Halseth 0b9bec7804 chanrestore: define ZeroHtlcTxFeeCommitVersion 2020-12-15 10:13:12 +01:00
Johan T. Halseth d5cd9861d2 channeldb+lnwallet: define zero-fee channel type 2020-12-15 10:13:07 +01:00
Johan T. Halseth abefa93065 lnwire+feature: define AnchorsZeroFeeHtlcTx feature 2020-12-15 10:13:04 +01:00
Johan T. Halseth 1627310fb0 itest: add HTLC aggregation test 2020-12-10 14:24:21 +01:00
Johan T. Halseth 42c51b662a itest/channel_force_close test: handle HTLCs going through sweeper
Now that the HTLC second-level transactions are going through the
sweeper instead of the nursery, there are a few things we must account
for.
1. The sweeper sweeps the CSV locked HTLC output one block earlier than
   the nursery.
2. The sweeper aggregates several HTLC second levels into one
   transaction. This also means it is not enough to check txids of the
   transactions spent by the final sweep, but we must use the actual
   outpoint to distinguish.
2020-12-10 14:24:21 +01:00
Johan T. Halseth 4b9fbe2146 itest/local_chain_claim test: mine one less blocks for anchor sweeps
In case of anchor channel types, we mine one less block before we expect
the second level sweep to appear in the mempool, since the sweeper
sweeps one block earlier than the nursery.
2020-12-10 14:24:21 +01:00
Johan T. Halseth 70eb52643c rpctest: increase sweeper BatchWindow during itests
Since we are checking HTLC aggregation, we must give the sweeper a bit
more time to aggregate them to avoid flakes.
2020-12-10 14:24:20 +01:00
Johan T. Halseth bb406c82a9 contractcourt/htlc_timeout_test: expand timeout tests 2020-12-10 14:24:20 +01:00
Johan T. Halseth 4992e41439 contraccourt+input: create resolver for timeout second level
In this commit we make the sweeper handle second level transactions for
HTLC timeout resolvers for anchor channels.
2020-12-10 14:24:20 +01:00
Johan T. Halseth 0c3b64a3cd contractcourt/timeout_resolver: extract logic into sweepSecondLevelTransaction
This commit moves the logic for sweeping the confirmed second-level
timeout transaction into its own method.

We do a small change to the logic: When setting the spending tx in the
report, we use the detected commitspend instead of the presigned tiemout
tx. This is to prepare for the coming change where the spending
transaction might actually be a re-signed timeout tx, and will therefore
have a different txid.
2020-12-10 14:24:20 +01:00
Johan T. Halseth 2f33425509 contractcourt/timeout_resolver: extract logic into spendHtlcOutput
This commit moves the code doing the initial spend of the HTLC output of
the commit tx into its own method.
2020-12-10 14:24:20 +01:00
Johan T. Halseth aabba32b34 contractcourt: add TestHtlcSuccessSecondStageResolutionSweeper
Test success resolvers going through the sweeper.
2020-12-10 14:24:20 +01:00
Johan T. Halseth 85ea181d67 contraccourt+input: create HtlcSecondLevelAnchorInput and resolver for
success tx

This commit makes the HTLC resolutions having non-nil SignDetails
(meaning we can re-sign the second-level transactions) go through the
sweeper. They will be offered to the sweeper which will cluster them and
arrange them on its sweep transaction. When that is done we will further
sweep the output on this sweep transaction as any other second-level tx.

In this commit we do this for the HTLC success resolver and the
accompanying HTLC success transaction.
2020-12-10 14:24:20 +01:00
Johan T. Halseth d02b486195 contractcourt: revamp HTLC success unit test
We add checkpoint assertions and resume the resolver from every
checkpoint to ensure it can handle restarts.
2020-12-10 14:24:20 +01:00
Johan T. Halseth 7142a302c9 contractcourt/success_resolver: remove sweep tx checkpoint
The sweep tx is not actually part of the resolver's encoded data, so the checkpointing was essentially a noop.
2020-12-10 14:24:19 +01:00
Johan T. Halseth 0b84d5f976 contractcourt/success_resolver: extract HTLC success handling into broadcastSuccessTx 2020-12-10 14:24:19 +01:00
Johan T. Halseth 9d33b00082 contractcourt/success_resolver: extract remoteHTLC sweep into resolveRemoteCommitOutput
This move the logic for sweeping the HTLC output on the remote
commitment into its own method.
2020-12-10 14:24:19 +01:00
Johan T. Halseth 9b08ef6d4e contractcourt/[incoming|outgoing]_contest_resolver: make inner resolver pointer
To make the linter happy, make a pointer to the inner resolver.
Otherwise the linter would complain with

copylocks: literal copies lock value

since we'll add a mutex to the resolver in following commits.
2020-12-10 14:24:19 +01:00
Johan T. Halseth 4da2b290f9 contractcourt/succes+timeout resolver: extract waitForSpend logic 2020-12-10 14:24:19 +01:00
Johan T. Halseth 5f613147ad contractcourt: decouple waitForHeight from commit sweep resolver
To make it usable from other resolvers.
2020-12-10 14:24:19 +01:00
Johan T. Halseth 65e50f6952 input/witnessgen: define witness type for HTLC 2nd level inputs
These will only be used for size upper bound estimations by the sweeper.
2020-12-10 14:24:19 +01:00
Johan T. Halseth 8eb6d7cf87 input/size: define witness constants needed
We define the witness constanst we need for fee estimation for this
HTLC second level type.
2020-12-10 14:24:19 +01:00
Johan T. Halseth 241e21a0d1 itest: use hex encoded hash in error message 2020-12-10 14:24:18 +01:00
Johan T. Halseth 09f2307d14 itest: increase htlc amt for local force close tests
Since the tests set a quite high fee rate before the node goes to chain,
the HTLCs wouldn't be economical to sweep at this fee rate.

Pre sweeper handling of the second-level transactions this was not a
problem, since the fees were set when the second-levels were created,
before the fee estimate was increased.
2020-12-10 14:24:18 +01:00
Johan T. Halseth 83f9aaec98 sweeper/tx_input_set: add logging for input set construction 2020-12-10 14:24:18 +01:00
Johan T. Halseth 6150995b46 sweep/txgenerator: log in case of no change output 2020-12-10 14:24:18 +01:00
Johan T. Halseth 1e68cdc8cf input+lnwallet+contractcourt: define SignDetails for HTLC resolutions 2020-12-10 14:24:18 +01:00
Johan T. Halseth eb8d22e194 lnwallet/channel: properly set SignDesc.Output
Only value was populated for some, which would cause code to rely on the
PkScript being there to fail.
2020-12-10 14:24:18 +01:00
Johan T. Halseth 08bb8abaa3 Merge pull request #4851 from halseth/sweeper-cnct-deadlock
sweeper: avoid deadlock on shutdown
2020-12-10 14:23:36 +01:00