mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 00:24:19 +01:00
peer: always initialize commit_info commit number, other fields.
We used to use talz, but that prevents valgrind from noticing when we use uninitialized fields. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -733,7 +733,7 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
Pkt *err;
|
||||
struct sha256 preimage;
|
||||
struct commit_info *ci = new_commit_info(peer);
|
||||
struct commit_info *ci;
|
||||
/* FIXME: We can actually merge these two... */
|
||||
static const struct state_table commit_changes[] = {
|
||||
{ RCVD_ADD_REVOCATION, RCVD_ADD_ACK_COMMIT },
|
||||
@@ -748,6 +748,7 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
{ RCVD_REMOVE_ACK_COMMIT, SENT_REMOVE_ACK_REVOCATION }
|
||||
};
|
||||
|
||||
ci = new_commit_info(peer, peer->local.commit->commit_num + 1);
|
||||
ci->sig = tal(ci, struct bitcoin_signature);
|
||||
err = accept_pkt_commit(peer, pkt, ci->sig);
|
||||
if (err)
|
||||
@@ -762,7 +763,6 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
return pkt_err(peer, "Empty commit");
|
||||
|
||||
/* Create new commit info for this commit tx. */
|
||||
ci->commit_num = peer->local.commit->commit_num + 1;
|
||||
ci->revocation_hash = peer->local.next_revocation_hash;
|
||||
|
||||
/* BOLT #2:
|
||||
@@ -1495,7 +1495,7 @@ static void do_commit(struct peer *peer, struct command *jsoncmd)
|
||||
assert(!peer->commit_jsoncmd);
|
||||
|
||||
peer->commit_jsoncmd = jsoncmd;
|
||||
ci = new_commit_info(peer);
|
||||
ci = new_commit_info(peer, peer->remote.commit->commit_num + 1);
|
||||
|
||||
assert(!peer->their_prev_revocation_hash);
|
||||
peer->their_prev_revocation_hash
|
||||
@@ -1511,7 +1511,6 @@ static void do_commit(struct peer *peer, struct command *jsoncmd)
|
||||
fatal("sent commit with no changes");
|
||||
|
||||
/* Create new commit info for this commit tx. */
|
||||
ci->commit_num = peer->remote.commit->commit_num + 1;
|
||||
ci->revocation_hash = peer->remote.next_revocation_hash;
|
||||
/* BOLT #2:
|
||||
*
|
||||
@@ -1566,9 +1565,13 @@ static void try_commit(struct peer *peer)
|
||||
}
|
||||
}
|
||||
|
||||
struct commit_info *new_commit_info(const tal_t *ctx)
|
||||
struct commit_info *new_commit_info(const tal_t *ctx, u64 commit_num)
|
||||
{
|
||||
struct commit_info *ci = talz(ctx, struct commit_info);
|
||||
struct commit_info *ci = tal(ctx, struct commit_info);
|
||||
ci->commit_num = commit_num;
|
||||
ci->tx = NULL;
|
||||
ci->cstate = NULL;
|
||||
ci->sig = NULL;
|
||||
return ci;
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ void peer_add_their_commit(struct peer *peer,
|
||||
const struct sha256_double *txid, u64 commit_num);
|
||||
|
||||
/* Allocate a new commit_info struct. */
|
||||
struct commit_info *new_commit_info(const tal_t *ctx);
|
||||
struct commit_info *new_commit_info(const tal_t *ctx, u64 commit_num);
|
||||
|
||||
/* Freeing removes from map, too */
|
||||
struct htlc *peer_new_htlc(struct peer *peer,
|
||||
|
||||
4
state.c
4
state.c
@@ -28,7 +28,7 @@ static void send_open_pkt(struct peer *peer,
|
||||
{
|
||||
/* Set up out commit info now: rest gets done in setup_first_commit
|
||||
* once anchor is established. */
|
||||
peer->local.commit = new_commit_info(peer);
|
||||
peer->local.commit = new_commit_info(peer, 0);
|
||||
peer->local.commit->revocation_hash = peer->local.next_revocation_hash;
|
||||
peer_get_revocation_hash(peer, 1, &peer->local.next_revocation_hash);
|
||||
|
||||
@@ -37,7 +37,7 @@ static void send_open_pkt(struct peer *peer,
|
||||
|
||||
static Pkt *init_from_pkt_open(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
struct commit_info *ci = new_commit_info(peer);
|
||||
struct commit_info *ci = new_commit_info(peer, 0);
|
||||
Pkt *err;
|
||||
|
||||
err = accept_pkt_open(peer, pkt, &ci->revocation_hash,
|
||||
|
||||
Reference in New Issue
Block a user