Commit Graph

549 Commits

Author SHA1 Message Date
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
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
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
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
Olaoluwa Osuntokun
9f215723a6
lnwallet: verify new optional ChannelReestablish fields in ProcessChanSyncMsg
In this commit, we add fully verification (other than checking the
commitment point matches after the fact) of the new optional fields
added to the lnwire.ChannelReestablish message. Two scenarios can
arise: we realize the remote party is on a prior state (and possibly
lost data), or we realize that *we* are on a prior state with the
remote party verifiably proving that they’re on a newer state.
2017-11-16 20:00:05 -08:00
Olaoluwa Osuntokun
6cd210041d
lnwallet: assert that no chan sync is needed before updates in TestChanSyncFullySynced 2017-11-16 20:00:05 -08:00
Olaoluwa Osuntokun
94ffb07b90
lnwallet: ensure created channels are stopped in ChanSync tests 2017-11-16 20:00:04 -08:00
Olaoluwa Osuntokun
a655396616
lnwallet: add optional data loss support to ChanSyncMsg()
In this commit we extend the set of fields populated within the
returned lnwire.ChannelReestablish to populate the optional data loss
fields. This entails included the commitment secret of the most
recently revoked remote commitment transaction and also our current
unrevoked commitment point.
2017-11-16 20:00:04 -08:00
Olaoluwa Osuntokun
d7cdf822e3
lnwallet: update commitmentKeyRing to account for distinct HTLC keys
In this commit, we update all the key derivation within the state
machine to account for the recent spec change which introduces a
distinct key for usages within all HTLC scripts. This change means that
the commitment payment and delay base points, are only required to be
online in the case that a party is forced to go to chain.

We introduce an additional local tweak to the keyring for the HTLC
tweak. Additionally, two new keys have been added: a local and a remote
HTLC key. Generation of sender/receiver HTLC scripts now use the local
and remote HTLC keys rather than the “payment” key for each party.
Finally, when creating/verifying signatures for second-level HTLC
transactions, we use these the distinct HTLC keys, rather than re-using
the payment keys.
2017-11-16 20:00:03 -08:00
Olaoluwa Osuntokun
a812974808
lnwallet: update sender/receiver HTLC scripts to use distinct HTLC keys
In this commit, we modify the naming and comments of the routines that
create the sender/receiver HTLC scripts to denote that a set of
distinct keys are used. The scripts materially haven’t changed, but the
set of keys expected has.
2017-11-16 20:00:02 -08:00
Olaoluwa Osuntokun
8b0de51003
lnwallet: populate our HtlcBasePoint when reserving a funding reservation 2017-11-16 20:00:01 -08:00
Conner Fromknecht
35e3201097
lnwallet/script_utils: adds public HtlcSpendSuccess witness func 2017-11-15 18:08:33 -08:00
Conner Fromknecht
305acb86d0
lnwallet/size: adds htlc success and timeout witness sizes 2017-11-15 18:04:44 -08:00
Conner Fromknecht
7888c6e040
lnwallet/witnessgen: add HtlcOfferedTimeLock witness type 2017-11-15 18:04:44 -08:00
Olaoluwa Osuntokun
e7e426a1cc
Merge pull request #398 from halseth/sighash-signdesc-hashtype
Use dynamic SigHash type when signing transactions.
2017-11-11 17:30:54 -08:00
Alex
9bc25df906 lnwallet: fix linter complaints re. capitalization in interface test 2017-11-11 17:24:48 -08:00
Alex
7b43c9a750 lnwallet: add timeout and more accurate check to reorg interface test 2017-11-11 17:24:48 -08:00
Olaoluwa Osuntokun
b6f64932c2
htlcswitch: face race condition in unit tests by returning invoice
In this commit we modify the primary InvoiceRegistry interface within
the package to instead return a direct value for LookupInvoice rather
than a pointer. This fixes an existing race condition wherein a caller
could modify or read the value of the returned invoice.
2017-11-11 16:09:29 -08:00
Olaoluwa Osuntokun
010815e280
lnwallet: no need to grab mutex in ProcessChanSyncMsg as is init method
In this method we fix an existing deadlock within the unit tests when
running with the race condition detector on. We don’t need to grab the
mutex within the ProcessChanSyncMsg method as this should be the very
first method called when initializing the channel if a channel state
sync is needed.
2017-11-11 15:50:33 -08:00
Olaoluwa Osuntokun
861412529d
lnwallet: add select on quit when waiting for job from sigPool
In this commit we ensure that the channel is always able to exit by
adding a select statement with a quit case when we’re waiting on the
result of a job that was previously sent into the sigPool.
2017-11-11 15:00:50 -08:00
Olaoluwa Osuntokun
03ba13fcf8
lnwallet: ensure sigPool goroutines can always exit 2017-11-11 14:59:56 -08:00
Olaoluwa Osuntokun
3f4b1592a3
lnwallet: add logging error message is unable to carry HTLC in state machine 2017-11-10 19:51:13 -08:00
Olaoluwa Osuntokun
1734f96544
lnwallet: add a set of unit tests to exercise the various ChanSync cases
In this commit, we’ve added a set of unit tests to cover all enumerated
channel sync scenarios, including the case where both nodes deem that
they’re unable to synchronize properly.
2017-11-10 19:51:01 -08:00
Olaoluwa Osuntokun
08c7fd9b4d
lnwallet: extend TestStateUpdatePersistence to assert proper htlc counters 2017-11-10 19:51:00 -08:00
Olaoluwa Osuntokun
32651e9311
lnwallet: revert commit 5240953de02d281be694b2c87d151d6c7dce2cb5
In this commit we revert a prior commit
(5240953de02d281be694b2c87d151d6c7dce2cb5) which was added as a stop
gap before we added the proper state needed to recover from cases where
the commitment transactions of both chains had diverged slightly due to
asymmetric dust limits.
2017-11-10 19:51:00 -08:00
Olaoluwa Osuntokun
e9d0e40a17
lnwallet: update existing channel unit tests to adhere to new channels API's 2017-11-10 19:51:00 -08:00
Olaoluwa Osuntokun
097e1c0f5c
lnwallet: update createTestChannels to adhere to new channeldb API's 2017-11-10 19:50:59 -08:00
Olaoluwa Osuntokun
7f667e2dbc
lnwallet: update funding flow to use new channeldb API's 2017-11-10 19:50:59 -08:00
Olaoluwa Osuntokun
367c6b10fc
lnwallet: add missing OP_CHECKSIG op in senderHTLCScript comment 2017-11-10 19:50:58 -08:00
Olaoluwa Osuntokun
c8479410d2
lnwallet: remove availableLocalBalance field, add new AvailableBalance method
In this commit we do away with the existing availableLocalBalance
attribute and instead add a new, more accurate AvailableBalance method.
The new method will compute the available balance within the channel ,
assuming a new state was created at the instance the method was called.
This new method will now properly account for HTLC fees.

AvailableBalance is now called within AddHTLC in order to ensure we
don’t add any HTLC’s that are unable to be paid for from the PoV of the
fees on the commitment transaction.
2017-11-10 19:50:58 -08:00
Olaoluwa Osuntokun
ded7c11bfe
lnwallet: update channelState interaction to respect new db commitment format 2017-11-10 19:50:57 -08:00
Olaoluwa Osuntokun
b50a94aeab
lnwallet: update ReceiveRevocation to use new DB API's
We no longer need to manually pass in the channel delta to
AppendToRevocationLog (now called AdvanceCommitChainTail) as the
pointers on-disk will be updated atomically.
2017-11-10 19:50:57 -08:00
Olaoluwa Osuntokun
4fa714afce
lnwallet: update RevokeCurrentCommitment to use new DB API's
In this commit we update the RevokeCurrentCommitment method to properly
use the new database UpdateCommitment method along with properly
converting the in-memory commitment to its corresponding on-disk
format.
2017-11-10 19:50:56 -08:00
Olaoluwa Osuntokun
563c07ffa2
lnwallet: re-write and rename LastCounters to ChanSyncMsg
The new version has additional comments, and is also a bit simpler that
the prior version.
2017-11-10 19:50:56 -08:00
Olaoluwa Osuntokun
b5476b2767
lnwallet: re-write and rename ReceiveReestablish to ProcessChanSyncMsg
In this commit we complete the partially completed ReceiveReestablish
method and rename it to ProcessChanSyncMsg. The new version now
properly implements retransmission as defined within BOLT#2.

Additionally, we’ve added a new case which will optimistically try and
force a resynchronization of the commitment states if we detect we can
deliver a new commitment signature sooner than later after realizing
that we need to retransmit our last revocation message when we recevied
a new state transition.
2017-11-10 19:50:55 -08:00
Olaoluwa Osuntokun
769fe5cc13
lnwallet: when signing a new commitment state, store a CommitDiff 2017-11-10 19:50:55 -08:00
Olaoluwa Osuntokun
611412bab0
lnwallet: add new createCommitDiff method
This commit adds a new method: createCommitDiff. The method will, given
a newly constructed commitment, its signature, and HTLC signatures will
create a channeldb.CommitDiff. The CommitDiff created is to be stored
on disk, as it can be used in the case that the remote party didn’t
receive our CommitSig message and also forgot all the updates that we
queued with the update.
2017-11-10 19:50:55 -08:00
Olaoluwa Osuntokun
e50b3e6517
lnwallet: populate htlc indexes within constructed commitment states 2017-11-10 19:50:54 -08:00
Olaoluwa Osuntokun
9c015a5824
lnwallet: revamp restoring channel state from disk after a restart
In this commit we complexly revamp the process of restoring all channel
state back into memory after a restart. We’ll now properly do the
following: restore the pending “dangling” commit of the remote party
into the in-memory commitment chain, re-populate all active HTLC’s back
into their respective update logs with the proper indexes/counters, and
properly restore the current commitment of the remote party back in
memory.
2017-11-10 19:50:54 -08:00
Olaoluwa Osuntokun
4b71e87b77
lnwallet: add new restoreHtlc method to the updateLog
This commit adds a new method to the updateLog which will be used when
restoring the state of a channel from disk after a restart. This new
method will add an entry to the updateLog without incrementing either
of the counters as the HTLC already comes pre populated with its
historical index.
2017-11-10 19:50:53 -08:00
Olaoluwa Osuntokun
51618f2ae3
lnwallet: modify populateHtlcIndexes to use info in commitment
It wasn’t necessary to pass in the dust limit, or the commitment itself
as it is already contained within the commitment struct.
2017-11-10 19:50:53 -08:00
Olaoluwa Osuntokun
60b814b4aa
lnwallet: group commitmentKeyRing and deriveCommitmentKey in file 2017-11-10 19:50:52 -08:00
Olaoluwa Osuntokun
d790eeb375
lnwallet: add [our|their]HtlcIndex to the commitment struct
With these new fields, we’ll be able to properly reconstruct the log
state after a restart, as each commitment will now note both the
current HTLC and log index.
2017-11-10 19:50:52 -08:00
Olaoluwa Osuntokun
145cd0b2b6
lnwallet: export HtlcWeight and CommitWeight publicly 2017-11-10 19:50:51 -08:00
Andrey Samokhvalov
9247168c5d not finished index persistence 2017-11-09 16:38:58 -08:00
Andrey Samokhvalov
28dd6e5d84 channeldb+lnwallet: add remote pending commiment persistance 2017-11-09 16:38:58 -08:00
Andrey Samokhvalov
a10ed36e8f htlcswitch+lnwallet: add malformed payment descriptor 2017-11-09 16:38:58 -08:00