diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 693a04704..8f044bcdd 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -451,7 +451,7 @@ void add_peer(struct lightningd *ld, u64 unique_id, peer->remote_funding_locked = false; peer->scid = NULL; peer->seed = NULL; - peer->balance = NULL; + peer->our_msatoshi = NULL; peer->state = UNINITIALIZED; peer->channel_info = NULL; peer->last_was_revoke = false; @@ -749,8 +749,9 @@ static void json_getpeers(struct command *cmd, json_add_string(response, "owner", p->owner->name); if (p->scid) json_add_short_channel_id(response, "channel", p->scid); - if (p->balance) { - json_add_u64(response, "msatoshi_to_us", *p->balance); + if (p->our_msatoshi) { + json_add_u64(response, "msatoshi_to_us", + *p->our_msatoshi); json_add_u64(response, "msatoshi_total", p->funding_satoshi * 1000); } @@ -1258,8 +1259,8 @@ static int peer_closing_complete(struct peer *peer, const u8 *msg) * * The amounts for each output MUST BE rounded down to whole satoshis. */ - out_amounts[LOCAL] = *peer->balance / 1000; - out_amounts[REMOTE] = peer->funding_satoshi - *peer->balance / 1000; + out_amounts[LOCAL] = *peer->our_msatoshi / 1000; + out_amounts[REMOTE] = peer->funding_satoshi - *peer->our_msatoshi / 1000; out_amounts[peer->funder] -= peer->closing_fee_received; derive_basepoints(peer->seed, &local_funding_pubkey, NULL, NULL, NULL); @@ -1391,9 +1392,9 @@ static void peer_start_closingd(struct peer *peer, peer->funding_satoshi, &peer->channel_info->remote_fundingkey, peer->funder, - *peer->balance / 1000, + *peer->our_msatoshi / 1000, peer->funding_satoshi - - *peer->balance / 1000, + - *peer->our_msatoshi / 1000, peer->our_config.dust_limit_satoshis, minfee, maxfee, startfee, local_scriptpubkey, @@ -1510,11 +1511,12 @@ static bool peer_start_channeld(struct peer *peer, const u8 *shutdown_scriptpubkey; /* Now we can consider balance set. */ - peer->balance = tal(peer, u64); + peer->our_msatoshi = tal(peer, u64); if (peer->funder == LOCAL) - *peer->balance = peer->funding_satoshi * 1000 - peer->push_msat; + *peer->our_msatoshi + = peer->funding_satoshi * 1000 - peer->push_msat; else - *peer->balance = peer->push_msat; + *peer->our_msatoshi = peer->push_msat; msg = towire_hsmctl_hsmfd_channeld(tmpctx, peer->unique_id); if (!wire_sync_write(peer->ld->hsm_fd, take(msg))) @@ -1580,7 +1582,7 @@ static bool peer_start_channeld(struct peer *peer, peer->funder, cfg->fee_base, cfg->fee_per_satoshi, - *peer->balance, + *peer->our_msatoshi, peer->seed, &peer->ld->dstate.id, &peer->id, diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 45772362e..78e4191e0 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -73,7 +73,7 @@ struct peer { struct short_channel_id *scid; /* Amount going to us, not counting unfinished HTLCs; if we have one. */ - u64 *balance; + u64 *our_msatoshi; /* Keys for channel. */ struct channel_info *channel_info; diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index f800a0e61..dbca93bdb 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -747,9 +747,9 @@ static void remove_htlc_in(struct peer *peer, struct htlc_in *hin) /* If we fulfilled their HTLC, credit us. */ if (hin->preimage) { log_debug(peer->log, "Balance %"PRIu64" -> %"PRIu64, - *peer->balance, - *peer->balance + hin->msatoshi); - *peer->balance += hin->msatoshi; + *peer->our_msatoshi, + *peer->our_msatoshi + hin->msatoshi); + *peer->our_msatoshi += hin->msatoshi; } tal_free(hin); @@ -770,7 +770,10 @@ static void remove_htlc_out(struct peer *peer, struct htlc_out *hout) fail_out_htlc(hout, NULL); } else { /* We paid for this HTLC, so deduct balance. */ - *peer->balance -= hout->msatoshi; + log_debug(peer->log, "Balance %"PRIu64" -> %"PRIu64, + *peer->our_msatoshi, + *peer->our_msatoshi - hout->msatoshi); + *peer->our_msatoshi -= hout->msatoshi; } tal_free(hout);