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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-01-22 06:45:27 +10:30
parent 5acb3c9848
commit 645958920e
3 changed files with 43 additions and 27 deletions

View File

@ -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))

View File

@ -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);
*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);
/* 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;
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! */

View File

@ -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 */