Commit Graph

238 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun 906c0451c8
peer: check for existence of channel when handling a remote close
This commit patches a bug in the code for handling a remote cooperative
channel closer. Previous if the region node didn’t know of the channel
which was being requested to close, then a panic would occur as the
entry read from the map would be nil.

To fix this bug, we now ensure that the channel exists before we
perform any actions on it. In a later commit which overhauls the
channel opening and closing to match that of the specification, this
logic will be modified to properly send an error message in response to
the failed channel closure.
2017-02-07 16:49:04 -08:00
Olaoluwa Osuntokun 8c059631df
peer+server: ensure the remote TCP connection is always closed 2017-02-06 15:05:07 -08:00
Olaoluwa Osuntokun f4b403679b
lnwallet: remove BlockChainIO as a dependency to LightningChannel
This commit removes the BlockChainIO interface as a dependency to the
LightningChannel struct as the interface is no longer used within the
operation of the LightningChannel.
2017-02-02 17:05:40 -08:00
Olaoluwa Osuntokun 4eebc7c994
peer: refactor the queueHandler to aggressively drain queue
This commit refactors the queueHandler slightly to be more aggressive
when attempting to drain the pending message queue.

With this new logic the queueHandler will now attempt to _completely_
drain the pendingMsgs queue by sending it all to the writeHandler
_before_ attempting to accept new messages from the outside
sub-systems. The previous queueHandler was a bit more passive and would
result in messages sitting the the pendingMessage queue longer than
required.
2017-02-01 17:02:03 -08:00
Olaoluwa Osuntokun 6333dfea8f
peer: fix memory alignment for integers used atomically on 32-bit archs
This commit fixes a panic that can occur on 32-bit systems to the
misalignment of a int64/uint64 that’s used atomically using the atomic
package. To fix this issue, we now move all int64/unit64 variables that
are used atomically to the top of the struct in order to ensure
alignment.

Cleaning up some dead-code, satoshisSent/satoshisReceived have been
removed as they aren’t currently used. Instead those values are
accessed directly from the channel themselves.
2017-01-30 00:53:17 -08:00
Olaoluwa Osuntokun 3c5a23b2c1
peer: estimate RTT to peer using the ping and pong messages
This commit enhances the peer struct slightly be attempting to measure
the ping time to the remote node based on when we send a ping message
an dhow long it takes for us to receive a pong response.

The current method used to measure RTT is rather rough and could be
make much more accurate via the usage of an EMA/WMA and also via
attempting to measure processing time within the readMessage and
writeMessage functions.
2017-01-25 18:21:01 -08:00
Olaoluwa Osuntokun 9906e07087
peer: correct logging messages (to:writeMessage, from:readMessage) 2017-01-24 17:49:17 -08:00
Olaoluwa Osuntokun 019edc9035
peer: display the src peer when logging read error 2017-01-23 20:33:29 -08:00
Olaoluwa Osuntokun 97bb8744c4
peer: fix logging message when receiving updates for unknown channel
The previous logging message was broken as that target chanpoint was
being overshadowed by the local variable declaration. The new logging
message will properly print the unknown channel point as well as the
peer who sent the message.
2017-01-22 14:37:08 -08:00
Olaoluwa Osuntokun 8c4b5ae0fc
peer: increase ping interval to 1 minute 2017-01-22 14:35:32 -08:00
Trevin Hofmann 40c7bac3aa multi: fix a variety of typos throughout the repo 2017-01-17 17:02:56 -08:00
Olaoluwa Osuntokun f82d957c90
lnwire+peer: introduce new error for unknown message type for forward compat
This commit adds a new error type to the `lnwire` package:
`UnknownMessage`. With this error we can catch the particular case of a
an error during reading that encounters a new or unknown message. When
we encounter this message in the peer’s readHandler, we can now
gracefully handle it by just skipping to the next message rather than
closing out the section entirely.

This puts us a bit closer to the spec, but not exactly as it has an
additional constraint that we can only ignore a new message if it has
an odd type. In a future release, we’ll modify this code to match the
spec as written.
2017-01-16 18:03:43 -08:00
Olaoluwa Osuntokun d884efea29
lnwire+lnd: Make Logging Messages Great Again
This commit modifies the login of sent/recv’d wire messages in trace
mode in order utilize the more detailed, and automatically generated
logging statements using pure spew.Sdump.

In order to avoid the spammy messages due to spew printing the
btcec.S256() curve paramter within wire messages with public keys, we
introduce a new logging function to unset the curve paramter to it
isn’t printed in its entirety. To insure we don’t run into any panics
as a result of a nil pointer defense, we now copy the public keys
during the funding process so we don’t run into a panic due to
modifying a pointer to the same object.
2017-01-14 17:52:18 -08:00
Olaoluwa Osuntokun 8cdb84c619
lnd: add new "perm" bit to the ConnectPeer RPC call
This commit modifies the ConnectPeer RPC call and partitions the
behavior of the call into two scenarios: the connection should be
persistent which causes the call to be non-blocking, and the connection
should only attempt to connect once — which causes the call to be
blocking and report any error back to the caller.

As a result, the pendingConnRequest map and the logic around it is no
longer needed.
2017-01-09 19:09:03 -08:00
Olaoluwa Osuntokun 6bd0e068c6
peer+htlcswitch: add support for multi-hop HTLC error propagation
This commit adds a critical capability to the daemon: proper handling
of error cases that occur during the dispatch and forwarding of
multi-hop payments.

The following errors are now properly handled within the daemon:
    * unknown payment hash
    * unknown destination
    * incorrect HTLC amount
    * insufficient link capacity

In response to any of these errors, an lnwire.CanceHTLC message will be
back propagated from the spot of the error back to the source of the
payment. In the case of a locally initiated HTLC payment, the error
will be propagated back to the client which initiated the payment.

At this point, proper encrypted error replies as defined within the
spec are not yet implemented and will be fully implemented within a
follow up PR.
2017-01-07 21:22:17 -08:00
Olaoluwa Osuntokun 594dc1b163
lnd: switch to the version of the connmgr in roasbeef's fork 2017-01-05 13:58:11 -08:00
Olaoluwa Osuntokun 5affed38fc
multi: update btcsuite API's to latest upstream changes
This commit makes a large number of minor changes concerning API usage
within the deamon to match the latest version on the upstream btcsuite
libraries.

The major changes are the switch from wire.ShaHash to chainhash.Hash,
and that wire.NewMsgTx() now takes a paramter indicating the version of
the transaction to be created.
2017-01-05 13:56:34 -08:00
Olaoluwa Osuntokun b991cd3d78
multi: allow force channel closures while not connected to peer
This commit adds a much needed feature to the daemon, namely the
ability to force close a channel while the source daemon doesn’t have
an active connection to the counter party. Previously this wasn’t
possible as ALL channel closures were routed through the htlcSwitch
which is only able to trigger a channel closure if the peer is online.

To remedy this, if the closure type is “force” then, we now handle the
channel closure and related RPC streaming updates from the call handler
site of the RPC itself. As a result, there are now only two htlcSwitch
channel closure types: breach, and regular. The logic that’s now in the
rpcSever should likely be refactored into a distinct sub-system, but
getting the initial functionality in is important.

Finally, the channel breach integration test has been modified to skip
connection the peers before attempting the forceful channel closure of
a revoked state as the remote peer no longer needs to be online.
2017-01-03 16:04:47 -08:00
Olaoluwa Osuntokun 3e1c98f2f7
breacharbiter: accept handoff for live channel on peer connect
This commit modifies the interaction between the breachArbiter and the
peer struct such that the breachArbiter _always_ has the latest version
of a contract.

Prior to this commit once we connected out to a peer which we had an
active contract with and the breachArbiter was watching, we’d have two
copies of the channel in memory, instead of just a single one. This was
wasteful and caused some duplicated log messages due to two instances
of the channel being active.
2016-12-27 16:45:05 -08:00
Olaoluwa Osuntokun c965eda29e
lnd: fully integrate the ChannelRouter of the new routing package
This commit fully integrates the ChannelRouter of the new routing
package into the main lnd daemon.

A number of changes have been made to properly support the new
authenticated gossiping scheme.

Two new messages have been added to the server which allow outside
services to: send a message to all peers possible excluding one, and
send a series of messages to a single peer. These two new capabilities
are used by the ChannelRouter to gossip new accepted announcements and
also to synchronize graph state with a new peer on initial connect.

The switch no longer needs a pointer to the routing state machine as it
no longer needs to report when channels closed since the channel
closures will be detected by the ChannelRouter during graph pruning
when a new block comes in.

Finally, the funding manager now crafts the proper authenticated
announcement to send to the ChannelRouter once a new channel has bene
fully confirmed. As a place holder we have fake signatures everywhere
since we don’t properly store the funding keys and haven’t yet adapted
the Signer interface (or create a new one) that abstracts out the
process of signing a generic interface.
2016-12-27 16:44:31 -08:00
Olaoluwa Osuntokun 326c62c6b5
peer: ensure queueMsg won't create deadlock if peer shutting down
This commit adds some additional measures to ensure that a call to
queueMsg while the peer is shutting down won’t result in a potential
deadlock.

Currently, during shutdown the outgoingQueue channel is attempted to be
cleared by he writeHandler, however adding an additional select
statement serves as a mother layer of defense from nasty dead locks.
2016-12-27 16:43:14 -08:00
Olaoluwa Osuntokun bd89a9312d
lnd: switch to using the connmgr for listening and persistent conns
This commit revamps the way in bound and outbound connections are
handled within lnd. Instead of manually managing listening goroutines
and also outbound connections, all the duty is now assigned to the
connmgr, a new btcsuite package.

The connmgr now handles accepting inbound (brontide) connections and
communicates with the server to hand off new connections via a
callback. Additionally, any outbound connection attempt is now made
persistent by default, with the assumption that (for right now),
connections are only to be made to peers we wish to make connections
to. Finally, on start-up we now attempt to connection to all/any of our
direct channel counter parties in order to promote the availability of
our channels to the daemon itself and any RPC users.
2016-12-14 18:15:55 -08:00
Olaoluwa Osuntokun 89326423dc
peer+htlcswitch: fix bandwidth update bug when using --debughtlc
This commit fixes a htlcSwitch bandwidth update bug that would manifest
when two sending daemons were started with the —debughtlc flag. The
invoice created for the debug HTLC has a value of 1000BTC. As a result
regardless of the amount sent, the switch’s state which be updated to
reflect that the daemon had just received a 1000BTC transfer.

To fix this bug, we now use the value of the HTLC itself for the
update, rather than the value if the invoice as they should match.
2016-12-14 18:04:13 -08:00
Andrey Samokhvalov d01f1b5ff4 fundingmanager+lnwallet: add HTLC dust limit logic 2016-12-13 11:01:57 -08:00
Andrey Samokhvalov 5a82240c6a lnwire+lnwallet+fundingmanager: general improvements 2016-12-13 11:01:57 -08:00
Olaoluwa Osuntokun 494fcec874
breacharbiter: introduce new sub-system to watch for breaches
This commit introduces a new sub-system into the daemon whose job it is
to vigilantly watch for any potential channel breaches throughout the
up-time of the daemon. The logic which was moved from the utxoNursery
in a prior commit now resides within the breachArbiter.

Upon start-up the breachArbiter will query the database for all active
channels, launching a goroutine for each channel in order to be able to
take action if a channel breach is detected. The breachArbiter is also
responsible for notifying the htlcSwitch about channel breaches in
order to black-list the breached linked during any multi-hop forwarding
decisions.
2016-11-28 19:44:09 -08:00
Olaoluwa Osuntokun 93cbfdbd60
htlcswitch: add new CloseType enum to account for all closure types 2016-11-28 18:44:22 -08:00
Olaoluwa Osuntokun a5d9ce2fac
utxonursery: remove contract breach retribution duties
This commit removes the previously added contract breach retribution
duties from the utxoNursery. Much of the code removed will instead be
moved to a new sub-system which continuously monitors the state of ALL
active contracts for their entire life time.
2016-11-28 16:53:23 -08:00
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 da3028e10c lnwallet: add HTLC count validation 2016-11-23 20:02:29 -06:00
Andrey Samokhvalov 5b9e4ae61e general: fix typos, rename variables, add comments 2016-11-23 20:02:29 -06:00
Olaoluwa Osuntokun 31e65e3333
peer: add logic to dispatch justice after revoke state broadcast
This commit adds the necessary logic a peer’s htlcManger goroutine to
dispatch justice (sweeping all the funds in a channel) after it has
been detected that the counter-party has broadcast a prior revoked
commitment state.

The task to generate the justice transaction is handed off to the
utxoNursery. Once the nursery has finished its duty, the peer launches
a new goroutine which will delete the state of the channel once the
justice transaction has been confirmed within a block.
2016-11-21 13:32:25 -06:00
Olaoluwa Osuntokun d98cac432b
peer: ensure access to activeChannels and htlcManagers is thread safe 2016-11-17 18:43:51 -08:00
Olaoluwa Osuntokun 6e01bb72b0
lnwallet+peer: minor typo fixes 2016-11-14 15:06:17 -08:00
Olaoluwa Osuntokun a4023144d3
peer: notify routing manager of newly loaded channels 2016-11-10 17:41:31 -08:00
Olaoluwa Osuntokun 297133316f
peer: implement the ping/pong workflow
This commit refactors the peer struct slightly in order to implement
the new ping/pong workflow added in a prior commit. Pings are currently
sent every 30 seconds unconditionally.
2016-11-10 17:15:41 -08:00
Andrey Samokhvalov 8dcf274a2d fix typos 2016-10-30 17:54:59 +03:00
Olaoluwa Osuntokun f37956e38e
routing: update Sphinx API to include r-hash and per-hop-payload
This commit modifies both the Sphinx packet generation and processing
for recent updates to the API.

With the version 1 Sphinx specification, the payment hash is now
included in the MACs in order to thwart any potential replay attacks.
As a result, any attempts to replay previous HTLC packets MUST re-use
the same payment hash, meaning that the first-hop node can simply
settle the HTLC immediately, thwarting the attacker.

Additionally, within the Sphinx packet, each hop now gets a per-hop
payload which contains the necessary details (CTLV value, fee, etc) for
the node to successfully forward the payment. This per-hop payload is
protected by a packet-wide MAC.
2016-10-27 20:40:26 -07: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 ee593b273c
rpc: query the database instead of active peers for the ListChannel RPC
This commit takes advantage of the newly added
channeldb.FetchAllChannels method to return the state of all active
channels for the ListChannels RPC command. With this change the state
of all channels can now be queried regardless of if any/all the peers
are currently online.

In a future modification a bit will be added to the channel information
which indicates if the LinkNode the channel was created with is
currently online or not.
2016-10-26 15:09:11 -07:00
Olaoluwa Osuntokun 290ea7ba5d
lnd: update peer+fundingManager due to channeldb field rename 2016-10-25 16:44:18 -07:00
Olaoluwa Osuntokun e6394a0862
routing: fix bug introduced during switch to pubkeys in routing table
This commit fixes a bug which was introduced when the routing table was
switched over to store full pub keys rather then public key hashes. The
switch was change was required in order to properly support onion
routing within the daemon. During the change the source node vertex
when receiving a message wasn’t converted to use public keys instead of
pubkeyhashes. As a result, nodes would be blind to any topology related
updates sent by its neighbors.

This commit fixes the bug by setting the source node of the received
message to the serialized public key rather than the pubkeyhash.
2016-10-23 18:38:44 -07:00
Olaoluwa Osuntokun afae7aad2a
lnwire: add concrete error type to ErrorGeneric 2016-10-23 13:41:23 -07:00
Andrey Samokhvalov 7196c4bb1c fundingmanager: add max pending channel check 2016-10-22 02:15:35 +03:00
Andrey Samokhvalov 14c6770b76 general: fix typos 2016-10-22 01:48:05 +03:00
andrew.shvv e515710a7d multi: use witnessScript everywhere instead of redeemScript
This commit consists of a mass variable renaming to call the pkScript being executed for segwit outputs the `witnessScript` instead of `redeemScript`. The latter naming convention is generally considered to be reserved for the context of BIP 16 execution. With segwit to be deployed soon, we should be using the correct terminology uniformly through the codebase. 

In addition some minor typos throughout the codebase has been fixed.
2016-10-15 16:02:09 -07:00
Olaoluwa Osuntokun 7b953c9c61
rpcserver: add REST workarounds, implement new RPC calls
This commit adds a few workarounds in order to concurrently support the
REST proxy as well as the regular gRPC interface. Additionally,
concrete support for the following RPC calls has been added:
GetTransactions, SubscriptTransactions, SubscribeInvoices, and
NewWitnessAddress.
2016-10-15 14:42:25 -07:00
Olaoluwa Osuntokun cfdf3f3ab5
peer: send any pending HTLC settles when the commit timer ticks
This commit adds an additional clause to the update of the current
commitment state each time the commitTimer ticks. We now additional
check to see if we have any active HTLC’s to settle, triggering a state
update if so.

This case is needed due to the possibility of desynchronization across
commitment transactions. As an example if any HTLC adds are sent after
the remote node receives our ack-sig, then they may remain uncommitted
within our local commitment chain. The addition of this check solves
the issue by ensuring convergence towards a symmetric commitment state.
2016-09-26 10:39:52 -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 e1b82566bd
lnd: integrate Sphinx onion routing when sending/receiving HTLC's
This commit alters the send/receive HTLC pipe line a bit in order to
fully integrate onion routing into the daemon.

The server now stores the global Sphinx router which all active
htlcManagers will used when processing upstream HTLC add messages.
Currently the onion routing private key is static, and identical to the
node’s current identity public key. In the future this key will be
rotated daily the node based on the current block hash.

When sending a payment via the SendPayment RPC, the routing manager is
now queried for the existence of a route before the payment request is
sent to the HTLC switch. If a path is found, then a Sphinx onion packet
encoding the route is created, then populated within the HTLC add
message.

Finally, when processing an upstream HTLC add request, the sphinx
packet is decoded, then processed by the target peer. If the peer is
indicated as the exit node, then the HTLC is queue’d to be settled
within the next state update.
2016-09-21 19:49:03 -07:00
Olaoluwa Osuntokun 62271768b0
peer: ensures invoices are marked as settled after redemption 2016-09-21 19:48:59 -07:00
Olaoluwa Osuntokun 0c4293ba82
lnd: extend the invoiceRegistry to wrap on-disk invoices with an in-memory cache
This commit extends the existing invoiceRegistry functionality to wrap
the on-disk invoices available via the channeldb with an in-memory
cache on invoices. Currently the in-memory cache is only reserved for
the storage of special “debug” invoices which all nodes are able to
settle immediately.
2016-09-21 19:48:22 -07:00
Olaoluwa Osuntokun ff70b3afa9
lnd: avoid wiping a channel twice 2016-09-12 19:07:52 -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 d0353b2864
lnwallet: add ability to trigger a force closure within channel state machine
This commit introduces the concept of a manually initiated “force”
closer within the channel state machine. A force closure is a closure
initiated by a  local subsystem which broadcasts the current commitment
state directly on-chain rather than attempting to cooperatively
negotiate a closure with the remote party.

A force closure returns a ForceCloseSummary which includes all the
details required for claiming all rightfully owned outputs within the
broadcast commitment transaction.

Additionally two new publicly exported channels are introduced, one
which is closed due a locally initiated force closure, and the other
which is closed once we detect that the remote party has executed a
unilateral closure by broadcasting their version of the commitment
transaction.
2016-09-12 19:07:35 -07:00
Olaoluwa Osuntokun 0d871dabb3
lnd: modify the daemon's initialization to use new wallet API's 2016-09-08 12:26:07 -07:00
BitfuryLightning d8bceb16f9 routing: Fix bugs with not sending routing messages
LIGHT-138, LIGHT-141. Due to some issues in sending/receiving parts of lnd,
messages with zero length are not sent. So added some mock content to
NeighborAck. Moved sender/receiver from routing message to wrap message
which contains lnwire routing message.
2016-09-06 20:01:21 -04:00
Olaoluwa Osuntokun 1b682b0f40
lnd: update server initialization due to ChainNotifier changes
This commit modifies the daemon’s initialization within the `lndMain`
method to create an instance of the current default ChainNotifier
outside of the LightningWallet.

At this point, since there are no other implementations of the
ChainNotifier, the current concrete implementation BtcdNotifier is used
by default. In the future, once other ChainNotifier implementations are
in place, config parsing should be fed into a factory function which
creates the proper ChainNotifier implementation.

Finally, several imports have been updated to reflect the change in
package name.
2016-09-01 19:13:27 -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 4bc315d061
lnd: minor clean up with comments + go fmt after latest PR merge 2016-08-11 11:56:03 -07:00
BitfuryLightning f8c851769f multi: initial integration of routing module
This commit integrates BitFury's current routing functionality into lnd. The
primary ochestration point for the routing sub-system in the routingMgr. The
routingMgr manages all persistent and volatile state related to routing within
the network.

Newly opened channels, either when the initiator or responder are inserted into
the routing table once the channel is fully open. Once new links are inserted
the routingMgr can then perform path selection in order to locate an "optimal"
path to a target destination.
2016-08-11 11:20:27 -07:00
Olaoluwa Osuntokun fc16159a37
lnd: perform HTLC forwarding to switch in distinct goroutine
This commit optimizes the previous deadlock bug-fix within the peer’s
channelManager which handles driving the LCP state machine with
additional context-specific state.

Rather than forwarding to the HTLC switch within the primary loop which
handles fully locked-in HTLCs, we now launch a distinct goroutine which
is responsible for properly forwarding lock-in HTLC’s to the
htlcSwitch.
2016-08-03 11:29:24 -07:00
Olaoluwa Osuntokun adb23a366f
lnd: implement update pipelining and htlc trickling+batching
This commit *significantly increases* the payment throughput per-core,
per-channel of the daemon.

With this commit updates are properly pipelined respecting the current
revocation window, htlc updates are batched, a timer is checked to push
chain convergence, and htlc update below the batch size are
periodically flushed to the remote chain.

The current pending update timer, trickle timer, and batch size have
been arbitrarily chosen based on my local tests. In the future these
parameters should be chosen to optimize response-time and throughput
after measurements are gathered.
2016-07-21 17:10:49 -07:00
Olaoluwa Osuntokun c0a28e3b7f
lnd: buffer upstream/downstream channels for htlc managers 2016-07-21 16:53:15 -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 2a57f9182a
lndc+lnd: fix panic when connecting to multiple peers, plus duplicate conn detection 2016-07-16 18:01:05 -07:00
Olaoluwa Osuntokun 98fae7f329
lnd: properly disconnect peer and clean up resources after critical errors 2016-07-13 16:40:07 -07:00
Olaoluwa Osuntokun 496d1e8edc
lnd: manually set sig pending bit in commitment state machine
This commit fixes a class of bug which would trigger a never ending
loop of “null” commitment updates between two peers.
2016-07-13 16:31:50 -07:00
Olaoluwa Osuntokun 88949e181a
lnd: implement per-channel state-machine driver within peer
With this commitment, the daemon is now able to properly send+redeem
single-hop HTLC’s with another daemon running on the same network.

The htlcManager gains an additional channel which is reads from
receiving updates from either downstream peers, or the rpc server. An
htlcManager is spawned for each active channel with the remote peer. As
a result, the readHandler must now de-multiplex any messages which
update a known channel to the proper htlcManager.

Batching HTLC add updates with a trickle timer has not yet been
implemented, but will be in the near future along with several other
optimizations.
2016-07-12 17:45:36 -07:00
Olaoluwa Osuntokun 9b29fa3a52
lnd: use channel barriers to synchronize on-chain events and a peer's readHandler 2016-07-12 17:38:14 -07:00
Olaoluwa Osuntokun 4548e4497d
lnd: set up messaging chans between peer and htlcSwitch
Each active channel now gains its a dedicated htlcManager goroutine
which currently accepts to two golang channels, and a lightning
channel. The “downstream” channel will be used for dispatched multi-hop
payments sent from the htlcSwitch, while the “upstream” channel will be
used once the readHandler de-multiplexes hltc add/timeout/settle
messages.

Each time a new channel is fully created after N confirmations, the
peer’s channelManager registers the new link with the htlcSwitch. Once
the channel is closed either cooperatively or non-cooperatively, then
the link is unregistered.
2016-07-09 16:41:54 -07:00
Olaoluwa Osuntokun c0383679d2
lnd: use asynchronous streaming responses for [open|close]channel RPC's
This commit switches the implementation of the open/close channel RPC’s
from a fully blocking synchronous model to one that’s async by default,
allowing callers to add a sync wrapper.

The new proto specs also allow for “updates” for the pending channels
in the form of new confirmations which progress the pending status of
the channel. At this point, only the final open/close updates have been
implemented. Obtaining confirmation notifications requires a bit of
re-working within the current ChainNotifier interface, thus this has
been deferred to a later time.
2016-07-07 15:31:07 -07:00
Olaoluwa Osuntokun e61a03a372
lnd: add support for channel state snapshots in peer 2016-06-22 22:22:09 -07:00
Olaoluwa Osuntokun 2e706f39b9
lnd: delete channel state from db after close 2016-06-22 22:20:37 -07:00
Olaoluwa Osuntokun 7e09a70706
cmd/lncli: properly reverse user txid input
This commit fixes a bug introduced within a prior commit. The prior
commit failed to drollery reverse the txid string taken in as user
input, therefore in order to properly close a channel, the user needed
to manually reverse the txid themselves.

With this change, `wire.NewShaHashFromStr` is used which properly
reverses the string within the constructor. This allows the string
reported not be directly used to the close an active channel.

This commit also corrects a few logging messages.
2016-06-22 11:10:33 -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
Olaoluwa Osuntokun fcff17c336
multi: change all imports to roasbeef's forks
This commit will allow the general public to build lnd without jumping
through hoops setting up their local git branches nicely with all of
our forks.
2016-05-15 17:22:37 +03:00
Paul Capestany 3f74cee023 Address `go install` issues
Error messages:

peer.go:12:2: cannot find package "li.lan/labs/plasma/lnwallet"
peer.go:13:2: cannot find package "li.lan/labs/plasma/lnwire"
2016-01-17 19:14:47 -08:00
Tadge Dryja 9e5f302288 move lnadr from main to lndc package 2016-01-17 10:45:07 -08:00
Olaoluwa Osuntokun 4c8b10617a add lnAddr implementation to peer.go, finish peer draft
* With this commit, then initial draft of the peer struct is finished.
Items to still complete include the interaction between the peer and
internal wallet, version handshake, pings, etc.
2016-01-16 19:26:49 -08:00
Tadge Dryja 2815afebb7 update imports to github 2016-01-16 10:45:54 -08:00
Olaoluwa Osuntokun 0c304cbb2f Flesh out the peer handling skeleton within peer/server 2016-01-14 23:58:04 -08:00
Tadge Dryja 58f0bfe252 plasma daemon can connect, receive connections, and send chat msgs. 2016-01-14 23:56:10 -08:00
Olaoluwa Osuntokun baf3b70e31 plasma: correct commit with sketch of lnwire.Message interface 2015-12-20 21:47:00 -06:00
Olaoluwa Osuntokun f52f2fd26c plamas/peer: just use net.Conn for generality 2015-12-20 17:10:09 -06:00
Olaoluwa Osuntokun d5f36d81c8 plasma: rough draft of peer struct 2015-12-20 15:16:38 -06:00