Commit Graph

2691 Commits

Author SHA1 Message Date
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 c986e52da7
funding+server: ensure we cancel all reservations when a peer disconnects
In this commit, we fix an existing issue that could at times cause an
inconsistent view between the set of total coins, and the set of segwit
coins in the wallet of the node. This could be caused by initiating a
funding flow, but then the funding negotiation breaking down somewhere
along the lines. In this case, us or the other peer will disconnect.
When we initiate funding flows, we lock coins exclusively, to ensure
that concurrent funding flows don’t end up double spending the same
coin. Before this commit, we wouldn’t ever unlock those coins. As a
result, our view of available coins would be skewed.

The walletbalance call would show all the coins, but when adding the
—witness_only flag, some coins would be missing, or gone all together.
This is because the former call actually scans the txstore and manually
tallies the amount of available coins, while the latter looks at the
sent of available outputs, which is filtered based on which coins are
locked.

To remedy this, we now ensure that when a peer disconnects, we wipe all
existing reservations which will return any locked outputs to the set
of available outputs for funding flows.
2017-11-26 14:08:53 -06:00
Olaoluwa Osuntokun 7016f5ba1e
build: update to latest btcd 2017-11-23 23:32:50 -06:00
Olaoluwa Osuntokun 56632235fd
peer: set FeeEstimator in ChannelLinkConfig when creating link 2017-11-23 23:10:21 -06:00
Olaoluwa Osuntokun caf824bbc4
build: update to latest btcwallet 2017-11-23 23:10:20 -06:00
Olaoluwa Osuntokun 62473009b5
htlcswitch: within link, with each new block, check to see if commit fee should change
In this commit we add a new case to the main select statement within a
channel link. This select statement will serve as a Sipping Bird which
will check the network fee rate (as returned by the fee estimator) and
compare that to the fee on the commitment transaction. Using the
shouldAdjustCommitFee function, we determine if we should update the
commitment fee. If so, then we’ll send an UpdateFee message and also
trigger a new commitment update.

We also add a new unit test: TestChannelLinkUpdateCommitFee to ensure
that we update the fee accordingly if the fee increases or decreases by
a large portion.
2017-11-23 23:10:19 -06:00
Olaoluwa Osuntokun c560200ba1
htlcswitch: add new shouldAdjustCommitFee helper function
In this commit, we add a new helper function to the link which will be
utilized in a later commit. This helper function will help us determine
if we should update the commitment fee, in response to a change in the
network fee return by our fee estimators.
2017-11-23 23:10:19 -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 c437f42227
build: update glide to latest btcd+btcwallet
In this commit we update our glide file to point to the new version of
my fork of btcd with the fee estimator RPC merged in, and also the
version of btcwallet that allows callers to manually specify a value
for the fee rate of a given transaction.
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 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 385023f0b7
cmd/lncli: add new --target_conf and --sat_per_byte args for relevant commands
In this commit, we expose the new fee control features to the relevant
commands on the command line. This will allow users to have a greater
degree of control of the fees they pay when: sending coins on chain,
opening a channel, or closing a channel.
2017-11-23 23:10:14 -06:00
Olaoluwa Osuntokun 530c49f12e
funding: sent channel to breachArbiter as soon as it's open 2017-11-23 23:10:14 -06:00
Olaoluwa Osuntokun 6e3d231619
funding: properly pass in channel state as argument of closure in Start 2017-11-23 23:10:13 -06:00
Olaoluwa Osuntokun a3cd248404
funding+utxonursery+breacharbiter: use new FeeEstimator API 2017-11-23 23:10:13 -06:00
Olaoluwa Osuntokun ad364ae9a1
chains+server: if not in simnet mode, use BtcdFeeEstimator 2017-11-23 23:10:12 -06:00
Olaoluwa Osuntokun 5a51600f95
htlcswitch: update CloseLink to accept ideal fee rate 2017-11-23 23:10:12 -06:00
Olaoluwa Osuntokun 259a01b29d
peer: integrate new channelCloser state machine for co-cop channel closes
In this commit, we refactor the existing channel closure logic for
co-op closes to use the new channelCloser state machine. This results
in a large degree of deleted code as all the logic is now centralized
to a single state machine.
2017-11-23 23:10:11 -06:00
Olaoluwa Osuntokun 1cf1d250b3
peer: update WipeChannel method to match recent htlcswitch API change 2017-11-23 23:10:11 -06:00
Olaoluwa Osuntokun 25082f0b5b
htlcswitch: update WipeChannel on Peer interface to simply take the chanPoint
The WipeChannel method doesn’t need to take the channel itself, as any
relevant indexes should be able to be queried based on the channel
point along.
2017-11-23 23:10:10 -06:00
Olaoluwa Osuntokun 3aabbce551
htlcswitch: update tests to adhere to new FeeEstimator changes 2017-11-23 23:10:10 -06:00
Olaoluwa Osuntokun 3c4a6f42fa
server: update OpenChannel to properly pass in custom funding fee 2017-11-23 23:10:09 -06:00
Olaoluwa Osuntokun afaa1681c8
rpc: OpenChannel, CloseChannel, SendMany/SendCoins now respect fee args
In this commit, the relevant RPC’s have been modified to properly
parse, and pass through the new fee control related parameters for each
of the RPC’s.
2017-11-23 23:10:09 -06:00
Olaoluwa Osuntokun 050500388c
chancloser: add new state machine to handle details of cooperative channel closure
In this commit, we add a new state machine to the project in order to
simplify and encapsulate the logic of negotiating the fees of the
closing transaction during the cooperative channel closure procedure.
This new implementation fixes several defects in the prior version of
the fee negotiation protocol as previously implemented within the peer.
Namely, we’ll now ensure that we converge to an acceptable fee
eventually, and clamp down the fee in the case that the starting fee is
greater than the fee of the commitment transaction.

The new fee negotiation also is very simple and should serve as a good
base for future improvements. After proposing our initial fee, if the
fee proposed by the remote party isn’t within 30% of our last fee, then
we increase/decrease our fee by 10%. This process continues until
either they send the same fee as we sent in a prior round, or they send
the identical fee that we sent in the last round.
2017-11-23 23:10:08 -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 a1c0e30051
lnwire: the FeeSatoshis field in the ClosingSigned message is now btcutil.Amount 2017-11-23 23:10:03 -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
Olaoluwa Osuntokun e20448ebc6
lnwallet: update StaticFeeEstimator to adhere to new FeeEstimator interface 2017-11-23 23:10:02 -06:00
Olaoluwa Osuntokun b4855b687e
lnwallet: add Start() and Stop() method to the FeeEstimator interface 2017-11-23 23:10:01 -06:00
Olaoluwa Osuntokun 0713c8c7ce
lnwallet: extend FeeEstimator methods to be able to return an error
In this commit, we extend the FeeEstimator methods to allow them to
return an error. This is required as most implementations aside from
the static fee estimator will want to be able to return errors to users
to indicate the inability to properly estimate fees.
2017-11-23 23:10:01 -06:00
Olaoluwa Osuntokun 9b1f21e283
lnrpc: now able to set confirmation target or fee to relevant RPC's
In this commit, we modify the OpenChannel, CloseChannel, SendCoins, and
SendMany RPC’s to be able to allow users to manually specify their
fees. Users can either specify a target number of confirmations, or a
target value for manual sat/byte.
2017-11-23 23:09:56 -06:00
Olaoluwa Osuntokun 6ef2770e57 lnwallet: move FeeEstimator into distinct file
In this commit, we move the FeeEstimator interface into a distinct file
as follow up commits will begin to flesh out the interface with
additional implementations.
2017-11-23 22:58:54 -06:00
Olaoluwa Osuntokun 56c5959ee5
Merge pull request #434 from halseth/close-channel-active
Only consider channel active if added to switch
2017-11-22 01:34:55 -06:00
Johan T. Halseth 3a0d4e78ae
travis.yml: build btcd version from glide.yaml for use in integration tests 2017-11-20 14:22:15 -08:00
Johan T. Halseth 6065c763e6
rpcserver: only set channel Active=true if added to htlcswitch
For a calls to ListChannels we now only set the
ActiveChannel.Active=true if the link is found by the
htlcswitch. This is done to be able to make it possible
to tell if a newly opened channel has been added to
the htlcswitch, such that we can synchronize on this
during tests before we attempt to close the  channel.
2017-11-20 14:22:14 -08:00
Johan T. Halseth ae7c6c7e8f
networktest: wait for channel to become active before attempting close 2017-11-20 14:21:57 -08:00
Olaoluwa Osuntokun 53f1743be0
lnwire: fix serialization order of global+local features in Init msg
Fixes #428.
2017-11-17 13:27:23 -08:00
andrew.shvv 4168c97a27 lnwallet: fix infinite loop in coin selection
Fix wrong calculation of overshot amount which causes coin select
function to go into infinite loop. If overshoot amount is calculated
by subtraction of totalSatoshis and amtNeeded than on the second
iteration of loop amtNeeded already include required fee inside, which
causes continuation of the coin selection loop.
2017-11-17 13:15:50 -08:00