Commit Graph

980 Commits

Author SHA1 Message Date
Johan T. Halseth
2a6ad6e634
channeldb+lnwallet: don't pass isRestoredChan to ChanSyncMsg
Since we have access to the internal state of the channel, we can
instead get it directly instead of passing it in as a parameter.
2019-09-25 14:04:44 +02:00
Johan T. Halseth
6e361d04cf
lnwallet+link: move marking channel states to link
Instead of marking the database state when processing the channel
reestablishment message, we wait for the result of this processing to
arrive in the link, and mark it accordingly in the database here.

We do this move the logic determining whether we should force close the
channel or not, and what state to mark it in the DB, to the same place,
as these need to be consistent.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
f40f4620f7
lnwallet/channel: make ErrCommitSyncLocalDataLoss type
This commit converts the ErrCommitSyncLocalDataLoss error into a struct,
that also holds the received last unrevoked commit point from the remote
party.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
07a42971bf
lnwallet/test_utils: make CreateTestChannel return random funding op
Previously it would always be the same, resulting in multiple calls to
the method not being usabel to create more than one set of channels.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
02b2787e44
multi: make MarkCommitmentBroadcasted take closeTx 2019-09-25 14:04:43 +02:00
Johan T. Halseth
eb1b84c0b4
channeldb+lnwallet: make ChanSyncMsg method on OpenChannel 2019-09-25 14:04:42 +02:00
Johan T. Halseth
0122dda88a
channeldb/channel: remove unused FullSync method
The exported FullSync method is only used by test code, so we remove it
and instead use SyncPending.
2019-09-25 14:04:42 +02:00
Johan T. Halseth
2e9452916e
lnwallet/interface_test: add RBF test cases to testPublishTransaction
Checks that we get ErrDoubleSpend as expected when publishing a
conflicting mempool transaction with the same fee as the existing one,
and that we can publish a replacement with a higher fee successfully.
2019-09-25 08:04:04 +02:00
Johan T. Halseth
61e1b48f57
lnwallet/btcwallet: check publication error types, handle replacement
error

Since btcwallet will return typed errors now, we can simplify the
matching logic in order to return ErrDoubleSpend.

In case a transaction cannot be published since it did not satisfy the
requirements for a valid replacement, return ErrDoubleSpend to indicate
it was not propagated.
2019-09-25 08:04:04 +02:00
Johan T. Halseth
7897b96e6a
lnwallet/interface_test: extract local utility functions
In preparation for extending the testPublishTransaction test, shorten it
by moving utility methods out of the local scope.
2019-09-25 08:01:42 +02:00
Conner Fromknecht
934b11fdac
Merge pull request #3509 from alrs/fix-lnwallet-test-goroutine
lnwallet: fix goroutines in tests
2019-09-19 14:01:45 -07:00
Lars Lehtonen
a600d1eefe lnwallet: fix in-goroutine tests 2019-09-19 19:49:45 +00:00
Johan T. Halseth
c308042ae0
lnwallet/channel: add missing chanpoint to log 2019-09-19 10:40:32 +02:00
Johan T. Halseth
1a4ba97562
Merge pull request #3274 from esneider/fix-typo-in-doc
Fix typo in doc
2019-09-18 08:37:06 +02:00
Olaoluwa Osuntokun
7b1166bbb7
Merge pull request #3458 from Roasbeef/go1.13
build: update travis and Makefile to build using Go 1.13
2019-09-14 11:18:51 +03:00
Lars Lehtonen
3b29ecb921 routing: Fix dropped errors in tests.
lnd: Fix dropped errors in tests.

contractcourt: Fix dropped errors in tests.

htlcswitch: Fix dropped errors in tests.

invoices: Fix dropped error in tests.

lnwallet: Fix dropped errors in tests.

macaroons: Fix dropped error in tests.
2019-09-13 06:28:05 +00:00
Olaoluwa Osuntokun
5ecde6d552
lnwallet+chainntnfs: update to use latest neutrino APIs 2019-09-11 05:57:06 -07:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Wilmer Paulino
59d19e0ca9
lnwallet: add MaxFeeRate method to LightningChannel 2019-09-03 16:49:54 -07:00
Wilmer Paulino
9e8a1707cc
lnwallet: modify FetchInputInfo to return additional information for utxos 2019-08-22 13:49:41 -07:00
Wilmer Paulino
c7bdfe149a
lnwallet/btcwallet: remove internal utxoCache
The cache wasn't really serving a purpose as FetchInputInfo isn't known
to be a hot path. Also, with a planned addition of returning the
confirmation status of an output within FetchInputInfo in a later
commit, caching won't be useful as we'll have to go to disk anyway to
determine the confirmation status.
2019-08-22 13:49:39 -07:00
Wilmer Paulino
a9efb61767
lnwallet: remove irrelevant fields in Utxo struct
These fields are only relevant for spent transaction outputs.
2019-08-22 13:49:38 -07:00
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
esneider
66b5574f4c Fix typo in doc 2019-07-05 19:40:04 -03: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