Commit Graph

897 Commits

Author SHA1 Message Date
Wilmer Paulino
3a982063a0
fundingmanager+lnwallet: ensure proposed channel reserve is above dust limit 2018-05-14 14:20:20 -04:00
Wilmer Paulino
3c33a8cb67
lnwallet: enforce backend node's min relay fee floor
In this commit, we fix an issue where sometimes transactions wouldn't
provide enough of a fee to be relayed by the backend node. This would
especially cause issues when sweeping outputs after a contract breach,
etc.

Now, we'll fetch the minimum relay fee from the backend node and ensure
it is set as a lower bound if the estimated fee ends up dipping below
it.
2018-05-14 14:20:18 -04:00
Conner Fromknecht
f963f91a3c
multi: use mutex-guarded ShortChanID() on OpenChannel 2018-05-09 16:06:49 -07:00
Johan T. Halseth
71228a6b06
lnwallet/channel: don't use commit height to determine FullySynced
This commit removes a faulty check we did to determine if the channel
commitments were fully synced. We assumed that if out local commitment
chain had a height higher than the remote, then we would have state
updates present in our chain but not in theirs, and owed a commitment.
However, there were cases where this wasn't true, and we would send a
new commitment even though we had no new updates to sign. This is a
protocol violation.

Now we don't longer check the heights to determine if we are fully
synced. A consequence of this is that we also need to check if we have
any pending fee updates that are nopt yet signed, as those are
considered non-empty updates.
2018-05-09 08:47:21 +02:00
Johan T. Halseth
9324bf7b1d
lnwallet/channel: return error in case of htlc index mismatch
This commit make us return an error in case a restored HTLC from a
pending remote commit has an index that is different from our local
update log index. It is appended with the assumption that these indexes
are the same, and if they are not we cannot really continue.
2018-05-08 13:41:52 +02:00
Johan T. Halseth
7e1f2a7dc3
lnwallet/channel: remove unused arguments 2018-05-08 13:41:52 +02:00
Johan T. Halseth
aa1c2cdf81
lnwallet/channel: add more info in case of crash
This commit adds a call to panic in case the HTLC we are looking for is
not found in the update log. It _should_ always be there, but we have
seen crashes resulting from it not being found. Since it will crash with
a nil pointer dereference below, we instead call panic giving us a bit
more information to work with.
2018-05-08 13:41:52 +02:00
Johan T. Halseth
1d676b77e1
lnwallet/channel: log pending remote commit during restore 2018-05-08 13:41:51 +02:00
Johan T. Halseth
1d172428c4
lnwallet/channel: return missing errors
This commit corrects a few cases where we would encounter errors, but
return nil by mistake.
2018-05-08 13:41:51 +02:00
Olaoluwa Osuntokun
88ff2af931
lnwallet: add new test to exercise creation of unilateral close summaries for pending broadcast commitments 2018-05-03 21:29:29 -07:00
Olaoluwa Osuntokun
8b06817482
lnwallet: modify NewUnilateralCloseSummary to be aware of pending remote commits
In this commit, we modify the NewUnilateralCloseSummary to be able to
distinguish between a unilateral closure using the lowest+highest
commitment the remote party possesses. Before this commit, if the remote
party broadcast their highest commitment, when they have a lower
unrevoked commitment, then this function would fail to find the proper
output, leaving funds on the chain.

To fix this, it's now the duty of the caller to pass remotePendingCommit
with the proper value. The caller should use the lowest unrevoked
commitment, and the height hint of the broadcast commitment to discern
if this is a pending commitment or not.
2018-05-03 21:29:28 -07:00
Olaoluwa Osuntokun
90bbc4f41b
lnwallet: move CreateTestChannels to new test_utils.go
In this commit, we move a set of useful functions for testing channels
into a new file. The old createTestChannels has been improved as it will
now properly set the height hint on the first created commitments, and
also no longer accepts any arguments as the revocation window no longer
exists.
2018-05-03 21:29:28 -07:00
Conner Fromknecht
cae1d468e7
lnwallet/channel: expose NextLocalHtlcIndex 2018-05-02 01:12:17 -07:00
Olaoluwa Osuntokun
c7c25445eb
lnwallet: add new test to ensure channel is able to update fees in both directions
Closes #1145.
2018-05-01 17:35:42 -07:00
Vegard Engen
d7a254328e Take into account that the new fee will not come in addition to old fee when updating commit fee 2018-04-29 22:42:20 +00:00
Conner Fromknecht
a2fdd8593d
lnwallet/interfaace_test: init neutrino with chain params 2018-04-26 16:03:28 -07:00
Conner Fromknecht
06a53aa5cc
lnwallet/btcwallet/config: add recovery window and bday 2018-04-26 16:03:28 -07:00
Conner Fromknecht
ae604061bf
lnwallet/btcwallet/btcwallet: pass recovery window to CreateNewWallet 2018-04-26 16:03:27 -07:00
Johan T. Halseth
b7bb53a8b8
channeldb/channel: add property ChanStatus in place of IsBorked to OpenChannel
This commit changes the bool `IsBorked` in OpenChannel to a `ChanStatus`
struct, of type ChannelStatus. This is used to indicated that a channel
that is technically still open, is either borked, or has had a
commitment broadcasted, but is not confirmed on-chain yet.

The ChannelStatus type has the value 1 for the status Borked, meaning it
is backwards compatible with the old database format.
2018-04-25 09:37:23 +02:00
Johan T. Halseth
3d0cb16677
lnwallet/channel: clearify that the spendDetails is spending funding outpoint 2018-04-25 09:37:22 +02:00
Olaoluwa Osuntokun
188b8462cd
lnwallet: update addr in transactions_test.go for new regtest hrp 2018-04-17 19:26:32 -07:00
Dimitris Tsapakidis
4009f7f874 multi: fix typos in comments 2018-04-17 19:03:27 -07:00
practicalswift
663c396235 multi: fix a-vs-an typos 2018-04-17 19:02:04 -07:00
Olaoluwa Osuntokun
32ad632aa1
Merge pull request #956 from halseth/channel-newlocalforceclosesummary
[refactor] lnwallet/channel: add NewLocalForceCloseSummary
2018-04-09 20:47:53 -07:00
Johan T. Halseth
3d55767838
lnwallet/reservation: remove RegisterMinHTLC
We remove this method, as our minHtlc value is set using the
CommitConstraints method.
2018-04-06 10:02:19 +02:00
Johan T. Halseth
8e77e1e6eb
lnwallet/channel: add NewLocalForceCloseSummary
This commit renames ForceCloseSummary to LocalForceCloseSummary, and
adds a new method NewLocalForceCloseSummary that can be used to derive a
LocalForceCloseSummary if our commitment transaction gets confirmed
in-chain. It is meant to accompany the NewUnilateralCloseSummary method,
which is used for the same purpose in the event of a remote commitment
being seen in-chain.
2018-04-06 09:46:30 +02:00
Olaoluwa Osuntokun
065b39bc0b
Merge pull request #1025 from Roasbeef/incoming-htlc-breach-retribution
lnwallet+test: properly generate the sender HTLC script in a contract breach scenario
2018-04-05 17:58:31 -07:00
Olaoluwa Osuntokun
7da8cb2910
lnwallet: add new TestNewBreachRetributionSkipsDustHtlcs test 2018-04-05 16:20:22 -07:00
Olaoluwa Osuntokun
f79af461d3
lnwallet: in NewBreachRetribution create the htlcRetributions slice to capacity, not length
In this commit, we fix an existing bug in the NewBreachRetribution
method. Rather than creating the slice to the proper length, we instead
now create it to the proper _capacity_. As we'll now properly filter out
any dust HTLCs, before this commit, even if no HTLCs were added, then
the slice would still have a full length, meaning callers could actually
interact with _blank_ HtlcRetribution structs.

The fix is simple: create the slice with the proper capacity, and append
to the end of it.
2018-04-05 16:19:49 -07:00
Olaoluwa Osuntokun
c393475d39
lnwallet: ensure that we skip dust HTLC's in NewBreachRetribution 2018-04-04 18:41:38 -07:00
Olaoluwa Osuntokun
4e44528bff
lnwallet: fix ordering of keys when we generate the sender script during a breach
In this commit, we fix an existing within lnd. Before this commit,
within NewBreachRetribution the order of the keys when generating the
sender HTLC script was incorrect. As in this case, the remote party is
the sender, their key should be first. However, the order was swapped,
meaning that at breach time, our transaction would be rejected as it had
the incorrect witness script.

The fix is simple: swap the ordering of the keys. After this commit, the
test extension added in the prior commit now passes.
2018-04-04 18:41:37 -07:00
Olaoluwa Osuntokun
1c5d62a804
lnwallet: add new concrete error InvalidHtlcSigError for failed htlc sig validation
In this commit we add a new error: InvalidHtlcSigError. This error will
be returned when we're unable to validate an HTLC signature sent by the
remote party. This will allow other nodes to more easily debug _why_ the
signature was rejected.
2018-04-04 17:41:10 -07:00
Olaoluwa Osuntokun
b422e4ec1e
lnwallet+funding+lnd: add new config option for min accepted channel size
In this commit we add a new command line option (and a sane default) to
allow users to specify the *smallest* inbound channel that they'll
accept. Having a higher-ish limit lets users limit their channels, and
also avoid a series of very low value "spam" channels.

The new option is --minchansize, and expressed in satoshis. If we
receive an inbound channel request for a value smaller than this, then
we'll immediately reject it.
2018-04-02 16:17:58 -07:00
Olaoluwa Osuntokun
6103ccb081
lnwallet: ensure we only accept/produce sane commitments
In this commit, we add an additional check within CreateCommitTx to
ensure that we will never create or accept a commitment transaction that
wasn't valid by consensus. To enforce this check, we use the
blockchain.CheckTransactionSanity method.
2018-03-27 15:37:15 -07:00
Olaoluwa Osuntokun
af4afdb6f0
lnwallet: use btcutil.NewAmount for BTC -> SAT conversions
In this commit, we fix an existing rounding related bug in the codebase.
The RPC interface for btcd and bitcoind return values in BTC rather than
in satoshis. So in several places, we're forced to convert ourselves
manually. The existing logic attempted to do this, but didn't properly
account for rounding. As a result, our values can be off due to not
rounding incorrectly.

The fix for this is easy: simply properly use btcutil.NewAmount
everywhere which does rounding properly.

Fixes #939.
2018-03-25 19:15:18 -07:00
Johan T. Halseth
a6e7dce7b7
lnwallet/channel: reject received commitment with too many htlc sigs
This commit adds a check that will make LightningChannel reject a
received commitment if it is accompanied with too many HTLC signatures.
This enforces the requirement in BOLT-2, saying:

if num_htlcs is not equal to the number of HTLC outputs in the local commitment transaction:
    * MUST fail the channel.

A test exercising the behaviour is added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth
70b86e596e
lnwallet/channel: use remote dustlimit when generating HTLC sigs
This commit fixes an issue which would arise in some cases when the
local and remote dust limits would differ, resulting in lnd not
producing the expected number of HTLC signatures. This was a result of
checking dust against the local instead of the remote dust limit.

A test exercising the scenario is added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth
263d6b9c1f
lnwallet/channel: don't accept immediately on empty htlc sigs
This commit fixes an issue where we would blindly accept a commitment
which came without any accompanying HTLC signatures. A test exercising
the scenario is added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth
241c79397f
lnwallet/channel: fix crash on receiving too few HTLC sigs
This commit fixes an out of bounds error that would occur in the case
where we received a new commitment where the accompanying HTLC sigs were
too few. Now we'll just reject such an commitment.

A test exercising the behavior is also added.
2018-03-22 14:58:22 +01:00
Olaoluwa Osuntokun
e0dc10b1a5
Merge pull request #824 from cfromknecht/multi-chain-coin-type
Configurable CoinType for HD Derivation
2018-03-13 18:14:30 -07:00
Olaoluwa Osuntokun
0befe41384
Merge pull request #782 from paddyquinn/master
funding: implement reservation zombie sweeper
2018-03-13 17:07:53 -07:00
Conner Fromknecht
ca7992e8dd
lnwallet/btcwallet/singer: use chainKeyScope to fetch scoped mgr 2018-03-13 16:33:46 -07:00
Conner Fromknecht
fbef815530
lnwallet/btcwallet/config: add CoinType to configuration 2018-03-13 16:33:46 -07:00
Conner Fromknecht
e760963ead
lnwallet/btcwallet/btcwallet: use coin type in key scope 2018-03-13 16:33:46 -07:00
Conner Fromknecht
e99243d86b
lnwallet/interface_test: inti btcwallet with test coin type 2018-03-13 16:33:46 -07:00
PaddyQuinn
5410725306 lnwallet: update comments 2018-03-12 19:37:18 -04:00
Conner Fromknecht
600ab9d149
lnwallet/interface_test: extend publish timeout
This commit extends the amount of time we wait
for transaction to enter the mempool from
10 to 30 seconds. The wallet's interface tests
seem to be particularly slow when run with the
race flag, a problem which is only exacerbated
by the slowness of travis.

With 10s and the race flag, I was able to repro
the issues locally fairly consistently.
2018-03-12 13:52:16 -07:00
Conner Fromknecht
5df8b52dae
multi: set initiator funding txn 2018-03-11 15:06:22 -07:00
Conner Fromknecht
2e1dcd316c
lnwallet/wallet: store funding txn during reservation 2018-03-11 13:58:41 -07: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
Conner Fromknecht
5539e23b05
lnwallet/channel_test: convert tests to new channel API for persistence 2018-03-09 17:35:54 -08:00
Conner Fromknecht
d420266911
lnwallet/channel: expose API changes to channel state transitions 2018-03-09 17:35:53 -08:00
Conner Fromknecht
6e542d5dfa
lnwallet/channel_test: init open channels with Packager 2018-03-09 14:45:30 -08:00
Conner Fromknecht
53e4422a2e
lnwallet/channel: integrate fwdpkgs w/ in-mem buffering 2018-03-09 14:45:30 -08:00
Olaoluwa Osuntokun
b8d0df998a
lnwallet: when validating fee updates, ensure newFee < balance 2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun
ac90a8288e
lnwallet: precalculate fees in mSAT to avoid multiple conversions 2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun
217166fb10
lnwallet: within validateCommitmentSanity check for balance underflow
In this commit, we add an additional check within
validateCommitmentSanity due to the recent change to unsigned integers
for peer balances in the channel state machine. If after evaluation
(just applying HTLC updates), the balances are negative, then we’ll
return ErrBelowChanReserve.
2018-03-08 12:50:48 -05:00
Olaoluwa Osuntokun
5f5e4554cb
lnwallet: if the initiator is unable to pay fees, then consume their entire output
In this commit, we add logic to account for an edge case in the
protocol. If they initiator if unable to pay the fees for a commitment,
then their *entire* output is meant to go to fees. The recent change to
properly interpret balances as unsigned integers (within the protocol)
let to the discovery of this missed edge case.
2018-03-08 12:50:48 -05:00
Olaoluwa Osuntokun
19bc477b9a
lnwallet: update interface tests to account for recent lnwire.MilliSatoshi change
lnwire.MilliSatoshi is now a signed integer, as a result, we’ll return
a different error if our balances go to negative due to the inability
to pay a the set fee.
2018-03-08 12:50:48 -05:00
Olaoluwa Osuntokun
8425a35684
lnwallet: in NewChannelReservation ensure commit fees are payable
In this commit, we fix a bug introduced by the recent change of
lnwire.MilliSatoshi to be an unsigned integer. After this change an
integer underflow was left undetected, as a result we’ll now
momentarily cast to a signed integer in order to ensure that both sides
can pay the proper fee.
2018-03-08 12:50:47 -05:00
Olaoluwa Osuntokun
5ecef17e0f
lnwallet: modify logging to display mSAT amount if funding constrains invalid 2018-03-08 12:50:47 -05:00
Olaoluwa Osuntokun
116406c7ec
Merge pull request #769 from Roasbeef/new-lightning-key-derivation
multi: modify key derivation to be fully deterministic, remove p2pkh, wallet now witness only
2018-03-06 17:21:55 -05:00
Olaoluwa Osuntokun
18e9475a9a
lnwallet/btcwallet: grab best header timestamp directly from wallet
In this commit, we modify the way we obtain the current best header
timestamp. In doing this, we fix an intermittent flake that would pop
up at times on the integration tests. This could occur as if the wallet
was lagging behind the chain backend for a re-org, then a hash that the
backend knew of, may not be known by the wallet.

To remedy this, we’ll take advantage of a recent change to btcwallet to
actually include the timestamp in its sync state.
2018-03-06 16:04:07 -05:00
Olaoluwa Osuntokun
d98e7a730d
lnwallet: update integration tests due to recent API changes 2018-03-06 16:04:06 -05:00
Olaoluwa Osuntokun
a144018e98
lnwallet: remove p2pkh as an address type, wallet is now pure segwit
In this commit, we modify the mechanics of the wallet to only allow
derivation of segwit-like addresses. Additionally, the ConfirmedBalance
method on the WalletController now only has a single argument, as it’s
assumed that the wallet is itself only concerned with segwit outputs.
2018-03-06 16:04:03 -05:00
Olaoluwa Osuntokun
0d1a40fb46
lnwallet: update tests due to recent API changes 2018-03-06 16:04:03 -05:00
Olaoluwa Osuntokun
5b063a0691
lnwallet: modify the way we derive revocation roots to be deterministic
In this commit, we modify the way we generate the secrets for
revocation roots to be fully deterministic. Rather than use a special
key and derive all sub-roots from that (mixing in some “salts”), we’ll
use the proper keychain.KeyFamily instead. This ensures that given a
static description of the channel, we’re able to re-derive our
revocation root properly.
2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun
a41f00e2d6
lnwallet: update funding flow to utilize keychain.KeyRing
In this commit, we modify the funding flow process to obtain all keys
necessary from the keychain.KeyRing interface. This ensure that all
keys we generate are fully deterministic.
2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun
fe12c908f8
lnwallet: add an instance of keychain.SecretKeyRing to the Config struct 2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun
22ee0a7576
lnwallet: update state machine due to channeldb and SignDescriptor changes 2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun
af1fd65655
lnwallet/btcwallet: update Signer implementation to use keychain.KeyDescriptor 2018-03-06 16:04:01 -05:00
Olaoluwa Osuntokun
a0dc06b954
lnwallet: update script_utils and tests due to SignDescriptor API change 2018-03-06 16:04:01 -05:00
Olaoluwa Osuntokun
73dd1536ed
lnwallet: update signdescriptor_test.go due to latest API changes 2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun
9ccdcaf747
lnwallet: update the SignDescriptor struct to use keychain.KeyDescriptor
In this commit, we update the SignDescriptor struct to instead use the
keychain.KeyDescriptor struct inplace of a raw public key. We do this
as this allows for a recovery mode, where the caller doesn’t know what
key was used exactly, but remembers the precise KeyDescriptor. A
stateless signer is still able to re-derive the proper key, as it’s
given the full path.
2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun
93280ad60a
lnwallet/btcwallet: update implementation to account for recent API changes
The new version of the internal core of btcwallet now uses KeyScopes
rather than address types to derive particular addresses. As a result,
in this commit, we update our API usage to ensure that proper addresses
are still derived.
2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun
6290a520fd
lnwallet/btcwallet: remove pruned interface methods
These methods are no longer a part of the interface. As a result, we
can safely delete them.
2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun
a26367f3cb
lnwallet: remove NewRawKey and FetchRootKey from the WalletController interface
In this commit, we remove two methods from the WalletController
interface which were previously used by the funding reservation process
(NewRawKey) and the p2p network (FetchRootKey) in order to derive
various keys for operation. This methods are no longer necessary as the
KeyRing interface implements the functionality in a deterministic
manner.
2018-03-06 16:03:59 -05:00
Johan T. Halseth
781c2a6eb4
lnwallet test: update test to new error message 2018-03-06 22:02:35 +01:00
Johan T. Halseth
0cbb759d0a
lnwallet: send ReservationError for invalid/incompatible reservation 2018-03-06 22:02:34 +01:00
Johan T. Halseth
bb63ad7da6
lnwallet: send ReservationError for unacceptable constraints 2018-03-06 22:02:34 +01:00
Johan T. Halseth
2cd7ec0833
lnwallet: add errors.go, errors sent to peer during funding 2018-03-06 22:02:34 +01:00
Olaoluwa Osuntokun
d8ce90306d
lnwallet/btcwallet: during initial creation catch the case of an existing wallet
In this commit, due to the recent changes within lnd itself, it may be
possible that a wallet already exists when the wallet has been signaled
to be created. As a result, *always* open the wallet ourselves, but
allow an existing wallet to already be in place.
2018-03-05 11:07:07 -05:00
Johan T. Halseth
dd6872da31
lnwallet test: add TestFeeRateTypes and TestStaticFeeEstimator 2018-02-26 22:42:27 +01:00
Johan T. Halseth
d7834ca4eb
lnwallet tests: update tests to new FeeEstimator and fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth
1f839d2526
lnwallet/channel: denominate in fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth
e1bb762cf7
lnwallet: denominate in fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth
088d9bc42f
lnwallet: add VSize method for returning size from TxWeightEstimator 2018-02-26 22:42:24 +01:00
Johan T. Halseth
f6ac5658e2
lnwallet: make SendOutputs take feerate in SatPerVByte 2018-02-26 22:42:24 +01:00
Johan T. Halseth
68557e43c1
lnwallet: add feerate types, make estimator return sat/vbyte 2018-02-26 22:42:24 +01:00
Conner Fromknecht
4449038ae5
lnwallet/btcwallet/btcwallet: adds extra double spend case
Adds an extra case to the select statement to catch
an error produced by btcd. The error is meant to signal
that an output was previously spent, which can appear
under certain race conditions in spending/broadcasting.
This caused our final itest to fail because it would
not try to recraft the justice txn.
2018-02-20 20:48:53 -08:00
Olaoluwa Osuntokun
34efb380be
lnwallet: update interface tests due to recent API change 2018-02-20 19:16:14 -08:00
Olaoluwa Osuntokun
d5923f3832
Merge pull request #594 from halseth/publish-transaction-error-codes
Ignore ErrRejectDuplicate errors
2018-02-20 19:05:53 -08:00
Jason Dufair
84551c616f lnwallet/lnrpc: Expose sync status to gRPC interface
This commit adds wallet_best_block_timestamp to the gRPC interface.
This is done in order to allow clients to calculate progress while
lnd syncs to the blockchain. wallet_best_block_timestamp is exposed
via the GetInfo() rpc call. Additionally, IsSynced() returns the
WalletBestBlockTimestamp as the second value in the tuple
that is returned, providing additional detail when querying about the
status of the sync. The BtcWallet interface has also been updated
accordingly.

This commit was created to support the issue to
[Add progress bar for chain sync] (lightninglabs/lightning-app#10) in
lightning-app
2018-02-20 19:00:06 -08:00
Johan T. Halseth
3fd7f28b39
lnwallet: don't ignore any returned error from PublishTransaction 2018-02-14 12:34:41 +01:00
Johan T. Halseth
d96b5b62eb
lnwallet test: add test for PublishTransaction return errors 2018-02-14 12:34:41 +01:00
Johan T. Halseth
1dcc89cca9
lnwallet/btcwallet: return concrete error type from PublishTransaction 2018-02-14 12:34:40 +01:00
Johan T. Halseth
a1a9834a53
lnwallet: add PublishTransaction error types 2018-02-14 12:34:40 +01:00
Olaoluwa Osuntokun
7f61d8cf3d
lnwallet: update tests to use latest neutrino API 2018-02-09 12:16:17 -08:00
Johan T. Halseth
82dc8e0794
lnwallet test: add channel constraints tests
This commit adds the tests TestMaxAcceptedHTLCs,
TestMaxPendingAmount, TestChanReserve and TestMinHTLC.
2018-02-08 18:35:25 -05:00
Johan T. Halseth
f9701cde63
lnwallet tests: set channel reserve during channel tests 2018-02-08 18:35:25 -05:00
Johan T. Halseth
7b9f098fe6
lnwallet: fully validate all channel constraints in validateCommitmentSanity
This commit introduces changes to the validateCommitmentSanity
function to fully validate all channel constraints.
validateCommitmentSanity now validates that the
MaxPendingAmount, ChanReserve, MinHTLC, & MaxAcceptedHTLCs
limits are all adhered to during the lifetime of a channel.

When applying a set of updates, the channel constraints are
validated from the point-of-view of either the local or the
remote node, to make sure the updates will be accepted.

Co-authored-by: nsa <elzeigel@gmail.com>
2018-02-08 18:35:25 -05:00
Johan T. Halseth
1873fe1381
lnwallet/channel: move common calculation of balance into computeView
This commit moves common logic used to calculate the state
of a commitment after applying a set of HTLC updates, into
the new method computeView. This method can be used when
calculating the available balance, validating the sanity
of a commitment after applying a set of updates, and also
when creating a new commitment, reducing the duplication
of this logic.
2018-02-08 18:35:25 -05:00
Johan T. Halseth
98d28611e4
lnwallet/channel: let evaluateHTLCView take mutate boolean
This commit adds a new boolean parameter mutateState to
evalueteHTLCView, that let us call it without neccessarily
mutating the addHeight/removeHeight of the HTLCs, which is
useful when evaluating the commitment validity without
mutating the state.
2018-02-08 18:35:25 -05:00
Johan T. Halseth
50f495fae1
lnwallet: cleanup of reservation.CommitConstraints, and move RemoteChanConstraints.
This commit adds some more comments and checks to
reservation.CommitConstraints, including making
MinHTLC value one of the passed constraints.

RemoteChanConstraints is also moved out of
reservation.
2018-02-08 18:35:24 -05:00
nsa
7e7516137d
lnwallet: validate commited channel constraints 2018-02-08 18:35:23 -05:00
Olaoluwa Osuntokun
9c483c38b1
lnwallet: update state machine to use new lnwire.Sig everywhere 2018-02-06 20:14:31 -08:00
Daniel McNally
8543497dcc multi: fixing it's/its typos in comments 2018-02-06 19:13:07 -08:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
MeshCollider
4b1cc98808 multi: apply roasbeef diff to support incoming socks.ProxiedAddr 2018-02-05 17:37:46 -08:00
Olaoluwa Osuntokun
18741831dd
Merge pull request #485 from halseth/fix-negative-balance
Use remoteACKed index when calculating availableBalance.
2018-02-05 16:23:17 -08:00
Olaoluwa Osuntokun
cfacc18f72
Merge pull request #711 from Roasbeef/funding-fail-first
funding: during funding error fail before sending Error to peer
2018-02-05 15:09:21 -08:00
Johan T. Halseth
9f2ec87ed6
lnwallet/sigpool: exit SubmitSignBatch on quit 2018-02-02 21:16:38 -05:00
Johan T. Halseth
f83f47541d
channel test: add TestDesyncHTLCs
This commit adds a test that trigger a case where the balance
could end up being negative when we used the logIndex when
calculating the channel's available balance. This could
happen when the logs got out of sync, and we would use
the balance from a settled HTLC even though we wouldn't
include it when signing the next state.
2018-02-02 21:16:37 -05:00
Johan T. Halseth
83b368d20e
lnwallet/channel: use remoteACKedIndex instead of logIndex in
availableBalance
2018-02-02 21:16:37 -05:00
Olaoluwa Osuntokun
609525f0e8
Merge pull request #712 from Roasbeef/avoid-dust-change-funding
lnwallet: avoid creating dust change outputs in funding txns
2018-02-01 16:20:52 -08:00
Olaoluwa Osuntokun
20098e8cb3
lnwallet: update transactions_test.go due to recent API changes 2018-01-31 14:31:14 -08:00
Jim Posen
916b83a6ee lnwallet: Implement test vectors from BOLT 03, Appendix C.
Appendix C of BOLT 03 contains a series of test vectors asserting that
commitment, HTLC success, and HTLC timeout transactions are created
correctly. Here the test cases are transcribed to Go structs and
verified.

We also break out some logic need to tests that bypass the constructor
and remove some redundant fields.
2018-01-31 14:30:56 -08:00
Olaoluwa Osuntokun
43fa9fe467
lnwallet: avoid creating dust change outputs in funding txns
Before this commit, if the remaining change was small enough, then it
was possible for us to generate a non-std funding transaction. This is
an issue as the txn would fail to propagate, meaning funds could
potentially be stuck in limbo if users didn't manually drop their
transaction history.

To avoid this scenario, we won't create a change output that is dusty.
Instead, we'll add these as miner fees.

Fixes #690.
2018-01-31 14:10:45 -08:00
Olaoluwa Osuntokun
246c05fcd8
lnwallet: add additional debug logging for txns during funding flows 2018-01-31 14:00:05 -08:00
Olaoluwa Osuntokun
1819abf224
lnwallet: increase size of test reservation due to high funding limit 2018-01-28 16:55:11 -08:00
Olaoluwa Osuntokun
3036fc0181 lnwallet: disallow creation of channels < 2x dust limit
Fixes #633.
2018-01-28 15:11:13 -08:00
Olaoluwa Osuntokun
63fe8aec5b
lnwallet: properly use in KB, not KiB to convert to sat/byte for bitcoind estimator
In this commit, we fix an existing bug. The fee estimation within
bitcoind is based on fee/KB (1000), not fee/KiB (1024).

Pointed out by @dabura667.
2018-01-28 14:53:58 -08:00
Olaoluwa Osuntokun
f85f1f97ca
lnwallet: add the second level witness script to the HtlcRetribution
In this commit, we add the second level witness script to the
HtlcRetribution struct. We do this as it’s possible that we when
attempt to sweep funds after a channel breach, then the remote party
has already gone to the second layer. In this case, we’ll then need to
update our SignDesc and also the witness, in order to do that we need
this script that’ll get us pass the second layer P2WSH check.
2018-01-22 19:19:58 -08:00
Olaoluwa Osuntokun
967a9ca7de
lnwallet: add new HtlcSecondLevelRevoke witness type
In this commit, we add a new witness type to the set of known types.
This new type will be used when we need to sweep an HTLC that the
remote party has taken to the second level.
2018-01-22 19:19:57 -08:00
Olaoluwa Osuntokun
109e42a567
lnwallet: update OfferedHtlcSuccessWitnessSize to factor in preimage size 2018-01-22 19:19:57 -08:00
Olaoluwa Osuntokun
cca0d64ea4
lnwallet: add size estimates for second level HTLC script+spends 2018-01-22 19:19:56 -08:00
Olaoluwa Osuntokun
783f01e1c7
multi: fix linter warnings 2018-01-22 19:19:56 -08:00
Olaoluwa Osuntokun
1604c75a9c
lnwallet: modify CreateCloseProposal to also return the close txid and local balance 2018-01-22 19:19:53 -08:00
Olaoluwa Osuntokun
5bbe126c34
lnwallet: add new NewUnilateralCloseSummary function
In this commit, we add a new function that allows a caller to create a
UnilateralCloseSummary with the proper materials. This will be used
within a new sub-system to be added in a later commit to properly
dispatch notifications when on-chain events happen for a channel.
2018-01-22 19:19:47 -08:00
Olaoluwa Osuntokun
341c1678fc
lnwallet: publicly export NewBreachRetribution 2018-01-22 19:19:47 -08:00
Olaoluwa Osuntokun
30c4196f91
lnwallet: remove the closeObserver from the channel state machine
In this PR, we entirely remove the closeObserver from the channel state
machine. It was added very early on before most of the other aspects of
the daemon were built out. This goroutine was responsible for
dispatching notifications to outside parties if the commitment
transaction was spent at all. This had several issues, since it was
linked to the *lifetime* of the channel state machine itself. As a
result of this linkage, we had to do weird stuff like hand off in
memory pointers to the state machine in order to ensure notifications
were properly dispatched.
2018-01-22 19:19:47 -08:00
Olaoluwa Osuntokun
b396d438bb
lnwallet: add new TestChannelUnilateralCloseHtlcResolution test case
In this commit, we add a new test case for unilateral channel closes to
ensure that if the remote party closes the commitment on-chain. Then
we’re able to sweep both incoming and outgoing HTLC’s from their
commitment. With this tests, we ensure that the values returned for
HtlcResolutions from the UnilateralCloseSummary are correct and allow
us to sweep all funds properly.
2018-01-22 19:19:33 -08:00
Olaoluwa Osuntokun
f9d5656d17
lnwallet: update unit tests to be aware of new channel API changes 2018-01-22 19:19:33 -08:00
Olaoluwa Osuntokun
d35709b38e
lnwallet: extend TestForceClose to close with both incoming+outgoing HTLCs
In this commit we add some additional scenarios to the TestForceClose
test. With this expanded test case, we now ensure the the party that
force closes is able to properly sweep both incoming and outgoing
HTLC’s fully with the information contained the HtlcResolution struct.
2018-01-22 19:19:33 -08:00
Olaoluwa Osuntokun
1d7a1ac0ee
lnwallet: update channel state machine tests to use distinct keys
In this commit, we update the channel state machine tests to use a new
key for each purpose. Before this commit, the same key would be used
the entire time. As a result, a few bugs slipped by that would’ve been
detected if we used fresh keys for each purpose. Additionally, this
reflect the real world case as we always use distinct keys for each
purpose to avoid key re-use.
2018-01-22 19:19:32 -08:00
Olaoluwa Osuntokun
b5496c52a2
lnwallet: newHtlcResolution now returns both incoming and outgoing HTLC resolutions
In this commit, we’ve added a new HtlcResolutions struct to house both
the incoming and outgoing HTLC resolutions. This struct will now be
coupled with the object that returns when we detect that a commitment
transaction was closed on chain. For incoming HTLC’s, we’ll check the
preimage cache to see if we can claim the HTLC on-chain. If we can,
then we’ll copy of the preimage, and make a proper incoming HTLC
resolution.
2018-01-22 19:19:32 -08:00
Olaoluwa Osuntokun
d98026f579
lnwallet: modify OutgoingHtlcResolution to also account for remote force closes
In this commit, we modify the OutgoingHtlcResolution struct to detect
if this is the remote party’s commitment transaction or not. With this
change, we’ll now be able to properly time out an HTLC that was
detected on the commitment transaction of the remote peer.
Additionally, we now populate the CsvDelay (if local commitment) and
the ClaimOutpoint (as we may be sweeping directly from the commitment
transaction now.
2018-01-22 19:19:32 -08:00
Olaoluwa Osuntokun
bcfe7192d7
lnwallet: add new IncomingHtlcResolution for resolving incoming HTLC's on-chain
In this commit, we add a new IncomingHtlcResolution struct. This is the
opposite of the existing OutgoingHtlcResolution struct. The items in
this new struct allow callers to sweep an incoming HTLC that we know
the preimage to. These will always be created when a commitment goes
on-chain. However, if we know the preimage, then that will be populated
in place of all zeroes in the Preimage field.
2018-01-22 19:19:31 -08:00
Olaoluwa Osuntokun
ecf6d758a2
lnwallet: add distinct CommitOutputResolution for resolving commit outputs on-chain
In this commit, we modify both the ForceCloseSummary, and the
UnilateralClosureSummary to return the items needed to sweep the
commitment output distinctly. By doing this, it’s now possible to pass
a dedicated struct to a sub-system in order to allow it to sweep a
commitment output. As the maturity delay is a part of this new struct,
this tells the caller if this was on the local commitment (CSV
required) or on the remote commitment (no CSV required).
2018-01-22 19:19:31 -08:00
Olaoluwa Osuntokun
42cd2fa5be
lnwallet: add new ActiveHtlcs to channel state machine
In this commit, we’ve added a new method to the channel state machine:
ActiveHtlcs. This method will allow callers to poll the state of the
channel to retrieve the set of HTLC’s active on *both* commitment
transactions.
2018-01-22 19:19:31 -08:00
Olaoluwa Osuntokun
5f6c15cfa4
lnwallet: RevokeCurrentCommitment now returns the set of active HTLC's
In this commit, we modify the RevokeCurrentCommitment method to now
return the set of active HTLC’s. This will be used by callers in the
future to update other sub-systems when the set of HTLC’s on the
commitment changes, and can also be used on the RPC level to
synchronize systems level integration tests.
2018-01-22 19:19:30 -08:00
Olaoluwa Osuntokun
75d2f09d4c
lnwallet: add a PreimageCache instead of a FeeEstimator as LightningChannel dep 2018-01-22 19:19:29 -08:00
Olaoluwa Osuntokun
b1503adfad
lnwallet: add new PreimageCache interface 2018-01-22 19:19:29 -08:00
Olaoluwa Osuntokun
a9d451e46d
lnwallet: add AcceptedHtlcTimeoutWitnessSize to size.go 2018-01-22 19:19:29 -08:00
Olaoluwa Osuntokun
774ec5b528
lnwallet: rename OfferedHtlcWitnessSize to OfferedHtlcSuccessWitnessSize 2018-01-22 19:19:28 -08:00
Olaoluwa Osuntokun
65619b11aa
lnwallet: modify TxWeightEstimator methods to allow chaining
By returning a *TxWeightEstimator from each method, we now all callers
to chain the methods. This adds a bit of nice sugar when interacting
with the struct.
2018-01-22 19:19:28 -08:00
Olaoluwa Osuntokun
ff872b798c
lnwallet: update WitnessType names to be more descriptive
In this commit, we rename several of the existing WitnessType
definitions to be more descriptive than they were previously. We also
add a number of additional types which we need to handle scripts for,
but weren’t yet added before. Finally, we modify the
receiverHtlcSpendTimeout to optionally take an additional parameter to
set the locktime of the spending transaction accordingly. This final
modification allows the caller to specify that the lock time has
already been set on the main transaction.
2018-01-22 19:19:27 -08:00
Olaoluwa Osuntokun
3fa0cde631
lnwallet: export senderHtlcSpendRedeem and make rename HtlcSpendSuccess to HtlcSecondLevelSpend 2018-01-22 19:19:21 -08:00
Jim Posen
0becaddcd5 lnwallet: Move mocks to separate file and augment mockSigner.
To implement the BOLT 03 test vectors, a more powerful mockSigner is
required. The new version of mockSigner stores multiple keys and signs
the transaction outputs with the appropriate one.
2018-01-22 19:00:28 -08:00
Alex
187f59556a multi: add bitcoind drivers and tests 2018-01-15 13:59:34 -08:00
Conner Fromknecht
c17b695128
lnwallet/btcwallet/blockchain: properly handle nil spend report
This commit adds an additional check in GetUtxo that
tests for the nil-ness of the spend report returned by
the neutrino backend. Previously, a nil error and
spend report could be returned if the rescan did not
find the output at or above the start height. This
was observed to have cause a nil pointer dereference
when the returning line attempted to access the output.
This case is now handled by returning a distinct error
signaling that the output was not found.
2018-01-09 18:14:25 -08:00
Olaoluwa Osuntokun
9a76b3ee58
lnwallet: only forward freshly locked in HTLC's in ReceiveRevocation
This commit fixes a nasty bug that has been lingering within lnd, and
has been noticed due to the added retransmission logic. Before this
commit, upon a restart, if we had an active HTLC and received a new
commitment update, then we would re-forward ALL active HTLC’s. This
could at times lead to a nasty cycle:
  * We re-forward an HTLC already processed.
  * We then notice that the time-lock is out of date (retransmitted
HTLC), so we go to fail it.
  * This is detected as a replay attack, so we send an
UpdateMalformedHTLC
  * This second failure ends up creating a nil entry in the log,
leading to a panic.
  * Remote party disconnects.
  * Upon reconnect we send again as we need to retransmit the changes,
this goes on forever.

In order to fix this, we now ensure that we only forward HTLC’s that
have been newly locked in at this next state. With this, we now avoid
the loop described above, and also ensure that we don’t accidentally
attempt an HTLC replay attack on our selves.

Fixes #528.

Fixes #545.
2018-01-08 19:50:25 -08:00
Olaoluwa Osuntokun
ae1731da27
lnwallet: add test case for InvalidCommitSigError 2018-01-08 19:50:23 -08:00
Olaoluwa Osuntokun
b4bdd55081
lnwallet: if we fail to validate a remote commit sig, return detailed error
In this commit, we add a new detailed error that’s to be returned
when/if the remote peer sends us an invalid commit signature. The new
error contains the transaction that we attempted to validate the
signature over, the sighs, and the state number. Returning this
additional information will serve to aide in debugging any
cross-implementation issues.
2018-01-08 19:50:22 -08:00
Olaoluwa Osuntokun
95de109844
lnwallet: return our final local balance from CompleteCooperativeClose
In this commit, add an additional return value to
CompleteCooperativeClose. We’ll now report to the caller our final
balance in the cooperative closure transaction. We report this as
depending on if we’re the initiator or not, our final balance may not
exactly match the balance we had in the last state.
2018-01-08 19:50:20 -08:00
Conner Fromknecht
20f4c61c8b
lnwallet/channel_test: adds TestBreachClose 2018-01-05 13:47:17 -08:00
Conner Fromknecht
9703ab9161
lnwallet/channel: exposes channelState via State for testing 2018-01-05 13:47:17 -08:00
Conner Fromknecht
bb8c5f82da
lnwallet/channel: delete state after ack from breach arb 2018-01-05 13:47:16 -08:00
Olaoluwa Osuntokun
9777176d7d
lnwallet: don't use persistent pointer to funding tx within channel state machine
This commit fixes a lingering bug that could at times cause
incompatibilities with other implementations when attempting a
cooperative channel close. Before this commit, we would use a pointer
to the funding txin everywhere. As a result, each time we made a new
state, or verified one, we would modify the sequence field of the main
txin of the commitment transaction. Due to this if we updated the
channel, then went to do a cooperative channel closure, the sequence of
the txin would still be set to the value we used as the state hint.

To remedy this, we now copy the txin each time when making the
commitment transaction, and also the cooperative closure transaction.
This avoids accidentally mutating the txin itself.

Fixes #502.
2017-12-22 19:26:35 +01:00
Matt Drollette
adf0d98194 multi: fix several typos in godoc comments 2017-12-17 18:40:05 -08:00
Johan T. Halseth
8e120d1e62 lnwallet test: add FFAnnounceChan flag to reservation init 2017-12-17 18:35:34 -08:00
Johan T. Halseth
fffe15f0fd lnwallet: add FundingFlag parameter to InitChannelReservation 2017-12-17 18:35:34 -08:00
Jim Posen
e66f3a37a3 lnwallet: Remove rHashMap.
rHashMap in LightningChannel is no longer needed since HTLCs are now
identified by ID/index instead of payment hash.
2017-12-14 17:53:58 -08:00
Jim Posen
317b44e220 lnwallet: Change channel update methods to accept HTLC ID.
Previously, some methods on a LightningChannel like SettleHTLC and
FailHTLC would identify HTLCs by payment hash. This would not always
work correctly if there are multiple HTLCs with the same payment hash,
so instead we change these methods to identify HTLCs by their unique
identifiers instead.
2017-12-14 17:53:58 -08:00
Olaoluwa Osuntokun
bead1ba31d
lnwallet: properly check error when creating commit tx in funding flow 2017-12-14 14:55:03 -08:00
Olaoluwa Osuntokun
5e5cc9b209
lnwallet: add new method to register our preferred minHTLC value
Before this commit, during a reservation, we wouldn’t ever specify our
minHTL value. We don’t yet fully validate all channel constrains, but
doing this now serves to ensure that once those features are merged,
we’ll actually be setting a valid value for minHTLC.
2017-12-13 17:15:43 -08:00
Olaoluwa Osuntokun
ef520f49c3
lnwallet: during channel resynchronization detect lack of commitment window
In this commit, we extend the ProcessChanSyncMsg to detect a case where
we don’t have the necessary revocation window to send out a new commit.
This can arise if the remote party sends us a new state, but we haven’t
yet fully processed their FundingLocked message yet, so we would be
unable to create a new commitment state.

We fix this by enumerating each of our actions in the case of an error.
If we get ErrNoWindow, then this indicates that we can’t give the
remote party the commitment we would like to optimistically send over.
This isn’t an issue though, as in the next round, we’ll resynchronize
our state.
2017-12-11 15:42:15 -08:00
Olaoluwa Osuntokun
62da377f78
lnwallet: properly reject new commitment if next revocation point isn't known 2017-12-11 15:32:31 -08:00
Olaoluwa Osuntokun
ff6993bb5d
lnwallet: ensure the onion blob is copied over properly when restore log updates
In this commit, we fix an existing bug that would cause issues within
the switch due to a value not being properly set. Before this commit we
would copy a byte array into a slice without first creating the
necessary capacity for that slice. To fix this, we’ll now ensure that
the blob has the proper capacity before copying over. Several tests
have been updated to always set a fake onion blob.
2017-12-10 16:14:41 -08:00
Olaoluwa Osuntokun
5b4aa82667
lnwallet: don't sign new commitment if next revocation point is unknown
In this commit, we extend the initial check within SignNextCommitment
to bail out early if we don’t yet know the commitment point of the
remote party. This prevents a class of nil pointer panics if we attempt
to create a new state without yet having received the FundingLocked
message.
2017-12-10 16:10:57 -08:00
Micah Lerner
231ed5bb32 lnwallet: Update tests to check destination addresses 2017-12-08 15:11:23 -08:00
Micah Lerner
6ae7d275ab lnwallet: Add destination addresses to listchaintxns 2017-12-08 15:11:23 -08:00
Olaoluwa Osuntokun
d6dcc4276c
lnwallet: add new IsPending method to the channel state machine
The IsPending method will allow callers to determine if a channel has
been fully confirmed or not.
2017-12-06 16:43:01 -08:00
Conner Fromknecht
e8590b12ba
lnwallet/channel: handle error from sigpool start 2017-12-02 17:16:43 -08:00
Olaoluwa Osuntokun
b8bed9a677
lnwallet: in BtcdFeeEstimator is sat/byte is too low, fallback to default rate
In this commit, we fix an existing bug within the EstimateFeePerWeight
method for the BtcdFeeEstimator. If the sat/byte value returned was too
low, then it was possible for us to end up with a zero valued
sat/weight. We correct this issue by detecting, and falling back to the
default fee rate if so.
2017-11-30 22:13:00 -08:00
Olaoluwa Osuntokun
c27e87f168
lnwallet: update UpdateFee msg usage to latest API changes 2017-11-30 22:10:42 -08:00
Olaoluwa Osuntokun
4bec706b11
lnwallet: fix bug in htlcIsDust, outgoing HTLC on remote commit is htlcSuccess 2017-11-30 22:09:49 -08:00
Olaoluwa Osuntokun
94ba7f964d
channel: properly roll over fee from commit tx during co-op chan close
In this commit, we fix an existing bug within our cooperative channel
closing transaction generation. Before this commit, we wouldn’t account
for the fee already allocated within the commitment transaction. As a
result, we would calculate the evaluated balance considering the fee
incorrectly. In this commit, we fix this by adding the commitment fee
to the balance of the initiator when crafting the closing transaction
2017-11-29 16:14:22 -08:00
Olaoluwa Osuntokun
63c8c299ed
lnwallet: use remote height as reference when gauging channel breaches 2017-11-28 12:26:02 -08:00
Micah Lerner
b98e993d76 lnallet: remove a TODO from signer.go
The TODO indicated that the fmt.Errorf call should be changed
to use the errors package, which allows for wrapping of errors
as necessary.
2017-11-27 20:09:05 -08:00
Liu-Cheng Xu
2fb7f5d4f3 lnwallet: fix typos 2017-11-27 17:24:45 -06:00
Olaoluwa Osuntokun
483dc3f96a
lnwallet: only the initiator needs to validate new fee updates
In this commit, we fix an existing bug, as only the initiator needs to
validate any new fee updates. If the initiator sends an invalid fee,
then it will be rejected by the responder as it may put them below
their required reserve.
2017-11-27 12:24:08 -08:00
Olaoluwa Osuntokun
3e90000e2a
lnwallet: reject UpdateFee messages if it puts initiator below the water
In this commit, we ensure that we reject any UpdateFee messages if
after applying the update, the initiator doesn’t have enough funds to
actually pay for the new commitment state.

A test has been added to exercise this new behavior.
2017-11-26 14:08:59 -06:00
Olaoluwa Osuntokun
807784a1c4
lnwallet: fix ChanReserve calculation in createTestChannels to be non-random 2017-11-26 14:08:58 -06:00
Olaoluwa Osuntokun
7d3e1308e4
lnwallet: add ability to properly retransmit UpdateFee state transitions
In this commit, we update the retransmission logic to ensure that we
properly retransmit any sent UpdateFee messages as part of a state
transition. When creating a CommitDiff, if we have a pending fee
update, then we’ll add that to the set of logs updates. When restoring
the commit diff from disk, if we encounter an UpdateFee entry, then
we’ll apply that as waiting to be ACK’d and skip adding it as a log
entry.

A new test has been added to excessive this new behavior.
2017-11-26 14:08:58 -06:00
Olaoluwa Osuntokun
52e6cb1a06
lnwallet: correct BTC -> SAT conversion in BtcdFeeEstimator
In this commit, we correct the BTC -> SAT conversion in
BtcdFeeEstimator. Previously, we use 10e8 instead of 1e8, causing us to
be off by an order of magnitude.
2017-11-26 14:08:57 -06:00
Olaoluwa Osuntokun
91bb95991e
lnwallet: make 1% reservation computation clearer
Adding 99 here didn’t really do anything but obfuscate when we were
trying to compute. We’re just using internet division to calculate 1%
of the channel capacity amount. This is the amount that the remote
party must remain above at all times.
2017-11-26 14:08:57 -06:00
Olaoluwa Osuntokun
24ad3e17de
lnwallet: reject funding flows if local amount is insufficient w.r.t fees 2017-11-26 14:08:56 -06:00
Olaoluwa Osuntokun
5a1a3c7277
lnwallet: add IsInitiator and CommitFeeRate methods to LightningChannel 2017-11-23 23:10:18 -06:00
Olaoluwa Osuntokun
1b716e6c87
lnwallet: update testListTransactionDetails to account for tx fee 2017-11-23 23:10:17 -06:00
Olaoluwa Osuntokun
39295dc5aa
lnwallet+peer: add new ResetState method to channel state machine
In this commit, we add a new ResetState method to the channel state
machine which will reset the state of the channel to `channelOpen`. We
add this as before this commit, it was possible for a channel to shift
into the closing state, the closing negotiation be cancelled for
whatever reason, resulting the the channel held by the breachArbiter
unable to act to potential on-chain events.
2017-11-23 23:10:16 -06:00
Olaoluwa Osuntokun
661f27a404
lnwallet: update test due to recent API changes 2017-11-23 23:10:08 -06:00
Olaoluwa Osuntokun
98cba87fb1
lnwallet: decouple closeObserver from main quit channel in LightningChannel
In this commit, we fix an existing bug that had ramifications within
the operation of the lnd daemon. Before this commit, if the Stop()
method was called, then the closeObserver would exit as well. This
means that would no longer be watching for channel breaches on-chain,
and could miss either a cooperative channel closure or an actual
contract breach.

To fix this, we now introduce a new method to stop for closeObserver:
CancelObserver(). This should ONLY be called once either: the contract
has been fully settled on-chain, or whom ever is watching the relevant
signals has a newer version of the channel that it will watch instead.
2017-11-23 23:10:07 -06:00
Olaoluwa Osuntokun
98a8951e5b
lnwallet: CompleteCooperativeClose now accepts final fee in btcutil.Amount 2017-11-23 23:10:07 -06:00
Olaoluwa Osuntokun
e96c62db65
lnwallet: no longer return fee from CreateCloseProposal
In this commit, we modify CreateCloseProposal to no longer return the
same fee passed in. In the past, this method accepted a fee rat rather
than an absolute fee, and would return the computed absolute fee. Now
that the method takes the absolute fee directly, this is unnecessary.
2017-11-23 23:10:06 -06:00
Olaoluwa Osuntokun
6d10677ef5
lnwallet: allow callers to specify fee for funding transaction in funding flow
In this commit, we modify the funding reservation workflow slightly to
allow callers to specify their own custom fee when initialization a
funding workflow. This gives power-users the ability to control exactly
how much in fees are paid for each new funding transaction.
2017-11-23 23:10:06 -06:00
Olaoluwa Osuntokun
36256f3f39
lnwallet/btcwallet: update SendOutputs implementation due to recent API changes 2017-11-23 23:10:05 -06:00
Olaoluwa Osuntokun
8b6842c760
lnwallet: update interface level tests to adhere to recent API changes 2017-11-23 23:10:04 -06:00
Olaoluwa Osuntokun
4a277276fd
lnwallet: update SendOutputs method on WalletController to accept fee
In this commit, we extend the existing SendOutputs method on the
WalletController interface to be able to accept a custom fee. With
this, users are now able to specify their exact fee, allowing the
wallet to be fee estimation agnostic.
2017-11-23 23:10:04 -06:00
Olaoluwa Osuntokun
78ccfb4989
lnwallet: add BtcdFeeEstimator implementation of FeeEstimator interface
In this commit, we add a new implementation of the FeeEstimator
interface: the BtcdFeeEstimator. This implementation of the
FeeEstimator is backed by an active bcd instance. Any requests to query
for the current fee for a given confirmation target are proxied to this
active bcd instance.
2017-11-23 23:10:02 -06:00