Browse Source

struct channel: keep a copy of configs, not just pointers.

This simplifies lifetime assumptions.  Currently all callers keep the
original around, but everything broke when I changed that in the next
patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
trytravis
Rusty Russell 6 years ago
parent
commit
22858f35f9
  1. 2
      channeld/channeld.c
  2. 18
      channeld/full_channel.c
  3. 8
      common/initial_channel.c
  4. 4
      common/initial_channel.h

2
channeld/channeld.c

@ -2340,7 +2340,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
case CHANNEL_ERR_HTLC_BELOW_MINIMUM:
failcode = WIRE_AMOUNT_BELOW_MINIMUM;
failmsg = tal_fmt(inmsg, "HTLC too small (%"PRIu64" minimum)",
peer->channel->config[REMOTE]->htlc_minimum_msat);
peer->channel->config[REMOTE].htlc_minimum_msat);
goto failed;
case CHANNEL_ERR_TOO_MANY_HTLCS:
failcode = WIRE_TEMPORARY_CHANNEL_FAILURE;

18
channeld/full_channel.c

@ -202,7 +202,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
tx = htlc_timeout_tx(*txs, &txid, i,
htlc->msatoshi,
htlc->expiry.locktime,
channel->config[!side]->to_self_delay,
channel->config[!side].to_self_delay,
feerate_per_kw,
keyset);
wscript = bitcoin_wscript_htlc_offer(*wscripts,
@ -213,7 +213,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
} else {
tx = htlc_success_tx(*txs, &txid, i,
htlc->msatoshi,
channel->config[!side]->to_self_delay,
channel->config[!side].to_self_delay,
feerate_per_kw,
keyset);
wscript = bitcoin_wscript_htlc_receive(*wscripts,
@ -259,10 +259,10 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
channel->funding_txout,
channel->funding_msat / 1000,
channel->funder,
channel->config[!side]->to_self_delay,
channel->config[!side].to_self_delay,
&keyset,
channel->view[side].feerate_per_kw,
channel->config[side]->dust_limit_satoshis,
channel->config[side].dust_limit_satoshis,
channel->view[side].owed_msat[side],
channel->view[side].owed_msat[!side],
committed,
@ -348,7 +348,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
if (htlc->msatoshi == 0) {
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
}
if (htlc->msatoshi < channel->config[recipient]->htlc_minimum_msat) {
if (htlc->msatoshi < channel->config[recipient].htlc_minimum_msat) {
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
}
@ -373,7 +373,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
*/
if (enforce_aggregate_limits
&& tal_count(committed) - tal_count(removing) + tal_count(adding)
> channel->config[recipient]->max_accepted_htlcs) {
> channel->config[recipient].max_accepted_htlcs) {
return CHANNEL_ERR_TOO_MANY_HTLCS;
}
@ -389,7 +389,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
* - SHOULD fail the channel.
*/
if (enforce_aggregate_limits
&& msat_in_htlcs > channel->config[recipient]->max_htlc_value_in_flight_msat) {
&& msat_in_htlcs > channel->config[recipient].max_htlc_value_in_flight_msat) {
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
}
@ -404,7 +404,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
*/
if (channel->funder == htlc_owner(htlc)) {
u32 feerate = view->feerate_per_kw;
u64 dust = channel->config[recipient]->dust_limit_satoshis;
u64 dust = channel->config[recipient].dust_limit_satoshis;
size_t untrimmed;
untrimmed = commit_tx_num_untrimmed(committed, feerate, dust,
@ -701,7 +701,7 @@ u32 approx_max_feerate(const struct channel *channel)
bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw)
{
u64 fee_msat, dust = channel->config[!channel->funder]->dust_limit_satoshis;
u64 fee_msat, dust = channel->config[!channel->funder].dust_limit_satoshis;
size_t untrimmed;
const struct htlc **committed, **adding, **removing;
gather_htlcs(tmpctx, channel, !channel->funder,

8
common/initial_channel.c

@ -35,8 +35,8 @@ struct channel *new_initial_channel(const tal_t *ctx,
return tal_free(channel);
channel->funder = funder;
channel->config[LOCAL] = local;
channel->config[REMOTE] = remote;
channel->config[LOCAL] = *local;
channel->config[REMOTE] = *remote;
channel->funding_pubkey[LOCAL] = *local_funding_pubkey;
channel->funding_pubkey[REMOTE] = *remote_funding_pubkey;
channel->htlcs = NULL;
@ -94,10 +94,10 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
channel->funding_msat / 1000,
channel->funder,
/* They specify our to_self_delay and v.v. */
channel->config[!side]->to_self_delay,
channel->config[!side].to_self_delay,
&keyset,
channel->view[side].feerate_per_kw,
channel->config[side]->dust_limit_satoshis,
channel->config[side].dust_limit_satoshis,
channel->view[side].owed_msat[side],
channel->view[side].owed_msat[!side],
channel_reserve_msat(channel, side),

4
common/initial_channel.h

@ -41,7 +41,7 @@ struct channel {
enum side funder;
/* Limits and settings on this channel. */
const struct channel_config *config[NUM_SIDES];
struct channel_config config[NUM_SIDES];
/* Basepoints for deriving keys. */
struct basepoints basepoints[NUM_SIDES];
@ -67,7 +67,7 @@ struct channel {
static inline u64 channel_reserve_msat(const struct channel *channel,
enum side side)
{
return channel->config[!side]->channel_reserve_satoshis * 1000;
return channel->config[!side].channel_reserve_satoshis * 1000;
}
/**

Loading…
Cancel
Save