From 645958920e39b60773b780d61af22645491852ab Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:45:27 +1030 Subject: [PATCH] peer: make_commit_txs() helper. We need to call it in several places, so unify it into a single function. Signed-off-by: Rusty Russell --- daemon/packets.c | 7 +++++- daemon/peer.c | 58 ++++++++++++++++++++++++++---------------------- daemon/peer.h | 7 +++++- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index 839e8d43e..c6075b92f 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -266,7 +266,12 @@ Pkt *accept_pkt_anchor(const tal_t *ctx, invert_cstate(peer->cstate); /* Now we can make initial (unsigned!) commit txs. */ - peer_make_commit_txs(peer); + make_commit_txs(peer, peer, + &peer->us.revocation_hash, + &peer->them.revocation_hash, + peer->cstate, + &peer->us.commit, + &peer->them.commit); peer->cur_commit_theirsig.stype = SIGHASH_ALL; if (!proto_to_signature(a->commit_sig, &peer->cur_commit_theirsig.sig)) diff --git a/daemon/peer.c b/daemon/peer.c index 5a3887b7e..98c45a2cb 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -784,7 +784,12 @@ static void created_anchor(struct lightningd_state *dstate, fatal("Insufficient anchor funds for commitfee"); /* Now we can make initial (unsigned!) commit txs. */ - peer_make_commit_txs(peer); + make_commit_txs(peer, peer, + &peer->us.revocation_hash, + &peer->them.revocation_hash, + peer->cstate, + &peer->us.commit, + &peer->them.commit); update_state(peer, BITCOIN_ANCHOR_CREATED, NULL); } @@ -827,35 +832,36 @@ const struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer) return peer->anchor.tx; } -void peer_make_commit_txs(struct peer *peer) +void make_commit_txs(const tal_t *ctx, + const struct peer *peer, + const struct sha256 *our_revocation_hash, + const struct sha256 *their_revocation_hash, + const struct channel_state *cstate, + struct bitcoin_tx **ours, struct bitcoin_tx **theirs) { struct channel_state their_cstate; - tal_free(peer->us.commit); - tal_free(peer->them.commit); - - /* FIXME: Where do we update revocation_hash fields? */ - peer->us.commit = create_commit_tx(peer, - &peer->us.finalkey, - &peer->them.finalkey, - &peer->them.locktime, - &peer->anchor.txid, - peer->anchor.index, - peer->anchor.satoshis, - &peer->us.revocation_hash, - peer->cstate); - - their_cstate = *peer->cstate; + *ours = create_commit_tx(ctx, + &peer->us.finalkey, + &peer->them.finalkey, + &peer->them.locktime, + &peer->anchor.txid, + peer->anchor.index, + peer->anchor.satoshis, + our_revocation_hash, + cstate); + + their_cstate = *cstate; invert_cstate(&their_cstate); - peer->them.commit = create_commit_tx(peer, - &peer->them.finalkey, - &peer->us.finalkey, - &peer->us.locktime, - &peer->anchor.txid, - peer->anchor.index, - peer->anchor.satoshis, - &peer->them.revocation_hash, - &their_cstate); + *theirs = create_commit_tx(ctx, + &peer->them.finalkey, + &peer->us.finalkey, + &peer->us.locktime, + &peer->anchor.txid, + peer->anchor.index, + peer->anchor.satoshis, + their_revocation_hash, + &their_cstate); } /* FIXME: Somehow we should show running DNS lookups! */ diff --git a/daemon/peer.h b/daemon/peer.h index f1b186d6f..55b88ce2c 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -97,6 +97,11 @@ struct peer { void setup_listeners(struct lightningd_state *dstate, unsigned int portnum); -void peer_make_commit_txs(struct peer *peer); +void make_commit_txs(const tal_t *ctx, + const struct peer *peer, + const struct sha256 *our_revocation_hash, + const struct sha256 *their_revocation_hash, + const struct channel_state *cstate, + struct bitcoin_tx **ours, struct bitcoin_tx **theirs); #endif /* LIGHTNING_DAEMON_PEER_H */