mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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>
This commit is contained in:
parent
ab09a42350
commit
064309df1a
@ -147,12 +147,10 @@ void queue_pkt_anchor(struct peer *peer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Sign their commit sig */
|
/* Sign their commit sig */
|
||||||
peer->them.commit->sig = tal(peer->them.commit,
|
peer->them.commit->sig.stype = SIGHASH_ALL;
|
||||||
struct bitcoin_signature);
|
|
||||||
peer->them.commit->sig->stype = SIGHASH_ALL;
|
|
||||||
peer_sign_theircommit(peer, peer->them.commit->tx,
|
peer_sign_theircommit(peer, peer->them.commit->tx,
|
||||||
&peer->them.commit->sig->sig);
|
&peer->them.commit->sig.sig);
|
||||||
a->commit_sig = signature_to_proto(a, &peer->them.commit->sig->sig);
|
a->commit_sig = signature_to_proto(a, &peer->them.commit->sig.sig);
|
||||||
|
|
||||||
queue_pkt(peer, PKT__PKT_OPEN_ANCHOR, a);
|
queue_pkt(peer, PKT__PKT_OPEN_ANCHOR, a);
|
||||||
}
|
}
|
||||||
@ -166,12 +164,10 @@ void queue_pkt_open_commit_sig(struct peer *peer)
|
|||||||
dump_tx("Creating sig for:", peer->them.commit->tx);
|
dump_tx("Creating sig for:", peer->them.commit->tx);
|
||||||
dump_key("Using key:", &peer->us.commitkey);
|
dump_key("Using key:", &peer->us.commitkey);
|
||||||
|
|
||||||
peer->them.commit->sig = tal(peer->them.commit,
|
peer->them.commit->sig.stype = SIGHASH_ALL;
|
||||||
struct bitcoin_signature);
|
|
||||||
peer->them.commit->sig->stype = SIGHASH_ALL;
|
|
||||||
peer_sign_theircommit(peer, peer->them.commit->tx,
|
peer_sign_theircommit(peer, peer->them.commit->tx,
|
||||||
&peer->them.commit->sig->sig);
|
&peer->them.commit->sig.sig);
|
||||||
s->sig = signature_to_proto(s, &peer->them.commit->sig->sig);
|
s->sig = signature_to_proto(s, &peer->them.commit->sig.sig);
|
||||||
|
|
||||||
queue_pkt(peer, PKT__PKT_OPEN_COMMIT_SIG, s);
|
queue_pkt(peer, PKT__PKT_OPEN_COMMIT_SIG, s);
|
||||||
}
|
}
|
||||||
@ -323,16 +319,15 @@ void queue_pkt_commit(struct peer *peer)
|
|||||||
*/
|
*/
|
||||||
assert(ci->prev->cstate->changes != ci->cstate->changes);
|
assert(ci->prev->cstate->changes != ci->cstate->changes);
|
||||||
|
|
||||||
ci->sig = tal(ci, struct bitcoin_signature);
|
ci->sig.stype = SIGHASH_ALL;
|
||||||
ci->sig->stype = SIGHASH_ALL;
|
peer_sign_theircommit(peer, ci->tx, &ci->sig.sig);
|
||||||
peer_sign_theircommit(peer, ci->tx, &ci->sig->sig);
|
|
||||||
|
|
||||||
/* Switch to the new commitment. */
|
/* Switch to the new commitment. */
|
||||||
peer->them.commit = ci;
|
peer->them.commit = ci;
|
||||||
|
|
||||||
/* Now send message */
|
/* Now send message */
|
||||||
update_commit__init(u);
|
update_commit__init(u);
|
||||||
u->sig = signature_to_proto(u, &ci->sig->sig);
|
u->sig = signature_to_proto(u, &ci->sig.sig);
|
||||||
u->ack = peer_outgoing_ack(peer);
|
u->ack = peer_outgoing_ack(peer);
|
||||||
|
|
||||||
queue_pkt(peer, PKT__PKT_UPDATE_COMMIT, u);
|
queue_pkt(peer, PKT__PKT_UPDATE_COMMIT, u);
|
||||||
@ -352,7 +347,7 @@ void queue_pkt_revocation(struct peer *peer)
|
|||||||
assert(!peer->us.commit->prev->revocation_preimage);
|
assert(!peer->us.commit->prev->revocation_preimage);
|
||||||
|
|
||||||
/* We have their signature on the current one, right? */
|
/* We have their signature on the current one, right? */
|
||||||
assert(peer->us.commit->sig);
|
memcheck(&peer->us.commit->sig, sizeof(peer->us.commit->sig));
|
||||||
|
|
||||||
peer->us.commit->prev->revocation_preimage
|
peer->us.commit->prev->revocation_preimage
|
||||||
= tal(peer->us.commit->prev, struct sha256);
|
= tal(peer->us.commit->prev, struct sha256);
|
||||||
@ -484,10 +479,8 @@ static Pkt *check_and_save_commit_sig(struct peer *peer,
|
|||||||
struct commit_info *ci,
|
struct commit_info *ci,
|
||||||
const Signature *pb)
|
const Signature *pb)
|
||||||
{
|
{
|
||||||
assert(!ci->sig);
|
ci->sig.stype = SIGHASH_ALL;
|
||||||
ci->sig = tal(ci, struct bitcoin_signature);
|
if (!proto_to_signature(pb, &ci->sig.sig))
|
||||||
ci->sig->stype = SIGHASH_ALL;
|
|
||||||
if (!proto_to_signature(pb, &ci->sig->sig))
|
|
||||||
return pkt_err(peer, "Malformed signature");
|
return pkt_err(peer, "Malformed signature");
|
||||||
|
|
||||||
/* Their sig should sign our commit tx. */
|
/* Their sig should sign our commit tx. */
|
||||||
@ -496,7 +489,7 @@ static Pkt *check_and_save_commit_sig(struct peer *peer,
|
|||||||
NULL, 0,
|
NULL, 0,
|
||||||
peer->anchor.witnessscript,
|
peer->anchor.witnessscript,
|
||||||
&peer->them.commitkey,
|
&peer->them.commitkey,
|
||||||
ci->sig))
|
&ci->sig))
|
||||||
return pkt_err(peer, "Bad signature");
|
return pkt_err(peer, "Bad signature");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1207,7 +1207,7 @@ const struct bitcoin_tx *bitcoin_commit(struct peer *peer)
|
|||||||
|
|
||||||
peer->us.commit->tx->input[0].witness
|
peer->us.commit->tx->input[0].witness
|
||||||
= bitcoin_witness_2of2(peer->us.commit->tx->input,
|
= bitcoin_witness_2of2(peer->us.commit->tx->input,
|
||||||
peer->us.commit->sig,
|
&peer->us.commit->sig,
|
||||||
&sig,
|
&sig,
|
||||||
&peer->them.commitkey,
|
&peer->them.commitkey,
|
||||||
&peer->us.commitkey);
|
&peer->us.commitkey);
|
||||||
@ -1377,17 +1377,6 @@ static void json_add_htlcs(struct json_result *response,
|
|||||||
json_array_end(response);
|
json_array_end(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is money we can count on. */
|
|
||||||
static const struct channel_state *last_signed_state(const struct commit_info *i)
|
|
||||||
{
|
|
||||||
while (i) {
|
|
||||||
if (i->sig)
|
|
||||||
return i->cstate;
|
|
||||||
i = i->prev;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: add history command which shows all prior and current commit txs */
|
/* FIXME: add history command which shows all prior and current commit txs */
|
||||||
|
|
||||||
/* FIXME: Somehow we should show running DNS lookups! */
|
/* FIXME: Somehow we should show running DNS lookups! */
|
||||||
@ -1415,11 +1404,11 @@ static void json_getpeers(struct command *cmd,
|
|||||||
|
|
||||||
/* FIXME: Report anchor. */
|
/* FIXME: Report anchor. */
|
||||||
|
|
||||||
last = last_signed_state(p->us.commit);
|
if (!p->us.commit) {
|
||||||
if (!last) {
|
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
last = p->us.commit->cstate;
|
||||||
|
|
||||||
json_add_num(response, "our_amount", last->a.pay_msat);
|
json_add_num(response, "our_amount", last->a.pay_msat);
|
||||||
json_add_num(response, "our_fee", last->a.fee_msat);
|
json_add_num(response, "our_fee", last->a.fee_msat);
|
||||||
|
@ -61,8 +61,8 @@ struct commit_info {
|
|||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
/* Channel state for this tx. */
|
/* Channel state for this tx. */
|
||||||
struct channel_state *cstate;
|
struct channel_state *cstate;
|
||||||
/* Other side's signature for last commit tx (if known) */
|
/* Other side's signature for this commit tx. */
|
||||||
struct bitcoin_signature *sig;
|
struct bitcoin_signature sig;
|
||||||
/* Revocation preimage (if known). */
|
/* Revocation preimage (if known). */
|
||||||
struct sha256 *revocation_preimage;
|
struct sha256 *revocation_preimage;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user