Commit Graph

137 Commits

Author SHA1 Message Date
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
Olaoluwa Osuntokun
d93e3e6fbe
server: assume default port if one not present for --externalip 2017-04-13 14:41:58 -07:00
Olaoluwa Osuntokun
a22ba92630
server: eliminate possibly deadlock, peerConnected now async
This commit eliminates a possible deadlock (or repeated peer connection
failures) that can arise due to the [inbound|outbound]PeerConnected
methods holding the peer mutex too long. We now alleviate this
concurrency issue by calling s.peerConnected in an asynchronous manner.
This is safe as all operations within the method are themselves
goroutine-safe.
2017-04-11 22:02:06 -07:00
Olaoluwa Osuntokun
ca053e5273
multi: minor coding style and comment clean ups post-discovery merge
This commit implements some minor coding style, commenting and naming
clean up after the recent major discovery service was merged into the
codebase.

Highlights of the naming changes:
* fundingManager.SendToDiscovery -> SendAnnouncement
* discovery.Discovery -> discovery.AuthenticatedGossiper

The rest of the changes consist primary of grammar fixes and proper
column wrapping.
2017-04-01 20:14:05 +02:00
Andrey Samokhvalov
d4055d7830 discovery+funding: add validation of the announcement messages
Add validation functions and include validation checks in the
annoncement process function.
2017-03-29 19:49:05 -07:00
Andrey Samokhvalov
fbf766e3c6 discovery+funding: add 'AnnounceSignature' proof exchange
Add the interaction between nodes of announce signature messages, which
will allow us to exhcnage the half channel announcemen proofs later.
2017-03-29 19:49:05 -07:00
Andrey Samokhvalov
4c52b6e6a4 lnd: replace 'routing' with 'discovery' package
Add usage of the 'discovery' package in the lnd, now discovery service
will be handle all lnwire announcement messages and send them to the
remote party.
2017-03-29 19:49:05 -07:00