daemon/output_to_htlc: routines to map outputs for HTLCs for a given commit_num.

And use this to resolve old transactions by comparing outputs with
HTLCs.

Rather than remembering the output ordering for every one of their
previous commitment transactions, we just remember the commitment
number for each commitment txid, and when we see it, derive all the
HTLC scriptpubkeys and the to-us and to-them scriptpubkeys, and figure
out which is which.

This avoids us having to save information on disk, except for the
txid->commitment-number mapping (and the shachain).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-08-18 14:23:45 +09:30
parent 7c2165f5b4
commit ec3344ce6e
7 changed files with 388 additions and 202 deletions

View File

@@ -467,6 +467,17 @@ bool is_p2sh(const u8 *script, size_t script_len)
return true;
}
bool is_p2wsh(const u8 *script, size_t script_len)
{
if (script_len != 1 + 1 + sizeof(struct sha256))
return false;
if (script[0] != OP_0)
return false;
if (script[1] != OP_PUSHBYTES(sizeof(struct sha256)))
return false;
return true;
}
/* A common script pattern: A can have it with secret, or B can have
* it after delay. */
u8 *bitcoin_redeem_secret_or_delay(const tal_t *ctx,