Commit Graph

957 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
cc4daa04ad
lnwallet: when signing create account if not found
In this commit, we address an edge case that can happen a user rescans
w/ their seed, while retaining their existing `channel.db`. Once they
rescan, if they go to sign for a channel sweep for example, the
commitment key family (actually an account) may not yet have been
created, causing the signing attempt to fail.

We remedy this always creating the account if we go to sign, and the
account isn't found. The change has been structured to make this the
exception, so we'll avoid always needing to do 2 DB hits (check if
account exists, sign), each time we sign.

A new test has been added to exercise this behavior. If the diff from
the `signer.go` file is removed, then the test will fail.
2019-08-20 19:08:03 -07:00
Johan T. Halseth
b9816259cb
fundingmanager+server: define subtractFees
Let one initiate a funding request with the remaining funds in the
wallet.
2019-07-18 00:58:12 +02:00
Johan T. Halseth
f15d81426c
lnwallet/wallet: define SubtractFees for InitFundingReserveMsg
This commit adds a SubtractFees option to the funding request, letting
the caller specify that the fees should be deducted from the funding
amount. This paves the way for letting the funding manager spend up to a
given amount when creating a channel, like the rest of the funds in the
wallet.
2019-07-18 00:33:15 +02:00
Johan T. Halseth
4239f7d600
lnwallet/wallet: add coinSelectSubtractFees 2019-07-18 00:33:15 +02:00
Johan T. Halseth
1b2297c2b5
lnwallet/wallet: extract contribution setup into initOurContribution
This lets us easily call unlock() in case contribution setup fails.
2019-07-18 00:33:15 +02:00
Johan T. Halseth
44384a1b5b
lnwallet: move coin selection before ChannelReservation
Now that coin selection is independent of creating the channel
reservation, we can move it first, in preparation for doing custom coin
selection.
2019-07-18 00:33:14 +02:00
Johan T. Halseth
98a3d04ba3
lnwallet: make selectCoinsAndChange return selected coins
This makes the method independent of the ChannelContribution struct.

We also add a function closure to the return of selectCoinsAndChange,
that let is unlock the selected output in case of error.
2019-07-18 00:33:14 +02:00
Johan T. Halseth
fcf74debe6
lnwallet+funding: rename Capacity and FundingAmt
Instead use LocalFundingAmt and RemoteFundingAmt to make it clear who is
contributing funds.
2019-07-18 00:33:14 +02:00
Johan T. Halseth
2f5c1a69fb
lnwallet test: add TestCoinSelect 2019-07-18 00:33:14 +02:00
Yaacov Akiba Slama
fe2a565bec Add test for unmined transaction DestAddresses
Co-authored-by: Christopher Coverdale <chris.coverdale24@gmail.com>
2019-07-10 09:39:46 +03:00
Yaacov Akiba Slama
f33df0928d Fill DestAddresses in unmined transactions 2019-07-10 09:38:27 +03:00
Olaoluwa Osuntokun
19ff8f2c1b
Merge pull request #3280 from Roasbeef/derive-first-empty-key-loc
lnwallet: fix key derivation for very first key in family
2019-07-08 21:53:40 -07:00
Conner Fromknecht
933e723ec7
Merge pull request #3178 from federicobond/once-refactor
multi: replace manual CAS with sync.Once in several more modules
2019-07-08 20:33:44 -07:00
Olaoluwa Osuntokun
bd46491d07 lnwallet: fix key derivation for very first key in family
In this commit, we fix an existing bug that would cause us to be unable
to derive the very first key in a key family if the wallet hadn't
already derived it in the past. This can happen if a user keeps their
same `channel.db`, but restores their wallet resulting in fresh
`wallet.db` state.

This is an existing issue due to the fact that we don't properly
distinguish between an empty key locator, and the very first key in a
`KeyFamily`: `(0, 0)`. Atm, `KeyLoactor{0, 0}.IsEmpty() == True`,
causing us to be unable to retrieve this key in certain cases since we
fall through and attempt address based derivation.

In order to remedy this, we add a new special case (until we upgrade
`KeyLoactor` formats, but needed for legacy reasons) to _try_ a regular
`KeyLoactor` based derivation if we fail to derive via address, and this
is an "empty" key loc. This has been tested in the field and shown to
work, with the one downside that in this "hot swap restoration" case,
we'll hit the database twice to derive the key.
2019-07-08 17:08:39 -07:00
Olaoluwa Osuntokun
2012b5dc1a
lnwallet: fix logic in testCreateSimpleTx test case
In this commit, we fix a logic flaw in the testCreateSimpleTx test case
which emerged once we the bug fix for dust outputs landed. Before this
commit, we would erroneously fail during valid test execution.
2019-06-18 19:55:24 -07:00
Olaoluwa Osuntokun
eaa043f585 lnwallet/btcwallet: use relay fee not tx fee rate for dust check
In this commit we fix a hidden bug in the transaction creating logic
that was only manifested recently due to higher fees on Bitcoin's
mainnet. Before this commit, we would use the target fee rate to
determine if an output was dust or not. However, this is incorrect, as
instead the relay fee should be used as this matches the policy checks
widely deployed in Bitcoin full node today.

To fix this issue we now properly use the relay fee when computing dust.
This fixes the issue for the `EstimateFee` call, but the `SendOutputs`
call also has a similar issue. However, this must be fixed within
`btcwallet` itself, so it has been left out of this commit

Fixes #3217.
2019-06-18 19:55:16 -07:00
Johan T. Halseth
7df7449c47
Merge pull request #3187 from yaslama/UnknownAsDefaultAddressType
Use UnknownAddressType value as default in lnwallet.AddressType
2019-06-17 12:18:55 +02:00
Johan T. Halseth
f63c5d0170
Merge pull request #3182 from yaslama/addressTypeInitialization
Initialize addressType to UnknownAddressType
2019-06-14 10:32:01 +02:00
Olaoluwa Osuntokun
e50339d44b
lnwallet/btcwallet: also include raw tx hex for unconf txns
In this commit, we patch a small bug in the newly added raw tx hex field
for ListTransactions. We now ensure that we also set the raw tx hex
field for unconfirmed transactions.
2019-06-13 13:54:33 -07:00
Federico Bond
0a9141763e multi: replace manual CAS with sync.Once in several more modules 2019-06-12 09:37:26 -03:00
Yaacov Akiba Slama
a6d1d2435b Use UnknownAddressType value as default in lnwallet.AddressType 2019-06-11 10:16:43 +03:00
Yaacov Akiba Slama
bbaf37b7d2 Initialize addressType to UnknownAddressType 2019-06-10 15:22:17 +03:00
Olaoluwa Osuntokun
eaf86cc4f9
lnwallet: add raw tx hex attribute to ListTransactionDetails 2019-06-07 07:36:32 -07:00
Conner Fromknecht
b26b88a1e2
lnwallet/channel: use proper commitment output sorting 2019-06-05 08:35:06 +02:00
Conner Fromknecht
a627c65d65
lnwallet/commit_sort: add commit sorting with htlc tie breaker 2019-06-05 08:34:45 +02:00
Olaoluwa Osuntokun
0343327994
Merge pull request #3026 from wpaulino/sweeper-fee-preference
sweep: add support for multiple fee preferences to UtxoSweeper
2019-05-27 16:02:37 -07:00
Olaoluwa Osuntokun
5f0fad85be multi: address lingering TODO by no longer wiping out local HTLCs on remote close
In this commit, we fix a lingering TOOD statement in the channel arb.
Before this commitment, we would simply wipe our our local HTLC set of
the HTLC set that was on the remote commitment transaction on force
close. This was incorrect as if our commitment transaction had an HTLC
that the remote commitment didn't, then we would fail to cancel that
back, and cause both channels to time out on chain.

In order to remedy this, we introduce a new `HtlcSetKey` struct to track
all 3 possible in-flight set of HTLCs: ours, theirs, and their pending.

We also we start to tack on additional data to all the unilateral close
messages we send to subscribers. This new data is the CommitSet, or the
set of valid commitments at channel closure time. This new information
will be used by the channel arb in an upcoming commit to ensure it will
cancel back HTLCs in the case of split commitment state.

Finally, we start to thread through an optional *CommitSet to the
advanceState method. This additional information will give the channel
arb addition information it needs to ensure it properly cancels back
HTLCs that are about to time out or may time out depending on which
commitment is played.

Within the htlcswitch pakage, we modify the `SignNextCommitment` method
to return the new set of pending HTLCs for the remote party's commitment
transaction and `ReceiveRevocation` to return the latest set of
commitment transactions on the remote party's commitment as well. This
is a preparatory change which is part of a larger change to address a
lingering TODO in the cnct.

Additionally, rather than just send of the set of HTLCs after the we
revoke, we'll also send of the set of HTLCs after the remote party
revokes, and we create a pending commitment state for it.
2019-05-27 14:34:13 -07:00
Wilmer Paulino
138d9b68f0
lnwallet+sweep: add String method to FeePreference 2019-05-24 15:30:36 -07:00
Joost Jager
d55a8b7b29
channel+cnct: remove preimage from channel and resolution
Now that the success resolver preimage field is always populated by the
incoming contest resolver, preimage lookups earlier in the
process (channel and channel arbitrator) can mostly be removed.
2019-05-15 14:41:49 +02:00
Conner Fromknecht
f79a9d97a9
Merge pull request #3068 from AdamISZ/commentfixes1
Typo corrections in various comments
2019-05-14 17:02:44 -07:00
AdamISZ
6e054886d8 Typo corrections in various comments 2019-05-10 17:15:54 +02:00
Johan T. Halseth
f589c86963
lnwallet/wallet: add missing error handling 2019-05-09 14:44:53 +02:00
Johan T. Halseth
6110182371
lnwallet/btcwallet: provide cancel chan as neutrino QuitChan option
This will make sure a long-running rescan can be canceled in case
Neutrino is the backend.
2019-05-09 14:44:52 +02:00
Johan T. Halseth
10070ecab7
lnwallet: make BlockChainIO.GetUTXO take cancel chan
Use quit channels as cancel chan for call to GetUTXO.
2019-05-09 14:44:47 +02:00
Johan T. Halseth
beb5d14ed9
lnwallet/btcwallet: add compile time check for BlockChainIO interface 2019-05-09 14:44:41 +02:00
Unknown
16aad1a9ee lnwallet+chainregistry: remove unused FeeEstimator from wallet cfg 2019-04-16 14:16:56 -07:00
Olaoluwa Osuntokun
c6b653457b lnwallet: add new WebApiFeeEstimator for API fee estimation.
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2019-04-16 14:16:53 -07:00
Valentine Wallace
4944eb3e54 lnwallet: add implementation of WebApiFeeSource for external APIs
This enables users to specify an external API for fee estimation.
The API is expected to return fees in the JSON format:
`{
	fee_by_block_target: {
	   a: x,
	   b: y,
	   ...
	   c: z
        }
 }`
 where a, b, c are block targets and x, y, z are fees in sat/kb.
 Note that a, b, c need not be contiguous.
2019-04-16 13:50:40 -07:00
Olaoluwa Osuntokun
9b8549011c lnwallet: add new WebApiFeeSource interface
In this commit, we add a new interface which will allow callers to drop
in an arbitrary Web API for fee estimation with an arbitrary
request/response schema.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2019-04-16 13:50:40 -07:00
Olaoluwa Osuntokun
c722f2c064
contractcourt: only look for local force close for non-recovered channel
In this commit, we modify the main `closeObserver` dispatch loop to only
look for the local force close if we didn't recover the channel. We do
this, as for a recovered channel, it isn't possible for us to force
close from a recovered channel.
2019-03-28 17:53:59 -07:00
Olaoluwa Osuntokun
4ff4e1b0de
lnwallet: account for case where remote party has 2 unrevoked commits in DLP 2019-03-28 17:53:55 -07:00
Olaoluwa Osuntokun
fc8337b146
lnwallet: send invalid commitment secret if restored chan in ChanSyncMsg
In this commit, we modify the `ChanSyncMsg` to send an invalid
commitment secret in `ChanSyncMsg`. We do this in order to force the
remote party to force close off-chain, if we're restoring a channel from
scratch and we never had any state updates within the channel. We need
to do this, as otherwise the remote party will think we can resume as
they're able to verify their own commit secret for state zero.
2019-03-28 17:53:54 -07:00
Olaoluwa Osuntokun
3e866c6cc5
lnwallet: add additional comment for case in ProcessChanSyncMsg 2019-03-28 17:53:53 -07:00
Olaoluwa Osuntokun
90d8a46ec6
lnwallet: allow DLP trigger transition in ProcessChanSyncMsg if chan restored
In this commit, we modify an existing case in `ProcessChanSyncMsg` to enter the DLP workflow if we detect that this is a restored channel.
2019-03-28 17:53:51 -07:00
Johan T. Halseth
54f1f32e71
lnwallet/interface_test: add testCreateSimpleTx 2019-03-15 23:47:15 +01:00
Johan T. Halseth
306c0c8aab
lnwallet: return ErrNoOutputs in case no outputs are sent to 2019-03-15 23:47:15 +01:00
Johan T. Halseth
bb092bc61e
lnwallet/interface: add CreateSimpleTx to wallet interface 2019-03-15 23:46:51 +01:00
Johan T. Halseth
6fb664dbe1
lnwallet/btcwallet: implement CreateSimpleTx 2019-03-15 23:46:50 +01:00
Olaoluwa Osuntokun
5ef95a51dc
Merge pull request #2766 from Roasbeef/chain-watcher-fix-off-by-one
contractcourt: fix off-by-one error in closeObserver
2019-03-15 13:26:08 -07:00
Wilmer Paulino
5c5c542f94
lnwallet/btcwallet: remove unnecessary tx in mempool/chain checks
The checks to determine whether the transaction broadcast failed due to
it already existing in the mempool/chain are no longer needed since the
underlying btcwallet PublishTransaction call will not return an error
when running into these cases.
2019-03-13 17:57:19 -07:00