Commit Graph

284 Commits

Author SHA1 Message Date
Conner Fromknecht
16318c5a41
multi: merge local+global features from remote peer 2019-11-08 05:31:47 -08:00
Olaoluwa Osuntokun
4592f87033
Merge pull request #3653 from Roasbeef/external-funding-chainfees
chainfees: create new chainfees package extracting fees from lnwallet
2019-10-31 17:44:00 -07:00
Olaoluwa Osuntokun
777ed104a3
chainfee: create new chainfee package extracting fees from lnwallet
In this commit, we create a new chainfee package, that houses all fee
related functionality used within the codebase. The creation of this new
package furthers our long-term goal of extracting functionality from the
bloated `lnwallet` package into new distinct packages. Additionally,
this new packages resolves a class of import cycle that could arise if a
new package that was imported by something in `lnwallet` wanted to use
the existing fee related functions in the prior `lnwallet` package.
2019-10-31 16:41:57 -07:00
Olaoluwa Osuntokun
a73ee28e46
multi: convert the existing channeldb.ChannelType uint8 into a bit field
In this commit, we convert the existing `channeldb.ChannelType` type
into a _bit field_. This doesn't require us to change the current
serialization or interpretation or the type as it is, since all the
current defined values us a distinct bit. This PR lays the ground work
for any future changes that may introduce new channel types (like anchor
outputs), and also any changes that may modify the existing invariants
around channels (if we're the initiator, we always have the funding
transaction).
2019-10-31 16:34:37 -07:00
Johan T. Halseth
12a1d05127
fundingmanager: make SendToPeer sync
Since the funding flow requires messages to go through, make use of
sync version of SendToPeer. Using the async version we would risk that
the message was dropped and the process would stall (it would properly
continue after a restart though).
2019-10-24 13:08:08 +02:00
Olaoluwa Osuntokun
0e13c5ac3f
lnwallet+funding: expose new ValidateChannel method for 1st party validation
In this commit, we use the recently added `chanvalidate` package to
verify channels once they have been confirmed in the funding manager. We
expose a new method on the `LightningWallet` struct: `ValidateChannels`
which calls the new shared 1st party verification code.

After the channel is fully confirmed in the funding manager, we'll now
use this newly exposed method to handle all validation. As a result, we
can remove the existing validation code in the funding manager, and rely
on the new code in isolation.
2019-10-03 16:23:23 -07:00
Olaoluwa Osuntokun
2dddbc84d9
lncfg+lnd: gate usage of tweakless commitments based on local/global feature bits
In this commit, we add a new legacy protocol command line flag:
`committweak`. When set, this forces the node to NOT signal usage of the
new commitment format. This allows us to test that we're able to
properly establish channels with legacy nodes. Within the server, we'll
now gate our signalling of this new feature based on the legacy protocol
config. Finally, when accepting/initiating a new channel funding, we'll
now check both the local and remote global feature bits, only using the
new commitment format if both signal the global feature bit.
2019-09-25 18:26:04 -07:00
Olaoluwa Osuntokun
b1d122773e
Merge pull request #1910 from halseth/fundingmanager-state-machine
Fundingmanager state machine cleanup
2019-09-25 16:31:51 -07:00
nsa
4d02100e12
fundingmanager+server: adding ChannelAcceptor to the fundingmanager 2019-09-25 12:07:30 -04:00
Johan T. Halseth
9f3fbda71f
fundingmanager: remove unnecessary Peer param to sendFundingLocked 2019-09-24 21:24:40 +02:00
Johan T. Halseth
5b8e97da29
funding: update comment aboute offline peers
Since fundingLocked now are being sent reliably, the only message left
to be sent reliably is the node announcement for private channels.
2019-09-24 21:24:40 +02:00
Johan T. Halseth
9ff6de5be1
funding: add TODO for consistency check 2019-09-24 21:24:39 +02:00
Johan T. Halseth
bda0e40dad
fundingmanager: save markedOpen before marking the channel open
This commit fixes a potential issue within the fundingmanager, where
failing to write the channel opening state could cause the channel being
marked open in the DB, but the opening state not being set. On startup
this would cause the channel state machine to not be able to resume.

We fix this by saving the channel opening state _first_. This works
because saving the opening state is idempotent, and in case a channel is
found pending at startup, it will re-register for confirmation
notifications and re-do the process.
2019-09-24 21:24:39 +02:00
Johan T. Halseth
88f5e06427
fundingmanager: unify handling of pending and non-pending channels at startup
Since the advanceFundingState now can handle pending channels, we'll
call it for both pending and non-pending channels, just making sure that
we re-initialize the channel barriers and re-publish the funding tx fro
pending channels.
2019-09-24 21:24:39 +02:00
Johan T. Halseth
8a61af6a55
fundingmanager: make advanceFundingState handle pending channels
This commit makes advanceFundingState check whether a channel is still
pending before checking the channel opening state. This lets us call it
directly, without checking whether a channel has confirmed first.
2019-09-24 21:24:39 +02:00
Johan T. Halseth
893c6cbc59
fundingmanager: make waitForFundingTimeout sync
This commit makes the waitForFundingTimeout method synchronous, and
return ErrConfirmationTimeout in case the timeout is reached.

We also simplify the internals by using waitForTimout defined earlier.
2019-09-24 21:24:35 +02:00
Johan T. Halseth
47fae26dc4
fundingmanager: define method waitForTimeout
This commit defines a new method waitForTimeout, that will be used to
listen for channels timing out. It handles a subset of what is already
handled by waitForFundingWithTimeout, but we want to break that one up
in smaller parts, and waitForTimeout is the first of these.
2019-09-24 21:24:34 +02:00
Johan T. Halseth
ea196f6e8f
fundingmanager make waitForFundingConfirmation decrement waitgroup
Since waitForFundingConfirmation is always called in a goroutine, we
make this explicit by requireing the caller to always increment the
waitgroup before calling it.
2019-09-24 21:24:34 +02:00
Johan T. Halseth
76857dbcdc
fundingmanager: move handleFundingConfirmation out of waitForFundingWithTimeout
Similarly to what we did in the previous commit, we move the
responsibility of marking the channel open by calling
handleFundingConfirmation out from waitForFundingWithTimeout to the
caller.
2019-09-24 21:24:34 +02:00
Johan T. Halseth
25f6094802
fungingmanager: move handleFundingConfirmation out of waitForfundingConfirmation
This commit moves the handling of a funding confirmation out of
waitForFundingConfirmation, and instead let the caller handle marking
the channel opened.
2019-09-24 21:24:34 +02:00
Johan T. Halseth
b51b76b469
fundingmanager: extract opening logic into new method handleFundingConfirmation
This commit moves the opening logic found within
waitForFundingConfirmation into a new method handleFundingConfirmation.
This will make it easier to later break up waitForFundingConfirmation,
and avoid code duplication.
2019-09-24 21:24:34 +02:00
Johan T. Halseth
b2a7e42f44
fundingmanager: commit to new states in stateStep
This commit moves the saving of the new channelOpeningState to the
stateStep method.
2019-09-24 21:24:33 +02:00
Johan T. Halseth
49bbf0eb61
fundingmanager: call advanceFundingState in place of handleFundingConfirmation
This commit removes the handleFundingConfirmation method, and instead
hands the newly confirmed channel of to advanceFundingState, which will
take the channel through the rest of the channel opening flow.
2019-09-24 21:24:33 +02:00
Johan T. Halseth
e274c2fb7c
fundingmanager: call advanceFundingState from handleFundingSigned
Since the advanceFundingSigned now can resume a channel from any state,
we resue the logic in handleFundingSigned instead of manually executing
each step of the funding flow.
2019-09-24 21:24:33 +02:00
Johan T. Halseth
cbf1fe6bb1
fundingmanager: define stateStep, make advanceFundingState sync
This commit make the advanceFundingStateMethod synchronous. It will now
query the database for a channel's opening state, and call the method
stateStep until the channel has finished the opening procedure.
2019-09-24 21:24:33 +02:00
Johan T. Halseth
08cb313934
fundingmanager: move startup state check into advanceFundingState method
This commit extracts the funding state check we do at startup into a new
method advanceFundingState. In later commits we will modify this method
to work for all funding state machine flows, not only on restart.
2019-09-24 21:24:33 +02:00
Johan T. Halseth
e189f78567
fundingmanager: remove dead code
Pending channels will never have a channel opening state, and hence will
never be pending.
2019-09-24 21:24:32 +02:00
Johan T. Halseth
e4301d3a8f
lnwire: rename ErrorCode -> FundingError
To make it clear that these errors are not part of the spec, rename them
to FundingError.
2019-09-20 10:55:21 +02:00
Johan T. Halseth
33fe09482b
lnwire+multi: define Error() for lnwire.Error
To make lnwire.Error actually satisfy the error interface, define the
Error method directly.
2019-09-20 10:55:21 +02:00
Johan T. Halseth
ff37b711c6
funding: dont's send ErrorCode on wire
Since the ErrorCodes are not part of the spec, they cannot be read by
other implementations.

Instead of only sending the error code we therefore send the complete
error message. This will have the same effect at the client, as it will
just get the full error instead of the code indicating which error it
is. It will also be compatible with other impls.

Note that the GRPC error codes will change, since we don't set them
anymore.
2019-09-20 10:55:20 +02:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02: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
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
e716251805
server+funding: remove unused remoteFundingAmt 2019-07-18 00:33:14 +02:00
Johan T. Halseth
452ee6aad4
fundingmanager+server: define MaxPendingChans. RejectPush in funding config
This commit makes the funding manager access the MaxPendingChannels and
RejectPush values from the fundingConfig instead of the global config
struct.

Done to avoid sharing state between tests.
2019-07-18 00:33:14 +02:00
Johan T. Halseth
00a86696a8
Merge pull request #3145 from federicobond/avoid-pubkey-serialization
discovery,fundingmanager: avoid serialization in NotifyWhenOnline
2019-06-12 10:50:35 +02:00
Federico Bond
9bd3055fb8 discovery,fundingmanager: avoid serialization in NotifyWhenOnline 2019-06-04 16:36:21 -03:00
Federico Bond
aea52f4bef multi: replace manual CAS with sync.Once in component start/stop
This guarantees callers that the method will not return until it
has executed completely at least once.
2019-05-30 17:14:04 -03:00
Joost Jager
dff0387363
lntest: move itest into package 2019-05-28 21:43:23 +02:00
Conner Fromknecht
08654786ad
fundingmanager: bump max non-initiator funding timeout to 2 weeks
The previous value was set to two days, which may not be enough to
handle large fee spikes where users still which to submit channels with
a low fee and don't mind lowering their time preference. Since the
timeout is only applied to channels that we don't initiate, there's real
downside since it's not our funds that are locked up.
2019-05-18 15:21:56 -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
AdamISZ
6e054886d8 Typo corrections in various comments 2019-05-10 17:15:54 +02:00
Johan T. Halseth
b53899c43c
lnd: rename package main->lnd 2019-04-23 20:57:33 +02:00
Wilmer Paulino
760f38736e
fundingmanager: populate additional edge info after adding to graph
This commit serves as another stop-gap for light clients since they are
unable to obtain the capacity and channel point of graph edges. Since
they're aware of these things for their own channels, they can populate
the information within the graph themselves once each channel has been
successfully added to the graph.
2019-04-18 21:57:40 -07:00
Wilmer Paulino
7946d0a256
multi: remove ErrDoubleSpend check for PublishTransaction
In this commit, we address a lingering issue within some subsystems that
are responsible for broadcasting transactions. Previously,
ErrDoubleSpend indicated that a transaction was already included in the
mempool/chain. This error was then modified to actually be returned for
conflicting transactions, but its callers were not modified accordingly.
This would lead to conflicting transactions to be interpreted as valid,
when they shouldn't be.
2019-03-13 17:57:19 -07:00
Johan T. Halseth
4698d18294
fundingmanager: don't spew shortChanID
gives uneccessary output as

2019-02-06 11:26:45.338 [INF] FNDG: Announcing ChannelPoint(cf659a58d68f206531136bf19dea82863a488937f9f4c3d489c450ad81c1724e:0), short_chan_id=(*lnwire.ShortChannelID)(0xc000670a60)(1977:1:0)
2019-02-06 16:04:16 +01:00
Valentine Wallace
5405028948 fundingmanager: inform ChannelNotifier about newly open channels. 2019-02-05 18:17:54 -08:00
Olaoluwa Osuntokun
6a3addbeda
Merge pull request #2563 from halseth/funding-ensure-max-value-less-than-cap
funding: cap the max_htlc value at channel capacity
2019-02-01 16:29:33 -08:00
Joost Jager
9e012ecc93
multi: move Input interface and related code
This commit is a step to split the lnwallet package. It puts the Input
interface and implementations in a separate package along with all their
dependencies from lnwallet.
2019-01-31 13:25:33 +01:00
Johan T. Halseth
da42ad245f
funding: cap the max_htlc value at channel capacity
We are not longer validating the max_value_in_flight field set by the
remote peer, so it is not always less than the channel capacity anymore.
We therefore make sure to cap it before advertising it.
2019-01-30 09:05:01 +01:00