From 0d30b89043cd9185bab2b2d813463cd93b41d071 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 21 Feb 2019 14:15:55 +1030 Subject: [PATCH] channeld: use amount_msat for struct htlc amount. Signed-off-by: Rusty Russell --- channeld/channeld.c | 32 +++++------ channeld/channeld_htlc.h | 3 +- channeld/commit_tx.c | 21 ++++---- channeld/full_channel.c | 91 ++++++++++++++++++-------------- channeld/full_channel.h | 4 +- channeld/test/run-commit_tx.c | 16 +++--- channeld/test/run-full_channel.c | 20 +++---- tests/test_pay.py | 4 +- 8 files changed, 101 insertions(+), 90 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index cd53a6395..0291f9792 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -589,21 +589,21 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u64 id; - u64 amount_msat; + struct amount_msat amount; u32 cltv_expiry; struct sha256 payment_hash; u8 onion_routing_packet[TOTAL_PACKET_SIZE]; enum channel_add_err add_err; struct htlc *htlc; - if (!fromwire_update_add_htlc(msg, &channel_id, &id, &amount_msat, + if (!fromwire_update_add_htlc(msg, &channel_id, &id, &amount.millisatoshis, &payment_hash, &cltv_expiry, onion_routing_packet)) peer_failed(&peer->cs, &peer->channel_id, "Bad peer_add_htlc %s", tal_hex(msg, msg)); - add_err = channel_add_htlc(peer->channel, REMOTE, id, amount_msat, + add_err = channel_add_htlc(peer->channel, REMOTE, id, amount, cltv_expiry, &payment_hash, onion_routing_packet, &htlc); if (add_err != CHANNEL_ERR_ADD_OK) @@ -866,12 +866,12 @@ static u8 *make_failmsg(const tal_t *ctx, goto done; case WIRE_AMOUNT_BELOW_MINIMUM: channel_update = foreign_channel_update(ctx, peer, scid); - msg = towire_amount_below_minimum(ctx, htlc->msatoshi, + msg = towire_amount_below_minimum(ctx, htlc->amount.millisatoshis, channel_update); goto done; case WIRE_FEE_INSUFFICIENT: channel_update = foreign_channel_update(ctx, peer, scid); - msg = towire_fee_insufficient(ctx, htlc->msatoshi, + msg = towire_fee_insufficient(ctx, htlc->amount.millisatoshis, channel_update); goto done; case WIRE_INCORRECT_CLTV_EXPIRY: @@ -888,7 +888,7 @@ static u8 *make_failmsg(const tal_t *ctx, goto done; case WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS: msg = towire_incorrect_or_unknown_payment_details( - ctx, htlc->msatoshi); + ctx, htlc->amount.millisatoshis); goto done; case WIRE_FINAL_EXPIRY_TOO_SOON: msg = towire_final_expiry_too_soon(ctx); @@ -897,7 +897,7 @@ static u8 *make_failmsg(const tal_t *ctx, msg = towire_final_incorrect_cltv_expiry(ctx, cltv_expiry); goto done; case WIRE_FINAL_INCORRECT_HTLC_AMOUNT: - msg = towire_final_incorrect_htlc_amount(ctx, htlc->msatoshi); + msg = towire_final_incorrect_htlc_amount(ctx, htlc->amount.millisatoshis); goto done; case WIRE_INVALID_ONION_VERSION: msg = towire_invalid_onion_version(ctx, sha256); @@ -1251,7 +1251,7 @@ static u8 *got_commitsig_msg(const tal_t *ctx, struct secret s; a.id = htlc->id; - a.amount_msat = htlc->msatoshi; + a.amount_msat = htlc->amount.millisatoshis; a.payment_hash = htlc->rhash; a.cltv_expiry = abs_locktime_to_blocks(&htlc->expiry); memcpy(a.onion_routing_packet, @@ -1899,7 +1899,7 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last if (h->state == SENT_ADD_COMMIT) { u8 *msg = towire_update_add_htlc(NULL, &peer->channel_id, - h->id, h->msatoshi, + h->id, h->amount.millisatoshis, &h->rhash, abs_locktime_to_blocks( &h->expiry), @@ -2419,7 +2419,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg) { u8 *msg; u32 cltv_expiry; - u64 amount_msat; + struct amount_msat amount; struct sha256 payment_hash; u8 onion_routing_packet[TOTAL_PACKET_SIZE]; enum channel_add_err e; @@ -2431,23 +2431,25 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg) status_failed(STATUS_FAIL_MASTER_IO, "funding not locked for offer_htlc"); - if (!fromwire_channel_offer_htlc(inmsg, &amount_msat, + if (!fromwire_channel_offer_htlc(inmsg, &amount.millisatoshis, &cltv_expiry, &payment_hash, onion_routing_packet)) master_badmsg(WIRE_CHANNEL_OFFER_HTLC, inmsg); e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id, - amount_msat, cltv_expiry, &payment_hash, + amount, cltv_expiry, &payment_hash, onion_routing_packet, NULL); - status_trace("Adding HTLC %"PRIu64" msat=%"PRIu64" cltv=%u gave %s", - peer->htlc_id, amount_msat, cltv_expiry, + status_trace("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s", + peer->htlc_id, + type_to_string(tmpctx, struct amount_msat, &amount), + cltv_expiry, channel_add_err_name(e)); switch (e) { case CHANNEL_ERR_ADD_OK: /* Tell the peer. */ msg = towire_update_add_htlc(NULL, &peer->channel_id, - peer->htlc_id, amount_msat, + peer->htlc_id, amount.millisatoshis, &payment_hash, cltv_expiry, onion_routing_packet); sync_crypto_write(&peer->cs, PEER_FD, take(msg)); diff --git a/channeld/channeld_htlc.h b/channeld/channeld_htlc.h index 2e6ef2cc1..37b06ffad 100644 --- a/channeld/channeld_htlc.h +++ b/channeld/channeld_htlc.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -13,7 +14,7 @@ struct htlc { /* The unique ID for this peer and this direction (LOCAL or REMOTE) */ u64 id; /* The amount in millisatoshi. */ - u64 msatoshi; + struct amount_msat amount; /* When the HTLC can no longer be redeemed. */ struct abs_locktime expiry; /* The hash of the preimage which can redeem this HTLC */ diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 845634384..b48b17538 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -45,7 +45,7 @@ static bool trim(const struct htlc *htlc, /* If these overflow, it implies htlc must be less. */ if (!amount_sat_add(&htlc_min, dust_limit, htlc_fee)) return true; - return htlc->msatoshi / 1000 < htlc_min.satoshis; + return amount_msat_less_sat(htlc->amount, htlc_min); } size_t commit_tx_num_untrimmed(const struct htlc **htlcs, @@ -70,7 +70,7 @@ static void add_offered_htlc_out(struct bitcoin_tx *tx, size_t n, ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); wscript = htlc_offered_wscript(tx->output, &ripemd, keyset); - tx->output[n].amount = htlc->msatoshi / 1000; + tx->output[n].amount = amount_msat_to_sat_round_down(htlc->amount).satoshis; tx->output[n].script = scriptpubkey_p2wsh(tx, wscript); SUPERVERBOSE("# HTLC %"PRIu64" offered amount %"PRIu64" wscript %s\n", htlc->id, tx->output[n].amount, tal_hex(wscript, wscript)); @@ -86,7 +86,7 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n, ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); wscript = htlc_received_wscript(tx, &ripemd, &htlc->expiry, keyset); - tx->output[n].amount = htlc->msatoshi / 1000; + tx->output[n].amount = amount_msat_to_sat_round_down(htlc->amount).satoshis; tx->output[n].script = scriptpubkey_p2wsh(tx->output, wscript); SUPERVERBOSE("# HTLC %"PRIu64" received amount %"PRIu64" wscript %s\n", htlc->id, tx->output[n].amount, tal_hex(wscript, wscript)); @@ -147,18 +147,19 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, #ifdef PRINT_ACTUAL_FEE { - u64 satoshis_out = 0; + struct amount_sat out = AMOUNT_SAT(0); + bool ok = true; for (i = 0; i < tal_count(htlcs); i++) { - if (!trim(htlcs[i], feerate_per_kw, dust_limit, - side)) - satoshis_out += htlcs[i]->msatoshi / 1000; + if (!trim(htlcs[i], feerate_per_kw, dust_limit, side)) + ok &= amount_sat_add(&out, out, amount_msat_to_sat_round_down(htlcs[i]->amount)); } if (amount_msat_greater_sat(self_pay, dust_limit)) - satoshis_out += self_pay.millisatoshis / 1000; + ok &= amount_sat_add(&out, out, amount_msat_to_sat_round_down(self_pay)); if (amount_msat_greater_sat(other_pay, dust_limit)) - satoshis_out += other_pay.millisatoshis / 1000; + ok &= amount_sat_add(&out, out, amount_msat_to_sat_round_down(other_pay)); + assert(ok); SUPERVERBOSE("# actual commitment transaction fee = %"PRIu64"\n", - funding.satoshis - satoshis_out); + funding.satoshis - out.satoshis); } #endif diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 27688e9f6..94eb10eda 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -73,12 +73,8 @@ static bool WARN_UNUSED_RESULT balance_add_htlc(struct amount_msat *msat, const struct htlc *htlc, enum side side) { - struct amount_msat htlc_msat; - - htlc_msat.millisatoshis = htlc->msatoshi; - if (htlc_owner(htlc) == side) - return amount_msat_sub(msat, *msat, htlc_msat); + return amount_msat_sub(msat, *msat, htlc->amount); return true; } @@ -87,11 +83,8 @@ static bool WARN_UNUSED_RESULT balance_remove_htlc(struct amount_msat *msat, const struct htlc *htlc, enum side side) { - struct amount_msat htlc_msat; enum side paid_to; - htlc_msat.millisatoshis = htlc->msatoshi; - /* Fulfilled HTLCs are paid to recipient, otherwise returns to owner */ if (htlc->r) paid_to = !htlc_owner(htlc); @@ -99,7 +92,7 @@ static bool WARN_UNUSED_RESULT balance_remove_htlc(struct amount_msat *msat, paid_to = htlc_owner(htlc); if (side == paid_to) - return amount_msat_add(msat, *msat, htlc_msat); + return amount_msat_add(msat, *msat, htlc->amount); return true; } @@ -184,9 +177,7 @@ static bool sum_offered_msatoshis(struct amount_msat *total, *total = AMOUNT_MSAT(0); for (i = 0; i < tal_count(htlcs); i++) { if (htlc_owner(htlcs[i]) == side) { - struct amount_msat m; - m.millisatoshis = htlcs[i]->msatoshi; - if (!amount_msat_add(total, *total, m)) + if (!amount_msat_add(total, *total, htlcs[i]->amount)) return false; } } @@ -211,15 +202,13 @@ static void add_htlcs(struct bitcoin_tx ***txs, const struct htlc *htlc = htlcmap[i]; struct bitcoin_tx *tx; u8 *wscript; - struct amount_msat htlc_amount; if (!htlc) continue; - htlc_amount.millisatoshis = htlc->msatoshi; if (htlc_owner(htlc) == side) { tx = htlc_timeout_tx(*txs, &txid, i, - htlc_amount, + htlc->amount, htlc->expiry.locktime, channel->config[!side].to_self_delay, feerate_per_kw, @@ -231,7 +220,7 @@ static void add_htlcs(struct bitcoin_tx ***txs, &keyset->self_revocation_key); } else { tx = htlc_success_tx(*txs, &txid, i, - htlc_amount, + htlc->amount, channel->config[!side].to_self_delay, feerate_per_kw, keyset); @@ -302,7 +291,9 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, static enum channel_add_err add_htlc(struct channel *channel, enum htlc_state state, - u64 id, u64 msatoshi, u32 cltv_expiry, + u64 id, + struct amount_msat amount, + u32 cltv_expiry, const struct sha256 *payment_hash, const u8 routing[TOTAL_PACKET_SIZE], struct htlc **htlcp, @@ -320,7 +311,7 @@ static enum channel_add_err add_htlc(struct channel *channel, htlc = tal(tmpctx, struct htlc); htlc->id = id; - htlc->msatoshi = msatoshi; + htlc->amount = amount; htlc->state = state; htlc->shared_secret = NULL; @@ -348,7 +339,7 @@ static enum channel_add_err add_htlc(struct channel *channel, old = htlc_get(channel->htlcs, htlc->id, htlc_owner(htlc)); if (old) { if (old->state != htlc->state - || old->msatoshi != htlc->msatoshi + || !amount_msat_eq(old->amount, htlc->amount) || old->expiry.locktime != htlc->expiry.locktime || !sha256_eq(&old->rhash, &htlc->rhash)) return CHANNEL_ERR_DUPLICATE_ID_DIFFERENT; @@ -366,10 +357,10 @@ static enum channel_add_err add_htlc(struct channel *channel, * `htlc_minimum_msat`: * - SHOULD fail the channel. */ - if (htlc->msatoshi == 0) { + if (amount_msat_eq(htlc->amount, AMOUNT_MSAT(0))) { return CHANNEL_ERR_HTLC_BELOW_MINIMUM; } - if (htlc->msatoshi < channel->config[recipient].htlc_minimum.millisatoshis) { + if (amount_msat_less(htlc->amount, channel->config[recipient].htlc_minimum)) { return CHANNEL_ERR_HTLC_BELOW_MINIMUM; } @@ -378,7 +369,7 @@ static enum channel_add_err add_htlc(struct channel *channel, * - for channels with `chain_hash` identifying the Bitcoin blockchain: * - MUST set the four most significant bytes of `amount_msat` to 0. */ - if (htlc->msatoshi > channel->chainparams->max_payment.millisatoshis) { + if (amount_msat_greater(htlc->amount, channel->chainparams->max_payment)) { return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED; } @@ -523,7 +514,7 @@ static enum channel_add_err add_htlc(struct channel *channel, enum channel_add_err channel_add_htlc(struct channel *channel, enum side sender, u64 id, - u64 msatoshi, + struct amount_msat amount, u32 cltv_expiry, const struct sha256 *payment_hash, const u8 routing[TOTAL_PACKET_SIZE], @@ -536,7 +527,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel, else state = RCVD_ADD_HTLC; - return add_htlc(channel, state, id, msatoshi, cltv_expiry, + return add_htlc(channel, state, id, amount, cltv_expiry, payment_hash, routing, htlcp, true); } @@ -689,15 +680,19 @@ static void htlc_incstate(struct channel *channel, if (!balance_add_htlc(&channel->view[sidechanged].owed[LOCAL], htlc, LOCAL)) status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Cannot add htlc #%"PRIu64" %"PRIu64 + "Cannot add htlc #%"PRIu64" %s" " to LOCAL", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); if (!balance_add_htlc(&channel->view[sidechanged].owed[REMOTE], htlc, REMOTE)) status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Cannot add htlc #%"PRIu64" %"PRIu64 + "Cannot add htlc #%"PRIu64" %s" " to REMOTE", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); status_trace("-> local %s remote %s", type_to_string(tmpctx, struct amount_msat, &channel->view[sidechanged].owed[LOCAL]), @@ -713,15 +708,19 @@ static void htlc_incstate(struct channel *channel, if (!balance_remove_htlc(&channel->view[sidechanged].owed[LOCAL], htlc, LOCAL)) status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Cannot remove htlc #%"PRIu64" %"PRIu64 + "Cannot remove htlc #%"PRIu64" %s" " from LOCAL", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); if (!balance_remove_htlc(&channel->view[sidechanged].owed[REMOTE], htlc, REMOTE)) status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Cannot remove htlc #%"PRIu64" %"PRIu64 + "Cannot remove htlc #%"PRIu64" %s" " from REMOTE", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); status_trace("-> local %s remote %s", type_to_string(tmpctx, struct amount_msat, &channel->view[sidechanged].owed[LOCAL]), @@ -982,16 +981,20 @@ static bool adjust_balance(struct channel *channel, struct htlc *htlc) /* Add it. */ if (!balance_add_htlc(&channel->view[side].owed[LOCAL], htlc, LOCAL)) { - status_broken("Cannot add htlc #%"PRIu64" %"PRIu64 + status_broken("Cannot add htlc #%"PRIu64" %s" " to LOCAL", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); return false; } if (!balance_add_htlc(&channel->view[side].owed[REMOTE], htlc, REMOTE)) { - status_broken("Cannot add htlc #%"PRIu64" %"PRIu64 + status_broken("Cannot add htlc #%"PRIu64" %s" " to REMOTE", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); return false; } @@ -1011,16 +1014,20 @@ static bool adjust_balance(struct channel *channel, struct htlc *htlc) } if (!balance_remove_htlc(&channel->view[side].owed[LOCAL], htlc, LOCAL)) { - status_broken("Cannot remove htlc #%"PRIu64" %"PRIu64 + status_broken("Cannot remove htlc #%"PRIu64" %s" " from LOCAL", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); return false; } if (!balance_remove_htlc(&channel->view[side].owed[REMOTE], htlc, REMOTE)) { - status_broken("Cannot remove htlc #%"PRIu64" %"PRIu64 + status_broken("Cannot remove htlc #%"PRIu64" %s" " from REMOTE", - htlc->id, htlc->msatoshi); + htlc->id, + type_to_string(tmpctx, struct amount_msat, + &htlc->amount)); return false; } } @@ -1059,6 +1066,7 @@ bool channel_force_htlcs(struct channel *channel, for (i = 0; i < tal_count(htlcs); i++) { enum channel_add_err e; struct htlc *htlc; + struct amount_msat amount; status_trace("Restoring HTLC %zu/%zu:" " id=%"PRIu64" msat=%"PRIu64" cltv=%u" @@ -1069,8 +1077,9 @@ bool channel_force_htlcs(struct channel *channel, type_to_string(tmpctx, struct sha256, &htlcs[i].payment_hash)); + amount.millisatoshis = htlcs[i].amount_msat; e = add_htlc(channel, hstates[i], - htlcs[i].id, htlcs[i].amount_msat, + htlcs[i].id, amount, htlcs[i].cltv_expiry, &htlcs[i].payment_hash, htlcs[i].onion_routing_packet, &htlc, false); diff --git a/channeld/full_channel.h b/channeld/full_channel.h index 925aa5304..8a217d176 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -84,7 +84,7 @@ u32 actual_feerate(const struct channel *channel, * @channel: The channel * @offerer: the side offering the HTLC (to the other side). * @id: unique HTLC id. - * @msatoshi: amount in millisatoshi. + * @amount: amount in millisatoshi. * @cltv_expiry: block number when HTLC can no longer be redeemed. * @payment_hash: hash whose preimage can redeem HTLC. * @routing: routing information (copied) @@ -97,7 +97,7 @@ u32 actual_feerate(const struct channel *channel, enum channel_add_err channel_add_htlc(struct channel *channel, enum side sender, u64 id, - u64 msatoshi, + struct amount_msat msatoshi, u32 cltv_expiry, const struct sha256 *payment_hash, const u8 routing[TOTAL_PACKET_SIZE], diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index c1a90684c..9bf0f882b 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -123,23 +123,23 @@ static const struct htlc **setup_htlcs(const tal_t *ctx) switch (i) { case 0: htlc->state = RCVD_ADD_ACK_REVOCATION; - htlc->msatoshi = 1000000; + htlc->amount = AMOUNT_MSAT(1000000); break; case 1: htlc->state = RCVD_ADD_ACK_REVOCATION; - htlc->msatoshi = 2000000; + htlc->amount = AMOUNT_MSAT(2000000); break; case 2: htlc->state = SENT_ADD_ACK_REVOCATION; - htlc->msatoshi = 2000000; + htlc->amount = AMOUNT_MSAT(2000000); break; case 3: htlc->state = SENT_ADD_ACK_REVOCATION; - htlc->msatoshi = 3000000; + htlc->amount = AMOUNT_MSAT(3000000); break; case 4: htlc->state = RCVD_ADD_ACK_REVOCATION; - htlc->msatoshi = 4000000; + htlc->amount = AMOUNT_MSAT(4000000); break; } @@ -217,15 +217,13 @@ static void report_htlcs(const struct bitcoin_tx *tx, for (i = 0; i < tal_count(htlc_map); i++) { const struct htlc *htlc = htlc_map[i]; - struct amount_msat htlc_amount; if (!htlc) continue; - htlc_amount.millisatoshis = htlc->msatoshi; if (htlc_owner(htlc) == LOCAL) { htlc_tx[i] = htlc_timeout_tx(htlc_tx, &txid, i, - htlc_amount, + htlc->amount, htlc->expiry.locktime, to_self_delay, feerate_per_kw, @@ -237,7 +235,7 @@ static void report_htlcs(const struct bitcoin_tx *tx, remote_revocation_key); } else { htlc_tx[i] = htlc_success_tx(htlc_tx, &txid, i, - htlc_amount, + htlc->amount, to_self_delay, feerate_per_kw, &keyset); diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 7e46434b6..406ca9154 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -121,31 +121,31 @@ static const struct htlc **include_htlcs(struct channel *channel, enum side side struct sha256 hash; enum channel_add_err e; enum side sender; - u64 msatoshi = 0; + struct amount_msat msatoshi = AMOUNT_MSAT(0); switch (i) { case 0: sender = !side; - msatoshi = 1000000; + msatoshi = AMOUNT_MSAT(1000000); break; case 1: sender = !side; - msatoshi = 2000000; + msatoshi = AMOUNT_MSAT(2000000); break; case 2: sender = side; - msatoshi = 2000000; + msatoshi = AMOUNT_MSAT(2000000); break; case 3: sender = side; - msatoshi = 3000000; + msatoshi = AMOUNT_MSAT(3000000); break; case 4: sender = !side; - msatoshi = 4000000; + msatoshi = AMOUNT_MSAT(4000000); break; } - assert(msatoshi != 0); + assert(msatoshi.millisatoshis != 0); memset(&preimage, i, sizeof(preimage)); sha256(&hash, &preimage, sizeof(preimage)); @@ -230,7 +230,7 @@ static void txs_must_be_eq(struct bitcoin_tx **a, struct bitcoin_tx **b) static void send_and_fulfill_htlc(struct channel *channel, enum side sender, - u64 msatoshi) + struct amount_msat msatoshi) { struct preimage r; struct sha256 rhash; @@ -531,8 +531,8 @@ int main(void) * here: it's as if local side paid for all the HTLCs. We can * fix this by having local side offer an HTLC, and having * remote side accept it */ - send_and_fulfill_htlc(lchannel, LOCAL, 7000000); - send_and_fulfill_htlc(rchannel, REMOTE, 7000000); + send_and_fulfill_htlc(lchannel, LOCAL, AMOUNT_MSAT(7000000)); + send_and_fulfill_htlc(rchannel, REMOTE, AMOUNT_MSAT(7000000)); assert(lchannel->view[LOCAL].owed[LOCAL].millisatoshis == rchannel->view[REMOTE].owed[REMOTE].millisatoshis); diff --git a/tests/test_pay.py b/tests/test_pay.py index 342131904..517843ba7 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -974,9 +974,9 @@ def test_forward_different_fees_and_cltv(node_factory, bitcoind): # We add one to the blockcount for a bit of fuzz (FIXME: Shadowroute would fix this!) shadow_route = 1 - l1.daemon.wait_for_log("Adding HTLC 0 msat=5010198 cltv={} gave CHANNEL_ERR_ADD_OK" + l1.daemon.wait_for_log("Adding HTLC 0 amount=5010198msat cltv={} gave CHANNEL_ERR_ADD_OK" .format(bitcoind.rpc.getblockcount() + 20 + 9 + shadow_route)) - l2.daemon.wait_for_log("Adding HTLC 0 msat=4999999 cltv={} gave CHANNEL_ERR_ADD_OK" + l2.daemon.wait_for_log("Adding HTLC 0 amount=4999999msat cltv={} gave CHANNEL_ERR_ADD_OK" .format(bitcoind.rpc.getblockcount() + 9 + shadow_route)) l3.daemon.wait_for_log("test_forward_different_fees_and_cltv: Actual amount 4999999msat, HTLC expiry {}" .format(bitcoind.rpc.getblockcount() + 9 + shadow_route))