Browse Source

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>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
645958920e
  1. 7
      daemon/packets.c
  2. 58
      daemon/peer.c
  3. 7
      daemon/peer.h

7
daemon/packets.c

@ -266,7 +266,12 @@ Pkt *accept_pkt_anchor(const tal_t *ctx,
invert_cstate(peer->cstate); invert_cstate(peer->cstate);
/* Now we can make initial (unsigned!) commit txs. */ /* 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; peer->cur_commit_theirsig.stype = SIGHASH_ALL;
if (!proto_to_signature(a->commit_sig, &peer->cur_commit_theirsig.sig)) if (!proto_to_signature(a->commit_sig, &peer->cur_commit_theirsig.sig))

58
daemon/peer.c

@ -784,7 +784,12 @@ static void created_anchor(struct lightningd_state *dstate,
fatal("Insufficient anchor funds for commitfee"); fatal("Insufficient anchor funds for commitfee");
/* Now we can make initial (unsigned!) commit txs. */ /* 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); 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; 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; struct channel_state their_cstate;
tal_free(peer->us.commit); *ours = create_commit_tx(ctx,
tal_free(peer->them.commit); &peer->us.finalkey,
&peer->them.finalkey,
/* FIXME: Where do we update revocation_hash fields? */ &peer->them.locktime,
peer->us.commit = create_commit_tx(peer, &peer->anchor.txid,
&peer->us.finalkey, peer->anchor.index,
&peer->them.finalkey, peer->anchor.satoshis,
&peer->them.locktime, our_revocation_hash,
&peer->anchor.txid, cstate);
peer->anchor.index,
peer->anchor.satoshis, their_cstate = *cstate;
&peer->us.revocation_hash,
peer->cstate);
their_cstate = *peer->cstate;
invert_cstate(&their_cstate); invert_cstate(&their_cstate);
peer->them.commit = create_commit_tx(peer, *theirs = create_commit_tx(ctx,
&peer->them.finalkey, &peer->them.finalkey,
&peer->us.finalkey, &peer->us.finalkey,
&peer->us.locktime, &peer->us.locktime,
&peer->anchor.txid, &peer->anchor.txid,
peer->anchor.index, peer->anchor.index,
peer->anchor.satoshis, peer->anchor.satoshis,
&peer->them.revocation_hash, their_revocation_hash,
&their_cstate); &their_cstate);
} }
/* FIXME: Somehow we should show running DNS lookups! */ /* FIXME: Somehow we should show running DNS lookups! */

7
daemon/peer.h

@ -97,6 +97,11 @@ struct peer {
void setup_listeners(struct lightningd_state *dstate, unsigned int portnum); 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 */ #endif /* LIGHTNING_DAEMON_PEER_H */

Loading…
Cancel
Save