Commit Graph

19 Commits

Author SHA1 Message Date
BitfuryLightning
327768f4ad routing: Move tools inside lnd. Refactor and delete unneeded stuff
Use [33]byte for graph vertex representation.
Delete unneeded stuff:
1. DeepEqual for graph comparison
2. EdgePath
3. 2-thread BFS
4. Table transfer messages and neighborhood radius
5. Beacons

Refactor:
1. Change ID to Vertex
2. Test use table driven approach
3. Add comments
4. Make graph internal representation private
5. Use wire.OutPoint as  EdgeId
6. Decouple routing messages from routing implementation
7. Delete Async methods
8. Delete unneeded channels and priority buffer from manager
9. Delete unneeded interfaces in internal graph realisation
10. Renamed ID to Vertex
2016-11-23 20:37:43 -06:00
Andrey Samokhvalov
5b9e4ae61e general: fix typos, rename variables, add comments 2016-11-23 20:02:29 -06:00
Olaoluwa Osuntokun
4fe23a8b3e
lnd: switch over to using brontide for p2p connections
This commit modifies the existing p2p connection authentication and
encryption scheme to now use the newly designed ‘brontide’
authenticated key agreement scheme for all connections.

Additionally, within the daemon lnwire.NetAddress is now used within
all peers which encapsulates host information, a node’s identity public
key relevant services, and supported bitcoin nets.
2016-10-27 19:49:17 -07:00
Olaoluwa Osuntokun
517255fdb1
test: rename CT to harnessTest, ensure all RPC's get distinct timeouts
This commit slightly modifies the existing CT struct in order to
maintain consistency with code-style. As a result of the name change,
all references have also been renamed from `ct` to `t`.

The Error and Errorf methods have been removed in favor of forcing
everything to be reported via `Fatalf`. Additionally a new method
(ProcessErrors) has been introduced to the networkHarness class in
order to encapsulate the underlying channel.
2016-10-23 19:27:24 -07:00
Olaoluwa Osuntokun
180d0aeb96
htlcswitch: fix link deletion bug with multiple open channels
This commit fixes a bug in the htlcSwitch’s logic to unregister links
after a peer has signaled that a channel has been closed. This bug
would arise when multiple channels were opened with a single peer, and
any of the channels were attempted to be closed. The cause of the bug
was that the slice reference within the map wasn’t previously updated
with the re-slicing to truncate the (duplicated, unneeded) element from
the slice. By updating the map’s reference directly, we fix this
behavior.

The safe handling of adding/removing links/interfaces between the
htlcSwitch’s two goroutines has sprawled a bit, and can be hard to
follow due to the map usage. In the future this section of the code
will be cleaned up and the redundant indexes removed.
2016-10-16 15:37:50 -07:00
Olaoluwa Osuntokun
f1d0b75b9d
routing: purge closed channels from the routing table
This commit properly removes any/all closed channels from the routing
table. In the current implementation individual links (channels)
between nodes are treated sparely from the PoV of the routing table. In
the future, this behavior should be modified such that, the routing
table views all the links between nodes as a single channel. Such a
change will simplify the task of path finding as the links can simply
be viewed as a channel with the sum of their capacities. The link layer
(htlcSwitch) will handle the details of fragmentation on a local basis.
2016-09-26 10:35:16 -07:00
Olaoluwa Osuntokun
e29d8e7e06
lnd: add support for multi-hop (Sphinx) onion routed payments
This commit adds full support for multi-hop onion routed payments
within the daemon.

The switch has been greatly extended in order to gain the functionality
required to manage Sphinx payment circuits amongst active links. A
payment circuit is initiated when a link sends an HTLC add to the
downstream htlcSwitch it received from the upstream peer. The switch
then examines the parsed sphinx packet to set up the clear/settle ends
of the circuit. Created circuits can be re-used amongst HTLC payments
which share the same RHash.

All bandwidth updates within a link’s internal state are now managed
with atomic increments/decrements in order to avoid race conditions
amongst the two goroutines the switch currently uses.

Each channel’s htlcManager has also been extended to parse out the
next-hop contained within Sphinx packets, and construct a proper
htlcPkt such that the htlcSwitch can initiate then manage the payment
circuit.
2016-09-21 19:49:14 -07:00
Olaoluwa Osuntokun
80b09f7d6f
lnd: properly execute force closures kicked off via RPC
This commit includes some slight refactoring to properly execute force
closures which are initiated by RPC clients.

The CloseLink method within the htlcSwitch has been extended to take an
additional parameter which indicates if the link should be closed
forcefully. If so, then the channelManager which dispatches the request
executes a force closure using the target channel state machine. Once
the closing transaction has been broadcast, the summary is sent to the
utxoNursery so the outputs can be swept once they’re mature.
2016-09-12 19:07:43 -07:00
Olaoluwa Osuntokun
366d076eda
lnd: properly initialize the htlcSwitch's quit channel 2016-09-01 19:13:13 -07:00
Olaoluwa Osuntokun
832fd248cd
lnd: add async updates for [open|close]channel RPC's
This commit modifies the internal workflow for opening or closing a
channel in order to create a path in which RPC clients can receive
updates. Updates are now communicated via channels from the goroutines
spawned by the RPC server to process the request, and the sub-system
within the daemon that actually executes the request.

With this change clients can now receive updates that the request is
pending (final message has been sent to the target client), or that the
request has been completed. Confirmation related updates have not yet
been implemented as that will require some changes to the ChainNotifier
interface.
2016-08-30 16:53:07 -07:00
Olaoluwa Osuntokun
4e416da4cd
htlcswitch: properly update channel bandwidth after payment recv
This commit fixes an omission within the htlcSwitch. With this commit,
a channels bandwidth is now properly updated once an incoming HTLC is
settled.

This also fixes a bug where if a node received a payment, it wouldn’t
be able to then utilize the newly available bandwidth to send further
payments.
2016-08-25 16:30:28 -07:00
Olaoluwa Osuntokun
c0614c0478
lnwallet: add basic tests for cooperative channel closure
This commit adds a basic test for cooperative channel closure. The
current test ensures correctness of the cooperative closure procedure
initiated by either the channel initiator, or the channel responder.
2016-07-27 11:32:35 -07:00
Olaoluwa Osuntokun
82ea6ebf78
lnd: eliminate deadlock bug between htlcSwitch and htlcManager
This commit fixes a concurrency bug between the server’s htlc switch,
and an instance of a peer’s active htlc manager goroutine.

The deadlock condition was triggered when the htlc manager’s downstream
`htlcPacket` channel was full, causing the htlcSwitch’s main loop to
block on a send while the htlcManager was attempting to send a packet
to the switch for forwarding. This scenario created a circular
dependency resting in a deadlock.

The fix for this bug is relatively straight forward, if the destination
interface is found when handling an outgoing payment, then a new
goroutine is spawned to complete the request.
2016-07-24 17:06:19 -07:00
Olaoluwa Osuntokun
979b43a3b8
lnd: add log ticker to htlcSwitch, log metrics before forwarding
This commit adds a ticker which attempts to print the total volume
sent/recv over the last 10 seconds if any updates took place during
that interval.

Additionally, when selecting a link to forward an htlcPacket insert a
break after selection in order to properly terminate the loop.
2016-07-21 16:21:33 -07:00
Olaoluwa Osuntokun
6283eb29bf
lnd: add synchronization to RPC initiated HTLC payments
With this commit, calls to htlcSwitch.SendHTLC() are now synchronous,
only returning after the payment has been fully settled. This will
allow one to accurately measure the commitment update speed with the
current state machine implementation which is missing a number of
low-hanging optimizations.

The htlcManager for each channel now keeps a map of cleared HTLC’s
keyed by the index number of the add entry within the state machine’s
HTLC log. This map of HTLC’s will later be used to properly implement
time outs

Additionally, a slight refactoring has been executed w.r.t handling
upstream/downstream messages. This cleans up the main htlcManager loop,
freeing it up for the addition of future logic to properly observe
timeouts as well as, proper batching+trickling of HTLC updates, and a
commitment signature ticker.
2016-07-16 18:21:01 -07:00
Olaoluwa Osuntokun
5912322995
lnd: unregister to htlcSwitch with nil chanPoint deletes all inks for interface 2016-07-13 16:35:52 -07:00
Olaoluwa Osuntokun
af7cfd6c8b
lnd: add basic HtlcSwitch logic for forwarding L2 payments 2016-07-12 17:40:39 -07:00
Olaoluwa Osuntokun
2dd662837e
lnd: introduce the HtlcSwitch service within daemon
This commit introduces the HtlcSwitch service into the daemon. The
purpose of the switch is to manage the message passing between the
goutiness within he peer managing each active channel. The switch
treats connected peers as interfaces, and their active channels as
links. All multi-hop, single-hop, and channel closure orchestration
will be managed by various goroutines within the HtlcSwitch.

The HtlcSwitch will also serve as the L2 contact point between the
yet-to-be-written LightningRouter and the switch, forwarding the new
htlc packet on the proper interface. Additionally, the switch will
handle dispatching htlc’s created locally via RPC, and multi-hop
forwarding initiated by peers.
2016-07-09 16:35:45 -07:00
Olaoluwa Osuntokun
1188fd2bf6
lnd: implement open+close channel workflow in daemon
This commit adds the necessary plumbing within the server, peer, and
rpcServer to handle opening and cooperatively closing a channel with a
remote peer.

Many new data structures have been added to the peer in order to allow
it to efficiently manage opening+.losing new/existing lightning
channels. Additional documentation has been added to several methods
within the peer struct, with some minor renaming along with way. The
peer has also gained a dedicated goroutine whose job it is to manage
any requests pertaining to opening, or closing any channels with the
remote peer.

The messages have been added to lnrpc define the requests and responses
to channel open+close messages. Additional channel logic has been added
between the rpcServer, peer, and server in order to properly manage the
necessary synchronization.
2016-06-21 13:14:05 -07:00