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:
Rusty Russell 2016-05-02 16:01:56 +09:30
parent ab09a42350
commit 064309df1a
3 changed files with 19 additions and 37 deletions

View File

@ -147,12 +147,10 @@ void queue_pkt_anchor(struct peer *peer)
}
/* Sign their commit sig */
peer->them.commit->sig = tal(peer->them.commit,
struct bitcoin_signature);
peer->them.commit->sig->stype = SIGHASH_ALL;
peer->them.commit->sig.stype = SIGHASH_ALL;
peer_sign_theircommit(peer, peer->them.commit->tx,
&peer->them.commit->sig->sig);
a->commit_sig = signature_to_proto(a, &peer->them.commit->sig->sig);
&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);
}
@ -166,12 +164,10 @@ void queue_pkt_open_commit_sig(struct peer *peer)
dump_tx("Creating sig for:", peer->them.commit->tx);
dump_key("Using key:", &peer->us.commitkey);
peer->them.commit->sig = tal(peer->them.commit,
struct bitcoin_signature);
peer->them.commit->sig->stype = SIGHASH_ALL;
peer->them.commit->sig.stype = SIGHASH_ALL;
peer_sign_theircommit(peer, peer->them.commit->tx,
&peer->them.commit->sig->sig);
s->sig = signature_to_proto(s, &peer->them.commit->sig->sig);
&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);
}
@ -323,16 +319,15 @@ void queue_pkt_commit(struct peer *peer)
*/
assert(ci->prev->cstate->changes != ci->cstate->changes);
ci->sig = tal(ci, struct bitcoin_signature);
ci->sig->stype = SIGHASH_ALL;
peer_sign_theircommit(peer, ci->tx, &ci->sig->sig);
ci->sig.stype = SIGHASH_ALL;
peer_sign_theircommit(peer, ci->tx, &ci->sig.sig);
/* Switch to the new commitment. */
peer->them.commit = ci;
/* Now send message */
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);
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);
/* 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
= 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,
const Signature *pb)
{
assert(!ci->sig);
ci->sig = tal(ci, struct bitcoin_signature);
ci->sig->stype = SIGHASH_ALL;
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");
/* Their sig should sign our commit tx. */
@ -496,7 +489,7 @@ static Pkt *check_and_save_commit_sig(struct peer *peer,
NULL, 0,
peer->anchor.witnessscript,
&peer->them.commitkey,
ci->sig))
&ci->sig))
return pkt_err(peer, "Bad signature");
return NULL;

View File

@ -1207,7 +1207,7 @@ const struct bitcoin_tx *bitcoin_commit(struct peer *peer)
peer->us.commit->tx->input[0].witness
= bitcoin_witness_2of2(peer->us.commit->tx->input,
peer->us.commit->sig,
&peer->us.commit->sig,
&sig,
&peer->them.commitkey,
&peer->us.commitkey);
@ -1377,17 +1377,6 @@ static void json_add_htlcs(struct json_result *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: Somehow we should show running DNS lookups! */
@ -1415,12 +1404,12 @@ static void json_getpeers(struct command *cmd,
/* FIXME: Report anchor. */
last = last_signed_state(p->us.commit);
if (!last) {
if (!p->us.commit) {
json_object_end(response);
continue;
}
last = p->us.commit->cstate;
json_add_num(response, "our_amount", last->a.pay_msat);
json_add_num(response, "our_fee", last->a.fee_msat);
json_add_num(response, "their_amount", last->b.pay_msat);

View File

@ -61,8 +61,8 @@ struct commit_info {
struct bitcoin_tx *tx;
/* Channel state for this tx. */
struct channel_state *cstate;
/* Other side's signature for last commit tx (if known) */
struct bitcoin_signature *sig;
/* Other side's signature for this commit tx. */
struct bitcoin_signature sig;
/* Revocation preimage (if known). */
struct sha256 *revocation_preimage;
};