Commit Graph

7250 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
80d38d6bbc
test: add network test case for repeated multi-hop invoice payments 2016-09-26 10:42:02 -07:00
Olaoluwa Osuntokun
bf0945a6bf
test: add test case for a simple one-hop invoice scenario 2016-09-26 10:41:05 -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
9bb917cd2a
test: add methods for connecting nodes, funding the wallet of nodes 2016-09-26 10:31:23 -07:00
Olaoluwa Osuntokun
50e7cbe3be
test: add ability to add additional nodes to the test network 2016-09-26 10:30:29 -07:00
Olaoluwa Osuntokun
d9c0e6653f
test: extract the identity pubkey of running lnd nodes into the lightningNode struct 2016-09-26 10:29:21 -07:00
Olaoluwa Osuntokun
301a9fea38
cmd/lncli: implementing parsing+display for list channels 2016-09-25 20:05:06 -07:00
Olaoluwa Osuntokun
7a6905d697
rpcserver: implement the ListChannels RPC 2016-09-25 20:04:10 -07:00
Olaoluwa Osuntokun
68c4f0432e
lnrpc: split off channel info from ListPeers into new ListChannels RPC
This commit extracts the channel information that was previously
returned within the ListPeers command to a new RPC command:
ListChannels. Additionally, any pending HTLC’s within the open channel
are also displayed.
2016-09-25 20:02:47 -07:00
Olaoluwa Osuntokun
0b841ec686
channeldb: store optional invoice fields as variable length byte arrays
This commit modifies the on-disk storage of invoices to stop the
optional fields (memo+receipt) on-disk as variable length byte arrays.
This change saves space as the optional fields now only take up as much
space as is strictly needed, rather than always being padded out to max
size (1KB).
2016-09-23 15:15:26 -07:00
Olaoluwa Osuntokun
6ff11ba65c
lnrpc: include the settled bit when listing and looking up invoices 2016-09-23 15:06:32 -07:00
Olaoluwa Osuntokun
62b37f45f5
channeldb: include in the invoice bucket when wiping and initializing the db 2016-09-23 15:06:06 -07:00
Olaoluwa Osuntokun
913504581d
chainntfns: eliminate dead lock possibility when dispatching notifications
This commit fixes a possible dead lock when dispatching notifications
caused by the circular communication between the notificationDisptcher
thread and the main notification thread within the btcrpcclient.

Rather than potentially blocking for eternity on a blocking send,
notifications are now instantly handled by appending the notification
on an unbounded queue then launching a goroutine to signal the
dispatcher thread that a new item is available within the queue.
2016-09-22 19:12:22 -07:00
Olaoluwa Osuntokun
7d0e1576ec
lnwire: remove the HTLC timeout msg in favor of a HTLC cancel msg
This commit removes the previous HTLC timeout in message in favor of a
HTLC cancel message. Within the protocol, a timeout message would never
be sent backwards along the route as in the case of an HTLC timeout
before/after the grace period, the course of action taken would be to
broadcast the current commitment transaction unilaterally on-chain.
2016-09-22 18:51:51 -07:00
Olaoluwa Osuntokun
e6ced8ee7a
test: ensure tests nodes are started with the debughtlc flag 2016-09-21 19:49:21 -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
17249316d6
rpcserver: use the first hop pubkey as the dest to the htlcSwitch
This commit modifies the sendpayment command slightly to use the pub
key of the *first* hop within the route as the destination within the
htlcPacket sent to the htlcSwitch.

Previously, since only single hop was implemented, the final
destination would be set within the htlcPkt, causing the route to fail
as the switch doesn’t have a direct link to the dest in the multi-hop
case.
2016-09-21 19:49:10 -07:00
Olaoluwa Osuntokun
9d5b0885d4
lnwallet/channel: add r-preimages to the PaymentDescriptor for settles 2016-09-21 19:49:07 -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
5402d705ab
build: update the glide files to include the sphinx package and pin the routing package 2016-09-21 19:48:56 -07:00
Olaoluwa Osuntokun
d34b90136f
cmd/lncli: the target destination for sendpayment must now be a compressed pubkey
This commit modifies the sendpayment message slightly to indicate that
the —dest value should be a hex-encoded compressed public key. This
change is required to stream line the integration of onion routing into
the daemon.
2016-09-21 19:48:53 -07:00
Olaoluwa Osuntokun
89310c8778
cmd/lncli: add new --debug_send option to sendpayment
This commit adds a new option to the send payment command. The new
option toggles usage of the debug HTLC R-Hash when sending the
described payment. This flag should be used in conjunction with lnd
nodes that have been started with the `—debughtlc` flag in order to
allow sending payments without first registering invoices.
2016-09-21 19:48:49 -07:00
Olaoluwa Osuntokun
7310d0a0f7
lnwallet: remove extraneous logging messages 2016-09-21 19:48:46 -07:00
Olaoluwa Osuntokun
9bd5105ae5
cmd/lncli: avoid unnecessarily re-encoding graph vertexes in routing table 2016-09-21 19:48:42 -07:00
Olaoluwa Osuntokun
071a6a54de
lnrpc: add the raw identity pub key to the GetInfo RPC 2016-09-21 19:48:39 -07:00
Olaoluwa Osuntokun
5ebaf9d1e7
routing: vertexes are now serialized pub keys instead of pubkey hashes 2016-09-21 19:48:35 -07:00
Olaoluwa Osuntokun
ca89ddb9ea
cmd/lncli: implement handling of new invoice RPC commands 2016-09-21 19:48:32 -07:00
Olaoluwa Osuntokun
2eb40d1614
rpcserver: implement new invoice related RPC commands 2016-09-21 19:48:28 -07:00
Olaoluwa Osuntokun
39c9dfb9e4
config: add a new --debughtlc config parameter
This commit adds a new configuration parameter to the deamon:
‘DebugHTLC’. When true, all outgoing HTLC’s sent via the RPC interface
will be sent paying to a special rHash value which all lnd nodes also
with the flag activated know the preimage to. Therefore all payments
sent to a 1-hop node will immediately be settled by that node.

By default, this flag is false, it it only intended to be used to
exercise local changes to 1-hop behavior manually.
2016-09-21 19:48:25 -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
39e6217860
lnrpc: add new invoice related RPC commands 2016-09-21 19:48:18 -07:00
Olaoluwa Osuntokun
d7c4074cd6
channeldb: add ability to retrieve all invoices from the database
This commit adds a new invoice related method: FetchAllInvoices. This
method allows callers to query the state of all invoices currently
stored within the database. The method takes a toggle bit which
determines if only pending (unsettled) invoices should be returned, or
if they al should be.
2016-09-21 19:48:15 -07:00
Olaoluwa Osuntokun
fa70990452
channeldb: store the invoice counter within the invoice index bucket
This commit moves the location of the invoice counter key which is an
auto-incrementing primary key for all invoices. Rather than storing the counter
in the same top-level invoice bucket, the counter is now stored within the
invoiceIndex bucket. With this change, the top-level bucket can now cleanly be
scanned in a sequential manner to retrieve all invoices.
2016-09-21 19:48:10 -07:00
Olaoluwa Osuntokun
28b72d368c
test: use context.WithTimeout to ensure async tests don't block indefinitely
This commit uses the context package’s WithTimeout to ensure tests
which rely on asynchrony behaviors cannot block the execution of the
integration tests for ever. All tests which rely on async gRPC
notifications now perform a 3 way select: on the timeout channel
closure, an error, and the response itself.

Additionally some slight refactoring has taken place within the current
set of integration tests, eliminating some unneeded factory functions.
2016-09-21 19:45:54 -07:00
Olaoluwa Osuntokun
b264ba198f
channeldb: add persistent invoice workflow
This commit adds the necessary database functionality required for a
high-level payment invoice workflow. Invoices can be added dealing the
requirements for fulfillment, looked by payment hash, and the finally
also settled by payment hash. For record keeping and the possibility of
reconciling future disputes, invoices are currently never deleted from
disk. Instead when an invoice is settled a bit is toggled indicating as
much.

The current invoiceManger within the daemon will be modified to use
this persistent invoice store, only storing certain “debug” invoices in
memory as dictated by a command line flag.
2016-09-16 17:24:55 -07:00
Olaoluwa Osuntokun
255b1b7727
test: fix some minor typos, expand comments 2016-09-15 12:25:10 -07:00
andrew.shvv
2788dbeaa8 Add RPC to show current total available channel capacity #29 (#35)
This commit adds a new RPC command: `channelbalance` which returns the
sum of all available channel capacity across all open channels. The
total balance is currently returned in units of `satoshis`. Additionally
the `networkHarness` has been modified slightly to allow specifying the
additional "extra" command line parameters when creating the initial
seed nodes. Minor refactoring within the integration tests has been
undertaken in order to increase code re-use across tests.

Closes #29.
2016-09-15 12:00:56 -07:00
Olaoluwa Osuntokun
4c01e42670
test: add integration tests for forced channel closure
This commit adds a basic test to exercise the scenario of forced
channel closure between to nodes with an existing channel open. The
test ensures that the latest commitment transaction it broadcast to the
chain and additionally that all time-locked outputs are sweeped with a
single transaction as soon as the inputs are mature enough.
2016-09-13 19:00:57 -07:00
Olaoluwa Osuntokun
d23bf8b633
test: properly mark txid's as seen within the networkWatcher 2016-09-13 18:56:40 -07:00
Olaoluwa Osuntokun
668063f61d
test: modify the networkHarness' OpenChannel method to use global IDs
This commit modifies the OpenChannel helper method within the
networkHarness to open the channel according to the destination node’s
global lighting ID rather than using a hard coded peer ID as before.

With this change the method is now much more general as the prior
temporary hack has been removed.
2016-09-13 15:38:45 -07:00
Olaoluwa Osuntokun
c604730b7d
cmd/lncli: accept --lighting_id parameter for openchannel 2016-09-13 15:36:36 -07:00
Olaoluwa Osuntokun
6c83f53206
rpcserver: allow targeting open channels via global lightning ID
This commit adds the ability to open channels according a node’s
“global” lightning ID in addition to the local relative peer ID.
2016-09-13 15:35:48 -07:00
Olaoluwa Osuntokun
7aaa46d7ff
lnrpc: change the target_node field in OpenChannelRequest to a byte array 2016-09-13 15:34:18 -07:00
Olaoluwa Osuntokun
112ad616f6
chainntnfs: remove unnecessary print statement in tests 2016-09-13 15:33:32 -07:00
Olaoluwa Osuntokun
49ce1040d4
lnwallet: adopt simple fee structure for commitment transactions
This commit modifies the prior funding workflow to account for fees
when creating the funding output. As a stop gap, the current fee for
the commitment transaction is now hard-coded at 5k satoshis. Once the
fee models are in place this should instead be some high multiple of
the current “average” fee rate within the network, continuing, the
proper fee should be adjusted from the commitment transaction has
outputs are added/removed.
2016-09-12 19:08:01 -07:00
Olaoluwa Osuntokun
ff70b3afa9
lnd: avoid wiping a channel twice 2016-09-12 19:07:52 -07:00
Olaoluwa Osuntokun
39044cb2fa
chainntnfs: fix recursive loop, add additional logging 2016-09-12 19:07:48 -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