Commit Graph

871 Commits

Author SHA1 Message Date
Rusty Russell eb5d832963 state: don't spend the "to-us" output from their commit tx.
There's no reason to, it's a simple p2wpkh to our key.

We still spend the "to-us" from our commit tx, since it could be
theoretically be stolen by the revocation value, and it's a complex
p2wsh which a normal wallet won't have the information to spend.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:50 +09:30
Rusty Russell c4713a6ed5 state: use htlc_onchain structure
Turns out that we want to pass information about the commit info, the
HTLC number and (sometimes) the R value, so create a struct for that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell bccd10c6d8 daemon: don't code check for cleared commits in the main loop, use pending queue.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell 33a477d65d daemon: add pending input queue.
You can't re-enter the state machine from a callback, so this allows you
to queue an input for when it returns.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell c94c495257 daemon: allow multiple watches on the same tx.
This turns out to make life easier for watching HTLC timeouts (we just
place a new watch for each HTLC).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell 77a89bcf2b watch: indicate which input of tx is spend the watch txo.
If we generate a tx which spends a heap of TXOs (eg. steal
transaction), we'll need this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell 9eabab78ab utils: tal_hexstr() helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell 6f2cb72c27 daemon/test: don't generate tiny dust HTLCs in testing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell a150bd191a remove_dust: don't ever create dust outputs.
This behavior will be specified in BOLT #3.

Closes: #14

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:28:49 +09:30
Rusty Russell 7614e513bd commit_tx: keep permutation map.
This lets us map the HTLCs back to outputs when txs occur onchain.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 76cb195ea1 daemon: dev-disconnect command.
This lets one end experience a disconnect without the other noticing.
Good for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell faed0ef736 daemon/test: use config file rather than long cli args.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 4bbb86ae30 daemon: clean up test dirs.
Move final helpers out of test-cli/

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 064309df1a peer: signature in commit_info is always valid.
It's given in the packet which creates the new commit_info, so no need to
make it a pointer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell ab09a42350 ccan: update (for htable_getfirst/getnext)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 7efc0efab1 scripteq: simple helper for comparing scripts.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +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 7bfbee136e permute_tx: fix map logic (again!)
8a4246cb36 (permute: use BIP69 order) removed the invert_map change
from a25ba452f3 (permute_tx: fix horrible thinko.) but it's still
needed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 4fe90ee3f5 peer: fix mutual close detection.
Since 43729c6856 (protocol: add output script to close_clearing message.)
the close scripts are not p2sh, but arbitrary.  Fix the close tx matching.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell a877b2f6ac state: fix redundant declaration.
The (non-matching!) description and declaration are both repeats.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell 5ba7692254 Makefile: fix config.h rebuilds in parallel.
Occasionally make seems to rebuild this in parallel, so make sure to
never have a partially complete one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-03 11:27:56 +09:30
Rusty Russell f4e94147a7 Remove unused script functions now we use witness.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 20:09:39 +09:30
Rusty Russell 43729c6856 protocol: add output script to close_clearing message.
We just use a p2sh to a single address for the moment, but that's simply for
non-segwit wallets; we'll pay to whatever the other side specifies.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 20:01:52 +09:30
Rusty Russell f24b73124a Remove txid normalization.
Since any transaction with all segregated-witness inputs is non-malleable,
and all our transactions are that, we can remove normalized txids.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 20:01:52 +09:30
Rusty Russell 7ac29241ee patch htlc-outputs-are-p2wsh.patch 2016-04-24 20:01:51 +09:30
Rusty Russell b1700b1a91 protocol: non-HTLC commit tx outputs are p2wpkh
This is changes the payments to either party to be p2wpkh.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:57:35 +09:30
Rusty Russell 6a54716b56 find_p2wsh_out: new helper to find a particular output.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:56:35 +09:30
Rusty Russell bd081d219d protocol: anchor output is now witness 2of2.
Rather than p2sh of a 2of2, it's now a version 0 witness program.
This means that the commit transaction input and mutual close
transaction input are both different.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:55:35 +09:30
Rusty Russell 8dce2e77f7 script: 2of2 witness support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:54:35 +09:30
Rusty Russell d26be323b6 measure_tx_cost: determine the BIP141 cost of a transaction.
BIP141 indicates that the rule for block size has changed: witness
bytes effectively count for 1, and non-witness bytes count for 4, but
the maximum total has increased to 4,000,000.

This means that fee estimates should use the witness cost (divided by
4), not the raw txlen.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:53:35 +09:30
Rusty Russell 8bd334380e peer: use tip mediantime for CSV timeout.
Using wallclock is gauche (and I saw it fail once in tests), so fix that
FIXME now it's easy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:52:35 +09:30
Rusty Russell 85554761c8 bitcoind: eliminate wallet routines.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:51:35 +09:30
Rusty Russell b5a6ac26c7 watch: don't hand blockhash, have commit_tx_depth() use get_last_mediantime()
There isn't a single blockhash; we may be on multiple forks.  But the one
caller which cares is commit_tx_depth(), which wants to know if the tx is
spendable yet.  So that uses get_last_mediantime().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:50:35 +09:30
Rusty Russell e3868b11d2 peer: use watch_txo to watch commit_tx outputs.
We really want to do this for HTLCs; we don't do anything useful yet, but
this code replaces the direct call to bitcoind_watch_addr().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:49:35 +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 6e39b0a642 chaintopology: get_last_mediantime()
This gets the median time of the block the tx is in.  If there is more
than one (different tips), it gets the last median time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:46:32 +09:30
Rusty Russell e09795d24e chaintopology: get full tx information for each block.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:42:18 +09:30
Rusty Russell e60b1b4efa bitcoind: use correct endianness for block hashes.
Like txids, we need to reverse them.  We didn't, but then we only used them
to pass to/from bitcoind.  We're about to get them from the block header,
so we need to fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:41:20 +09:30
Rusty Russell e7b9a913a6 bitcoind: getrawblock helper.
It turns out using the verbose=false parameter, you can get the raw block
from getblock.  Do that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:40:29 +09:30
Rusty Russell 3d9cb81215 watch: express everything in terms of watch_tx and watch_txo.
With segregated witness, we can (in advance!) specify the txid or tx
output we want to watch, so convert to that now.  For the moment it's
done by pretending we have normalized txids; that goes away after the
conversion.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:39:21 +09:30
Rusty Russell 14d722d48d bitcoind: pretend normalized txids are in the block.
This lets us live in a segwit world, before segwit.  It's a shim which we
can remove once we've changed all our outputs.

We need a few more sleeps in our test script, since we've slowed
things down by doing these calls for every tx in every block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:38:13 +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 01e46d154e bitcoind: getchaintips support.
This allows us to sae the block topology in detail.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:36:13 +09:30
Rusty Russell 1d27428aab log: use real time for logs, even if dev-mocktime is used.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:35:13 +09:30
Rusty Russell 45fa89e134 daemon/test/test.sh: neaten state checks.
Better debugging when things go wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:34:13 +09:30
Rusty Russell 410fc3b272 misc: remove some unused functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-24 19:33:13 +09:30
Rusty Russell 01820a1a5a Fill out TODO.md into a useful list (mainly by grepping for FIXMEs).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-12 16:07:47 +09:30
Rusty Russell fd22b97e24 tests: fix check for segwit support.
"help unknowncommand" exits with 0, unfortunately.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-12 14:42:22 +09:30
Rusty Russell b4c5b5b578 Note that we need segwit-enabled bitcoind.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-12 14:26:38 +09:30
Rusty Russell 1568774e62 daemon: assert that all anchor inputs are witness.
Otherwise, they're malleable.  We only care about our own anchor:
their anchor is their problem (and they'll probably get away with it).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-04-12 14:17:47 +09:30