From 1f9103c9d339710ade02c7649d590550ab206a63 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 8 Mar 2016 10:43:15 +1030 Subject: [PATCH] daemon: rename num_htlcs to commit_tx_counter. Much clearer name. Signed-off-by: Rusty Russell --- daemon/packets.c | 17 +++++++++-------- daemon/peer.c | 4 ++-- daemon/peer.h | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index 3b233783d..9d15c593f 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -216,8 +216,8 @@ Pkt *pkt_update_signature(const tal_t *ctx, const struct peer *peer) peer_sign_theircommit(peer, cur->their_commit, &sig); u->sig = signature_to_proto(u, &sig); - assert(peer->num_htlcs > 0); - peer_get_revocation_preimage(peer, peer->num_htlcs-1, &preimage); + assert(peer->commit_tx_counter > 0); + peer_get_revocation_preimage(peer, peer->commit_tx_counter-1, &preimage); u->revocation_preimage = sha256_to_proto(u, &preimage); return make_pkt(ctx, PKT__PKT_UPDATE_SIGNATURE, u); @@ -230,7 +230,8 @@ Pkt *pkt_update_complete(const tal_t *ctx, const struct peer *peer) update_complete__init(u); - peer_get_revocation_preimage(peer, peer->num_htlcs-1, &preimage); + assert(peer->commit_tx_counter > 0); + peer_get_revocation_preimage(peer, peer->commit_tx_counter-1, &preimage); u->revocation_preimage = sha256_to_proto(u, &preimage); return make_pkt(ctx, PKT__PKT_UPDATE_COMPLETE, u); @@ -473,7 +474,7 @@ Pkt *accept_pkt_htlc_add(const tal_t *ctx, &cur->htlc->expiry, &cur->htlc->rhash); peer_add_htlc_expiry(peer, &cur->htlc->expiry); - peer_get_revocation_hash(peer, peer->num_htlcs+1, + peer_get_revocation_hash(peer, peer->commit_tx_counter+1, &cur->our_revocation_hash); memcheck(&cur->their_revocation_hash, sizeof(cur->their_revocation_hash)); @@ -532,7 +533,7 @@ Pkt *accept_pkt_htlc_fail(const tal_t *ctx, struct peer *peer, const Pkt *pkt) funding_remove_htlc(&cur->cstate->a, i); /* FIXME: Remove timer. */ - peer_get_revocation_hash(peer, peer->num_htlcs+1, + peer_get_revocation_hash(peer, peer->commit_tx_counter+1, &cur->our_revocation_hash); /* Now we create the commit tx pair. */ @@ -588,7 +589,7 @@ Pkt *accept_pkt_htlc_timedout(const tal_t *ctx, funding_remove_htlc(&cur->cstate->a, i); /* FIXME: Remove timer. */ - peer_get_revocation_hash(peer, peer->num_htlcs+1, + peer_get_revocation_hash(peer, peer->commit_tx_counter+1, &cur->our_revocation_hash); /* Now we create the commit tx pair. */ @@ -638,7 +639,7 @@ Pkt *accept_pkt_htlc_fulfill(const tal_t *ctx, } funding_remove_htlc(&cur->cstate->a, i); - peer_get_revocation_hash(peer, peer->num_htlcs+1, + peer_get_revocation_hash(peer, peer->commit_tx_counter+1, &cur->our_revocation_hash); /* Now we create the commit tx pair. */ @@ -694,7 +695,7 @@ static void update_to_new_htlcs(struct peer *peer) peer->us.revocation_hash = cur->our_revocation_hash; peer->them.revocation_hash = cur->their_revocation_hash; - peer->num_htlcs++; + peer->commit_tx_counter++; } Pkt *accept_pkt_update_accept(const tal_t *ctx, diff --git a/daemon/peer.c b/daemon/peer.c index a7e59be63..5dfb38760 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -340,7 +340,7 @@ static struct peer *new_peer(struct lightningd_state *dstate, peer->curr_cmd.cmd = INPUT_NONE; list_head_init(&peer->pending_cmd); peer->current_htlc = NULL; - peer->num_htlcs = 0; + peer->commit_tx_counter = 0; peer->close_tx = NULL; peer->cstate = NULL; peer->close_watch_timeout = NULL; @@ -1292,7 +1292,7 @@ static void set_htlc_command(struct peer *peer, if (r_fulfill) peer->current_htlc->r = *r_fulfill; - peer_get_revocation_hash(peer, peer->num_htlcs+1, + peer_get_revocation_hash(peer, peer->commit_tx_counter+1, &peer->current_htlc->our_revocation_hash); /* FIXME: Do we need current_htlc as idata arg? */ diff --git a/daemon/peer.h b/daemon/peer.h index 74b24f90e..e525d1f91 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -112,7 +112,7 @@ struct peer { /* Current HTLC, if any. */ struct htlc_progress *current_htlc; /* Number of HTLC updates (== number of previous commit txs) */ - u64 num_htlcs; + u64 commit_tx_counter; /* FIXME: Group closing fields together in anon struct. */ /* Closing tx and signature once we've generated it */