mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
protocol fix: use locktime from *other* side.
Which emerged clearly when setting one side's locktime differently than the other. Each side specifies the (minimum) time they need to notice a fraud attempt: this constrains the *other* side. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -37,7 +37,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
|||||||
if (!proto_to_pubkey(theirs->final, &theirkey))
|
if (!proto_to_pubkey(theirs->final, &theirkey))
|
||||||
return tal_free(tx);
|
return tal_free(tx);
|
||||||
|
|
||||||
if (!proto_to_locktime(ours, &locktime))
|
if (!proto_to_locktime(theirs, &locktime))
|
||||||
return tal_free(tx);
|
return tal_free(tx);
|
||||||
|
|
||||||
/* First output is a P2SH to a complex redeem script (usu. for me) */
|
/* First output is a P2SH to a complex redeem script (usu. for me) */
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
|
|||||||
struct sha256 rhash;
|
struct sha256 rhash;
|
||||||
size_t i, p2sh_out;
|
size_t i, p2sh_out;
|
||||||
u64 fee = 10000;
|
u64 fee = 10000;
|
||||||
u32 locktime_seconds;
|
u32 locktime;
|
||||||
|
|
||||||
err_set_progname(argv[0]);
|
err_set_progname(argv[0]);
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
o1 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
o1 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||||
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
||||||
if (!proto_to_locktime(o1, &locktime_seconds))
|
if (!proto_to_locktime(o2, &locktime))
|
||||||
errx(1, "Invalid locktime in o1");
|
errx(1, "Invalid locktime in o2");
|
||||||
|
|
||||||
/* We need our private key to spend commit output. */
|
/* We need our private key to spend commit output. */
|
||||||
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||||
@@ -89,8 +89,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Create redeem script */
|
/* Create redeem script */
|
||||||
redeemscript = bitcoin_redeem_revocable(ctx, &pubkey1,
|
redeemscript = bitcoin_redeem_revocable(ctx, &pubkey1,
|
||||||
locktime_seconds,
|
locktime, &pubkey2, &rhash);
|
||||||
&pubkey2, &rhash);
|
|
||||||
|
|
||||||
/* Now, create transaction to spend it. */
|
/* Now, create transaction to spend it. */
|
||||||
tx = bitcoin_tx(ctx, 1, 1);
|
tx = bitcoin_tx(ctx, 1, 1);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
o1 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
o1 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
||||||
o2 = pkt_from_file(argv[5], PKT__PKT_OPEN)->open;
|
o2 = pkt_from_file(argv[5], PKT__PKT_OPEN)->open;
|
||||||
if (!proto_to_locktime(o2, &locktime_seconds))
|
if (!proto_to_locktime(o1, &locktime_seconds))
|
||||||
errx(1, "Invalid locktime in o2");
|
errx(1, "Invalid locktime in o2");
|
||||||
|
|
||||||
if (!pubkey_from_hexstr(argv[6], &outpubkey))
|
if (!pubkey_from_hexstr(argv[6], &outpubkey))
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ B_FINALKEY=`getprivkey $B_FINALADDR`
|
|||||||
|
|
||||||
# Both sides say what they want from channel
|
# Both sides say what they want from channel
|
||||||
$PREFIX ./open-channel $A_SEED $A_AMOUNT $A_CHANGEPUBKEY $A_TMPKEY $A_FINALKEY $A_TXIN > A-open.pb
|
$PREFIX ./open-channel $A_SEED $A_AMOUNT $A_CHANGEPUBKEY $A_TMPKEY $A_FINALKEY $A_TXIN > A-open.pb
|
||||||
$PREFIX ./open-channel $B_SEED $B_AMOUNT $B_CHANGEPUBKEY $B_TMPKEY $B_FINALKEY $B_TXIN > B-open.pb
|
# B asks for a (dangerously) short locktime, for testing unilateral close.
|
||||||
|
$PREFIX ./open-channel --locktime=60 $B_SEED $B_AMOUNT $B_CHANGEPUBKEY $B_TMPKEY $B_FINALKEY $B_TXIN > B-open.pb
|
||||||
|
|
||||||
# Now sign anchor.
|
# Now sign anchor.
|
||||||
$PREFIX ./open-anchor-scriptsigs A-open.pb B-open.pb $A_TXINKEY > A-anchor-scriptsigs.pb
|
$PREFIX ./open-anchor-scriptsigs A-open.pb B-open.pb $A_TXINKEY > A-anchor-scriptsigs.pb
|
||||||
|
|||||||
Reference in New Issue
Block a user