Commit Graph

374 Commits

Author SHA1 Message Date
Wilmer Paulino
87ff463abd
htlcswitch+lnd: make max cltv expiry configurable 2019-07-26 18:05:58 -07:00
Conner Fromknecht
9eda94a40e
peer: don't reply if peer's request initial_graph_sync
We stopped requesting this from other nodes as it is very expensive as
the graph continues to grow. In this commit we will also stop
responding, as nodes are recommended to begin using the `gossip_queries`
and upcoming `extended_gossip_queries` to reconcile missing graph data.
2019-07-15 14:09:42 -07:00
Conner Fromknecht
efcdefee39
peer: pass watchtower client's to active links 2019-06-13 19:54:19 -07:00
Joost Jager
064e8492de
cnct+htlcswitch+invoices: move invoice parameter check out of link
This commit is the final step in making the link unaware of invoices. It
now purely offers the htlc to the invoice registry and follows
instructions from the invoice registry about how and when to respond to
the htlc.

The change also fixes a bug where upon restart, hodl htlcs were
subjected to the invoice minimum cltv delta requirement again. If the
block height has increased in the mean while, the htlc would be canceled
back.

Furthermore the invoice registry interaction is aligned between link and
contract resolvers.
2019-05-15 14:42:12 +02: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
Johan T. Halseth
c4415f0400
Merge pull request #3044 from cfromknecht/spelling-fixes
multi: fix spelling mistakes
2019-05-07 08:50:36 +02:00
Conner Fromknecht
a11a8693ae
peer: break sendMessage on server quit
This commit modifies sendMessage to break on the server's quit channel,
which allows synchronous callers of SendMessage or SendLazyMessage to
receive an error during server shutdown which can be independent of a
particular peer's shutdown.

As of https://github.com/lightningnetwork/lnd/pull/2916, all replies
made by gossip syncers were modified to be synchronous. In certain
cases, This would prevent the syncers from shutting down promptly, as
they would try to offload a batch a of messages that could not be
aborted. Now, an error will be propagated back to the caller, allowing
them to detect the error condition, and reevaluate their own quit
signals, releasing any waitgrouped goroutines and permitting a quick
shutdown.
2019-05-06 14:56:52 -07:00
Conner Fromknecht
17b2140cb5
multi: fix spelling mistakes 2019-05-04 15:35:37 -07:00
Conner Fromknecht
ca358e9673
lnpeer+peer: use importable lnpeer.ErrPeerExiting
As a prepatory step to making gossip replies synchronous, we will move
the ErrPeerExiting error into the lnpeer package so that it can be
imported by the discovery package. With synchronous sends, this error
can now be detected and handled by goroutines in the syncer, and cause
them to exit instead of continue to sending backlogs.
2019-04-26 20:04:49 -07:00
Olaoluwa Osuntokun
42b081bb37
Merge pull request #2924 from cfromknecht/write-and-flush
peer: resume partial writes due to timeouts
2019-04-26 18:25:37 -07:00
Johan T. Halseth
b53899c43c
lnd: rename package main->lnd 2019-04-23 20:57:33 +02:00
Conner Fromknecht
e013577a4f
peer: remove write backoff
This commit removes the write backoff, since subsequent retries no
longer need to access the write pool. Subsequent flushes will resume
writing any partial writes that occurred before the timeout until the
message is received or the idle write timer is triggered.

In the future, we can add callbacks that execute on write events
timeouts. This can be useful for mobile clients that might roam, as the
timeout could indicate the connection is dead even if the OS has not
reported it closed. The callback can be used then, for example, to
initiate another outbound connection to test whether or not the issue is
related to the connection.
2019-04-22 16:05:41 -07:00
Conner Fromknecht
bfbf3015ad
peer: replace Write with split WriteMessage then Flush methods
This commit modifies the way the link writes messages to the wire, by
first buffering ciphertexts to the connection using WriteMessage, and
then calling Flush separately. Currently, the call to Write tries to do
both, which can result in a blocking operation for up to the duration of
the write timeout. Splitting these operations permits less blocking in
the write pool, since now we only need to use a write worker to
serialize and encrypt the plaintext.

After the write pool is released, the peer then attempts to flush the
message using the appropriate write timeout. If a timeout error occurs,
the peer will continue to flush the message w/o serializing or
encrypting the message again, until the message is fully written to the
wire or the write idle timer disconnects the peer.
2019-04-22 16:05:26 -07:00
Conner Fromknecht
f8345d38fb
peer: only set ping time once
As a preliminary step to integrating the separated WriteMessage and
Flush calls in the peer, we'll modify the peer to only set a timestamp
on Ping messages once. This makes sense for two reasons, 1) if the
message has already been partially written, we have already committed to
a ping time, and 2) a ciphertext containing the first ping time will
already be buffered in the connection, and we will only be attempting to
Flush on timeout errors.
2019-04-22 16:05:10 -07:00
Joost Jager
ab4da0f53d
cnct: define separate broadcast delta for outgoing htlcs
This commits exposes the various parameters around going to chain and
accepting htlcs in a clear way.

In addition to this, it reverts those parameters to what they were
before the merge of commit d1076271456bdab1625ea6b52b93ca3e1bd9aed9.
2019-04-05 11:36:07 +02:00
Wilmer Paulino
70be812747
discovery+server: use new gossiper's SyncManager subsystem 2019-04-03 15:44:43 -07:00
Wilmer Paulino
80b84eef9c
config+peer: replace NoChanUpdates flag with NumGraphSyncPeers
In this commit, we replace the NoChanUpdates flag with a flag that
allows us to specify the number of peers we want to actively receive new
graph updates from. This will be required when integrating the new
gossiper SyncManager subsystem with the rest of lnd.
2019-04-03 15:43:51 -07:00
Olaoluwa Osuntokun
893cff60c4
Merge pull request #2839 from joostjager/htlc-expiry-check
link: increase expiry grace delta for exit hop and forwarded htlcs
2019-04-01 18:15:56 -07:00
Olaoluwa Osuntokun
73eb37b3a9
peer: don't attempt to load any channels that have a non-default state, other then recovered
In this commit, we modify the filter we use to determine if we should
add a new channel to the switch to reflect the new channel restoration
state. For all other non-default states, we want to avoid loading in a
channel, but for the restoration state, we need to load the link in
order to ensure we initiate the data loss protection protocol once we
connect to the remote peer.
2019-03-28 17:53:24 -07:00
Conner Fromknecht
7358535725
peer+server: log pubkey@addr 2019-03-26 16:41:13 -07:00
Conner Fromknecht
93e56f9ee8
peer: add symmetric write idle timeout
In this commit, we add a 5 minute idle timer to
the write handler. After catching the write
timeouts, it's been observed that some connections
have trouble reading a message for several hours.
This typically points to a deeper issue w/ the peer
or, e.g. the remote peer switched networks. This now
mirrors the idle timeout used in the read handler,
such that we will disconnect a peer if we are unable
to send or receive a message from the peer after 5
minutes.

We also modify the readHandler to drain its
idleTimer's channel in the even that the timer had
already fired, but we successfully sent the message.
2019-03-26 16:40:41 -07:00
Conner Fromknecht
b78e5f6742
peer: reduce write timeout to 5 seconds
This commit reduces the peer's write timeout to 5s.
Now that the peer catches write timeouts and doesn't
disconnect, this will ensure we spend less time blocking
in the write pool in case others also need to access the
workers concurrently. Slower peers will now only block
for 5s, after every reattempt w/ exponential backoff.
2019-03-26 16:40:24 -07:00
Conner Fromknecht
99150b41d6
peer: retry writes with delay on timeout errors
This commit modifies the writeHandler to catch timeout
errors, and retry writes to the socket after a small
backoff, which increases exponentially from 5s to 1m.
With the growing channel graph size, some lower-powered
devices can be slow to pull messages off the wire during
validation. The current behavior will cause us to
disconnect the peer, and resend all of the messages that
the remote peer is slow to validate. Catching the timeout
helps in preventing such expensive reconnection cycles,
especially as the network continues to grow.

This is also a preliminary step to reducing the
write timeout constant. This will allow concurrent usage
of the write pools w/out devoting excessive amounts of
time blocking the pool for slow peers.
2019-03-26 16:40:07 -07:00
Joost Jager
cd535b9401
link: increase expiry grace delta
This commit increase the expiry grace delta to a value above the
broadcast delta. This prevents htlcs from being accepted that would
immediately trigger a channel force close.

A correct delta is generated in server.go where there is access to
the broadcast delta and passed via the peer to the links.

Co-authored-by: Jim Posen <jim.posen@gmail.com>
2019-03-26 18:42:00 +01:00
Conner Fromknecht
2e5bc783f7
peer: preallocate errchans opt 2019-03-05 17:08:35 -08:00
Conner Fromknecht
f39edd8000
peer: add SendMessageLazy 2019-03-05 17:08:22 -08:00
Conner Fromknecht
660bbaf646
peer: add message reordering based on priority 2019-03-05 17:08:05 -08:00
Conner Fromknecht
6f1ccf14e9
Revert "peer: reduce write timeout to 10s"
This reverts commit db2c104111c3c12e1651120fe5a51ce03dad8c58.
2019-03-04 13:55:09 -08:00
Olaoluwa Osuntokun
a6cf6f4237
lnwallet+peer: remove unnecessary MaxPendingAmount method
We don't need this method, as we can directly access it from the peer
via public fields with its current usage.
2019-02-25 12:51:31 -03:00
Olaoluwa Osuntokun
b13d8cd261
Merge pull request #2434 from valentinewallace/fwding-policy-max-htlc
Set max HTLC in forwarding policies.
2019-02-25 12:43:15 -03:00
Conner Fromknecht
db2c104111
peer: reduce write timeout to 10s 2019-02-21 20:11:47 -08:00
Conner Fromknecht
603601a4c8
peer+server: use peer-level readPool 2019-02-21 20:11:33 -08:00
Conner Fromknecht
9a3c0b8bca
peer+server: switch to pool.Write from pool.WriteBuffer 2019-02-21 20:10:51 -08:00
Valentine Wallace
90cbf9fe35 peer: set max htlc when loading active channels on start 2019-02-21 18:39:32 -08:00
Valentine Wallace
20b3114100 htlcswitch+lnwallet+peer: default max htlc in fwding policy of new chans
In this commit, we set a default max HTLC in the forwarding
policies of newly open channels.

The ForwardingPolicy's MaxHTLC field (added in this commit)
will later be used to decide whether an HTLC satisfies our policy before
forwarding it.

To ensure the ForwardingPolicy's MaxHTLC default matches the max HTLC
advertised in the ChannelUpdate sent out for this channel,  we also add
a MaxPendingAmount() function to the lnwallet.Channel.
2019-02-21 18:39:32 -08:00
Olaoluwa Osuntokun
9d23d382fc
Merge pull request #2419 from cfromknecht/brontide-buffer-pool
brontide: read buffer pool
2019-02-18 17:51:17 -08:00
Conner Fromknecht
6f96d04b72
multi: add buffer.Write and pool.WriteBuffer, make GCQueue generic 2019-02-15 19:31:24 -08:00
Conner Fromknecht
de282172a1
peer+server+test_utlils: use new ChanStatusManager
This commit hooks up the new netann.ChanStatusManager,
replacing the prior method which used the
watchChannelStatus goroutine.
2019-02-14 17:13:44 -08:00
Olaoluwa Osuntokun
bceb048a76
Merge pull request #2385 from cfromknecht/peer-write-buffer
peer: write buffer pool
2019-02-01 17:04:30 -08:00
Olaoluwa Osuntokun
5167b02312
Merge pull request #2500 from Roasbeef/mandatory-dlp
server: require the DLP bit for all incoming/outgoing connections
2019-01-31 20:14:15 -08:00
Conner Fromknecht
24dcd3c44e
peer+server: use server-wide writeBufferPool for peer write buffers 2019-01-31 19:21:36 -08:00
Olaoluwa Osuntokun
f57f40e767
channeldb: add prefix naming to ChannelStatus enum variables
In this commit, we add a prefix naming scheme to the ChannelStatus enum
variables. We do this as it enables outside callers to more easily
identify each individual enum variable as a part of the greater
enum-like type.
2019-01-28 20:24:32 -08:00
Valentine Wallace
0fd6004958
multi: partition lnwire.ChanUpdateFlag into ChannelFlags and MessageFlags
In this commit:

* we partition lnwire.ChanUpdateFlag into two (ChanUpdateChanFlags and
ChanUpdateMsgFlags), from a uint16 to a pair of uint8's

* we rename the ChannelUpdate.Flags to ChannelFlags and add an
additional MessageFlags field, which will be used to indicate the
presence of the optional field HtlcMaximumMsat within the ChannelUpdate.

* we partition ChannelEdgePolicy.Flags into message and channel flags.
This change corresponds to the partitioning of the ChannelUpdate's Flags
field into MessageFlags and ChannelFlags.

Co-authored-by: Johan T. Halseth <johanth@gmail.com>
2019-01-22 08:42:26 +01:00
Olaoluwa Osuntokun
b7244244ae
peer: disconnect peers that don't have our required feature bits 2019-01-18 18:30:55 -08:00
Conner Fromknecht
2cf220a137
peer: handle message encoding errors on write
In this commit, we modify the peer's writeMessage
method to properly handle errors returned from
encoding an lnwire message and from setting the
write deadline on the connection. Since an error
would likely result in an empty byte slice, the
worse case seems to be that we may have tried to
send an empty message on the wire.

Lastly, we correct the way we compute bytes sent
on the wire to properly count the number of bytes
*written*, and not just the length of the encoded
message.
2019-01-10 19:49:44 -08:00
Olaoluwa Osuntokun
a49e39de75
peer: don't d/c on invalid node alias 2019-01-07 12:53:45 -08:00
Joost Jager
6c027e2bc9 htlcswitch: remove lnrpc dependency
This commits removes an unwanted dependency that prevents
moving parts of rpcserver to a sub server.
2019-01-03 09:07:56 +01:00
Olaoluwa Osuntokun
fa160f559c
multi: replace per channel sigPool with global daemon level sigPool
In this commit, we remove the per channel `sigPool` within the
`lnwallet.LightningChannel` struct. With this change, we ensure that as
the number of channels grows, the number of gouroutines idling in the
sigPool stays constant. It's the case that currently on the daemon, most
channels are likely inactive, with only a hand full actually
consistently carrying out channel updates. As a result, this change
should reduce the amount of idle CPU usage, as we have less active
goroutines in select loops.

In order to make this change, the `SigPool` itself has been publicly
exported such that outside callers can make a `SigPool` and pass it into
newly created channels. Since the sig pool now lives outside the
channel, we were also able to do away with the Stop() method on the
channel all together.

Finally, the server is the sub-system that is currently responsible for
managing the `SigPool` within lnd.
2018-12-16 15:40:14 -08:00
Johan T. Halseth
0dd7eed64e
peer: define resendChanSyncMsg
This method is used to fetch channel sync messages for closed channels
from the db, and respond to the peer.
2018-11-21 10:28:56 +01:00
Johan T. Halseth
780e1bbead
peer: correct variable name, print error 2018-11-21 10:12:04 +01:00