Commit Graph

61 Commits

Author SHA1 Message Date
Glenn Willen 2b431b171b config: Allow overriding the transaction fee rate 2016-11-06 10:35:48 -08:00
Rusty Russell 144c40afd0 irc: get much less chatty.
We're going to wean off IRC, but as a quick fix, only announce 0-60 seconds
after we see a join, or every 6 hours.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-21 12:05:33 +10:30
Rusty Russell f66358882a config: different defaults for mainnet and testnet.
In particular, remove fee ranges on testnet (too unreliable) and accept
a single confirm.

(Note that an earlier version of this had a bug when there was no
config file, this version includes the fix).

Closes: #40
Reported-by: Glenn Willen
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:18 +10:30
Rusty Russell c0d0606d66 lightningd: move testnet flag out of config.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:18 +10:30
Rusty Russell 1e6f7059d3 lightningd: allow --commit-fee-max=0 for "no limit"
For testnet, fee estimates are not reliable at all.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +10:30
Rusty Russell b45b4eaba6 bitcoind: explicit flag to bitcoin-cli for testnet/regtest.
Three days of on and off debugging, before I realized my server was talking
to a non-testnet bitcoind.  There was a bitcoind on that machine running
on testnet, but it uses the same dir and config, so the --bitcoin-datadir
option couldn't help.

This is more certain: specify whether we're testnet on every single query.
Now we can skip the attempt to parse bitcoin.conf, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 8c8fa2cecd config: make sure that anchor-confirms is non-zero.
We don't actually look into mempool, so setting zero is misleading.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 221a96cdeb getinfo: new RPC command
Useful for getting ID, what port (if not set in config file).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-13 03:37:07 +09:30
Christian Decker 2f6eefc49b routing: Wiring in the IRC peer discovery
Added a flag to disable the IRC discovery and calling the entrypoint to
start the IRC client loop.
2016-09-07 23:49:39 +02:00
Rusty Russell c83fb1a2dd waitinvoice: RPC call for processing incoming invoices.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 27715f7732 invoice: order by when they were paid.
We need some ordering to deliver them to the JSON "waitinvoice" command;
we use a counter where 0 means "unpaid".

We keep two lists now, one for unpaid and one for paid invoices.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 060ff29b45 Rename payment to invoice.
And rename JSON's accept-payment command to invoice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 012574790d pay: make interface idempotent.
We stopped automatically retransmitting locally-generated add/removes
after a reconnect, but this breaks the "pay" interface as it stands.

The correct solution to this is to make the pay interface idempotent:
you can trigger it as many times as you want and it will only succeed
once.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:04:59 +09:30
Rusty Russell 830a65de46 daemon: --add-route option.
This allows hardcoded routes in the config file, which is required until
we get route advertisements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 319c2ec5fc peer: keep addresses separately from peers.
This makes more sense eventually: we may know the network addresses of
many peers, not just those we're connecting to.  So keep a mapping, and
update it when we successfully connect outwards.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 190b30e958 daemon: test restarting.
We add a "dev-restart" command which causes the daemon to close fds
and exec itself.  Then we do it after every command, with the caveat
that we always send a commit before newhtlc, because if not committed,
that is forgotten.  Fulfillhtlc and failhtlc get resent, since they're
idempotent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 71b8a07c56 db.c: database API.
These tables could use a rework, as they largely reflect our internal
state.  But it's a start.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 3866d7605c daemon: reconnect support.
To do this we keep an order counter so we know how to retransmit.  We
could simply keep old packets, but this is a little clearer for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:08 +09:30
Rusty Russell 02cb7abd9d bitcoind: keep running fee estimate.
This avoids us having to query it when we create anchor transaction, and
lets us always use dynamic fee information.

The config options for max and min are now percentages, rather than absolute.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 4563ff91e9 lightningd: don't create rpc socket & listening socket until topology known.
We can deref a NULL tip pointer otherwise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:24 +09:30
Rusty Russell fa7934dfe3 htlc: implement deadline as per BOLT.
Thus a node MUST estimate the deadline for successful redemption for
  each HTLC it offers.  A node MUST NOT offer a HTLC after this
  deadline, and MUST fail the connection if an HTLC which it offered is
  in either node's current commitment transaction past this deadline.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 21a29d9b4d daemon: fix bug when we close two peers simulatneously.
If a block triggers two peers to close, we ran io_break() on both of them; the
second overrode the first and we didn't end up freeing that one.

Rather than chase such bugs in future, simply iterate to see if any
peers need freeing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell f994a44827 daemon/peer: keep our own node connection information.
Note that the base fee is in millisatoshi, the proportional fee is
in microsatoshi per satoshi. ie. 1,000,000 means charge 1 satoshi for
every satoshi carried.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell f4f0c1aa18 daemon: add dev-routefail command.
We're about to change the code so that if it can't route, it will fail
the HTLC.  The current low-level tests will hate this, so have a dev switch
to turn that off.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 26a03acfd0 daemon: routing infrastructure.
Simple routing topology, and ability to ask about the cheapest route.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell a3375516e5 daemon: don't ever use timeouts in seconds, always blocks,
The protocol still supports both, but we now only support blocks.

It's hard to do risk management with timeouts in seconds, given block
variance.  This is also signficantly simpler, as HTLC timeouts are
always fired in response to blocks, not wall-clock times.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 12:00:17 +09:30
Rusty Russell 5027410ab1 daemon: payment infrastructure.
A new 'accept-payment' command tells the node to fulfill HTLCs using
the R value if the amount is correct.  It's not wired in yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 35d1b13cde daemon: commit outstanding changes via timer.
While useful for testing, it doesn't make sense to have an explicit commit
command; we should commit whenever there are outstanding changes.

We have a 10ms timer to allow limited batching, however.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-10 06:30:11 +09:30
Rusty Russell fe1ba96332 daemon: time options use opt_time.
Currently this mean --bitcoin-poll; we're going to change the other time
options to block heights anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-10 06:29:12 +09:30
Rusty Russell 82c2325467 timeout: make all timers one-shot.
It's closer to what we want, and simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-10 06:26:09 +09:30
Rusty Russell c94f77fd14 forever-confirms: warn if less than 100.
BOLT #onchain considers 100 the minimum depth to be "irrevocable".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-04 16:12:50 +09:30
Rusty Russell 03a538ca02 check-bolt: check that comments in code match the specs.
And fix the mistakes!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 7b4de8e445 watch: use chaintopology
Rather than polling for interesting bitcoin txs via importaddress, we use
the chain topology to register our interest directly.x 

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:48:35 +09:30
Rusty Russell 521d3d53ed chaintopology: keep track of the bitcoin block topology.
This allows us to track precise transaction depth ourselves,
particularly in the case of branching.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:37:13 +09:30
Rusty Russell 51de503096 daemon: keep track of simple addresses for injecting funds.
We need to control the *inputs* to the anchor tx, to make sure they
pay to witness scripts (thus the anchor is immalleable).  The easiest
way to do this is to hand out P2SH addresses for the user, and have
them pay into those.  Then they hand us that tx and we use it to
create the anchor.

This is not a long-term solution!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-12 13:07:03 +09:30
Rusty Russell 8c468c1e15 daemon: use fee rates rather than absolute fees (BOLT #2)
And divide fees as specified there.

We still use fixed values rather than floating, and we don't send or
handle update_fee messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:12:43 +10:30
Rusty Russell b423b33236 protocol: implement close as per BOLT #2.
We don't actually implement closing when we have HTLCs (we should
allow it, as that's what the clearing phase is for), since soon we'll
rewrite HTLC to match the async HTLC protocol of BOLT #2.

Note that this folds the close paths, using a simple check if we have
a close transaction.  That's a slight state layer violation, but
reduces code duplication.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:09:41 +10:30
Rusty Russell 6a062d8527 daemon: check protobuf-c version, report failure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:09:42 +10:30
Rusty Russell 8f2e66089b daemon: add --bitcoin-datadir for bitcoin-cli.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:40 +10:30
Rusty Russell 168ed96b12 daemon: close command.
This performs a mutual close.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell 45c5c83d6f daemon: exit main loop to free dead peers.
When a peer is finally to be freed (ie. STATE_CLOSED), doing this
inside the state logic is a bit fraught.  We're better off exiting the
io loop and freeing it there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell 1018823f97 daemon: HTLC expiry limits.
Don't accept an HTLC which is about to expire, nor one which will take
too long to expire.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell a3e3f83d9f daemon: dev-mocktime command
Useful for precise timing control for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell 9f560a9494 daemon: --closing-fee
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell 8f0e10309a daemon: --bitcoind-poll=<seconds>
Speeds up testing significantly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell 5b9f8d8bbd bitcoind: serialize requests.
bitcoind has a limit of 16 requests at once, by default, so our simplest
solution is to serialize them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell 34e32978b8 bitcoind: warn if their bitcoin config doesn't have walletbroadcast=0.
Because we use the bitcoin wallet to create the anchor transaction, we
need to make sure it doesn't broadcast it; safest to check their config
for the option.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell fc49e3fd74 daemon: rename 'state' to 'dstate' everywhere.
This is the daemon state, not the state machine state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell e9237f94b1 daemon/watch: API to watch various bitcoin transactions.
This uses the functions in bitcoind to provide callbacks when various
things happen.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell 5ec8ff91e4 daemon/bitcoind: communication with bitcoind.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30