Commit Graph
100 Commits
Author SHA1 Message Date
Johan T. Halseth 7162af7656 docs: update release notes 2021-11-02 08:55:25 +01:00
Johan T. Halseth 6be6585643 kvdb/bolt_compact: filter out non-ASCII from bucket name before printing
Printing the raw bucket name lead to weird characters and even sounds
being printed.
2021-11-02 08:54:35 +01:00
Johan T. HalsethandOliver Gugger 10aaa35db5 kvdb: add loggableKeyName method
Safely logs the bucket key name as hex if it includes special
characters.

Co-authored-by: Oliver Gugger <gugger@gmail.com>
2021-11-02 08:54:35 +01:00
Johan T. Halseth fb99994720 breacharbiter_test: assert publication of adjusted justice tx
Since the breacharbiter will publish an adjusted justice tx after
detecing a spend from the breached commitment, we could get into a race
where sometime it would not get the second spend before publication,
resulting in a deadlock on the publTx channel.

Now we instead wait for the publication of this adjusted tx before
notifying the second spend.
2021-05-21 09:53:20 +02:00
Johan T. Halseth b74c1ca822 breach tests: increase cleanup timeout
1 second was not always enough for the breacharbiter to cleanup,
  especially in case of the more complex split sweep.
2021-05-20 09:50:14 +02:00
Johan T. Halseth 07c0277f3b breacharbiter_test: select on quit chan on publication
Since publication would deadlock on publishing the tx in case the test
had failed we also select on the brar quit channel.
2021-05-20 09:12:32 +02:00
Johan T. Halseth 02268b8912 breacharbiter: fix revoked funds calculation
Since we also must count revoked funds swept from second level revoked
outputs, we move the funds counting into the updateBreachInfo method,
where we already are checking whether the spend is by us or the remote.

We also clean up the logs a bit, to log the incremental sweep of funds
that now can happen.
2021-05-12 12:32:29 +02:00
Johan T. Halseth db0ec12412 breacharbiter: broadcast "splitted" justice tx if spend all not
confirming

In case 4 block passes without our justice tx confirming, we'll "split"
it up, and separately sweep the commitment outs, and HTLC outs.
2021-05-12 12:32:29 +02:00
Johan T. Halseth 2d710154c4 breacharbiter: create split variants of justice tx
We define a new struct justiceTxVariants, which holds three different
justice transactions:

1. The "normal" justice tx that spends all breached outputs
2. A tx that spends only the breached to_local output and to_remote output
   (can be nil if none of these exist)
3. A tx that spends all the breached HTLC outputs (can be nil if no HTLC
   outputs exist)

This will later be used to sweep the time sensitive outputs separately,
in case the normal justice tx doesn't confirm in time.
2021-05-12 12:32:29 +02:00
Johan T. Halseth 783d1f9578 breacharbiter: remove justiceTx finalization
Now that we don't rely on the justice tx TXID anymore, we can remove
finalization of it. Instead we'll recreate the transaction when needed
from the persisted retribution info.
2021-05-12 12:32:29 +02:00
Johan T. Halseth 3be9b74694 breacharbiter: replace justice tx conf check with spend check
Since we want to potentially broadcast multiple versions of the justice
TX, instead of waiting for confirmation of a specific TXID, we instead
wait for the breached outputs to be spent.
2021-05-12 12:32:29 +02:00
Johan T. Halseth c3b2791158 breacharbiter: don't transition to second level if own spend 2021-05-12 12:32:29 +02:00
Johan T. Halseth 0a0b5f89c9 input: create IsHtlcSpendRevoke 2021-05-12 12:32:29 +02:00
Johan T. Halseth e7ee5ad51f breacharbiter_test: extract sweep tx creation into method 2021-05-12 12:32:29 +02:00
Johan T. Halseth a192718807 breacharbiter_test: distinguish spending transactions from justice tx
inputs

Since we want to test more complex combinations of spends of the
breached outputs, we use two maps tracking

1. which transaction will spend the outpoint
2. which outpoints we expect the breacharbiter to include in the justice
   tx

This let us trigger spends of the individual outputs, and depending on
what we want to test check whether the breacharbiter sweeps the expected
outpoints.
2021-05-12 12:32:28 +02:00
Johan T. Halseth 3aa5e650fb lntest/mock: set input index on spend event 2021-05-12 12:32:28 +02:00
Johan T. Halseth a6724c1088 breacharbiter: split waitForSpendEvent
We split the method waitForSpendEvent into two, such that we can reuse
it in case the commitment is spent by various transactions.
2021-05-12 12:32:28 +02:00
Johan T. Halseth bca5839929 breacharbiter: extract countRevokedFunds 2021-05-12 12:32:28 +02:00
Johan T. Halseth 820e77d574 lncfg: make anchor channels by default
This commit again enables anchor channels by default.

During itests we still keep anchors opt-in, as many of the tests rely on
the behaviour of non-anchor channels.
2021-05-11 10:27:54 +02:00
Johan T. Halseth 8e1087d1cd lwallet: only count public channels towards our reserved value
Since private channels (most likely) won't be used for routing other
than as last hop, they bear a smaller risk that we must quickly force
close them in order to resolve a HTLC up/downstream.

In the case where it actually has to be force to resolve a payment (if
it is the first/last hop on a routed payment), we can assume that the
router will have UTXOs available from the reserved value from the
incoming public channel.
2021-05-11 10:27:54 +02:00
Johan T. Halseth a0b6a0b00b lnwallet: cap value reserved for anchor fee bumping
We cap the maximum value we'll reserve for anchor channel fee bumping at
10 times the per-channel amount such that nodes with a high number of
channels don't have to keep around a very large amount for the unlikely
scanario that they all close at the same time.
2021-05-11 10:27:54 +02:00
Johan T. Halseth 6f2f23aae6 Merge pull request #5284 from yuki-js/master
lnrpc: Change State -> state in GetState
2021-05-10 10:41:09 +02:00
Johan T. Halseth b1d9525d29 Merge pull request #5269 from bhandras/healthcheck_module
kvdb: separate healthcheck module
2021-05-07 14:05:48 +02:00
Johan T. Halseth a8d813a4e5 Merge pull request #5277 from guggero/neutrino-update
mod: bump neutrino dep to latest version
2021-05-07 13:56:55 +02:00
Johan T. Halseth 2f99cd7ba1 Merge pull request #5268 from yyforyongyu/fix-whitelist
trivial: update log_error_whitelist
2021-05-07 13:56:21 +02:00
Johan T. Halseth 683a3f952a Merge pull request #5275 from halseth/mod-update-btcd
mod: update btcd to latest master
2021-05-07 13:55:39 +02:00
Johan T. Halseth 99c609c1a8 mod: update btcd to latest master 2021-05-07 11:36:46 +02:00
Johan T. Halseth ac49031396 chainwatcher: only continue breach handling after successfully marked
closed

This commit makes the handoff procedure between the breachabiter and
chainwatcher use a function closure to mark the channel pending closed
in the DB. Doing it this way we know that the channel has been markd
pending closed in the DB when ProcessACK returns.

The reason we do this is that we really need a "two-way ACK" to have the
breacharbiter know it can go on with the breach handling. Earlier it
would just send the ACK on the channel and continue. This lead to a race
where breach handling could finish before the chain watcher had marked
the channel pending closed in the database, which again lead to the
breacharbiter failing to mark the channel fully closed.

We saw this causing flakes during itests.
2021-05-06 12:37:11 +02:00
Johan T. Halseth bdc1f3100d breachabirter+contraccourt: convert ProcessACK to function closure 2021-05-06 12:37:11 +02:00
Johan T. Halseth 13c00127da itest: add SendPayment AMP itest 2021-04-27 09:47:24 +02:00
Johan T. Halseth a2a61a104f itest: make sendAndAssertSuccess take context 2021-04-27 09:47:23 +02:00
Johan T. Halseth c4fc72d573 routerrpc+routing: set AMP options for payments specified as AMP in SendPayment 2021-04-27 09:47:23 +02:00
Johan T. Halseth 8f57dcf28f routerrpc: validate DestFeatures from RPC 2021-04-27 09:47:23 +02:00
Johan T. Halseth 0b9137cdac lnrpc: add AMP feature bits 2021-04-27 09:47:23 +02:00
Johan T. Halseth 56a2c65477 router: use SetID as identifier for SendToRoute AMP-payments 2021-04-27 09:47:23 +02:00
Johan T. Halseth f07c9d002c routing: use Identifier in place of PaymentHash
Since we want to support AMP payment using a different unique payment
identifier (AMP payments don't go to one specific hash), we change the
nomenclature to be Identifier instead of PaymentHash.
2021-04-27 09:47:23 +02:00
Johan T. Halseth 6104d12cf8 routerrpc: add amp bool to SendPayment
For now this is how you indicate you want to perform an AMP payment to
the destination.
2021-04-27 09:47:23 +02:00
Johan T. Halseth 5531b812e3 routing: use AMP shard tracker
We'll use the AMP-specific ShardTracker for payments having non-nil
AMPOptions.
2021-04-27 09:47:23 +02:00
Johan T. Halseth 2d397b12b1 amp: create amp.ShardTracker
We'll use this AMP-specific ShardTracker for AMP payments.  It will be
used to derive hashes for each HTLC attempt using the underlying AMP
derivation scheme.
2021-04-27 09:47:23 +02:00
Johan T. Halseth c1e82e534d amp: add Merge and Zero to Sharer interface 2021-04-27 09:45:14 +02:00
Johan T. Halseth e1399fb1ec routing/router: use attempt's unique hash if set on restart 2021-04-27 09:45:13 +02:00
Johan T. Halseth 06f045fca3 channedb/mp_payment: add Hash to individual HTLCs
For AMP payments the hash used for each HTLC will differ, and we will
need to retrive it after a restart. We therefore persist it with each
attempt.
2021-04-27 09:44:19 +02:00
Johan T. Halseth 41ae3530a3 routing/payment_lifecycle: use ShardTracker to track shards
We'll let the payment's lifecycle register each shard it's sending with
the ShardTracker, canceling failed shards. This will be the foundation
for correct AMP derivation for each shard we'll send.
2021-04-27 09:43:40 +02:00
Johan T. Halseth 6474b253d6 routing/shards: add ShardTracker interface
We'll use this to keep track of the outstanding shards and which
preimages we are using for each. For now this is a simple map from
attempt ID to hash, but later we'll hide the AMP child derivation behind
this interface.
2021-04-27 08:27:33 +02:00
Johan T. Halseth a9f19b100b router+switch: rename paymentID->attemptID
To distinguish the attempt's unique ID from the overall payment
identifier, we name it attemptID everywhere, and note that the
paymentHash argument won't be the actual payment hash for AMP payments.
2021-04-27 08:27:33 +02:00
Johan T. Halseth 7795353e9f channeldb: return full payment for inflight payments
We might as well return all info, and we'll need the individual HTLCs
in later commits.
2021-04-27 08:27:32 +02:00
Johan T. Halseth c207a1528b Merge pull request #5238 from guggero/windows-dep-fix
mod+tools: pin down build flag dependent go.sum entry
2021-04-26 14:57:21 +02:00
Johan T. Halseth a36c95f732 Merge pull request #4588 from bjarnemagnussen/coinselect-align-fee-estimates
chanfunding: fee estimation based on change output in `CoinSelect`
2021-04-16 13:43:51 +02:00
Johan T. Halseth faf5049848 Merge pull request #4599 from hsjoberg/lndmobile-restart
mobile: re-initialize listeners via RecreateListeners
2021-04-15 08:53:55 +02:00
Johan T. Halseth cd87fe89eb Merge pull request #5181 from yyforyongyu/refactor-itest
itest: move funding tests into one file
2021-04-08 09:53:29 +02:00
Johan T. Halseth 46c9140ac0 Merge pull request #5180 from GameXG/master2
lnd: fix #5179 panic: runtime error: invalid memory address or nil po…
2021-04-07 09:10:22 +02:00
Johan T. Halseth d1c7059f14 Merge pull request #5178 from halseth/mobile-docker-prefix
make: pass mobile subserver prefix to docker when generating mobile RPC
2021-04-06 14:54:11 +02:00
Johan T. Halseth 173342a463 Merge pull request #5010 from halseth/walletunlocker-unify-mobile
[mobile] Allow state API on mobile, simplify callback mechanism
2021-04-06 13:35:03 +02:00
Johan T. Halseth 2868b22083 make: pass mobile subserver prefix to docker when generating mobile RPC 2021-04-06 12:52:27 +02:00
Johan T. Halseth 980beba985 mobile: return error in case lnd is already running 2021-04-06 11:38:37 +02:00
Johan T. Halseth 321141600e mobile/bindings: update API for falafel v0.8.1 2021-04-06 10:49:50 +02:00
Johan T. Halseth cf5b0b7943 mobile: include stateservice, use same listener for all services 2021-04-06 10:49:50 +02:00
Johan T. Halseth db28e7c891 lnd: consolidate WalletUnlocker- and AdminAuthOptions 2021-04-06 10:49:45 +02:00
Johan T. Halseth 8789247bf9 print current falafel version 2021-04-06 10:45:32 +02:00
Johan T. Halseth 2338a12729 Merge pull request #5172 from hsjoberg/state-small
lnrpc: Change State -> state in SubscribeStateResponse
2021-04-06 10:40:04 +02:00
Johan T. Halseth 1231c90a19 routing: avoid open DB transaction if no zombies to prune
We add a simple length check to the channels to be pruned to avoid
opening the DB if there is nothing to be done.
2021-03-30 11:04:13 +02:00
Johan T. Halseth a0f3624303 routing: delay initial zombie prune by 30 sec
Since zombie pruning can be very slow on some devices (e.g. mobile) it
would stall lnd startup. Since it is not essential for pruning to be
finished for lnd to be functional, we instead delay the initial prune by
30 seconds.

Note that we could also wait for the graphPruneInterval to tick, but
since this is by default 2 hours, it is unlikely that a mobile app will
ever be open that long.
2021-03-30 11:04:13 +02:00
Johan T. Halseth d85d82824c Merge pull request #5145 from Roasbeef/neutrino-filter-ver-update
build: update to latset version of neutrino
2021-03-26 10:01:54 +01:00
Johan T. Halseth b1309277b9 Merge pull request #4590 from hsjoberg/signal-proper-shutdown-glob
signal: handle shutdown properly
2021-03-18 19:09:31 +01:00
Johan T. Halseth 6046c5cf86 Merge pull request #5119 from ellemouton/lncli-start-signal-interceptor
lncli: start signal interceptor in getContext
2021-03-18 09:30:11 +01:00
Johan T. Halseth d53633eab5 Merge pull request #5005 from halseth/walletunlocker-unify-staterpc
[RPC] SubscribeState RPC for getting unlocking state of wallet and RPC
2021-03-18 08:41:07 +01:00
Johan T. Halseth b4bc6f918e lncli: add state command 2021-03-17 12:09:38 +01:00
Johan T. Halseth 9ef556624e lnrpc: add StateService 2021-03-17 12:09:38 +01:00
Johan T. Halseth 419ad86209 Merge pull request #5112 from halseth/walletunlocker-mac-responsechan-close
lnd: close MacResponseChan when wallet is unlocked
2021-03-17 10:40:25 +01:00
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