mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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>
This commit is contained in:
parent
a877b2f6ac
commit
4fe90ee3f5
@ -399,6 +399,8 @@ static struct peer *new_peer(struct lightningd_state *dstate,
|
|||||||
peer->anchor.watches = NULL;
|
peer->anchor.watches = NULL;
|
||||||
peer->cur_commit.watch = NULL;
|
peer->cur_commit.watch = NULL;
|
||||||
peer->closing.their_sig = NULL;
|
peer->closing.their_sig = NULL;
|
||||||
|
peer->closing.our_script = NULL;
|
||||||
|
peer->closing.their_script = NULL;
|
||||||
peer->cleared = INPUT_NONE;
|
peer->cleared = INPUT_NONE;
|
||||||
/* Make it different from other node (to catch bugs!), but a
|
/* Make it different from other node (to catch bugs!), but a
|
||||||
* round number for simple eyeballing. */
|
* round number for simple eyeballing. */
|
||||||
@ -708,35 +710,34 @@ static bool is_unrevoked_commit(const struct commit_info *ci,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A mutual close is a simple 2 output p2sh to the final addresses, but
|
|
||||||
* without knowing fee we can't determine order, so examine each output. */
|
|
||||||
static bool is_mutual_close(const struct peer *peer,
|
static bool is_mutual_close(const struct peer *peer,
|
||||||
const struct bitcoin_tx *tx)
|
const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
const u8 *ctx, *our_p2sh, *their_p2sh;
|
const u8 *ours, *theirs;
|
||||||
bool matches;
|
|
||||||
|
ours = peer->closing.our_script;
|
||||||
|
theirs = peer->closing.their_script;
|
||||||
|
/* If we don't know the closing scripts, can't have signed them. */
|
||||||
|
if (!ours || !theirs)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (tx->output_count != 2)
|
if (tx->output_count != 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!is_p2sh(tx->output[0].script, tx->output[0].script_length)
|
/* Without knowing fee amounts, can't determine order. Check both. */
|
||||||
|| !is_p2sh(tx->output[1].script, tx->output[1].script_length))
|
if (scripteq(tx->output[0].script, tx->output[0].script_length,
|
||||||
return false;
|
ours, tal_count(ours))
|
||||||
|
&& scripteq(tx->output[1].script, tx->output[1].script_length,
|
||||||
|
theirs, tal_count(theirs)))
|
||||||
|
return true;
|
||||||
|
|
||||||
/* FIXME: Cache these! */
|
if (scripteq(tx->output[0].script, tx->output[0].script_length,
|
||||||
ctx = tal(NULL, u8);
|
theirs, tal_count(theirs))
|
||||||
our_p2sh = scriptpubkey_p2sh(ctx,
|
&& scripteq(tx->output[1].script, tx->output[1].script_length,
|
||||||
bitcoin_redeem_single(tx, &peer->us.finalkey));
|
ours, tal_count(ours)))
|
||||||
their_p2sh = scriptpubkey_p2sh(ctx,
|
return true;
|
||||||
bitcoin_redeem_single(tx, &peer->them.finalkey));
|
|
||||||
|
|
||||||
matches =
|
return false;
|
||||||
(memcmp(tx->output[0].script, our_p2sh, tal_count(our_p2sh)) == 0
|
|
||||||
&& memcmp(tx->output[1].script, their_p2sh, tal_count(their_p2sh)) == 0)
|
|
||||||
|| (memcmp(tx->output[0].script, their_p2sh, tal_count(their_p2sh)) == 0
|
|
||||||
&& memcmp(tx->output[1].script, our_p2sh, tal_count(our_p2sh)) == 0);
|
|
||||||
tal_free(ctx);
|
|
||||||
return matches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_depth_cb(struct peer *peer, int depth,
|
static void close_depth_cb(struct peer *peer, int depth,
|
||||||
|
Loading…
Reference in New Issue
Block a user