Commit Graph
100 Commits
Author SHA1 Message Date
Johan T. Halseth e45d4d703a Merge pull request #2762 from halseth/reliable-payments-lookup-circuitmap
[reliable payments] persist htlcswitch pending payments
2019-06-08 18:05:30 +02:00
Johan T. Halseth dd88015985 htlcswitch/switch test: add TestSwitchGetPaymentResult
TestSwitchGetPaymentResult tests that the switch interacts as expected
with the circuit map and network result store when looking up the result
of a payment ID. This is important for not to lose results under
concurrent lookup and receiving results.
2019-06-07 16:53:33 +02:00
Johan T. Halseth dd3abbc4ef htlcswitch/payment_result_test: add TestNetworkResultStore
TestNetworkResultStore tests that the networkResult store behaves as
expected, and that we can store, get and subscribe to results.
2019-06-07 16:53:33 +02:00
Johan T. Halseth f556b375ff lnd_test: add testHoldInvoicePersistence
testHoldInvoicePersistence tests that a sender to a hold-invoice, can be
restarted before the payment gets settled, and still be able to receive
the preimage.
2019-06-07 16:53:32 +02:00
Johan T. Halseth 2cc778d309 htlcswitch/switch: use paymentResultStore to keep track of results 2019-06-07 16:53:32 +02:00
Johan T. Halseth 2dea790b55 multi: make GetPaymentResult take payment hash
Used for logging in the switch, and when we remove the pending payments,
only the router will have the hash stored across restarts.
2019-06-07 16:53:32 +02:00
Johan T. Halseth 1febe1a6d5 htlcswitch/payment_result: add paymentResultStore
paymentResultStore is a persistent store where we keep track of all
received payment results. This is used to ensure we don't lose results
from payment attempts on restarts.
2019-06-07 16:53:32 +02:00
Johan T. Halseth df3f5d02ad htlcswitch/payment_result: add (de)serialization of networkResult + test 2019-06-07 16:53:32 +02:00
Johan T. Halseth f5dee02ff4 htlcswitch/mock: set SelfKey and mock ErrorSource 2019-06-07 16:42:25 +02:00
Johan T. Halseth 473afbcac5 Merge pull request #3163 from Roasbeef/spend-ntfn-fix
build: update to latest btcd version
2019-06-06 11:30:55 +02:00
Johan T. Halseth 6d52128da0 routing/router test: assert SendToRoute init values
This commit adds an assertion to the SendToRoute test that the payment
value stored to the DB during SendToRoute execution is the correct one.

This assertion would fail before the previous commit that fixed a
missing value initialization.
2019-06-04 10:34:59 +02:00
Johan T. Halseth 1161d87eec routing/router: correct SendToRoute's amount record in DB
Previously we would mistakenly use the payment value from the dummy
LightningPayment struct, which would obviously be 0 always. Now we
instead calculate the value from the given route.
2019-06-04 10:13:33 +02:00
Johan T. Halseth 3a44574625 chainntnfs/neutrinonotify: async call GetUtxo from RegisterSpendNtfn
Since GetUtxo is a potentially long running call, we would see
RegisterSpendNtfn block in some cases, in particular on starting the
chain watcher, causing lnd to hang on startup.

This commit makes the call to GetUtxo in a go routine, letting
RegisterSpendNtfn return immediately when the notification events are
created.
2019-06-04 09:58:04 +02:00
Johan T. Halseth 5882e54bf3 route test: add a simple unit test for the TotalFees method
Checks fees on 0, 1, and 2-hop routes.
2019-05-28 11:16:34 +02:00
Johan T. Halseth f829d33d6f route: return 0 fee from TotalFees for empty route.
Otherwise we would crash calling the method on empty routes.
2019-05-28 11:03:14 +02:00
Johan T. Halseth 28fdf9712d Merge pull request #3125 from halseth/make-fmt-router-rpc
routerrpc test: run make fmt
2019-05-28 09:43:28 +02:00
Johan T. Halseth 7cb25a5afb channeldb/control_tower test: add TestPaymentControlDeleteNonInFlight
TestPaymentControlDeleteNonInFlight checks that calling DeletaPayments
only deletes payments from the database that are not in-flight.
2019-05-27 20:19:00 +02:00
Johan T. Halseth 649ee875fd routing/router_test: add test case for ForwardingError on SendHTLC 2019-05-27 20:19:00 +02:00
Johan T. Halseth 589f0fcc5d control_tower: make initial bucket bucket creation stricter 2019-05-27 20:18:59 +02:00
Johan T. Halseth 95b4828780 channeldb: derive PaymentStatus implicitly from stored info 2019-05-27 20:18:59 +02:00
Johan T. Halseth d705b8a013 channeldb+multi: rename Grounded->Unknown, Completed->Succeeded 2019-05-27 20:18:59 +02:00
Johan T. Halseth d78d3f50b9 channeldb: move deprecated code to migration_09_legacy_serialization.go
And unexport deprecated code.
2019-05-27 20:18:59 +02:00
Johan T. Halseth 1b788904f0 channeldb+router: record payment failure reason in db 2019-05-27 20:18:59 +02:00
Johan T. Halseth 60e2367973 routing/router_test: add TestRouterPaymentStateMachine
TestRouterPaymentStateMachine tests that the router interacts as
expected with the ControlTower during a payment lifecycle, such that it
payment attempts are not sent twice to the switch, and results are
handled after a restart.
2019-05-27 20:18:59 +02:00
Johan T. Halseth 3f76bc0629 routing+server: define PaymentSessionSource 2019-05-27 20:18:59 +02:00
Johan T. Halseth f4306b1178 routing/payment_session+router: make PaymentSession interface 2019-05-27 20:18:58 +02:00
Johan T. Halseth adc4640f4f routing: export MissionControl 2019-05-27 20:18:58 +02:00
Johan T. Halseth 3323800e02 routing/router: resume payment state machine at startup
On startup the router will fetch the in-flight payments from the control
tower, and resume their execution.
2019-05-27 20:18:58 +02:00
Johan T. Halseth 677cb018c9 routing/control_tower: add FetchInFlightPayments 2019-05-27 20:18:58 +02:00
Johan T. Halseth de1bf8a518 routing/router: persist payment state machine
This commit makes the router use the ControlTower to drive the payment
life cycle state machine, to keep track of active payments across
restarts.  This lets the router resume payments on startup, such that
their final results can be handled and stored when ready.
2019-05-27 20:18:58 +02:00
Johan T. Halseth dd73c51a34 routing/payment_lifecycle: extract create attempt into method 2019-05-27 20:18:58 +02:00
Johan T. Halseth e9b2182cdc routing/payment_lifecycle: extract error handling into method 2019-05-27 20:18:58 +02:00
Johan T. Halseth 83bfaa4fb4 routing: extract payment flow into method on paymentLifecycle
This encapsulates all state needed to resume a payment from any point of
the payment flow, and that must be shared between the different stages
of the execution. This is done to prepare for breaking the send loop
into smaller parts, and being able to resume the payment from any point
from persistent state.
2019-05-27 20:18:57 +02:00
Johan T. Halseth ae7bf2cb7b routing/router: move sending and receiving payment result into loop 2019-05-27 20:18:57 +02:00
Johan T. Halseth 59c2557cc9 channeldb/control_tower test: test new payment behavior 2019-05-27 20:18:57 +02:00
Johan T. Halseth 1af1832ff7 channeldb/control_tower: add payment information during state changes
This commit gives a new responsibility to the control tower, letting it
populate the payment bucket structure as the payment goes through
its different stages.

The payment will transition states Grounded->InFlight->Success/Failed,
where the CreationInfo/AttemptInfo/Preimage must be set accordingly.

This will be the main driver for the router state machine.
2019-05-27 20:18:57 +02:00
Johan T. Halseth 6d80661bbb channeldb/payments: add StatusFailed 2019-05-27 20:18:57 +02:00
Johan T. Halseth bb4aadd16c channeldb/control_tower: remove non-strict option
Since we have performed a migration, the db should be in a consistent
state, and we can remove the non-strict option.
2019-05-27 20:18:57 +02:00
Johan T. Halseth b7189ba028 channeldb test: add TestOutgoingPaymentsMigration 2019-05-27 20:18:57 +02:00
Johan T. Halseth 693807cf6e channeldb/control_tower: add FetchSentPayments 2019-05-27 20:18:56 +02:00
Johan T. Halseth 801521ed2d channeldb/migration: add migration for new payment bucket structure
migrateOutgoingPayments moves the OutgoingPayments into a new bucket format
where they all reside in a top-level bucket indexed by the payment hash. In
this sub-bucket we store information relevant to this payment, such as the
payment status.

To avoid that the router resend payments that have the status InFlight (we
cannot resume these payments for pre-migration payments) we delete those
statuses, so only Completed payments remain in the new bucket structure.
2019-05-27 20:18:56 +02:00
Johan T. Halseth 178996f0d3 channeldb/payments+control_tower: split OutgoingPayments
This commit changes the format used to store payments within the
DB. Previously this was serialized as one continuous struct
OutgoingPayment, which also contained an Invoice struct we where only
using a few fields of. We now split it up into two simpler sub-structs
CreationInfo, AttemptInfo and PaymentPreimage.

We also want to associate the payments more closely with payment
statuses, so we move to this hierarchy:

There's one top-level bucket "sentPaymentsBucket" which contains a set
of sub-buckets indexed by a payment's payment hash. Each such sub-bucket
contains several fields:
paymentStatusKey -> the payment's status
paymentCreationInfoKey -> the payment's CreationInfo.
paymentAttemptInfoKey -> the payment's AttemptInfo.
paymentSettleInfoKey -> the payment's preimage (or zeroes for
non-settled payments)

The CreationInfo is information that is static during the whole payment
lifcycle. The attempt info is set each time a new payment attempt
(route+paymentID) is sent on the network. The preimage is information
only known when a payment succeeds.  It therefore makes sense to split
them.

We keep legacy serialization code for migration puproses.
2019-05-27 20:18:56 +02:00
Johan T. Halseth f022810f8b channeldb/codec: add privateKey serialization 2019-05-27 20:18:56 +02:00
Johan T. Halseth 2417f40532 channeldb: put payment status in new bucket
We move the payment status to a new bucket hierarchy. Old buckets and
fetch methods are kept around for migration purposes.
2019-05-27 20:18:56 +02:00
Johan T. Halseth d027e10201 htlcswitch+channeldb: move control tower to channeldb 2019-05-27 20:18:56 +02:00
Johan T. Halseth 6e102d64b9 Merge pull request #3101 from AdamISZ/make-unit-cover-pkg
Allow unit-cover target for make to filter by package
2019-05-27 13:18:45 +02:00
Johan T. Halseth 1df148d8ef routerrpc test: run make fmt 2019-05-27 12:33:43 +02:00
Johan T. Halseth 34032eff0b make: increase itest timeout to 40 min
Needed for neutrino itest on darwin.
2019-05-27 09:29:03 +02:00
Johan T. Halseth 991b4174fd lnd_test: fix spelling 2019-05-27 09:29:03 +02:00
Johan T. Halseth ca1e9dcecb lntest: skip zeroConf ListUnspent for neutrino 2019-05-27 09:29:03 +02:00
Johan T. Halseth 19d6cc00e5 travis: enable neutrino itest 2019-05-27 09:29:03 +02:00
Johan T. Halseth fe9ff3828e lnd_test: skip reorg test for neutrino backend 2019-05-27 09:29:03 +02:00
Johan T. Halseth 39d3aa6eca lnd_test: add t.Skip to *harnessTest 2019-05-27 09:29:03 +02:00
Johan T. Halseth 2d49ee56e2 lntest: add Name() to BackendCfg 2019-05-27 09:29:03 +02:00
Johan T. Halseth 8f5a4beaad lntest: add NeutrinoCfg 2019-05-27 09:29:02 +02:00
Johan T. Halseth 335a039ba2 lnd_test: alter testUnconfirmedChannelFunding to work with Neutrino
We slightly alter testUnconfirmedChannelFunding to instead of using an
external deposit to test unconfirmed channel funding, we use one of our
own unconfirmed change outputs.

This is done since Neutrino currently has now way of knowing about
incoming unconfirmed outputs.
2019-05-27 09:29:02 +02:00
Johan T. Halseth 3df0821aa3 make: add backend tag for itests
Defaults to running itests with btcd.
2019-05-27 09:29:02 +02:00
Johan T. Halseth 8e8bb9ff09 lntest+lnd_test: build flag btcd for BtcdBackendCfg 2019-05-27 09:29:02 +02:00
Johan T. Halseth aec00b1277 lntest+lnd_test: add Connect and Disconnect miner for BackendCfgs
This commit gives the current chainbackend the ability to connect and
disconnect the chain backend at will. We do this to let the chain
backend initiate the connection to the miner, not the other way around.

This is a preparation for using Neutrino as a backend, as it only allows
making outbound connections.

We must also move the setup of the chainbackend to after to miner, to
know the address to connect to.
2019-05-27 09:29:02 +02:00
Johan T. Halseth 1788fa1566 rpcserver: print unconfirmed balance, add TODO for racy balance 2019-05-27 09:29:02 +02:00
Johan T. Halseth ea50502a79 go mod: update to latest neutrino dep 2019-05-24 12:41:31 +02:00
Johan T. Halseth af3b04e53f Merge pull request #3103 from halseth/syncmanager-resync-historical
discovery/sync_manager: restart historical sync on first connected peer
2019-05-24 12:17:02 +02:00
Johan T. Halseth 6ba6982ae7 discovery/sync_manager_test: add TestSyncManagerHistoricalSyncOnReconnect
TestSyncManagerHistoricalSyncOnReconnect tests that the sync manager will
re-trigger a historical sync when a new peer connects after a historical
sync has completed, but we have lost all peers.
2019-05-24 11:05:30 +02:00
Johan T. Halseth 526486ae24 discovery/sync_manager: restart historical sync on first connected peer
To handle the case where we have been without peers, and get a new
connection, we reset the historical scan booleans when the first active
syncer is connected to trigger another historical sync.
2019-05-24 11:05:29 +02:00
Johan T. Halseth 6cd71b7f7a Merge pull request #2312 from xsb/color-node-update
rpc: add node color to NodeUpdate and GetInfo
2019-05-23 14:21:05 +02:00
Johan T. Halseth 4806003b74 Merge pull request #2704 from MDrollette/multiple-opts
config: allow adding multiple tls ips and domains
2019-05-22 08:59:19 +02:00
Johan T. Halseth 437f83998e Merge pull request #3098 from cfromknecht/increase-funding-timeout
fundingmanager: bump max non-initiator funding timeout to 2 weeks
2019-05-22 08:46:54 +02:00
Johan T. Halseth 339080394d Merge pull request #3096 from grunch/add-minchansize-to-sample-conf
Add minchansize to sample config file
2019-05-21 09:52:03 +02:00
Johan T. Halseth 777f1b7b23 Merge pull request #3076 from sangaman/proto-typos
lnrpc: fix typos
2019-05-20 15:00:55 +02:00
Johan T. Halseth 2c1c29e060 Merge pull request #3081 from halseth/route-remove-totalfees
routing/route+multi: remove redundant TotalFees field
2019-05-20 15:00:01 +02:00
Johan T. Halseth 60bad9a4e5 Merge pull request #2974 from OpinionatedGeek/patch-1
Build LND subservers when building docker image
2019-05-20 14:40:53 +02:00
Johan T. Halseth 15bed506b1 routing/route+multi: remove redundant TotalFees field
Instead get it on demand using method TotalFees().
2019-05-16 23:58:32 +02:00
Johan T. Halseth cd02c22977 htlcswitch+router: move deobfuscator creation to GetPaymentResult call
In this commit we move handing the deobfuscator from the router to the
switch from when the payment is initiated, to when the result is
queried.

We do this because only the router can recreate the deobfuscator after a
restart, and we are preparing for being able to handle results across
restarts.

Since the deobfuscator cannot be nil anymore, we can also get rid of
that special case.
2019-05-16 23:56:12 +02:00
Johan T. Halseth f99d0c4c68 htlcswitch/switch+payment_result: define networkResult, extractResult 2019-05-16 23:56:12 +02:00
Johan T. Halseth 5a8b892bb6 routing/router: extract sessionKey generation
We extract the session key such that we can later store it across
restarts.
2019-05-16 23:56:12 +02:00
Johan T. Halseth ec087a9f73 htlcswitch+router: define PaymentResult, GetPaymentResult
This lets us distinguish an critical error from a actual payment result
(success or failure). This is important since we know that we can only
attempt another payment when a final result from the previous payment
attempt is received.
2019-05-16 23:56:12 +02:00
Johan T. Halseth be129eb7c7 htlcswitch/switch: remove numPendingPayments only used in tests 2019-05-16 23:56:12 +02:00
Johan T. Halseth cff4d3547d htlcswitch/switch: clarify paymentID uniqueness
With the following commits, it'll become important to not resuse
paymentIDs, since there is no way to tell whether the HTLC in question
has already been forwarded and settled/failed.

We clarify this in the SendHTLC comments, and alter the tests to not
attempt to resend an HTLC with a duplicate payment ID.
2019-05-16 23:56:11 +02:00
Johan T. Halseth bbbe3a37f5 htlcswitch/switch: make parseFailedPayment not dependent on pkt
We will later persist the fields necessary to decrypt a received error.
2019-05-16 23:56:11 +02:00
Johan T. Halseth ed81cec0fa routing/router: remove sendToSwitch method 2019-05-16 23:56:11 +02:00
Johan T. Halseth c9e8ff6a34 switch+router+server: move NextPaymentID to router
This commit moves the responsibility of generating a unique payment ID
from the switch to the router. This will make it easier for the router
to keep track of which HTLCs were successfully forwarded onto the
network, as it can query the switch for existing HTLCs as long as the
paymentIDs are kept.

The router is expected to maintain a map from paymentHash->paymentID,
such that they can be replayed on restart. This also lets the router
check the status of a sent payment after a restart, by querying the
switch for the paymentID in question.
2019-05-16 23:56:06 +02:00
Johan T. Halseth f1cb54f943 routing/router: define PaymentAttemptDispatcher interface
The switch satisfies this interface, and makes it easy to mock the send
method from the router.
2019-05-16 23:53:08 +02:00
Johan T. Halseth b917820c5b lntest/node: set up InvoicesClient for HarnessNode 2019-05-15 14:42:04 +02:00
Johan T. Halseth c706b9549a Merge pull request #3019 from sangaman/subscribe-single-invoice-rhashstr
invoicesrpc: SubscribeSingleInvoice check RHashStr
2019-05-14 14:28:31 +02:00
Johan T. Halseth f589c86963 lnwallet/wallet: add missing error handling 2019-05-09 14:44:53 +02:00
Johan T. Halseth 183adf6e61 chainntnfs/neutrino: provide n.quit as neutrino QuitChan option
This will make sure a long-running rescan can be canceled in the case
the notifier is shutting down.
2019-05-09 14:44:53 +02:00
Johan T. Halseth 6110182371 lnwallet/btcwallet: provide cancel chan as neutrino QuitChan option
This will make sure a long-running rescan can be canceled in case
Neutrino is the backend.
2019-05-09 14:44:52 +02:00
Johan T. Halseth 10070ecab7 lnwallet: make BlockChainIO.GetUTXO take cancel chan
Use quit channels as cancel chan for call to GetUTXO.
2019-05-09 14:44:47 +02:00
Johan T. Halseth beb5d14ed9 lnwallet/btcwallet: add compile time check for BlockChainIO interface 2019-05-09 14:44:41 +02:00
Johan T. Halseth 21c989ffcc channeldb/graph: don't nil curve of returned PubKey
Nilling the key would cause signature verification to crash if the
returned key was used.

A test to exercise the behavior is added.
2019-05-09 10:49:58 +02:00
Johan T. Halseth 89fd43ebcb channeldb: add Route (de)serialization + test
We will store the routes used during payment attempts, so we need
serialization code.
2019-05-09 09:59:43 +02:00
Johan T. Halseth c4415f0400 Merge pull request #3044 from cfromknecht/spelling-fixes
multi: fix spelling mistakes
2019-05-07 08:50:36 +02:00
Johan T. Halseth ee257fd0eb multi: move Route to sub-pkg routing/route 2019-04-29 14:52:33 +02:00
Johan T. Halseth 1387af8c94 Merge pull request #2982 from Roasbeef/faster-chain-watcher-dlp-tests
contractcourt: speed up TestChainWatcherDataLossProtect by ditching q…
2019-04-26 10:27:56 +02:00
Johan T. Halseth ef6c2f5adc mod: update to latest btcwallet, btcd, btcutil, neutrino
Resolves a crash when using neutrino backend, and a bugfix for filter
matchin.
2019-04-26 10:17:02 +02:00
Johan T. Halseth 7f4d1cee6d lntest: don't return from ensureConnected on non-error
This would casue the method to return before the peer list check was
performed.
2019-04-24 09:44:15 +02:00
Johan T. Halseth ab327dc8c1 lnd_test: check Dave's balance in WaitNoErr
Resolves a flake.
2019-04-24 09:01:38 +02:00
Johan T. Halseth ccff4fc0a5 make: point makefile to new main package 2019-04-23 20:57:33 +02:00
Johan T. Halseth b53899c43c lnd: rename package main->lnd 2019-04-23 20:57:33 +02:00
Johan T. Halseth 9d1e1db42e lnd: move main method to cmd/lnd/main.go 2019-04-23 20:56:33 +02:00