Commit Graph

343 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
d98d4523e1
Merge pull request #1159 from wpaulino/onion-service-support
multi: add onion services support
2018-06-04 21:46:51 -07:00
Wilmer Paulino
2e0484be19
multi: ensure addresses are no longer assumed to be TCP addresses only
In this commit, we go through the codebase looking for TCP address
assumptions and modifying them to include the recently introduced onion
addresses. This enables us to fully support onion addresses within the
daemon.
2018-06-04 20:41:49 -07:00
Wilmer Paulino
08f80b6cf3
server: use advertised address when reestablishing inbound connections
In this commit, we update the way we reestablish inbound connections if
we lose connectivity to a node we have an open channel with. Rather than
fetching the node's advertised port, we'll fetch one of their advertised
addresses instead. This ensure that if the remote node is running behind
a proxy, we do not see the proxy's address.
2018-06-04 20:41:48 -07:00
Wilmer Paulino
1012f876e1
server: add automatic creation of v2 onion services
In this commit, we allow the daemon to use the recently introduced Tor
Controller implementation. This will automatically create a v2 onion
service at startup in order to listen for inbound connections over Tor.

Co-Authored-By: Eugene <crypt-iq@users.noreply.github.com>
2018-06-04 20:41:45 -07:00
Wilmer Paulino
3bb1733fa2
discovery+server: use network-specific functions for fallback SRV lookup
In this commit, we fix a bug where a fallback SRV lookup would leak
information if `lnd` was set to route connections over Tor. We solve
this by using the network-specific functions rather than the standard
ones found in the `net` package.
2018-06-04 20:41:43 -07:00
Wilmer Paulino
3669a40c52
server: add support to advertise onion addresses
In this commit, we allow `lnd` to properly parse onion addresses in
order to advertise them to the network when set through the
`--externalip` flag.

Co-Authored-By: Eugene <crypt-iq@users.noreply.github.com>
2018-06-04 20:41:41 -07:00
maurycy
3be08e69cf multi: 64bit aligment of atomic vars on arm/x86-32 2018-06-04 20:02:34 -07:00
Olaoluwa Osuntokun
d2bcb708f3
server: demote 'sending message' log to trace 2018-06-04 19:50:44 -07:00
Johan T. Halseth
08d9edd059
server: increase updateChan buffer to 2 2018-06-01 08:55:06 +02:00
Olaoluwa Osuntokun
d7b21859d5
server: upon disconnect, prune peer query state from gossiper 2018-05-31 16:30:57 -07:00
Olaoluwa Osuntokun
199bbe2fd4
server: if remote peer knows of gossip queries, skip initial table dump 2018-05-31 16:30:57 -07:00
Olaoluwa Osuntokun
f70f1f318d
server: set the dataloss protect and gossip queries feature bits 2018-05-31 16:30:57 -07:00
Olaoluwa Osuntokun
486f87576c
server: instantiate the chanSeries struct in the gossiper's config 2018-05-31 16:30:56 -07:00
Wilmer Paulino
4a200d28eb
lnd: add interrupt handler to handle shutdown requests while syncing
chain backend
2018-05-23 11:26:07 -04:00
Olaoluwa Osuntokun
f494433cbf
routing+server: add new QueryBandwidth method to reduce outbound failures
In this commit, we introduce a new method to the channel router's config
struct: QueryBandwidth. This method allows the channel router to query
for the up-to-date available bandwidth of a particular link. In the case
that this link emanates from/to us, then we can query the switch to see
if the link is active (if not bandwidth is zero), and return the current
best estimate for the available bandwidth of the link. If the link,
isn't one of ours, then we can thread through the total maximal
capacity of the link.

In order to implement this, the missionControl struct will now query the
switch upon creation to obtain a fresh bandwidth snapshot. We take care
to do this in a distinct db transaction in order to now introduced a
circular waiting condition between the mutexes in bolt, and the channel
state machine.

The aim of this change is to reduce the number of unnecessary failures
during HTLC payment routing as we'll now skip any links that are
inactive, or just don't have enough bandwidth for the payment. Nodes
that have several hundred channels (all of which in various states of
activity and available bandwidth) should see a nice gain from this w.r.t
payment latency.
2018-05-14 16:23:54 -07:00
Olaoluwa Osuntokun
b73eef12b3
Merge pull request #945 from jimpo/decayedlog
Move DecayedLog from lightning-onion to htlcswitch.
2018-05-10 20:06:53 -07:00
Olaoluwa Osuntokun
f0050e7ffb
Merge pull request #1201 from lightningnetwork/peer-async-disconnect
server: Peer Async Disconnect w/ Scheduled peerConnected
2018-05-10 17:05:16 -07:00
Olaoluwa Osuntokun
b271ed5ffb
Merge pull request #1199 from cfromknecht/queue-msg-err-chans
peer/server: Remove Broadcast err chans
2018-05-10 16:55:57 -07:00
Conner Fromknecht
8c04dd0030
server: add peer connection callback scheduling
This commit adds a simple scheduling mechanism for
resolving potential deadlocks when dropping a stale
connection (via pubkey inspection).

Ideally, we'd like to wait to activate a new peer until
the previous one has exited entirely. However, the current
logic attempts to disconnect (and wait) until the peer
has been cleaned up fully, which can result in
deadlocks with other portions of the codebase, since
other blocking methods may also need acquire the mutex
before the peer can exit.

When existing connections are replaced, they now
schedule a callback that is executed inside the
peerTerminationWatcher. Since the peer now waits for
the clean exit of the prior peer, this callback is
now executed with a clean slate, adds the peer to
the server's maps, and initiates peer's Start() method.
2018-05-08 16:37:14 -07:00
Conner Fromknecht
d20adc8e0e
server: use nil errChan for broadcasts
This skips creating errChans when sending messages to
peer during broadcast. This should be a minor memory
optimization, as well as not requiring channel sends
on those which will never be read.
2018-05-08 16:35:49 -07:00
Olaoluwa Osuntokun
72f48b6abe
htlcswitch+server: ensure we always send an update w/ a TempChannelFailure
In this commit, we ensure that any time we send a TempChannelFailure
that's destined for a multi-hop source sender, then we'll always package
the latest channel update along with it.
2018-05-08 13:00:28 -04:00
Jim Posen
56e65339e0 multi: Complete upgrade to new sphinx package interface. 2018-05-02 00:22:25 -07:00
Johan T. Halseth
e9eab3f79f
server: reliably hand off breach from the ChainArbitrator to the breachArb
This commit make the server populate the ChainArbitrator's
ContractBreach method, by a method that will reliably handoff the breach
event ot the breachArbiter. The server will now forward the breach event
to the breachArbiter, and only let the closure return a non-nil error
when the breachArbiter ACKs this event.
2018-05-02 08:43:32 +02:00
Sean Erle Johnson
938d367232 server: change PeerNotFound to PeerNotConnected 2018-04-18 12:34:57 -07:00
Dimitris Tsapakidis
4009f7f874 multi: fix typos in comments 2018-04-17 19:03:27 -07:00
Olaoluwa Osuntokun
9d29c4f43d
server: only swap out the port for inbound connections
Note that the check is actually reversed to the quirk atm in the server
logic, where inbound and outbound are reversed.

Fixes #1063.
2018-04-09 19:55:01 -07:00
Olaoluwa Osuntokun
de0a2ee49b
server: don't directly mutate net.TCPAddr for inbound connections to set peer port
In this commit, we fix a minor logging bug introduced in a prior commit.
Before we would directly modify the *net.TCPAddr that was a part of the
brontide connection. This achieved our goal, but would print weird log
messages as we mutated the port in the already established connection.

In this commit, we fix that by ensuring we create a copy iff it's a
net.TCPAddr, then modify that and replace the instance in the
lnwire.NetAddress.

Fixes #991.
2018-04-02 16:14:33 -07:00
Olaoluwa Osuntokun
9b729654f6
server: remove all pending conn reqs within DisconnectPeer 2018-03-31 16:26:19 -07:00
Olaoluwa Osuntokun
6be6b48e09
Merge pull request #840 from halseth/openchannel-csv-delay
Add CSV delay flag to openchannel
2018-03-31 16:05:08 -07:00
Conner Fromknecht
2490b9b6e3
server: cleanup persistent connection retries
This commits changes the behavior of our connection
reestablishment, and resolves some minor issues that
could lead to uncancelled requests or an infinite
connection loop.

 - Will not attempt to Remove connection requests with
   an ID of 0. This can happen for reconnect attempts
   that get scheduled, but have not started at the
   time the server cancels the connection requests.

 - Adds a per-peer cancellation channel, that is
   closed upon a successful inbound or outbound
   connection. The goroutine spwaned to handle the
   reconnect by the peerTerminationWatch now
   selects on this channel, and skips reconnecting
   if it is closed before the backoff matures.

 - Properly computes the backoff when no entry in
   persistentPeersBackoff is found. Previously, a
   value of 0 would be returned, cause all subsequent
   backoff attempts to use a backoff of 0.

 - Cancels a peers retries and remove connections
   immediately after receiving an inbound connection,
   to mimic the structure of OutboundPeerConnected.

 - Cancels all persistent connection requests after
   calling DisconnectPeers.

 - Allow additional connection attempts to peers, even if
   there already exists a pending connection attempt.
2018-03-31 00:51:12 -07:00
Olaoluwa Osuntokun
4480052cd6
server: ensure a default backoff is always used 2018-03-30 19:11:12 -07:00
Olaoluwa Osuntokun
d34c37f3dd
server: when constructing peer addr's attempt to locate proper port, fallback to default port
In this commit, we fix an existing bug within the codebase: if a peer
connected to us inbound, then we'd attempt to use the assigned port when
re-establishing a connection to them. We fix this issue in this commit
by adding a new method to look up any advertisements for the peer, and
use the specified port that matches our connection attempt. If we can't
find a proper advertisement, then we'll simply use the default peer
port.
2018-03-30 15:59:11 -07:00
Olaoluwa Osuntokun
b2e1d6988c
server: don't immediately add bootstrap peer to set of persistent connections 2018-03-30 15:16:18 -07:00
Olaoluwa Osuntokun
90636b49b2 server: properly format peer pubkey in NotifyWhenOnline logging msg
Fixes #978.
2018-03-30 13:15:49 -07:00
Johan T. Halseth
6f98803967
server: add remoteCsvDelay to openChanReq 2018-03-22 14:53:59 +01:00
Olaoluwa Osuntokun
9ec80e2083
server: properly segment the nursery store according to active net 2018-03-14 18:27:28 -07:00
Conner Fromknecht
a9904b328f
servrer: pass ExtractErrorEncrypter 2018-03-13 16:33:29 -07:00
Olaoluwa Osuntokun
800eea931f
build+multi: switch from bolt to bbolt
In this commit, we switch from boltbd/bolt to coreos/bbolt as the
former is no longer being actively maintained.
2018-03-10 19:01:13 -08:00
Olaoluwa Osuntokun
2a6876bde2
server: ensure the replay database is stored under the graph+network namespace
In this commit we modify the storage location of the sphinx replay
database to be under the precise network, and not only the graph sub
directory. Before this commit, due to the usage of filepath.Dir(), the
db would lie under /graph/, rather than say, /graph/simnet.
2018-03-10 13:02:29 -08:00
Conner Fromknecht
c976a550cb
server: initialize switch with circuit db 2018-03-09 21:18:15 -08:00
Conner Fromknecht
a4d8b30367
server: initialize server with persistent sphinx router 2018-03-08 21:12:05 -05:00
Olaoluwa Osuntokun
a540003bb9
server: set the FwdingLog attribute in the switch's config 2018-03-06 13:56:12 -05:00
Johan T. Halseth
3dc9e3c7d4
server: express fee rates using fee rate types 2018-02-26 22:42:26 +01:00
MeshCollider
2c2ed3c6a9 multi: Unify use of NodeKey in log messages 2018-02-19 17:48:39 -08:00
MeshCollider
4c42079436 multi: ensure NodeKey is set in rpc/cli 2018-02-19 17:48:39 -08:00
MeshCollider
915c4201b9 multi: remove internal peer_id usage 2018-02-19 17:48:39 -08:00
Conner Fromknecht
a03e95410b
server: adds truncated exponential backoff + rand for retry
This commit adds an backoff policy to the peer termination
watcher to avoid getting stuck in tight connection loops
with failing peers. The maximum backoff is now set to 128s,
and each backoff is randomized so that two instances using
the same algorithm have some hope of desynchronizing.
2018-02-08 18:15:20 -08:00
Olaoluwa Osuntokun
22951cb364
lnd: account for new lnwire.Sig API and channeldb API changes 2018-02-06 20:14:33 -08:00
Daniel McNally
8543497dcc multi: fixing it's/its typos in comments 2018-02-06 19:13:07 -08:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
MeshCollider
4b1cc98808 multi: apply roasbeef diff to support incoming socks.ProxiedAddr 2018-02-05 17:37:46 -08:00
MeshCollider
4affab7bd7 multi: Addressing Tor support review comments 2018-02-05 17:37:46 -08:00
nsa
698df2ac16 torsvc: added new type that multiplexes torsvc and net packages
This commit adds the `lnnet` package which contains an
implementation of the newly created LightningNet interface which
multiplexes the Dial and DNS-related functions to use net
by default and torsvc if a flag is specified. This modularization
makes for cleaner code.
2018-02-05 17:37:46 -08:00
nsa
8c482f2be7 multi: Added a NetInterface to clean up config.go
This commit adds a new interface named NetInterface and two
implementations of it: RegularNet & TorProxyNet. These two structs
are used in config.go in an attempt to clean up the code and
abstract away the dialer and DNS functions.
2018-02-05 17:37:46 -08:00
nsa
e132ad8433 torsvc: Added new module to house Tor functions
This commit adds a new module named 'torsvc' which houses all Tor
functionality in an attempt to isolate it and make it reusable in
other projecs. Some additional tweaks were made to config.go and
to the bootstrapper.
2018-02-05 17:37:46 -08:00
nsa
e2142c778f multi: Added Tor support
This commit adds Tor support. Users can set the --TorSocks flag
to specify which port Tor's SOCKS5 proxy is listening on so that
lnd can connect to it. When this flag is set, ALL traffic gets
routed over Tor including DNS traffic. Special functions for
DNS lookups were added, and since Tor doesn't natively support
SRV requests, the proxySRV function routes connects us to
a DNS server via Tor and SRV requests can be issued directly
to the DNS server.

Co-authored-by: MeshCollider <dobsonsa68@gmail.com>
2018-02-05 17:37:46 -08:00
Olaoluwa Osuntokun
47dc2d3b70
server: grab the read-mutex within the main loop of the peerBootstrapper
A recent commit modified the mutex in the server to the read/write. In
order to further reduce contention, we’ll grab the read lock when we’re
examining get set of peers to ignore.
2018-01-28 14:50:25 -08:00
Olaoluwa Osuntokun
eddb8dae0c
Merge pull request #655 from cfromknecht/server-locking-improvments
Server: Reduce Contention due to Exclusive Locking
2018-01-26 12:18:27 -08:00
Olaoluwa Osuntokun
4f91b66c51
Merge pull request #467 from bcongdon/feature/customize-alias-and-color
cmd/lncli+lnd: Add alias and color customization
2018-01-24 16:48:36 -08:00
Conner Fromknecht
a514f7e6b0
server: improve server contention around mutex
This commit aims to reduce the contention on the server's primary
mutex by (1) replacing it with a RWMutex, and (2) not holding an
exclusive lock throughout the duration of the SendToPeer method.

For the latter, we now only have to hold a shared lock until all
messages have been queued, where as before an exclusive lock
was held until all messages had been acknowledged by the target
peer's write handler. Since the initial syncing of announcements
with peer now comprises a couple thousand messages on testnet,
these changes should help keep the server from deadlocking while
completing and long-lived syncing operations.
2018-01-23 19:14:20 -08:00
Olaoluwa Osuntokun
5df6704a9c
contractcourt: make synchronous chain watcher notifications optional
In this commit, we modify the way that notifications are dispatched
within the chainWatcher. Before we would *always* wait for an ack back
before we started to clean up he database state. This would at times
lead to deadlocks. To remedy this, we now allow callers to decide if
they want notifications to be sync or not. The only current caller that
requires this is the breach arbiter.
2018-01-22 19:19:58 -08:00
Olaoluwa Osuntokun
783f01e1c7
multi: fix linter warnings 2018-01-22 19:19:56 -08:00
Olaoluwa Osuntokun
bbca53507f
contractcourt: extend the ChainArbitratorConfig with IsOurAddress closure
In this commit, we add the IsOurAddress field into the config of the
chain arb. With this new function closure, the chain arb is able to
detect co-op on chain closes automatically.
2018-01-22 19:19:53 -08:00
Olaoluwa Osuntokun
a0cc1d1b2d
breacharbiter: utilize new channel on-chain event stream to watch for breaches
In this commit, we modify the breach arbiter to no longer require
holding a channel object directly in order to receive new notifications
about possible breaches. Instead, we’ll contact the chain arbiter to
request a new channel event subscription.

As a result of the new architecture, we no longer need to receive a
handoff once the new channel comes online, as the chainWatcher will
always be active and watching the channel until it’s been closed.
2018-01-22 19:19:50 -08:00
Olaoluwa Osuntokun
24a16b4f49
lnd: properly initialize entities of new contractcourt package 2018-01-22 19:19:42 -08:00
Benjamin Congdon
92ac81b3b0
lnd+server: Allow configurable Node Alias and Color
This commit sets the Node's Alias and Color to the values set in config.
2018-01-18 09:31:48 -06:00
Johan T. Halseth
84e5adcdd0
server: add min_htlc_msat parameter to OpenChannel method 2018-01-12 22:56:37 +01:00
Olaoluwa Osuntokun
882b1313ba Merge remote-tracking branch 'origin/pr/445' 2018-01-06 17:22:30 -08:00
Brian KimJohnson
000a83bc04 server: add bootstrap peers to persistent peers for conn retry
Peers are treated as transient by default. When a peer is disconnected,
no attempt is made to reconnect. However, if we have a channel open
with a peer that peer will be added as persistent. If a persistent peer
becomes disconnected then we will attempt to reconnect.

This behavior implies that a fresh node - those without any channels -
will fall off the network over time as remote nodes restart or due to
connectivity changes. This change marks bootstrap peers as persistent
and ensures that the node remains connected to those specific peers over
time. This does not keep the node connected in the case that all
bootstrap peers are down.

Fixes #451.
2018-01-06 17:21:49 -08:00
Conner Fromknecht
e86900b412
server: remove ChainIO dep from BreachConfig 2018-01-05 13:47:18 -08:00
Olaoluwa Osuntokun
702bf7be29
server: Broadcast now takes a set of peers to skip
In this commit, we modify the Broadcast to take a *set* of peers to
skip, rather than just a single peer. We make this modification as when
a new channel is discovered, it’s likely the case that we get the
announcement from several peers rather than a single peer. With this
change, we’ll ensure that the caller (who is aware of the set of
senders) is able to properly avoid wasting bandwidth by re-sending the
message to all peers that sent it to us originally.
2017-12-26 16:25:40 +01:00
Johan T. Halseth
db8b4cad4a
server: fix deadlock in sendToPeer at peer shutdown
This commit fixes a deadlock that could occur when
a peer disconnected during a call to sentToPeer. In
This particular case, a message would successfully
be queued, the peer would shutdown, and we would
block waiting for an error to be returned on the
message's error channel, which would deadlock.
This fixes that by also checking for peer shutdown.
2017-12-21 23:32:39 +01:00
Johan T. Halseth
2f926f1a47 server: add NotifyWhenOnline method to gossiper 2017-12-19 13:01:59 -06:00
Johan T. Halseth
8a79bbf383 server: return error from sendPeerMessages
This commit adds a return error to sendPeerMessages,
making it possible to observe if a message sent to
a peer fails or succeeds.
2017-12-19 13:01:59 -06:00
nsa
9fcb845bd2 server: use private parameter when opening channel 2017-12-17 18:35:34 -08:00
Conner Fromknecht
9713cd81fc
server: reorder short-circuit in peer termination watcher
This commit reorders logic in the peer termination
watcher such that we short circuit earlier if we
already have pending persistent connection requests.
Before, the debug statement may have indicated that
a reconnection was being attempted, even though it
may have exited before submitting the request to
the connection manager.
2017-12-13 15:21:57 -08:00
Olaoluwa Osuntokun
1121b0c48b
server+funding: fix bug where funding tx could have zero fees attached
In this commit, we fix an existing bug that would cause funding
transaction to be broadcast without any fees attached at all. This is
only an issue if the fee rate reported is extremely so, as can happen
on testnet. In this case, when we went to scale down to sat/weight, we
would return a value of zero due to integer division. If we went via
the EstimateFeePerWeight call directly, then it would've been detected.
However, we accept the fee/byte from the user directly on the command
line this wasn't being done.

To fix this, we'll now manually set the fee to a sane value, if it
returns a value that can't properly be scaled to fee/weight.
2017-12-12 17:47:39 -08:00
Olaoluwa Osuntokun
c57eda4c6d
server: set default color for self NodeAnnouncements 2017-12-02 18:38:20 -08:00
Olaoluwa Osuntokun
724adb158c
server: lookup DNS seeds directly by active chain's genesis hash
In this commit, we fix a bug that would cause the DNS seeds to be
*always* active regardless of which chain+network we were on. Before we
would look up the network in the reverseChainMap. However, if we were
on regtest or testate, then it would still (incorrectly) resolve to a
valid hash.

To remedy this, we now directly use the genesis hash of the current
active chain.
2017-12-02 18:05:52 -08:00
Olaoluwa Osuntokun
87840f215b
server: disable network bootstrapping for regtest 2017-11-30 22:07:06 -08:00
Olaoluwa Osuntokun
c986e52da7
funding+server: ensure we cancel all reservations when a peer disconnects
In this commit, we fix an existing issue that could at times cause an
inconsistent view between the set of total coins, and the set of segwit
coins in the wallet of the node. This could be caused by initiating a
funding flow, but then the funding negotiation breaking down somewhere
along the lines. In this case, us or the other peer will disconnect.
When we initiate funding flows, we lock coins exclusively, to ensure
that concurrent funding flows don’t end up double spending the same
coin. Before this commit, we wouldn’t ever unlock those coins. As a
result, our view of available coins would be skewed.

The walletbalance call would show all the coins, but when adding the
—witness_only flag, some coins would be missing, or gone all together.
This is because the former call actually scans the txstore and manually
tallies the amount of available coins, while the latter looks at the
sent of available outputs, which is filtered based on which coins are
locked.

To remedy this, we now ensure that when a peer disconnects, we wipe all
existing reservations which will return any locked outputs to the set
of available outputs for funding flows.
2017-11-26 14:08:53 -06:00
Olaoluwa Osuntokun
ad364ae9a1
chains+server: if not in simnet mode, use BtcdFeeEstimator 2017-11-23 23:10:12 -06:00
Olaoluwa Osuntokun
3c4a6f42fa
server: update OpenChannel to properly pass in custom funding fee 2017-11-23 23:10:09 -06:00
Conner Fromknecht
2b74a6549f
server: instantiate utxon with NurseryConfig 2017-11-16 16:16:04 -08:00
Laura Cressman
ed6ad22e85 config+server+networktest: make trickleDelay configurable
Add option to set trickleDelay for AuthenticatedGossiper in
command line, with default value of 300 milliseconds. Pass this
value to newServer, which uses it when creating a new instance of
AuthenticatedGossiper. Also set this value to 300 milliseconds when
creating nodes in integration tests.
2017-11-15 16:50:19 -08:00
Olaoluwa Osuntokun
d894917458
server: add new shouldRequestGraphSync method to gate third feature bit
In this commit, we add a new method shouldRequestGraphSync which the
server will use in order to determine if we should request a full
channel graph sync from a newly connected remote peer. Atm, we’ll only
request a full sync iff, we have less than two peers. This is only the
initial basic logic, as we’ll later extend this to be more
comprehensive.

With this change, we’ll no longer be blasted by full channel graph
dumps for _each_ new connection after we deem that we’ve been
sufficiently bootstrapped to the network.
2017-10-18 15:18:13 -07:00
Olaoluwa Osuntokun
56d4c15914
peer: add localFeatures as parameter to newPeer
In this commit we add the set of local features advertised as a
parameter to the newPeer function. With this change, the server will be
able to programmatically determine _which_ bits should be set on a
connection basis, rather than re-using the same global set of bits for
each peer.
2017-10-18 15:16:09 -07:00
Jim Posen
ee49cdd103 server: Respect the initial_routing_sync feature bit.
Only synchronize routing info with peer if they request it by setting
the appropriate local feature bit.
2017-10-17 22:47:20 -07:00
Jim Posen
9fd77a6e40 multi: Update lnd to use new feature vector API. 2017-10-17 22:47:20 -07:00
Olaoluwa Osuntokun
61be23dc31
htlcswitch+server: add new field SelfKey to htlcswitch.Config
This commit adds a new field to the switch’s Config, namely the public
key of the backing lightning node. This field will soon be used to
return more detailed errors messages back to the ChannelRouter itself.
2017-10-16 18:39:17 -07:00
Olaoluwa Osuntokun
9b0b945a3d
Revert "server: BroadcastMessage will no longer block until completion"
This reverts commit 6db90ef09ab974df0ff09aeaf75a3d80414d4f50.

The root cause was fixed by commit
f4e7c36c80e8e2be9edb78b3b317c69d28d6d78f. As a result, this commit is no
longer needed.
2017-10-16 14:54:30 -07:00
Olaoluwa Osuntokun
7300452225
Revert "server: make sendToPeer async"
This reverts commit b7704e2de3dc96a4aebc2f47908a8f9def1da7f6.

The root issue was fixed by commit
f4e7c36c80e8e2be9edb78b3b317c69d28d6d78f. As a result, this commit is no
longer needed.
2017-10-16 14:53:24 -07:00
Olaoluwa Osuntokun
b7704e2de3
server: make sendToPeer async
This commit removes another case of unnecessary blockage, by modifying
the sendToPeer method to be fully asynchronous. From the PoV of the
callers that utilize this method currently, there’s no reason to block
until the completion of this method. Additionally, as the graph grows
larger without more intelligent the number of messages sent during
initial dump will start to be prohibitive to waiting for full
completion before proceeding.
2017-10-14 17:07:08 -07:00
Olaoluwa Osuntokun
6db90ef09a
server: BroadcastMessage will no longer block until completion
In this commit, we make the BroadcastMessage method on the server more
asynchronous by abandoning the two wait groups that it used for
synchronization. It has been observed that a circular waiting loop
between the AuthenticatedGossiper and a peer’s readHandler can cause
the system to dead lock.

By removing this unnecessary synchronization, we avoid the deadlock
case and allow the gossiper itself to no longer block in this scenario.
2017-10-14 16:04:06 -07:00
Conner Fromknecht
7aa64d58da server: improves readibility of peer connection logic 2017-10-13 16:12:31 -07:00
Conner Fromknecht
96ff63d219 server: fixes race condition during unexpected peer disconnect 2017-10-13 16:12:31 -07:00
Olaoluwa Osuntokun
63838f5764
peer+server: use new sphinx package and htlcswitch package type names 2017-10-10 22:19:21 -07:00
Olaoluwa Osuntokun
e5c303375b
server: in peerBootstrapper check for enough conns before attempting backoff
In this commit we modify the main loop within the peerBootstrapper
slightly to check for a sufficient amount of connections, _before_
checking to see if we need to back off the main loop. With this, we
avoid unnecessarily backing off unless an actual error occurs.
2017-10-10 22:19:13 -07:00
Olaoluwa Osuntokun
3b7855e449
routing: implement 2-week zombie channel pruning
This commit implements 2-week zombie channel pruning. This means that
every GraphPruneInterval (currently set to one hour), we’ll scan the
channel graph, marking any channels which haven’t had *both* edges
updated in 2 weeks as a “zombie”. During the second pass, all “zombie”
channel are removed from the channel graph all together.

Adding this functionality means we’ll ensure that we maintain a
“healthy” network view, which will cut down on the number of failed
HTLC routing attempts, and also reflect an active portion of the graph.
2017-10-04 20:46:09 -07:00
Brandon
3907ae65c2 routing+discovery: implement 2-week network view pruning 2017-10-04 20:40:21 -07:00
Olaoluwa Osuntokun
32508344db
server: use Debugf instead of Debug for logging in peerBootstrapper 2017-10-04 16:58:57 -07:00
Olaoluwa Osuntokun
c8226b1393
server: fix logging statement in peerBootstrapper
This commit fixes an incorrect logging statement within the
peerBootstrapper goroutine. We we’re using a Debug method previously
when we should’ve been using Debugf in order to properly pass the
logging statement through.
2017-10-04 14:52:54 -07:00
John Griffith
54c4fc4559 htlcswitch+server: pass onion error to ChannelRouter 2017-10-02 22:12:50 -07:00
Johan T. Halseth
4b4c431d67
server: add NotifyWhenOnline method.
This commit adds a listener queue for each peer, that can be used
to queue listeners that will be notified when the targetted peer
eventually comes online.
2017-10-02 13:29:51 +02:00
Olaoluwa Osuntokun
bd63e048d8
server: remove stray logging debugging statement from peerBootstrapper 2017-09-25 11:06:47 -07:00
Conner Fromknecht
e32d3024ae
server: instantiate breacharbiter using BreachConfig 2017-09-19 19:18:20 -07:00
Olaoluwa Osuntokun
8a208ae3cd
server: disable bootstrapping for simnet mode by default 2017-09-12 22:13:52 +02:00
Olaoluwa Osuntokun
fe0a7b6a09
multi: fix linter errors 2017-09-03 17:05:11 -07:00
Olaoluwa Osuntokun
1196c2e254
server: introduce new peerBootstrapper goroutine to seed initial conns
This commit adds a new primary goroutine to the server struct:
peerBootstrapper. If peer boostrapping isn’t disabled in the config,
this new goroutine will be launched to attempt to establish a set of
initial connections for a new node. The logic is pretty straight
forward: first a set of initial connections is attempted, if after our
first epoch, we don’t have enough connections yet, then we’ll attempt
to query for an additional set. In each iteration, if we haven’t been
successful, then we increase our exponential backoff in order to not
spam any of our bootstrapping sources.
2017-09-03 16:58:21 -07:00
Olaoluwa Osuntokun
2eb718e177
server: populate gossiper with chainhash of active chain 2017-09-03 16:41:43 -07:00
Olaoluwa Osuntokun
c09713ebd1
peer+server: rename discoverSrv to authGossiper 2017-08-22 00:53:25 -07:00
Olaoluwa Osuntokun
01b0ddf1c5
lnd+rpc: update RPC responses to convert mSAT to SAT 2017-08-22 00:52:56 -07:00
Olaoluwa Osuntokun
c4e43dbaa2
server: avoid nil pointer deference within OutboundPeerConnected 2017-08-15 17:49:35 -07:00
Olaoluwa Osuntokun
472d9967e5
server: fix some minor style deviations in new server code 2017-08-10 21:20:54 -07:00
Olaoluwa Osuntokun
bee7ed7758
server: re-introduce the quit channel to the server
This commit re-introduces the quit channel to the server as an upcoming
addition needs to synchronize its shutdown with the lifetime of the
server.
2017-08-10 21:19:00 -07:00
Olaoluwa Osuntokun
947544753f
server: use %x (hex encoding) when logging peer's pub key 2017-08-10 21:17:07 -07:00
Conner Fromknecht
91d6b0492e server: refactors w/ single mutex and sync disconnect
This commit alters the synchronization patterns used in the server
  such that the internal state is protected by a single mutex.  Overall,
  this simplifies the ability to reason about the behavior and
  manipulation of the internal state, which has resolved a few of flakes
  related to race conditions that were observed before hand.

  Invoking DisconnectPeer is now fully synchronous, and waits until
  the provided peer's peerTerminationWatcher has exited before
  returning.  Currently this is done by tracking the watcher using the
  peer's WaitGroup, and locking until the peer has shutdown.

  The server's API has also been refactored such that all public methods
  are safe for concurrent use. Therefore, other subsystems should be
  sure to make use of these endpoints to avoid corrupting the internal
  state.
2017-08-10 16:14:01 -07:00
Johan T. Halseth
c497a63f14 server: return copy of current node announcement instead of ref 2017-08-08 12:29:27 -07:00
Olaoluwa Osuntokun
d38b4471c2
server: if a fresh announcement is requested, ensure seqno increases 2017-08-07 16:31:20 -07:00
Olaoluwa Osuntokun
43b736225b
multi: add new method to generate fresh node announcments 2017-08-04 18:32:33 -07:00
Olaoluwa Osuntokun
d39410cc01
rpc: wrap canceling a breach watch in a select case 2017-08-03 16:40:15 -07:00
Olaoluwa Osuntokun
c2aafe7e51
server: add a method to query if the server has started
This commit adds a new utility method to the server struct itself. This
method will allow callers to query the state of the server in order to
decide if the server has been started or not. This can be useful
elsewhere in the project as we start to decouple the lifetime of
certain sub-systems from others.
2017-08-02 20:56:34 -07:00
Johan T. Halseth
ebbe6d7a10 server: set HaveNodeAnnouncement=true for self LightningNode 2017-08-02 15:58:58 -07:00
Olaoluwa Osuntokun
07212588fc
funding: update funding workflow to adhere to BOLT-0002
This commit updates the main single-funder funding workflow within the
fundingManager (initiated via the rpcserver or by a message from a
connected peer) to fully adhere to the funding protocol outlined in
BOLT-0002.

The major changes are as follows:
  * All messages modified to use the new funding messages in BOLT-0002.
  * The initiator of a funding workflow no longer decides how many
confirmations must elapse before the channel can be considered open.
  * Rather than each side specifying their desired CSV delay, both
sides now specify the CSV delay for the _other_ party.
2017-07-30 17:51:57 -07:00
Olaoluwa Osuntokun
34bb0ec36f
server: within peerTerminationWatcher exit early if daemon is exiting 2017-07-30 17:51:41 -07:00
Olaoluwa Osuntokun
a04fa76a4c
lnwire+htlcswitch: minor grammatical, formatting fixes after error PR 2017-07-14 20:08:37 -07:00
Andrey Samokhvalov
79b8d26b1a htlcswitch+router+server: handle payment error topology updates
In previous commits we have intoduced the onion errors. Some of this
errors include lnwire.ChannelUpdate message. In order to change
topology accordingly to the received error, from nodes where failure
have occured, we have to propogate the update to the router subsystem.
2017-07-14 19:08:04 -07:00
Andrey Samokhvalov
6bbb7cbfc3 lnd: hook up encrypted onion error scaffolding
In this commit daemon have been changed to set the proper hooks in the
channel link and switch subsystems so that they could send and receive
encrypted onion errors.
2017-07-14 19:08:04 -07:00
Andrey Samokhvalov
ef73062c14 peer+server+htlcswitch: add reason to disconnnect function
In order to recognize exact reason of the disconnect the additional
field have been added in the disconnect function.
2017-07-14 19:08:04 -07:00
Olaoluwa Osuntokun
11f7a227ab
server: update to latest htlcswitch API changes 2017-06-17 00:10:22 +02:00
Olaoluwa Osuntokun
aec8c8dc77
lnd: decouple rpcServer from server, wait till chain synced before starting server
This commit overhauls the way that lnd is created with the goal of
ensuring the chain backends are fully synced up before the daemon
itself starts. The rpcServer has been slightly decoupled from the
server itself s.t we can start the rpcServer independently of the
server. This is required as we’ll now wait (unless we’re in simnet
mode) for the chain to fully sync up before we even _start_ any of the
server’s goroutines.
2017-06-05 19:22:12 -07:00
Olaoluwa Osuntokun
fb4121ba6c
server: Peers method now grabs data directly with read mutex
This commit modifies the Peers method on the server such that a caller
is able to query this method without the main serger goroutines
started. This is a small component in a larger change which will let us
start the RPC server independently of the server.
2017-06-05 19:15:22 -07:00
Olaoluwa Osuntokun
25dc294cf0
server: all references to primary interfaces are now through chainControl 2017-06-05 18:53:37 -07:00
Andrey Samokhvalov
c4955258f1 htlcswicth: start use htlcswitch and channel link inside lnd
In current commit big shift have been made in direction of unit testable
payments scenarios. Previosly two additional structures have been added
which had been spreaded in the lnd package before, and now we apply
them in the lnd itself:

1. ChannelLink - is an interface which represents the subsystem for
managing the incoming htlc requests, applying the changes to the
channel, and also propagating/forwarding it to htlc switch.

2. Switch - is a central messaging bus for all incoming/outgoing htlc's.
The goal of the switch is forward the incoming/outgoing htlc messages
from one channel to another, and also propagate the settle/fail htlc
messages back to original requester.

With this abtractions the folowing schema becomes nearly complete:

abstraction
    ^
    |
    | - - - - - - - - - - - - Lightning - - - - - - - - - - - - -
    |
    | (Switch)		        (Switch)		  (Switch)
    |  Alice <-- channel link --> Bob <-- channel link --> Carol
    |
    | - - - - - - - - - - - - - TCP - - - - - - - - - - - - - - -
    |
    |  (Peer) 		        (Peer)	                  (Peer)
    |  Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
2017-05-31 11:06:08 -07:00
Olaoluwa Osuntokun
75858a604a
lnd: use a single instance of a FeeEstimator daemon-wide 2017-05-16 19:11:49 -07:00
bryanvu
abe2e502d5 lnwallet: add FeeEstimator interface, StaticFeeEstimator implementation
This commit adds the FeeEstimator interface, which can be used for
future fee calculation implementations. Currently, there is only the
StaticFeeEstimator implementation, which returns the same fee rate for
any transaction.
2017-05-15 20:26:11 -07:00
Olaoluwa Osuntokun
5fe3a5631d
server: eliminate possible initial connection churn by ignoring duplicate inbound conns
This commit fixes a bug that was introduced when the connection
handling was re-worked to properly handle the case of concurrent
connections being made. In certain cases after a successful initial
connection, a peer’s stray goroutine would still attempt to establish a
second outbound connection even though a connection had already been
established. This was properly handled by the connecting peer, but not
he receiving peer. This commit adds the additional logic to the
receiving peer to ensure that we properly handle this case.
2017-05-11 15:21:02 -07:00
Olaoluwa Osuntokun
a75439f56b
lnd: properly initialize ChannelRouter with FilteredChainView 2017-05-11 15:20:57 -07:00
Andrey Samokhvalov
8e4199ee92 discovery+server: make waiting proofs persistent
In this commit waiting proofs array have been replaced with persistant
boltd storage which removes the possibility for the half proof to be
lost during half proof exchange.
2017-05-05 17:02:49 -07:00
Olaoluwa Osuntokun
6429962d27
rpc: modify DisconnectPeer implementation to do all validation within rpcServer
This commit modifies the implementation of the new DisconnectPeer RPC
in the following ways:
   * all validation has moved from the server to the rpcserver
   * rather than iterating over _all_ channels, we now only check the
     peer’s channels
   * the disconnectPeerMsg now has a public key object
      * this allows us to also verify that the user submitted a valid
        pub key string
   * we now check if a peer was persistent when disconnecting so we can
     remove them from the persistent peer map
2017-05-05 16:02:20 -07:00
Olaoluwa Osuntokun
98adeb6657
server: properly add user initiated persistent conns to persistentPeers map
This commit fixes a prior bug wherein if a user connected to a peer
using the —perm command, then once the peer was disconnected, we
wouldn’t automatically connect to them.
2017-05-05 15:57:14 -07:00
afederigo
cf605c81ab lnd: add server calls for disconnecting peers
Issue: 139

This commit contains client-side and server-side functionality
for disconnecting peers. rpc-client calls server side method and sends
message with pubKey.
2017-05-05 14:24:25 -07:00
Olaoluwa Osuntokun
f335250512
server: fix regression in handling persistent connection requesrts
This commit fixes a bug that was introduced when the concurrent
connection handling logic was re-written: if we don’t properly add the
persistent outbound connection to the persistent conn reqs map. The fix
is easy: add the pending conn req to the proper map.
2017-05-04 17:40:49 -07:00
Olaoluwa Osuntokun
e1152148b7
server: only attempt to reconnect to peer if connection not pending
This commit fixes a bug that would possibly result in tens of goroutine
beaching launched in an attempt to persistently connect to a peer. This
bug has been fixed by ensuring that we’ll only launch a new pending
connection attempt if we don’t already have one pending.
2017-05-04 17:39:08 -07:00
Olaoluwa Osuntokun
4cb76071a2
server+peer: re-write persistent connection handling
The prior methods we employed to handle persistent connections could
result in the following situation: both peers come up, and
_concurrently_ establish connection to each other. With the prior
logic, at this point, both connections would be terminated as each peer
would go to kill the connection of the other peer. In order to resolve
this issue in this commit, we’ve re-written the way we handle
persistent connections.

The eliminate the issue described above, in the case of concurrent peer
connection, we now use a deterministic method to decide _which_
connection should be closed. The following rule governs which
connection should be closed: the connection of the peer with the
“smaller” public key should be closed. With this rule we now avoid the
issue described above.

Additionally, each peer now gains a peerTerminationWatcher which waits
until a peer has been disconnected, and then cleans up all resources
allocated to the peer, notifies relevant sub-systems of its demise, and
finally handles re-connecting to the peer if it's persistent. This
replaces the goroutine that was spawned in the old version of
peer.Disconnect().
2017-04-23 19:58:03 -07:00
Olaoluwa Osuntokun
fe3c90362e
server: move establishment of persistent connections to Start() 2017-04-23 19:21:35 -07:00
Olaoluwa Osuntokun
920fcf3392
lnwire: modify newAlias to no longer return an error 2017-04-19 14:59:22 -07:00
Olaoluwa Osuntokun
d74d3fa0f3
server: initialize temp chan ID seed, add new FindChannel func for fundingMgr 2017-04-16 15:40:01 -07:00
Olaoluwa Osuntokun
7ac50b060e
rpc: re-write GetNetworkInfo implementation to use single db transaction
This commit re-writes the GetNetworkInfo implenetaiton to use a single
database transaction. We’re now able to do this due to the recent
change in the API for the ChannelGraph struct and it’s related objects.
The recent change allows the passed callback to accept a db
transaction, with this, the callback is now able to issue another
traversal routine _within_ the prior one.
2017-04-14 13:18:02 -07:00
Olaoluwa Osuntokun
eb37dba3f6
funding: modify fundingManager config to use SignMessage for ann's
This commit modifies the fundingManager config to use the a SignMesage
function rather than two distinct functions for singing one half the
channel announcement proofs. This change unifies the signing of
messages under a single abstraction: the MessageSigner interface.
2017-04-14 11:17:48 -07:00