Commit Graph
100 Commits
Author SHA1 Message Date
Johan T. Halseth d742529bb2 rpcserver: set AmtPaidMsat when creating RPC invoice 2018-09-07 14:13:48 +02:00
Johan T. Halseth 90a9f5882a lnrpc: add field amt_paid_msat to Invoice 2018-09-07 14:13:48 +02:00
Johan T. Halseth baee07ef48 Merge pull request #1846 from roeierez/invoice_amt_paid
rpcserver: amount paid should be in satoshis as other fields used for amount
2018-09-05 12:58:59 +02:00
Johan T. Halseth 0d4df54118 autopilot/agent: signal balanceUpdates on own channel 2018-09-04 10:18:15 +02:00
Johan T. Halseth a9a9c9aeb4 autopilot/agent: signal chanPendingOpenUpdates on own channel 2018-09-04 10:17:59 +02:00
Johan T. Halseth 186e6d4da4 autopilot/agent: signal chanOpenFailureUpdates on own channel
We do this to avoid a huge amount of goroutines piling up when autopilot
is trying to open many channels, as they will all block trying to send
the update on the stateUpdates channel. Now we instead send them on a
buffered channel, similar to what is done with the nodeUpdates.
2018-09-04 10:17:33 +02:00
Johan T. Halseth 4a88c61a90 autopilot/agent: signal nodeUpdates on own channel
We do this to avoid a huge amount of goroutines piling up on initial
graph sync, as they will all block trying to send the node update on the
stateUpdates channel. Now we instead make a new buffered channel
nodeUpdates, and just return immediately if there is already a signal in
the channel waiting to be processed.
2018-09-04 10:17:09 +02:00
Johan T. Halseth 3e992f094d autopilot/agent: move signal processing out of select 2018-09-04 10:06:15 +02:00
Johan T. Halseth f82fd5fe86 chainntnfs/bitcoind: fallback to scan manually only in case of err != nil 2018-08-24 14:46:20 +02:00
Johan T. Halseth 01d8953737 chainntnfs/btcd: fallback to scan manually only in case of err != nil 2018-08-24 14:46:20 +02:00
Johan T. Halseth 31dc387e0f chainntnfs/btcd+bitcoind tests: use common TxConfStatus 2018-08-24 14:46:20 +02:00
Johan T. Halseth 79b2ee7da5 chainntnfs/btcd+bitcoind: use common TxConfStatus 2018-08-24 14:46:20 +02:00
Johan T. Halseth b552984fcd chainntnfs: define common TxConfStatus type 2018-08-24 14:46:20 +02:00
Johan T. Halseth 89c33731fe chainntnfs/bitcoind: remove unnecessary check for tx==nil 2018-08-24 14:46:20 +02:00
Johan T. Halseth 4a60887974 chainntnfs/btcd: remove unnecessary check for tx==nil 2018-08-24 14:46:19 +02:00
Johan T. Halseth a91466e9fa chainntnfs/bitcoind tests: check found mempool case 2018-08-24 13:51:54 +02:00
Johan T. Halseth cb3ec07685 chainntnfs/test_util: set 10ms trickleInterval for miner 2018-08-24 13:50:47 +02:00
Johan T. Halseth 8344b05c38 contractcourt/chanarb test: expand TestChannelArbitratorCommitFailure to coop and local force close 2018-08-23 10:04:43 +02:00
Johan T. Halseth 4933120d38 contractcourt/channel arbitrator: add coopCloseTrigger on startup for pendingClose channel 2018-08-23 10:04:43 +02:00
Johan T. Halseth e9066c2d34 peer: print warning if selfPolicy not found 2018-08-23 07:50:18 +02:00
Johan T. Halseth 030eca2347 lnd_test: test payment failing because < min_htlc 2018-08-23 07:50:18 +02:00
Johan T. Halseth 19e3a194fa peer+server: make fetchLastChanUpdate _always_ fetch our own update
This commit fixes a bug that would cause us to fetch our peer's
ChannelUpdate in some cases, where we really wanted to fetch our own.

The reason this happened was that we passed the peer's pubkey to
fetchLastChanUpdate, making us match on their policy. This would lead to
ChannelUpdates being sent during routing which would have no effect on
the attempted path.

We fix this by always use our own pubkey in fetchLastChanUpdate, and
also uses the common methods within the server to be able to extract the
update even when only one policy is known.
2018-08-23 07:50:18 +02:00
Johan T. Halseth de5e9e139c server: make extractChannelUpdate extract from set of potential policies 2018-08-23 07:50:17 +02:00
Johan T. Halseth 229fd88289 peer: use custom MinHTLC value at initial link add
This commit fixes a bug within the peer, where we would always use the
default forwarding policy when adding new links to the switch. Mostly
this wasn't a problem, as we most often are using default values for new
channels, but the min_htlc value is a value that is set by the remote,
not us.

If the remote specified a custom min_htlc during channel creation, we
would still use our DefaultMinHtlc value when first adding the link,
making us try to forward HTLCs that would be rejected by the remote.

We fix this by getting the required min_htlc value from the channel
state machine, and setting this for the link's forwarding policy.

Note that on restarts we will query the database for our latest
ChannelEdgePolicy, and use that to craft the forwardingPolicy. This
means that the value will be set correctly if the policy is found in the
database.
2018-08-23 07:50:17 +02:00
Johan T. Halseth f4f7b64b2d lnwallet/channel: add FwdMinHtlc(), returning MinHTLC from localChanCfg 2018-08-23 07:50:17 +02:00
Johan T. Halseth 7eee09c454 lnd_test: check ChannelUpdate for custom min_htlc 2018-08-23 07:50:17 +02:00
Johan T. Halseth e069dd7f04 fundingmanager test: test that custom MinHTLC is in ChannelUpdate 2018-08-23 07:50:17 +02:00
Johan T. Halseth e174fbd759 fundingmanager: use value the _remote_ require us to use in ChannelUpdate
This commit fixes a bug that would make us advertise the remote's
min_htlc value in our channel update.

The min_htlc value is set by a node Alice to limit its exposure to small
HTLCs, and the channel counter party should not forward HTLCs of value
smaller than this to Alice. This means that the value a node Bob should
advertise in its ChannelUpdate, is the min_htlc value the counter party
require all HTLCs to be above.

Instead of populating the ChannelUpdate with the MinHtlc value found in
the remote constraints, we now use the value from the local constraints.
2018-08-23 07:50:17 +02:00
Johan T. Halseth 0c65719613 fundingmgr: check quit channel when sending update
Avoids deadlock during failing fundingmanager tests.
2018-08-23 07:50:16 +02:00
Johan T. Halseth 4c15353116 lnd test: make waitForChannelUpdate take array of updates 2018-08-23 07:50:16 +02:00
Johan T. Halseth fd7b1c2d5e lntest/lnd test: make OpenChannel take channel param struct
Also add option for setting min_htlc value on channel creation.
2018-08-23 07:50:16 +02:00
Johan T. Halseth 6a6d3ff557 funding tests: account for returned err channel 2018-08-23 07:40:41 +02:00
Johan T. Halseth 67d36eb79d funding: make SendAnnouncement return error chan instead of error 2018-08-23 07:40:41 +02:00
Johan T. Halseth 4b04e1afd1 routing: return ErrRejected if found in reject cache
We make sure to return an error other than ErrIgnored, as ErrIgnored is
expected to only be returned for updates where we already have the
necessary information in the database.

In case of a channel ID found in the rejectCache, there was a
possibility that we had rejected an invalid update for this channel
earlier, and when attempting to add the current update we wouldn't
distinguish the failure to add from an outdated/ignored update.
2018-08-23 07:40:40 +02:00
Johan T. Halseth c56082006f discovery/gossiper: formatting 2018-08-23 07:40:40 +02:00
Johan T. Halseth 0bc415c683 discovery/gossiper: don't return on errChan for ChannelUpdate not yet processed
Previosuly we would immediately return nil on the error channel for
premature ChannelUpdates, which would break the expection that a a
returned non-error meant the update was successfully added to the
database. This meant that the caller would believe the update was added
to the database, while it is actually still in volatile memory and can
be lost during restarts.

This change makes us handle premature ChannelUpdates as we handle other
premature announcements within the gossiper, by deferring sending on the
error channel until we have reprocessed the update.
2018-08-23 07:40:40 +02:00
Johan T. Halseth 7bbb2bbc80 discovery/gossiper: return on errChan on ValidationBarrier error 2018-08-23 07:40:40 +02:00
Johan T. Halseth c8ce2aa2d2 discovery/gossiper: reaturn early of no premature to process 2018-08-23 07:40:39 +02:00
Johan T. Halseth d0e8aeece1 discovery/gossiper: return on errChan in case of ChanAnn/Upd on wrong chain
Previously we wouldn't return anything in the case where the
announcement were meant for a chain we didn't recognize. After this
change we should return an error on the error channel in all flows
within the gossiper.
2018-08-23 07:40:39 +02:00
Johan T. Halseth 54f67f72b1 discovery/gossiper: define ErrGossiperShuttingDown 2018-08-23 07:40:39 +02:00
Johan T. Halseth 18e680f192 router: simplify edge outdated logic, return ErrOutdated if old. 2018-08-23 07:40:39 +02:00
Johan T. Halseth bb71856204 contractcourt/channel_arbitrator test: add TestChannelArbitratorEmptyResolutions 2018-08-23 00:03:22 +02:00
Johan T. Halseth ed5db96e05 contractcourt/channel_arbittrator: ignore noResolutions error on startup 2018-08-23 00:03:22 +02:00
Johan T. Halseth b031d87daf contractcourt/briefcase: test FetchContractResolutions error when no resolutions logged 2018-08-23 00:03:22 +02:00
Johan T. Halseth 53286b8cee contractcourt test: add TestChannelArbitratorCommitFailure 2018-08-23 00:03:22 +02:00
Johan T. Halseth f2a033e965 contractcourt/channel_arbitrator: override trigger on startup if IsClosing
At ChannelArbitrator startup we now check the database close status of
the channel. If we detect that the channel is closed, but our state
machine hasn't advanced to reflect that (possibly because of a shutdown
before the state transition was finished), we manually trigger the state
transition to recover.
2018-08-23 00:03:22 +02:00
Johan T. Halseth 1758ad829f contractcourt/[chain|channel]_arbitrator: define IsPendingClose 2018-08-23 00:03:22 +02:00
Johan T. Halseth 6b24ca0387 contractcourt test: add TestChannelArbitratorPeristence 2018-08-23 00:03:21 +02:00
Johan T. Halseth 75df58c68b contractcourt: move responsibility for closing force closes to chanArb
This commit moves the responsibility for closing local and remote force
closes in the database from the chain watcher to the channel arbitrator.

We do this because we previously would close the channel in the
database, before sending the event to the channel arbitrator. This could
lead to a situation where the channel was marked closed, but the channel
arbitrator didn't receive the event before shutdown. As we don't listen
for chain events for channels that are closed, those channels would be
stuck in the pending close state forever, as the channel arbitrator
state machine wouldn't progress.

We fix this by letting the ChannelArbitrator close the channel in the
database. After the contract resolutions are logged (in the state
callback before transitioning to StateContractClosed) we mark the
channel closed in the database. This way we make sure that it is marked
closed only if the resolutions have been successfully persisted.
2018-08-23 00:03:21 +02:00
Johan T. Halseth c11e0940c2 contractcourt/channel_arbitrator test: test new coop close actions 2018-08-23 00:03:21 +02:00
Johan T. Halseth ad1d78884a contractcourt: move responsibility for closing coop close channel to chanArb 2018-08-23 00:03:21 +02:00
Johan T. Halseth 3549f2bc17 contractcourt/[channel|chain]_arbitrator: define MarkChannelClosed 2018-08-22 23:51:04 +02:00
Johan T. Halseth 740db4716f contractcourt/channel_arbitrator test: test state transitions 2018-08-22 23:51:04 +02:00
Johan T. Halseth 862c7ae223 contractcourt/channel_arbitrator test: check both respChan and errChan
// Both are sent on, so in some cases we would read from errChan first,
making the test fail.
2018-08-22 23:51:04 +02:00
Johan T. Halseth 06c683d48d contractcourt/channel_arbitrator: move next state commit out of stateStep 2018-08-22 23:51:04 +02:00
Johan T. Halseth 6df302d7f5 contractcourt/channel_arbitrator: remove state callback
This commit removes the state callback, and instead logs the contract
resolutions directly after receiving the unilateral close event. The
resolutions won't change so there's not really necessary to wait to log
them, and this greatly simplifies the code.
2018-08-22 23:51:04 +02:00
Johan T. Halseth 245dae0071 contractcourt/channel_arbitrator: properly commit to next state 2018-08-22 23:51:04 +02:00
Johan T. Halseth 7b1ac0a979 lnd test: check inactive channel disables in testSendUpdateDisableChannel 2018-08-17 23:24:14 +02:00
Johan T. Halseth 52941cec53 lntest: add SuspendNode 2018-08-17 23:24:13 +02:00
Johan T. Halseth 53d319ad10 lnd_test: use shutdownAndAssert 2018-08-17 23:24:13 +02:00
Johan T. Halseth 4581aa313c server: handle case where both policies are not present in fetchLastChanUpdateByOutPoint 2018-08-17 23:24:13 +02:00
Johan T. Halseth 5deffd228c peer: call disableChannel with disabled=false after loading channels
This to ensure now active channel is available in the router, for path
finding, as it might have been disabled if the peer has been offline a
while.
2018-08-17 23:24:13 +02:00
Johan T. Halseth e9cc7492a9 server: add goroutine watchChannelStatus
This commit adds a goroutine watchChannelStatus to the server, which
will query the switch for the status of all open channels every
InactiveChanTimeout / 4. If a channel's status has remained unchanged
during the last InactiveChanTimeout it'll send out a ChannelUpdate
setting the disabled bit accordingly.
2018-08-17 23:24:13 +02:00
Johan T. Halseth 9e44b38eee config: define InactiveChanTimeout 2018-08-17 23:24:13 +02:00
Johan T. Halseth b5bfdd72b5 server+peer: rename disableChannel->announceChanStatus
Now takes a boolean whether to disable/activate, and keeps track of the
last update sent to avoid sending duplicates.
2018-08-17 23:24:12 +02:00
Johan T. Halseth 887722f38f htlcswitch/switch: add method HasActiveLink 2018-08-17 23:24:12 +02:00
Johan T. Halseth 940d0735f8 lnd_test: use dave to listen for ChannelUpdates in testSendUpdateDisableChannel
This commit changes the test testSendUpdateDisableChannel to use Dave to
listen for channel updates, as was originally intended.

Since a ChannelUpdate won't propagate in the network if the channel is
already closed (if the closing transaction has been mined), we change
the closing procedure to initiate the closing process, wait for the
ChannelUpdates, then finally mining the closing transaction. This avoids
a propagation race between the mined block and the ChannelUpdate.
2018-08-17 23:24:12 +02:00
Johan T. Halseth 304577f617 server: make sure timestamp always increases when creating new ChannelUpdate 2018-08-17 23:24:12 +02:00
Johan T. Halseth 8826db32e8 server: let gossiper hand policy update to router
ProcessLocalAnnouncement will attempt to call UpdateEdge with the new
policy. If we call it manually before handing it to the gossiper, that
call will fail with "Outdated" and the announcement won't propagate.
2018-08-17 23:24:12 +02:00
Johan T. Halseth a57a972b26 dep: remove gographviz dependency 2018-08-17 09:38:50 +02:00
Johan T. Halseth c39c2d7c37 lncli: remove --render option from describegraph 2018-08-17 09:36:56 +02:00
Johan T. Halseth 2a3b52535e autopilot: check if already connected before returning error
This commit fixes a small bug that could cause us to disconnect an
already connected peer if no addresses where provided to the ConnectPeer
method. Now we instead first check if we are already connected, and
return early.
2018-08-17 09:26:54 +02:00
Johan T. Halseth 5476f6d310 contractcourt/contract_resolvers: correct off-by-one HTLC expiry
This commit attempts to fix an inconsistency in when we consider an HTLC
to expire. When we first launched the resolver we would compare the
current block height against the expiry, while for new incoming blocks
we would compare against expiry-1.

This lead to a flake during integration tests, during a call to
RestartNode after _exactly_ enough blocks for the HTLC to expire. In
some cases the resolver would see the new blocks and consider the HTLC
to be expired (because of the -1), while in some cases resolver would
shut down before seeing the new blocks, and upon restart wouldn't act on
the new height because we did not compare against -1.

This commit fixes this by doing the same comparison in both cases.
2018-08-14 09:15:48 +02:00
Johan T. Halseth 6e33115da9 lnd_test: return err from assertNumActiveHtlcs, print predErr 2018-08-14 09:09:02 +02:00
Johan T. Halseth 64c2c6b118 peer: print ChanStatus return value, not address 2018-08-11 12:51:50 +02:00
Johan T. Halseth afccca59c4 lnd_test: add testDataLossProtection
This commit adds the integration test testDataLossProtection, that
ensures that when a node loses state, the channel counterparty will
force close the channel, and they both can recover their funds.
2018-07-31 15:16:24 +02:00
Johan T. Halseth 00154bda24 contractcourt/chain_watcher: attempt dispatchRemoteClose using data loss commitPoint
This commit makes the chainwatcher attempt to dispatch a remote close
when it detects a remote state with a state number higher than our
known remote state. This can mean that we lost some state, and we check
the database for (hopefully) a data loss commit point retrieved during
channel sync with the remote peer. If this commit point is found in the
database we use it to try to recover our funds from the commitment.
2018-07-31 15:16:24 +02:00
Johan T. Halseth ebed786b2a htlcswitch/link: inspect sync errors, force close channel
This commit makes the link inspect the error encountered during channel
sync, force closing the channel if we detect a remote data loss.
2018-07-31 15:16:23 +02:00
Johan T. Halseth 410b730778 lnwallet/channel test: add TestChanSyncFailure 2018-07-31 15:16:23 +02:00
Johan T. Halseth 78a4a15bb4 lnwallet/channel: check validity of received commitPoint
This commit adds a check for the LocalUnrevokedCommitPoint sent to us by
the remote during channel reestablishment, ensuring it is the same point
as they have previously sent us.
2018-07-31 15:16:23 +02:00
Johan T. Halseth a2f2d28d0b lnwallet/channel: enumerate error cases from remote chain desync
This commit enumerates the various error cases we can encounter when we
compare our remote commit chain to the view the remote communicates to us
via msg.NextLocalCommitHeight.

We now compare this height to our remote tail and tip height, returning
relevant error in case of a unrecoverable desync, and re-send a
commitment signature (including log updates) in case we owe one.
2018-07-31 15:16:23 +02:00
Johan T. Halseth f1757d6da4 lnwallet/channel: enumerate error cases from local chain desync
This commit enumerates the various error cases we can encounter when we
compare our local commit chain to the view the remote communicates to us
via msg.RemoteCommitTailHeight.

We now compare this height to our local tail height (note that there's
never a local "tip" at this point), returning relevant error in case of
a unrecoverable desync, and re-send a revocation in case we owe one.
2018-07-31 15:16:23 +02:00
Johan T. Halseth 7fb3be84df lnwallet/channel test: rename ErrCommitSyncDataLoss->ErrCommitSyncLocalDataLoss 2018-07-31 15:16:23 +02:00
Johan T. Halseth 48f1458ae5 lnwallet/channel: define channel sync errors
This commit defines a few new errors that we can potentially encounter
during channel reestablishment:
* ErrInvalidLocalUnrevokedCommitPoint
* ErrCommitSyncLocalDataLoss
* ErrCommitSyncRemoteDataLoss

in addition to the already defined errors
* ErrInvalidLastCommitSecret
* ErrCannotSyncCommitChains
2018-07-31 15:16:23 +02:00
Johan T. Halseth 3825ca71dd lnwallet/channel: reduce scope of commitSecretCorrect 2018-07-31 15:16:22 +02:00
Johan T. Halseth 6cdf0e2d6e channeldb/channel: methods for marking borked+dataloss commitPoint in db 2018-07-31 15:16:22 +02:00
Johan T. Halseth ea6aca26a5 channeldb: make chanStatus unexported
Since the ChanStatus field can be changed from concurrent callers, we
make it unexported and add the method ChanStatus() for safe retrieval.
2018-07-31 15:07:30 +02:00
Johan T. Halseth b437d03174 fundingmanager test: add TestFundingManagerMaxPendingChannels 2018-07-31 14:53:22 +02:00
Johan T. Halseth 8b6e7b24aa fundingmanager: count channels pending open when checking MaxPending 2018-07-31 14:53:22 +02:00
Johan T. Halseth 3afa16b7a6 mock: make ListUnspentWitness return new outpoints each call 2018-07-31 14:53:21 +02:00
Johan T. Halseth 5b77ebddb2 lnwallet test: account for funding tx being published by fundingmanager 2018-07-31 14:53:21 +02:00
Johan T. Halseth b885e8d288 fundingmanager test: check reservation canceled after tx broadcast 2018-07-31 14:53:21 +02:00
Johan T. Halseth 2a77b57788 lnwallet + funding: move funding tx publish to fundingmgr
This commit moves the responsibility for publishing the funding tx to
the network from the wallet to the funding manager. This is done to
distinguish the failure of completing the reservation within the wallet
and failure of publishing the transaction.

Earlier we could fail to broadcast the transaction, which would cause us
to fail the funding flow. This is not something we can do directly,
since the CompeteReservation call will mark the channel IsPending in the
databas.e
2018-07-31 14:53:21 +02:00
Johan T. Halseth 8865bcf3d9 fundingmanager: delete active reservation after channel is in DB
This commit makes sure we delete a pending channel from the set of
activeReservations within the fundingmanager immediately after the
channel is moved to the openChannelBucket in the DB. Previously we
wouldn't do this before the funding tx was confirmed, making it possible
that failing the funding flow at a later point would try to cancel a
non-existent reservation context.
2018-07-31 14:53:21 +02:00
Johan T. Halseth eed052eba5 lnwallet/channel: extract local balance from spend instead of stored commit 2018-07-31 08:27:03 +02:00
Johan T. Halseth 2626bba105 contractcourt/chain_watcher: use commitPoint directly instead of isPendingCommit 2018-07-31 08:27:03 +02:00
Johan T. Halseth d9e9b6197c lnwallet/channel test: take commitPoint in NewUnilateralCloseSummary 2018-07-31 08:27:03 +02:00
Johan T. Halseth 06ceba429f lnwallet/channel: make NewUnilateralCloseSummary take commitPoint 2018-07-31 08:27:03 +02:00
Johan T. Halseth f8751350bc lnd_test: set --nolisten for node being cheated
In this commit we modify the integration tests slightly, by setting the
parties that gets breached during the breach tests to --nolisten. We do
this to ensure that once the data protection logic is in place, they
nodes won't automatically connect, detect the state desync and recover
before we are able to trigger the breach.
2018-07-31 08:27:03 +02:00
Johan T. Halseth 22e21da370 htlcswitch tests: add missing OnChannelFailure to test link configs 2018-07-31 08:27:03 +02:00