Commit Graph

106 Commits

Author SHA1 Message Date
Johan T. Halseth
8b02064c7b
multi: provide mempool=true to RegisterSpendNtfn 2018-04-03 11:24:07 +02:00
Johan T. Halseth
2fa2b545fc
breacharbiter: reuse spend events instead of re-registering
This commit fixes a broadcast loop within the breach arbiter, that would
occur when HTLC outputs had been taken to the second level. The breach
arbiter would register for a spend event, but would immediately go on to
create and publish the justice, without waiting for the response to be
received on the spend channel. This lead to a race, where the outpoint
could actually already have been spent, but the notification would
arrive after the breach arbiter checked the channel, and publishing the
justice TX would fail because it was a double spend. This would create a
"broadcast loop", as seen in the logs from the integration test
revoked_uncooperative_close_retribution_remote_hodl.

This is fixed by reusing an existing spend event for the outputs,
meaning we will actually receive on the first channel we initiated,
making the broadcast loop more likely to terminate.
2018-03-23 13:36:57 +01:00
Olaoluwa Osuntokun
800eea931f
build+multi: switch from bolt to bbolt
In this commit, we switch from boltbd/bolt to coreos/bbolt as the
former is no longer being actively maintained.
2018-03-10 19:01:13 -08:00
Johan T. Halseth
d4cedc2917
breacharbiter: use EstimateFeePerVSize 2018-02-26 22:42:26 +01:00
Johan T. Halseth
cabc07ea7d
breacharbiter: check ErrDoubleSpend from PublishTransaction 2018-02-14 12:34:42 +01:00
Conner Fromknecht
3021a246f1
breacharbiter: avoid infinite loop in exactRetribution
After a shutdown has been initiated, both registrations
for spend ntfns and publishing txns can fail. The current
behavior in the face of such failures is to continue trying,
which is fine if we are online. However, this causes an
infinite loop during shutdown, and lnd cannot exit since
the routine is tracked by the brar's waitgroup.

A simple fix is to select on the brar's quit channel after
detecting a failure from either, allowing the breach arbiter
to break out of this death cycle.
2018-02-07 17:42:48 -08:00
Olaoluwa Osuntokun
2faafbcd93
breacharbiter: properly account for second-level spends during breach remedy
In this commit, we address an un accounted for case during the breach
remedy process. If the remote node actually went directly to the second
layer during a channel breach attempt, then we wouldn’t properly be
able to sweep with out justice transaction, as some HTLC inputs may
actually be spent at that point.

In order to address this case, we’ll now catch the transaction
rejection, then check to see which input was spent, promote that to a
second level spend, and repeat as necessary. At the end of this loop,
any inputs which have been spent to the second level will have had the
prevouts and witnesses updated.

In order to perform this transition, we now also store the second level
witness script in the database. This allow us to modify the sign desc
with the proper input value, as well as witness script.
2018-01-22 19:20:01 -08:00
Olaoluwa Osuntokun
4e6c816d11
breacharbiter: correct weight estimation for inputs in justice tx
Before this commit, we had the weight estimates flipped. When sweeping
w/o any delay, we’re spending a regular P2WKH output. When we’re
sweeping their CSV delayed output, we’ll using the entire to-local
script, so we need to properly account for that.
2018-01-22 19:20:01 -08:00
Olaoluwa Osuntokun
7b675446f0
breacharbiter: properly accept new incoming channels for watching 2018-01-22 19:20:00 -08:00
Olaoluwa Osuntokun
0d75dde153
breacharbiter: also listen for the co-op chan close signal 2018-01-22 19:19:55 -08:00
Olaoluwa Osuntokun
a0cc1d1b2d
breacharbiter: utilize new channel on-chain event stream to watch for breaches
In this commit, we modify the breach arbiter to no longer require
holding a channel object directly in order to receive new notifications
about possible breaches. Instead, we’ll contact the chain arbiter to
request a new channel event subscription.

As a result of the new architecture, we no longer need to receive a
handoff once the new channel comes online, as the chainWatcher will
always be active and watching the channel until it’s been closed.
2018-01-22 19:19:50 -08:00
Olaoluwa Osuntokun
94504a9d41
breacharbiter: notify the ChainArbitrator of fresh signals for a channel on startup 2018-01-22 19:19:37 -08:00
Olaoluwa Osuntokun
367231320b
breacharbiter: no longer watch for pending close, ChannelArbitrator will
In this commit, we remove all the code win the BreachArbiter that was
dedicated to sweeping output on the remote party’s commitment
transaction, and also responding to unilateral channel closes. We no
longer need to do this, as this is now the duty of the
ChannelArbitrator.
2018-01-22 19:19:36 -08:00
Conner Fromknecht
fb228a0f7d
breacharbiter: reliable handoff from wallet 2018-01-05 13:46:36 -08:00
Matt Drollette
adf0d98194 multi: fix several typos in godoc comments 2017-12-17 18:40:05 -08:00
Olaoluwa Osuntokun
923cbe62a0
breacharbiter: also cancel the channel's observer in case of close, or hand-off 2017-11-23 23:10:16 -06:00
Olaoluwa Osuntokun
1d65839bca
peer: update cooperative closure unit tests to latest negotiation policy
With the new negotiation policy, we instead just need to ensure that
our fee inches closer to the other party’s with each iteration, and
that it’s within the proper bounds.
2017-11-23 23:10:15 -06:00
Olaoluwa Osuntokun
ce7a981b4f
breacharbiter: add chainhash to retributionInfo struct
In this commit we add a chainhash field to the retributionInfo struct
as within the database, channels are now further namespaced by their
chain hash, and all ChannelCloseSummary structs now also carry the
chain hash of their respective chain.
2017-11-10 19:51:08 -08:00
Jim Posen
a13ad0a339 multi: Fix various typos. 2017-10-25 13:20:54 -07:00
Jim Posen
10a336db46 lnwallet: Use TxWeightEstimator in breacharbiter. 2017-10-19 17:37:53 -07:00
Conner Fromknecht
5b6ab9a078
breacharbiter: filters outputs for dust outputs before sweeping
This commit refactors the breach arbiter such that it ignores
  commitment values below the remote party's dust limit when trying
  to sweep funds after a channel breach. The wallet is now
  permitted to pass nil sign descriptors for commitment outputs,
  which are then ignored by the arbiter.

  All non-dust outputs are accumulated into a single slice of
  outputs inside the breach arbiter to simplify the internals.
  Doing so permitted a work flow that reduces the total number
  of allocations made while processing breaches.

  The SpendableOutputs is also expanded to include public methods
  to access the witness type and sign descriptors, which was useful
  in refactoring the craft justice transaction logic.
2017-09-25 18:56:59 -07:00
Conner Fromknecht
ec288ddf5b
ba+utxno: final pass for formatting 2017-09-19 19:18:21 -07:00
Conner Fromknecht
a8d667ba35
breacharbiter: sweep incoming + outgoing htlcs
This commit also adds a BreachConfig to abstract
  the instantiation of the breach arbiter, as well
  as various formatting improvements.
2017-09-19 19:18:20 -07:00
Conner Fromknecht
f0ac991979
breacharbiter: use BOLT 5 constants 2017-09-19 19:18:19 -07:00
Conner Fromknecht
d88804178e
breacharbiter: unifies ba sweep txn creation 2017-09-19 19:18:14 -07:00
Conner Fromknecht
cfe1530205 breacharbiter: makes newline formatting consistent with lnd 2017-08-25 17:56:50 -07:00
Conner Fromknecht
c3736e6893 breacharbiter: adds persistence to retribution flow
This commit introduces a RetributionStore interface, which
  establishes the methods used to access persisted information
  regarding breached channels. A RetributionStore is used to
  persist retributionInfo regarding all channels for which
  the wallet has signaled a breach.

  The current design could be improved by moving certain
  functionality, e.g. closing channels and htlc links, such
  that they are handled by upstream by their respective
  subsystems. This was investigated, but deemed preferable to
  postpone to a later update to prevent the current
  implementation from sprawling amongst too many packages.

  The test suite creates a mockRetributionStore and ensures that
  it exhibits the same behavior as the retribution store backed
  by a channeldb.DB.
2017-08-25 17:56:50 -07:00
Conner Fromknecht
6ffe33f01a lnw+ba+utxon+cdb: reverts OutPoint and TxOut encoding 2017-08-25 17:56:50 -07:00
Conner Fromknecht
8698085e35 breacharbiter: reverts retributionInfo naming and realign diffs 2017-08-25 17:56:50 -07:00
Conner Fromknecht
4cdce1fc0a breacharbiter+channeldb: resolves rebase conflicts 2017-08-25 17:56:50 -07:00
Philip Hayes
56793a1041 utxonursery: finish migrating to lnwire OutPoint serialization 2017-08-25 17:56:50 -07:00
Philip Hayes
b19c483a04 breacharbiter: add retribution state persistence
This commit adds a breached contract retribution storage layer using
boltdb to the breach arbiter. The breach arbiter now stores retribution
state on disk between detecting a contract breach, broadcasting a
justice transaction that sweeps the channel, and finally witnessing the
justice transaction confirm on the blockchain. It is critical that such
state is persisted on disk, so that if our node restarts at any point
during the retribution procedure, we can recover and continue from the
persisted state.
2017-08-25 17:56:50 -07:00
Olaoluwa Osuntokun
0097cb969d
breacharbiter: convert settled balance from mSAT to SAT 2017-08-22 00:52:34 -07:00
Olaoluwa Osuntokun
563fac84cc
breacharbiter: sweep commitment output in case of unilateral close
This commit adds a new responsibility to the breach arbiter: the
service is now responsible for sweeping the commitment outputs to-self,
in the case of a unilateral commitment broadcast by the remote party.
In this new commitment design, this output won’t be immediately
recognized by the wallet due to using a tweaked public key. As a
result, we need to sweep this output into the wallet manually.
2017-07-30 17:52:32 -07:00
Olaoluwa Osuntokun
522712b9a6
breacharbiter: update wallet/signer API usage to due recent changes 2017-07-30 17:52:04 -07:00
Olaoluwa Osuntokun
3b1db2b186
test: update integration test set up to reflect recent RPC change
A prior commit modified the walletbalance RPC to return satoshi instead
of BTC. As a result, we need to update the SetUp method in the
networkHarness to ensure we expect the proper value when asserting
wallet balances.
2017-07-04 15:53:06 -07:00
Andrey Samokhvalov
c4955258f1 htlcswicth: start use htlcswitch and channel link inside lnd
In current commit big shift have been made in direction of unit testable
payments scenarios. Previosly two additional structures have been added
which had been spreaded in the lnd package before, and now we apply
them in the lnd itself:

1. ChannelLink - is an interface which represents the subsystem for
managing the incoming htlc requests, applying the changes to the
channel, and also propagating/forwarding it to htlc switch.

2. Switch - is a central messaging bus for all incoming/outgoing htlc's.
The goal of the switch is forward the incoming/outgoing htlc messages
from one channel to another, and also propagate the settle/fail htlc
messages back to original requester.

With this abtractions the folowing schema becomes nearly complete:

abstraction
    ^
    |
    | - - - - - - - - - - - - Lightning - - - - - - - - - - - - -
    |
    | (Switch)		        (Switch)		  (Switch)
    |  Alice <-- channel link --> Bob <-- channel link --> Carol
    |
    | - - - - - - - - - - - - - TCP - - - - - - - - - - - - - - -
    |
    |  (Peer) 		        (Peer)	                  (Peer)
    |  Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
2017-05-31 11:06:08 -07:00
bryanvu
abe2e502d5 lnwallet: add FeeEstimator interface, StaticFeeEstimator implementation
This commit adds the FeeEstimator interface, which can be used for
future fee calculation implementations. Currently, there is only the
StaticFeeEstimator implementation, which returns the same fee rate for
any transaction.
2017-05-15 20:26:11 -07:00
Olaoluwa Osuntokun
459583ca04
breacharbiter: don't watch for channel closes if time locked balance is non-zero
This commit fixes a slight logic error in the breachArbiter. Previously
we wouldn’t watch a pending channel for closure if the regular
(settled) balance was non-zero. However, this was incorrect, as it’s
possible for us to be on the receiving side of a channel force closure.
This error would leave certain channels as “pending close zombies”
forever until a user manually deleted the entry (or promoted it to be
fully closed).

To fix this, we now utilize the new `TimeLockedBalance` field to make a
better judgment as to if the utxoNursery is watching over a channel or
not.
2017-05-14 19:07:14 -07:00
Olaoluwa Osuntokun
d47f004fbd
peer+rpcserver+breacharbiter: usel latest ChainNotifier API 2017-05-11 15:20:55 -07:00
Olaoluwa Osuntokun
2aa68a8517
breacharbiter: fix bug, properly populate ChannelCloseSummary 2017-05-04 17:40:52 -07:00
Olaoluwa Osuntokun
83a425b74c
breacharbiter: at startup, watch pending closed channels to mark as fully closed
This commit adds a start up check to the breachArbiter: it will now
watch all channels which are in the “pending closed” state, to ensure
that state of the database is up to date at all times. Once any of the
closing transactions for these channels have been confirmed, then they
will properly be marked as such within the database.
2017-05-04 17:40:27 -07:00
Olaoluwa Osuntokun
4609bd462f
breacharbiter: mark channel as fully closed after retribution enacted 2017-05-04 17:40:24 -07:00
Olaoluwa Osuntokun
27329ed9db
breacharbiter: mark channel as fully closed upon detection of unilateral close
This commit modifies the breachArbiter to properly mark a channel as
_fully_ closed once the transaction which force closed the channel has
been confirmed within the chain.
2017-05-04 17:40:14 -07:00
Olaoluwa Osuntokun
4f758eb549
breacharbiter: modify db API usage to match recent changes 2017-05-04 17:40:11 -07:00
bryanvu
7048480a4a minor: fixed arbiter spelling and comment/error messages in funding rpc messages 2017-02-24 11:37:33 -08:00
Olaoluwa Osuntokun
384fe61e73
multi: fix go vet warnings throughout code base 2017-02-16 19:33:19 +08:00
Olaoluwa Osuntokun
2c0d5e0f0d
breacharbiter: stop the stale contract when a live contract appears
This commit modifies the logic of the contract hand-off within the
breachArbiter to ensure that only a single internal closeObserver
goroutine is ever active for a given contract.

This modification cleans up the logs in the case of multiple
reconnections and may possible eliminate some non-deterministic bugs
related to channel force closures.
2017-02-02 17:28:15 -08:00
Trevin Hofmann
40c7bac3aa multi: fix a variety of typos throughout the repo 2017-01-17 17:02:56 -08:00
Olaoluwa Osuntokun
8990de4d99
breacharbiter: ensure failure to retrieve channels triggers start-up error
This commit moves the fetching of active channels from the
contractObserver goroutine up to the Start() method on the
breachArbiter. By doing this, we ensure that the user receives an error
(under the current set up) if the btcd node that lnd is connected to
doesn’t have their txindex enabled.
2017-01-14 18:03:51 -08:00
Olaoluwa Osuntokun
5affed38fc
multi: update btcsuite API's to latest upstream changes
This commit makes a large number of minor changes concerning API usage
within the deamon to match the latest version on the upstream btcsuite
libraries.

The major changes are the switch from wire.ShaHash to chainhash.Hash,
and that wire.NewMsgTx() now takes a paramter indicating the version of
the transaction to be created.
2017-01-05 13:56:34 -08:00
Olaoluwa Osuntokun
beb6303e2f
breacharbiter: only log if we have any active channels
This commit modifies the contractObserver slightly to along log if we
have any active channels, which avoids a meaningless log message.
2017-01-05 13:21:47 -08:00
Olaoluwa Osuntokun
276c384455
breacharbiter: fix double channel close panic bug
This commit fixes s bug in the breachArbiter which was introduced
during the change that added the live channel hand off from an active
peer. Rather than closing the settle channel of the _older_
breachObserver, the settle channel of the newer beachObserver was being
closed. This would result in a panic once the channel itself was
actually settled as the channel would be closed again.

To fix this bug, we now properly close the channel of the old settle
signal instead of the new one.
2016-12-30 16:30:11 -08:00
Olaoluwa Osuntokun
3e1c98f2f7
breacharbiter: accept handoff for live channel on peer connect
This commit modifies the interaction between the breachArbiter and the
peer struct such that the breachArbiter _always_ has the latest version
of a contract.

Prior to this commit once we connected out to a peer which we had an
active contract with and the breachArbiter was watching, we’d have two
copies of the channel in memory, instead of just a single one. This was
wasteful and caused some duplicated log messages due to two instances
of the channel being active.
2016-12-27 16:45:05 -08:00
Olaoluwa Osuntokun
71c6e837e3
breacharbiter: fix bug, don't exit main loop due to unknown contract 2016-11-28 20:08:06 -08:00
Olaoluwa Osuntokun
494fcec874
breacharbiter: introduce new sub-system to watch for breaches
This commit introduces a new sub-system into the daemon whose job it is
to vigilantly watch for any potential channel breaches throughout the
up-time of the daemon. The logic which was moved from the utxoNursery
in a prior commit now resides within the breachArbiter.

Upon start-up the breachArbiter will query the database for all active
channels, launching a goroutine for each channel in order to be able to
take action if a channel breach is detected. The breachArbiter is also
responsible for notifying the htlcSwitch about channel breaches in
order to black-list the breached linked during any multi-hop forwarding
decisions.
2016-11-28 19:44:09 -08:00