Skip to content

Commit

Permalink
daemons: use amount_msat/amount_sat in all internal wire transfers.
Browse files Browse the repository at this point in the history
As a side-effect of using amount_msat in gossipd/routing.c, we explicitly
handle overflows and don't need to pre-prune ridiculous-fee channels.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 21, 2019
1 parent 0d30b89 commit 3ac0e81
Show file tree
Hide file tree
Showing 57 changed files with 1,013 additions and 801 deletions.
6 changes: 3 additions & 3 deletions channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ channel_init,1000
channel_init,,chain_hash,struct bitcoin_blkid
channel_init,,funding_txid,struct bitcoin_txid
channel_init,,funding_txout,u16
channel_init,,funding_satoshi,u64
channel_init,,funding_satoshi,struct amount_sat
channel_init,,our_config,struct channel_config
channel_init,,their_config,struct channel_config
# FIXME: Fix generate-wire.py to allow NUM_SIDES*u32 here.
Expand All @@ -23,7 +23,7 @@ channel_init,,old_remote_per_commit,struct pubkey
channel_init,,funder,enum side
channel_init,,fee_base,u32
channel_init,,fee_proportional,u32
channel_init,,local_msatoshi,u64
channel_init,,local_msatoshi,struct amount_msat
channel_init,,our_basepoints,struct basepoints
channel_init,,our_funding_pubkey,struct pubkey
channel_init,,local_node_id,struct pubkey
Expand Down Expand Up @@ -69,7 +69,7 @@ channel_funding_locked,,depth,u32

# Tell channel to offer this htlc
channel_offer_htlc,1004
channel_offer_htlc,,amount_msat,u64
channel_offer_htlc,,amount_msat,struct amount_msat
channel_offer_htlc,,cltv_expiry,u32
channel_offer_htlc,,payment_hash,struct sha256
channel_offer_htlc,,onion_routing_packet,1366*u8
Expand Down
19 changes: 10 additions & 9 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ static void send_channel_update(struct peer *peer, int disable_flag)
disable_flag
== ROUTING_FLAGS_DISABLED,
peer->cltv_delta,
peer->channel->config[REMOTE].htlc_minimum.millisatoshis,
peer->channel->config[REMOTE].htlc_minimum,
peer->fee_base,
peer->fee_per_satoshi,
advertised_htlc_max(peer->channel).millisatoshis);
advertised_htlc_max(peer->channel));
wire_sync_write(GOSSIP_FD, take(msg));
}

Expand All @@ -316,7 +316,7 @@ static void make_channel_local_active(struct peer *peer)
msg = towire_gossipd_local_add_channel(NULL,
&peer->short_channel_ids[LOCAL],
&peer->node_ids[REMOTE],
peer->channel->funding.satoshis);
peer->channel->funding);
wire_sync_write(GOSSIP_FD, take(msg));

/* Tell gossipd and the other side what parameters we expect should
Expand Down Expand Up @@ -942,7 +942,7 @@ static secp256k1_ecdsa_signature *calc_commitsigs(const tal_t *ctx,

msg = towire_hsm_sign_remote_commitment_tx(NULL, txs[0],
&peer->channel->funding_pubkey[REMOTE],
*txs[0]->input[0].amount);
(struct amount_sat){*txs[0]->input[0].amount});

msg = hsm_req(tmpctx, take(msg));
if (!fromwire_hsm_sign_tx_reply(msg, commit_sig))
Expand Down Expand Up @@ -980,7 +980,8 @@ static secp256k1_ecdsa_signature *calc_commitsigs(const tal_t *ctx,
struct bitcoin_signature sig;
msg = towire_hsm_sign_remote_htlc_tx(NULL, txs[i + 1],
wscripts[i + 1],
*txs[i+1]->input[0].amount,
(struct amount_sat)
{ *txs[i+1]->input[0].amount },
&peer->remote_per_commit);

msg = hsm_req(tmpctx, take(msg));
Expand Down Expand Up @@ -1251,7 +1252,7 @@ static u8 *got_commitsig_msg(const tal_t *ctx,
struct secret s;

a.id = htlc->id;
a.amount_msat = htlc->amount.millisatoshis;
a.amount = htlc->amount;
a.payment_hash = htlc->rhash;
a.cltv_expiry = abs_locktime_to_blocks(&htlc->expiry);
memcpy(a.onion_routing_packet,
Expand Down Expand Up @@ -2431,7 +2432,7 @@ 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.millisatoshis,
if (!fromwire_channel_offer_htlc(inmsg, &amount,
&cltv_expiry, &payment_hash,
onion_routing_packet))
master_badmsg(WIRE_CHANNEL_OFFER_HTLC, inmsg);
Expand Down Expand Up @@ -2730,7 +2731,7 @@ static void init_channel(struct peer *peer)
if (!fromwire_channel_init(peer, msg,
&peer->chain_hash,
&funding_txid, &funding_txout,
&funding.satoshis,
&funding,
&conf[LOCAL], &conf[REMOTE],
feerate_per_kw,
&peer->feerate_min, &peer->feerate_max,
Expand All @@ -2743,7 +2744,7 @@ static void init_channel(struct peer *peer)
&funder,
&peer->fee_base,
&peer->fee_per_satoshi,
&local_msat.millisatoshis,
&local_msat,
&points[LOCAL],
&funding_pubkey[LOCAL],
&peer->node_ids[LOCAL],
Expand Down
10 changes: 5 additions & 5 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,20 +1066,20 @@ 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"
" id=%"PRIu64" amount=%s cltv=%u"
" payment_hash=%s",
i, tal_count(htlcs),
htlcs[i].id, htlcs[i].amount_msat,
htlcs[i].id,
type_to_string(tmpctx, struct amount_msat,
&htlcs[i].amount),
htlcs[i].cltv_expiry,
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, amount,
htlcs[i].id, htlcs[i].amount,
htlcs[i].cltv_expiry,
&htlcs[i].payment_hash,
htlcs[i].onion_routing_packet, &htlc, false);
Expand Down
14 changes: 7 additions & 7 deletions closingd/closing_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ closing_init,2001
closing_init,,crypto_state,struct crypto_state
closing_init,,funding_txid,struct bitcoin_txid
closing_init,,funding_txout,u16
closing_init,,funding_satoshi,u64
closing_init,,funding_satoshi,struct amount_sat
closing_init,,local_fundingkey,struct pubkey
closing_init,,remote_fundingkey,struct pubkey
closing_init,,funder,enum side
closing_init,,local_msatoshi,u64
closing_init,,remote_msatoshi,u64
closing_init,,our_dust_limit,u64
closing_init,,min_fee_satoshi,u64
closing_init,,fee_limit_satoshi,u64
closing_init,,initial_fee_satoshi,u64
closing_init,,local_sat,struct amount_sat
closing_init,,remote_sat,struct amount_sat
closing_init,,our_dust_limit,struct amount_sat
closing_init,,min_fee_satoshi,struct amount_sat
closing_init,,fee_limit_satoshi,struct amount_sat
closing_init,,initial_fee_satoshi,struct amount_sat
closing_init,,local_scriptpubkey_len,u16
closing_init,,local_scriptpubkey,local_scriptpubkey_len*u8
closing_init,,remote_scriptpubkey_len,u16
Expand Down
Loading

0 comments on commit 3ac0e81

Please sign in to comment.