Commit Graph

2561 Commits

Author SHA1 Message Date
Rusty Russell 6c79550c22 test_lightningd.py: test updating feerates.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 1a38c98a7e chaintopology: implement dev-setfees to force feerate changes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 552e56d002 channeld: send update_fee messages.
We only send them when we're not awaiting revoke_and_ack: our
simplified handling can't deal with multiple in flights.

Closes: #244
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell c3cb7f1c85 channeld: don't assert that we're expecting revoke_and_ack.
We can have it happen on reconnect due to fee changes; we should really
detect this case, but it's harmless to let it happen as a noop.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell d28ee02cbf channeld: handle feerate on reconnect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 062f18127d channeld: handle incoming feerate changes.
We allow from the 100-confirm economical rate to 5x the immediate rate.

Closes: #243
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 6fac3438dd channeld: track feerates.
Handling feerates for the fundee (who only receives fee_update) is
simple: it's practically atomic since we accept commitment and send
revocation, thus they're applied to both sides at once.

Handling feerates for the funder is more complex: in theory we could
have multiple in flight.  However, if we avoid this using the same
logic as we use to suppress multiple commitments in flight, it's
simple again.

We fix the test code to use real feerate manipulation, thus have to
remove an assert about feerate being non-zero.  And now we have
feechanges, we need to rely on the changes_pending flags, as we can
have changes without an HTLCs changing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 8999e2293a channeld: implement approx_max_feerate.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell f45d962a14 channeld: implement and refine fee-related functions.
We had some in the header, now implement them, and add a channel_feerate()
accessor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell b836b452dc feerate: keep feerates separately for each side.
When we support changing them, they can be different during the transition.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 24b4326b30 onchaind: use normal feerate, not last feerate from transaction.
This is used by onchaind when creating its own transactions.  Note we
don't send updates yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell ccf86a138a chaintopology: add notify_feerate_change() callback.
We'll use this to tell peers to change feerate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell d44088db83 fund-channel: use real feerate.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell e2287ce545 openingd: use real feerates.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell f1e4cad9d4 feerate: use u32 everywhere.
The wire protocol uses this, in the assumption that we'll never see feerates
in excess of 4294967 satoshi per kiloweight.

So let's use that consistently internally as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 88af0f5bf8 tests: change --override-fee-rate to --override-fee-rates and use in tests.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 7151c65535 chaintopology: track three different feerates.
Depending on what we're doing, we can want different ones.  So use
IMMEDIATE (estimatesmartfee 2 CONSERVATIVE), NORMAL (estimatesmartfee
4 ECONOMICAL) and SLOW (estimatesmartfee 100 ECONOMICAL).

If one isn't available, we try making each one half the previous.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell ef4d54df94 chaintopology: use satoshi-per-kw everywhere.
This means we convert it when retrieving from bitcoind; internally it's
always satoshi-per-1000-weight aka millisatoshi-per-weight.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell b954662f06 bitcoind: use estimatesmartfee.
estimatefee is deprecated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 35a6ab8151 invoice: don't allow payments in expired invoices.
Fixes: #363
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Rusty Russell e302d6193c invoice: store expiry time in db.
This is backwards-compat: sets existing expiry for invoices to ~infinity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Rusty Russell 1e6d5d82aa invoice: record expiry in data structure.
We don't enforce it yet, but you can query it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Rusty Russell 2d05644dfd json_invoice: add optional expiry argument.
This just includes it in the bolt11 return for the moment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Rusty Russell fbc5ba12e4 invoice: simplify find_invoice_by_label.
Passing a list_head is a remnant of when we had two lists.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Rusty Russell 70f15fb068 json_invoice: remove 'r' argument.
It was only for debugging early on.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Rusty Russell 40315bfb91 test: fix dependencies.
Test objects must be added to $(ALL_OBJS) so they correctly depend on
CCAN headers etc.

Also, each test in a subdir must depend on headers and src in the parent
directory, as it will often #include them directly.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-22 19:40:46 +01:00
Rusty Russell 37b4ab306e run-channel.c: move under channeld/
This also fixes dependencies, since it actually depends on channeld objects.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-22 19:40:46 +01:00
Rusty Russell 593d0fa625 lightningd: initialize dev_subdaemon_fail to false.
Our testsuite uses --dev-fail-on-subdaemon-fail, so I didn't notice this
until I turned that off to chase a bug.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-22 19:40:46 +01:00
Rusty Russell 0a131c6389 channel: use flag to indicate we're awaiting revoke_and_ack.
We currently scan through HTLCs: this isn't enough if we've only got a
feechange in the commitment, so use a flag (but keep both for now for
debugging).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-22 19:40:46 +01:00
Rusty Russell c328a76438 channeld: use flags to track whether changes are pending.
This is required when we have non-HTLC changes (ie. fees).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-22 19:40:46 +01:00
Rusty Russell 5fb4577890 channeld/full_channel: fix incorrect reutrn from channel_rcvd_revoke_and_ack.
It was always returning false; it was supposed to return true if
we had added pending changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-22 19:40:46 +01:00
Damian Mee 211791f6d2 Lightning daemon path fixed 2017-11-20 22:14:07 +01:00
Christian Decker 77497b526f jsonrpc: Add listpayments method
Returns a list of transfers and their state.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker be97673259 wallet: Add function to retrieve a list of payments
Used by the JSON-RPC for the listtransfers call. Currently does not
support any form of paging.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker e0d86376e2 wallet: Track outgoing payments in the database
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker 6ceb375650 wallet: Record issued invoices in the payments table
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker d1cc5f4552 wallet: Add unit tests for payment persistence
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker 967dd6c776 wallet: Add functions to store and manipulate payments
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker 6601c43edc db: Add payments table
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker 490ee76162 wallet: Add payment struct to track status of transfers
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:28:03 +00:00
Christian Decker 4d8ad4e17d pytest: Test that upon reconnect the channel gets re-enabled
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:13:45 +00:00
Christian Decker aeeb0b7011 channel: Re-enable channel after reconnect
Simply done by sending an enabling update after reconnect.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:13:45 +00:00
Rusty Russell 9b42f49d2c onchaind: fix feerate determination.
There were two bugs here.  First, grind_feerate() needs to check the
actual range of feerates, not the same rate over and over!  Secondly,
we need to grind the feerate for the HTLC-success tx, too.

These were masked by the fact that our tests always use the same feerate!
"Untested code is buggy code"

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-17 14:27:54 +01:00
Rusty Russell 5281541ec6 closingd: start with proper maximum fee, not our guesstimate.
Fixes: #348
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:41:45 +01:00
Rusty Russell 7ece90038b derive_basepoints: actually derive a separate HTLC key.
This means we'll find anywhere still using the payment key,
even though we still expose the private payment key to channeld.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:40:57 +01:00
Rusty Russell 46f2e17905 openingd: update to BOLT with htlckey.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:40:57 +01:00
Rusty Russell fc05779f78 subdaemons: pass back and forth the htlc points.
Openingd sets it to the same as the payment point for the remote side.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:40:57 +01:00
Rusty Russell 654c2f4eb8 onchaind: use HTLC key for htlc signatures.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:40:57 +01:00
Rusty Russell 3363bab6c9 channeld: use HTLC key for htlc signatures.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:40:57 +01:00
Rusty Russell 4db460903a htlc_tx: wire up the htlc points.
All the callers need to pass it in: currently channeld and openingd just
fake it by copying the payment point.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-16 17:40:57 +01:00