df: rename 'funder' to 'opener'

Previously we've used the term 'funder' to refer to the peer
paying the fees for a transaction; v2 of openchannel will make
this no longer true. Instead we rename this to 'opener', or the
peer sending the 'open_channel' message, since this will be universally
true in a dual-funding world.
This commit is contained in:
lisa neigut
2019-09-09 11:11:24 -05:00
committed by Rusty Russell
parent 964a3583c4
commit 0e20e3c5e7
36 changed files with 243 additions and 243 deletions

View File

@@ -24,7 +24,7 @@ msgdata,channel_init,remote_fundingkey,pubkey,
msgdata,channel_init,remote_basepoints,basepoints, msgdata,channel_init,remote_basepoints,basepoints,
msgdata,channel_init,remote_per_commit,pubkey, msgdata,channel_init,remote_per_commit,pubkey,
msgdata,channel_init,old_remote_per_commit,pubkey, msgdata,channel_init,old_remote_per_commit,pubkey,
msgdata,channel_init,funder,enum side, msgdata,channel_init,opener,enum side,
msgdata,channel_init,fee_base,u32, msgdata,channel_init,fee_base,u32,
msgdata,channel_init,fee_proportional,u32, msgdata,channel_init,fee_proportional,u32,
msgdata,channel_init,local_msatoshi,amount_msat, msgdata,channel_init,local_msatoshi,amount_msat,
1 #include <common/cryptomsg.h>
24 msgdata,channel_init,remote_per_commit,pubkey,
25 msgdata,channel_init,old_remote_per_commit,pubkey,
26 msgdata,channel_init,funder,enum side, msgdata,channel_init,opener,enum side,
27 msgdata,channel_init,fee_base,u32,
28 msgdata,channel_init,fee_proportional,u32,
29 msgdata,channel_init,local_msatoshi,amount_msat,
30 msgdata,channel_init,our_basepoints,basepoints,

View File

@@ -669,10 +669,10 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* - if the sender is not responsible for paying the Bitcoin fee: * - if the sender is not responsible for paying the Bitcoin fee:
* - MUST fail the channel. * - MUST fail the channel.
*/ */
if (peer->channel->funder != REMOTE) if (peer->channel->opener != REMOTE)
peer_failed(peer->pps, peer_failed(peer->pps,
&peer->channel_id, &peer->channel_id,
"update_fee from non-funder?"); "update_fee from non-opener?");
status_debug("update_fee %u, range %u-%u", status_debug("update_fee %u, range %u-%u",
feerate, peer->feerate_min, peer->feerate_max); feerate, peer->feerate_min, peer->feerate_max);
@@ -975,7 +975,7 @@ static void send_commit(struct peer *peer)
} }
/* If we wanted to update fees, do it now. */ /* If we wanted to update fees, do it now. */
if (peer->channel->funder == LOCAL) { if (peer->channel->opener == LOCAL) {
u32 feerate, max = approx_max_feerate(peer->channel); u32 feerate, max = approx_max_feerate(peer->channel);
feerate = peer->desired_feerate; feerate = peer->desired_feerate;
@@ -1240,11 +1240,11 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
} }
/* We were supposed to check this was affordable as we go. */ /* We were supposed to check this was affordable as we go. */
if (peer->channel->funder == REMOTE) { if (peer->channel->opener == REMOTE) {
status_debug("Feerates are %u/%u", status_debug("Feerates are %u/%u",
channel_feerate(peer->channel, LOCAL), channel_feerate(peer->channel, LOCAL),
channel_feerate(peer->channel, REMOTE)); channel_feerate(peer->channel, REMOTE));
assert(can_funder_afford_feerate(peer->channel, assert(can_opener_afford_feerate(peer->channel,
channel_feerate(peer->channel, channel_feerate(peer->channel,
LOCAL))); LOCAL)));
} }
@@ -1432,7 +1432,7 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
peer->old_remote_per_commit = peer->remote_per_commit; peer->old_remote_per_commit = peer->remote_per_commit;
peer->remote_per_commit = next_per_commit; peer->remote_per_commit = next_per_commit;
status_debug("revoke_and_ack %s: remote_per_commit = %s, old_remote_per_commit = %s", status_debug("revoke_and_ack %s: remote_per_commit = %s, old_remote_per_commit = %s",
side_to_str(peer->channel->funder), side_to_str(peer->channel->opener),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit), &peer->remote_per_commit),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct pubkey,
@@ -2107,7 +2107,7 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
} }
/* Make sure they have the correct fee. */ /* Make sure they have the correct fee. */
if (peer->channel->funder == LOCAL) { if (peer->channel->opener == LOCAL) {
msg = towire_update_fee(NULL, &peer->channel_id, msg = towire_update_fee(NULL, &peer->channel_id,
channel_feerate(peer->channel, REMOTE)); channel_feerate(peer->channel, REMOTE));
sync_crypto_write(peer->pps, take(msg)); sync_crypto_write(peer->pps, take(msg));
@@ -2812,7 +2812,7 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
* sufficient (by a significant margin) for timely processing of the * sufficient (by a significant margin) for timely processing of the
* commitment transaction. * commitment transaction.
*/ */
if (peer->channel->funder == LOCAL) { if (peer->channel->opener == LOCAL) {
peer->desired_feerate = feerate; peer->desired_feerate = feerate;
/* Don't do this for the first feerate, wait until something else /* Don't do this for the first feerate, wait until something else
* happens. LND seems to get upset in some cases otherwise: * happens. LND seems to get upset in some cases otherwise:
@@ -3067,7 +3067,7 @@ static void init_channel(struct peer *peer)
struct pubkey funding_pubkey[NUM_SIDES]; struct pubkey funding_pubkey[NUM_SIDES];
struct channel_config conf[NUM_SIDES]; struct channel_config conf[NUM_SIDES];
struct bitcoin_txid funding_txid; struct bitcoin_txid funding_txid;
enum side funder; enum side opener;
struct existing_htlc **htlcs; struct existing_htlc **htlcs;
bool reconnected; bool reconnected;
u8 *funding_signed; u8 *funding_signed;
@@ -3102,7 +3102,7 @@ static void init_channel(struct peer *peer)
&points[REMOTE], &points[REMOTE],
&peer->remote_per_commit, &peer->remote_per_commit,
&peer->old_remote_per_commit, &peer->old_remote_per_commit,
&funder, &opener,
&peer->fee_base, &peer->fee_base,
&peer->fee_per_satoshi, &peer->fee_per_satoshi,
&local_msat, &local_msat,
@@ -3148,7 +3148,7 @@ static void init_channel(struct peer *peer)
" next_idx_remote = %"PRIu64 " next_idx_remote = %"PRIu64
" revocations_received = %"PRIu64 " revocations_received = %"PRIu64
" feerates %s range %u-%u", " feerates %s range %u-%u",
side_to_str(funder), side_to_str(opener),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit), &peer->remote_per_commit),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct pubkey,
@@ -3197,7 +3197,7 @@ static void init_channel(struct peer *peer)
&funding_pubkey[LOCAL], &funding_pubkey[LOCAL],
&funding_pubkey[REMOTE], &funding_pubkey[REMOTE],
option_static_remotekey, option_static_remotekey,
funder); opener);
if (!channel_force_htlcs(peer->channel, if (!channel_force_htlcs(peer->channel,
cast_const2(const struct existing_htlc **, htlcs))) cast_const2(const struct existing_htlc **, htlcs)))
@@ -3211,7 +3211,7 @@ static void init_channel(struct peer *peer)
&peer->node_ids[REMOTE]); &peer->node_ids[REMOTE]);
/* Default desired feerate is the feerate we set for them last. */ /* Default desired feerate is the feerate we set for them last. */
if (peer->channel->funder == LOCAL) if (peer->channel->opener == LOCAL)
peer->desired_feerate = channel_feerate(peer->channel, REMOTE); peer->desired_feerate = channel_feerate(peer->channel, REMOTE);
/* from now we need keep watch over WIRE_CHANNEL_FUNDING_DEPTH */ /* from now we need keep watch over WIRE_CHANNEL_FUNDING_DEPTH */

View File

@@ -85,7 +85,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
enum side funder, enum side opener,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u32 feerate_per_kw, u32 feerate_per_kw,
@@ -131,7 +131,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
* 3. Subtract this base fee from the funder (either `to_local` or * 3. Subtract this base fee from the funder (either `to_local` or
* `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)). * `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)).
*/ */
try_subtract_fee(funder, side, base_fee, &self_pay, &other_pay); try_subtract_fee(opener, side, base_fee, &self_pay, &other_pay);
#ifdef PRINT_ACTUAL_FEE #ifdef PRINT_ACTUAL_FEE
{ {

View File

@@ -28,7 +28,7 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
* commit_tx: create (unsigned) commitment tx to spend the funding tx output * commit_tx: create (unsigned) commitment tx to spend the funding tx output
* @ctx: context to allocate transaction and @htlc_map from. * @ctx: context to allocate transaction and @htlc_map from.
* @funding_txid, @funding_out, @funding: funding outpoint. * @funding_txid, @funding_out, @funding: funding outpoint.
* @funder: is the LOCAL or REMOTE paying the fee? * @opener: is the LOCAL or REMOTE paying the fee?
* @keyset: keys derived for this commit tx. * @keyset: keys derived for this commit tx.
* @feerate_per_kw: feerate to use * @feerate_per_kw: feerate to use
* @dust_limit: dust limit below which to trim outputs. * @dust_limit: dust limit below which to trim outputs.
@@ -47,7 +47,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
enum side funder, enum side opener,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u32 feerate_per_kw, u32 feerate_per_kw,

View File

@@ -101,7 +101,7 @@ struct channel *new_full_channel(const tal_t *ctx,
const struct pubkey *local_funding_pubkey, const struct pubkey *local_funding_pubkey,
const struct pubkey *remote_funding_pubkey, const struct pubkey *remote_funding_pubkey,
bool option_static_remotekey, bool option_static_remotekey,
enum side funder) enum side opener)
{ {
struct channel *channel = new_initial_channel(ctx, struct channel *channel = new_initial_channel(ctx,
funding_txid, funding_txid,
@@ -116,7 +116,7 @@ struct channel *new_full_channel(const tal_t *ctx,
local_funding_pubkey, local_funding_pubkey,
remote_funding_pubkey, remote_funding_pubkey,
option_static_remotekey, option_static_remotekey,
funder); opener);
if (channel) { if (channel) {
channel->htlcs = tal(channel, struct htlc_map); channel->htlcs = tal(channel, struct htlc_map);
@@ -295,7 +295,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
txs = tal_arr(ctx, struct bitcoin_tx *, 1); txs = tal_arr(ctx, struct bitcoin_tx *, 1);
txs[0] = commit_tx( txs[0] = commit_tx(
ctx, &channel->funding_txid, channel->funding_txout, ctx, &channel->funding_txid, channel->funding_txout,
channel->funding, channel->funder, channel->funding, channel->opener,
channel->config[!side].to_self_delay, &keyset, channel->config[!side].to_self_delay, &keyset,
channel_feerate(channel, side), channel_feerate(channel, side),
channel->config[side].dust_limit, channel->view[side].owed[side], channel->config[side].dust_limit, channel->view[side].owed[side],
@@ -384,8 +384,8 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
} }
/* /*
* There is a corner case where the funder can spend so much that the * There is a corner case where the opener can spend so much that the
* non-funder can't add any non-dust HTLCs (since the funder would * non-opener can't add any non-dust HTLCs (since the opener would
* have to pay the additional fee, but it can't afford to). This * have to pay the additional fee, but it can't afford to). This
* leads to the channel starving at the feast! This was reported by * leads to the channel starving at the feast! This was reported by
* ACINQ's @t-bast * ACINQ's @t-bast
@@ -394,7 +394,7 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
* (https://github.com/ElementsProject/lightning/pull/3498). * (https://github.com/ElementsProject/lightning/pull/3498).
* *
* To mostly avoid this situation, at least from our side, we apply an * To mostly avoid this situation, at least from our side, we apply an
* additional constraint when we're funder trying to add an HTLC: make * additional constraint when we're opener trying to add an HTLC: make
* sure we can afford one more HTLC, even if fees increase by 100%. * sure we can afford one more HTLC, even if fees increase by 100%.
* *
* We could do this for the peer, as well, by rejecting their HTLC * We could do this for the peer, as well, by rejecting their HTLC
@@ -408,7 +408,7 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
* This mitigation will become BOLT #2 standard by: * This mitigation will become BOLT #2 standard by:
* https://github.com/lightningnetwork/lightning-rfc/issues/740 * https://github.com/lightningnetwork/lightning-rfc/issues/740
*/ */
static bool local_funder_has_fee_headroom(const struct channel *channel, static bool local_opener_has_fee_headroom(const struct channel *channel,
struct amount_msat remainder, struct amount_msat remainder,
const struct htlc **committed, const struct htlc **committed,
const struct htlc **adding, const struct htlc **adding,
@@ -418,7 +418,7 @@ static bool local_funder_has_fee_headroom(const struct channel *channel,
size_t untrimmed; size_t untrimmed;
struct amount_sat fee; struct amount_sat fee;
assert(channel->funder == LOCAL); assert(channel->opener == LOCAL);
/* How many untrimmed at current feerate? Increasing feerate can /* How many untrimmed at current feerate? Increasing feerate can
* only *reduce* this number, so use current feerate here! */ * only *reduce* this number, so use current feerate here! */
@@ -540,7 +540,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
*/ */
/* Also we should not add more htlc's than sender or recipient /* Also we should not add more htlc's than sender or recipient
* configured. This mitigates attacks in which a peer can force the * configured. This mitigates attacks in which a peer can force the
* funder of the channel to pay unnecessary onchain fees during a fee * opener of the channel to pay unnecessary onchain fees during a fee
* spike with large commitment transactions. * spike with large commitment transactions.
*/ */
min_concurrent_htlcs = channel->config[recipient].max_accepted_htlcs; min_concurrent_htlcs = channel->config[recipient].max_accepted_htlcs;
@@ -614,7 +614,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
&remainder)) &remainder))
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
if (channel->funder == sender) { if (channel->opener== sender) {
if (amount_msat_less_sat(remainder, fee)) { if (amount_msat_less_sat(remainder, fee)) {
status_debug("Cannot afford fee %s with %s above reserve", status_debug("Cannot afford fee %s with %s above reserve",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
@@ -625,7 +625,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
} }
if (sender == LOCAL if (sender == LOCAL
&& !local_funder_has_fee_headroom(channel, && !local_opener_has_fee_headroom(channel,
remainder, remainder,
committed, committed,
adding, adding,
@@ -634,12 +634,12 @@ static enum channel_add_err add_htlc(struct channel *channel,
} }
} }
/* Try not to add a payment which will take funder into fees /* Try not to add a payment which will take opener into fees
* on either our side or theirs. */ * on either our side or theirs. */
if (sender == LOCAL) { if (sender == LOCAL) {
if (!get_room_above_reserve(channel, view, if (!get_room_above_reserve(channel, view,
adding, removing, adding, removing,
channel->funder, channel->opener,
&remainder)) &remainder))
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
/* Should be able to afford both their own commit tx /* Should be able to afford both their own commit tx
@@ -649,7 +649,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
committed, committed,
adding, adding,
removing, removing,
channel->funder); channel->opener);
/* set fee output pointer if given */ /* set fee output pointer if given */
if (htlc_fee && amount_sat_greater(fee, *htlc_fee)) if (htlc_fee && amount_sat_greater(fee, *htlc_fee))
*htlc_fee = fee; *htlc_fee = fee;
@@ -667,7 +667,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
committed, committed,
adding, adding,
removing, removing,
!channel->funder); !channel->opener);
/* set fee output pointer if given */ /* set fee output pointer if given */
if (htlc_fee && amount_sat_greater(fee, *htlc_fee)) if (htlc_fee && amount_sat_greater(fee, *htlc_fee))
*htlc_fee = fee; *htlc_fee = fee;
@@ -970,7 +970,7 @@ u32 approx_max_feerate(const struct channel *channel)
struct amount_sat avail; struct amount_sat avail;
const struct htlc **committed, **adding, **removing; const struct htlc **committed, **adding, **removing;
gather_htlcs(tmpctx, channel, !channel->funder, gather_htlcs(tmpctx, channel, !channel->opener,
&committed, &removing, &adding); &committed, &removing, &adding);
/* Assume none are trimmed; this gives lower bound on feerate. */ /* Assume none are trimmed; this gives lower bound on feerate. */
@@ -1001,28 +1001,28 @@ u32 approx_max_feerate(const struct channel *channel)
/* We should never go below reserve. */ /* We should never go below reserve. */
if (!amount_sat_sub(&avail, if (!amount_sat_sub(&avail,
amount_msat_to_sat_round_down(channel->view[!channel->funder].owed[channel->funder]), amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]),
channel->config[!channel->funder].channel_reserve)) channel->config[!channel->opener].channel_reserve))
avail = AMOUNT_SAT(0); avail = AMOUNT_SAT(0);
return avail.satoshis / weight * 1000; /* Raw: once-off reverse feerate*/ return avail.satoshis / weight * 1000; /* Raw: once-off reverse feerate*/
} }
bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw) bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw)
{ {
struct amount_sat needed, fee; struct amount_sat needed, fee;
struct amount_sat dust_limit = channel->config[!channel->funder].dust_limit; struct amount_sat dust_limit = channel->config[!channel->opener].dust_limit;
size_t untrimmed; size_t untrimmed;
const struct htlc **committed, **adding, **removing; const struct htlc **committed, **adding, **removing;
gather_htlcs(tmpctx, channel, !channel->funder, gather_htlcs(tmpctx, channel, !channel->opener,
&committed, &removing, &adding); &committed, &removing, &adding);
untrimmed = commit_tx_num_untrimmed(committed, feerate_per_kw, dust_limit, untrimmed = commit_tx_num_untrimmed(committed, feerate_per_kw, dust_limit,
!channel->funder) !channel->opener)
+ commit_tx_num_untrimmed(adding, feerate_per_kw, dust_limit, + commit_tx_num_untrimmed(adding, feerate_per_kw, dust_limit,
!channel->funder) !channel->opener)
- commit_tx_num_untrimmed(removing, feerate_per_kw, dust_limit, - commit_tx_num_untrimmed(removing, feerate_per_kw, dust_limit,
!channel->funder); !channel->opener);
fee = commit_tx_base_fee(feerate_per_kw, untrimmed); fee = commit_tx_base_fee(feerate_per_kw, untrimmed);
@@ -1032,38 +1032,38 @@ bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw
* node's current commitment transaction: * node's current commitment transaction:
* - SHOULD fail the channel * - SHOULD fail the channel
*/ */
/* Note: sender == funder */ /* Note: sender == opener */
/* How much does it think it has? Must be >= reserve + fee */ /* How much does it think it has? Must be >= reserve + fee */
if (!amount_sat_add(&needed, fee, if (!amount_sat_add(&needed, fee,
channel->config[!channel->funder].channel_reserve)) channel->config[!channel->opener].channel_reserve))
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Cannot add fee %s and reserve %s", "Cannot add fee %s and reserve %s",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
&fee), &fee),
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
&channel->config[!channel->funder].channel_reserve)); &channel->config[!channel->opener].channel_reserve));
status_debug("We need %s at feerate %u for %zu untrimmed htlcs: we have %s/%s", status_debug("We need %s at feerate %u for %zu untrimmed htlcs: we have %s/%s",
type_to_string(tmpctx, struct amount_sat, &needed), type_to_string(tmpctx, struct amount_sat, &needed),
feerate_per_kw, untrimmed, feerate_per_kw, untrimmed,
type_to_string(tmpctx, struct amount_msat, type_to_string(tmpctx, struct amount_msat,
&channel->view[LOCAL].owed[channel->funder]), &channel->view[LOCAL].owed[channel->opener]),
type_to_string(tmpctx, struct amount_msat, type_to_string(tmpctx, struct amount_msat,
&channel->view[REMOTE].owed[channel->funder])); &channel->view[REMOTE].owed[channel->opener]));
return amount_msat_greater_eq_sat(channel->view[!channel->funder].owed[channel->funder], return amount_msat_greater_eq_sat(channel->view[!channel->opener].owed[channel->opener],
needed); needed);
} }
bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw) bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw)
{ {
if (!can_funder_afford_feerate(channel, feerate_per_kw)) if (!can_opener_afford_feerate(channel, feerate_per_kw))
return false; return false;
status_debug("Setting %s feerate to %u", status_debug("Setting %s feerate to %u",
side_to_str(!channel->funder), feerate_per_kw); side_to_str(!channel->opener), feerate_per_kw);
start_fee_update(channel->fee_states, channel->funder, feerate_per_kw); start_fee_update(channel->fee_states, channel->opener, feerate_per_kw);
return true; return true;
} }

View File

@@ -25,7 +25,7 @@ struct existing_htlc;
* @local_fundingkey: local funding key * @local_fundingkey: local funding key
* @remote_fundingkey: remote funding key * @remote_fundingkey: remote funding key
* @option_static_remotekey: use `option_static_remotekey`. * @option_static_remotekey: use `option_static_remotekey`.
* @funder: which side initiated it. * @opener: which side initiated it.
* *
* Returns state, or NULL if malformed. * Returns state, or NULL if malformed.
*/ */
@@ -43,7 +43,7 @@ struct channel *new_full_channel(const tal_t *ctx,
const struct pubkey *local_funding_pubkey, const struct pubkey *local_funding_pubkey,
const struct pubkey *remote_funding_pubkey, const struct pubkey *remote_funding_pubkey,
bool option_static_remotekey, bool option_static_remotekey,
enum side funder); enum side opener);
/** /**
* channel_txs: Get the current commitment and htlc txs for the channel. * channel_txs: Get the current commitment and htlc txs for the channel.
@@ -151,7 +151,7 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
struct htlc **htlcp); struct htlc **htlcp);
/** /**
* approx_max_feerate: what's the max funder could raise fee rate to? * approx_max_feerate: what's the max opener could raise fee rate to?
* @channel: The channel state * @channel: The channel state
* *
* This is not exact! To check if their offer is valid, try * This is not exact! To check if their offer is valid, try
@@ -160,14 +160,14 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
u32 approx_max_feerate(const struct channel *channel); u32 approx_max_feerate(const struct channel *channel);
/** /**
* can_funder_afford_feerate: could the funder pay the fee? * can_opener_afford_feerate: could the opener pay the fee?
* @channel: The channel state * @channel: The channel state
* @feerate: The feerate in satoshi per 1000 bytes. * @feerate: The feerate in satoshi per 1000 bytes.
*/ */
bool can_funder_afford_feerate(const struct channel *channel, u32 feerate); bool can_opener_afford_feerate(const struct channel *channel, u32 feerate);
/** /**
* channel_update_feerate: Change fee rate on non-funder side. * channel_update_feerate: Change fee rate on non-opener side.
* @channel: The channel * @channel: The channel
* @feerate_per_kw: fee in satoshi per 1000 bytes. * @feerate_per_kw: fee in satoshi per 1000 bytes.
* *

View File

@@ -938,7 +938,7 @@ int main(void)
tx = newtx; tx = newtx;
} while (tx->wtx->num_outputs > 1); } while (tx->wtx->num_outputs > 1);
/* Now make sure we cover case where funder can't afford the fee; /* Now make sure we cover case where opener can't afford the fee;
* its output cannot go negative! */ * its output cannot go negative! */
for (;;) { for (;;) {
struct amount_sat base_fee struct amount_sat base_fee
@@ -959,7 +959,7 @@ int main(void)
assert(feerate_per_kw == 9651936); assert(feerate_per_kw == 9651936);
printf("\n" printf("\n"
"name: commitment tx with fee greater than funder amount\n" "name: commitment tx with fee greater than opener amount\n"
"to_local_msat: %"PRIu64"\n" "to_local_msat: %"PRIu64"\n"
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %u\n", "local_feerate_per_kw: %u\n",

View File

@@ -314,7 +314,7 @@ static void update_feerate(struct channel *channel, u32 feerate)
ret = channel_update_feerate(channel, feerate); ret = channel_update_feerate(channel, feerate);
assert(ret); assert(ret);
if (channel->funder == LOCAL) { if (channel->opener == LOCAL) {
ret = channel_sending_commit(channel, NULL); ret = channel_sending_commit(channel, NULL);
assert(ret); assert(ret);
ret = channel_rcvd_revoke_and_ack(channel, NULL); ret = channel_rcvd_revoke_and_ack(channel, NULL);

View File

@@ -10,7 +10,7 @@ msgdata,closing_init,funding_txout,u16,
msgdata,closing_init,funding_satoshi,amount_sat, msgdata,closing_init,funding_satoshi,amount_sat,
msgdata,closing_init,local_fundingkey,pubkey, msgdata,closing_init,local_fundingkey,pubkey,
msgdata,closing_init,remote_fundingkey,pubkey, msgdata,closing_init,remote_fundingkey,pubkey,
msgdata,closing_init,funder,enum side, msgdata,closing_init,opener,enum side,
msgdata,closing_init,local_sat,amount_sat, msgdata,closing_init,local_sat,amount_sat,
msgdata,closing_init,remote_sat,amount_sat, msgdata,closing_init,remote_sat,amount_sat,
msgdata,closing_init,our_dust_limit,amount_sat, msgdata,closing_init,our_dust_limit,amount_sat,
1 #include <common/cryptomsg.h>
10 msgdata,closing_init,funding_satoshi,amount_sat,
11 msgdata,closing_init,local_fundingkey,pubkey,
12 msgdata,closing_init,remote_fundingkey,pubkey,
13 msgdata,closing_init,funder,enum side, msgdata,closing_init,opener,enum side,
14 msgdata,closing_init,local_sat,amount_sat,
15 msgdata,closing_init,remote_sat,amount_sat,
16 msgdata,closing_init,our_dust_limit,amount_sat,

View File

@@ -40,7 +40,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
const struct amount_sat out[NUM_SIDES], const struct amount_sat out[NUM_SIDES],
enum side funder, enum side opener,
struct amount_sat fee, struct amount_sat fee,
struct amount_sat dust_limit) struct amount_sat dust_limit)
{ {
@@ -49,7 +49,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
out_minus_fee[LOCAL] = out[LOCAL]; out_minus_fee[LOCAL] = out[LOCAL];
out_minus_fee[REMOTE] = out[REMOTE]; out_minus_fee[REMOTE] = out[REMOTE];
if (!amount_sat_sub(&out_minus_fee[funder], out[funder], fee)) if (!amount_sat_sub(&out_minus_fee[opener], out[opener], fee))
peer_failed(pps, channel_id, peer_failed(pps, channel_id,
"Funder cannot afford fee %s (%s and %s)", "Funder cannot afford fee %s (%s and %s)",
type_to_string(tmpctx, struct amount_sat, &fee), type_to_string(tmpctx, struct amount_sat, &fee),
@@ -243,7 +243,7 @@ static void send_offer(struct per_peer_state *pps,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
const struct amount_sat out[NUM_SIDES], const struct amount_sat out[NUM_SIDES],
enum side funder, enum side opener,
struct amount_sat our_dust_limit, struct amount_sat our_dust_limit,
struct amount_sat fee_to_offer) struct amount_sat fee_to_offer)
{ {
@@ -263,7 +263,7 @@ static void send_offer(struct per_peer_state *pps,
funding_txout, funding_txout,
funding, funding,
out, out,
funder, fee_to_offer, our_dust_limit); opener, fee_to_offer, our_dust_limit);
/* BOLT #3: /* BOLT #3:
* *
@@ -321,7 +321,7 @@ receive_offer(struct per_peer_state *pps,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
const struct amount_sat out[NUM_SIDES], const struct amount_sat out[NUM_SIDES],
enum side funder, enum side opener,
struct amount_sat our_dust_limit, struct amount_sat our_dust_limit,
struct amount_sat min_fee_to_accept, struct amount_sat min_fee_to_accept,
struct bitcoin_txid *closing_txid) struct bitcoin_txid *closing_txid)
@@ -372,7 +372,7 @@ receive_offer(struct per_peer_state *pps,
funding_txid, funding_txid,
funding_txout, funding_txout,
funding, funding,
out, funder, received_fee, our_dust_limit); out, opener, received_fee, our_dust_limit);
if (!check_tx_sig(tx, 0, NULL, funding_wscript, if (!check_tx_sig(tx, 0, NULL, funding_wscript,
&funding_pubkey[REMOTE], &their_sig)) { &funding_pubkey[REMOTE], &their_sig)) {
@@ -380,7 +380,7 @@ receive_offer(struct per_peer_state *pps,
struct bitcoin_tx *trimmed; struct bitcoin_tx *trimmed;
struct amount_sat trimming_out[NUM_SIDES]; struct amount_sat trimming_out[NUM_SIDES];
if (funder == REMOTE) if (opener == REMOTE)
trimming_out[REMOTE] = received_fee; trimming_out[REMOTE] = received_fee;
else else
trimming_out[REMOTE] = AMOUNT_SAT(0); trimming_out[REMOTE] = AMOUNT_SAT(0);
@@ -402,7 +402,7 @@ receive_offer(struct per_peer_state *pps,
funding_txout, funding_txout,
funding, funding,
trimming_out, trimming_out,
funder, received_fee, our_dust_limit); opener, received_fee, our_dust_limit);
if (!trimmed if (!trimmed
|| !check_tx_sig(trimmed, 0, NULL, funding_wscript, || !check_tx_sig(trimmed, 0, NULL, funding_wscript,
&funding_pubkey[REMOTE], &their_sig)) { &funding_pubkey[REMOTE], &their_sig)) {
@@ -603,7 +603,7 @@ int main(int argc, char *argv[])
struct amount_sat our_dust_limit; struct amount_sat our_dust_limit;
struct amount_sat min_fee_to_accept, commitment_fee, offer[NUM_SIDES]; struct amount_sat min_fee_to_accept, commitment_fee, offer[NUM_SIDES];
struct feerange feerange; struct feerange feerange;
enum side funder; enum side opener;
u8 *scriptpubkey[NUM_SIDES], *funding_wscript; u8 *scriptpubkey[NUM_SIDES], *funding_wscript;
u64 fee_negotiation_step; u64 fee_negotiation_step;
u8 fee_negotiation_step_unit; u8 fee_negotiation_step_unit;
@@ -627,7 +627,7 @@ int main(int argc, char *argv[])
&funding, &funding,
&funding_pubkey[LOCAL], &funding_pubkey[LOCAL],
&funding_pubkey[REMOTE], &funding_pubkey[REMOTE],
&funder, &opener,
&out[LOCAL], &out[LOCAL],
&out[REMOTE], &out[REMOTE],
&our_dust_limit, &our_dust_limit,
@@ -692,13 +692,13 @@ int main(int argc, char *argv[])
* commitment transaction: * commitment transaction:
* - SHOULD send a `closing_signed` message. * - SHOULD send a `closing_signed` message.
*/ */
whose_turn = funder; whose_turn = opener;
for (size_t i = 0; i < 2; i++, whose_turn = !whose_turn) { for (size_t i = 0; i < 2; i++, whose_turn = !whose_turn) {
if (whose_turn == LOCAL) { if (whose_turn == LOCAL) {
send_offer(pps, chainparams, send_offer(pps, chainparams,
&channel_id, funding_pubkey, &channel_id, funding_pubkey,
scriptpubkey, &funding_txid, funding_txout, scriptpubkey, &funding_txid, funding_txout,
funding, out, funder, funding, out, opener,
our_dust_limit, our_dust_limit,
offer[LOCAL]); offer[LOCAL]);
} else { } else {
@@ -718,7 +718,7 @@ int main(int argc, char *argv[])
funding_wscript, funding_wscript,
scriptpubkey, &funding_txid, scriptpubkey, &funding_txid,
funding_txout, funding, funding_txout, funding,
out, funder, out, opener,
our_dust_limit, our_dust_limit,
min_fee_to_accept, min_fee_to_accept,
&closing_txid); &closing_txid);
@@ -728,8 +728,8 @@ int main(int argc, char *argv[])
/* Now we have first two points, we can init fee range. */ /* Now we have first two points, we can init fee range. */
init_feerange(&feerange, commitment_fee, offer); init_feerange(&feerange, commitment_fee, offer);
/* Apply (and check) funder offer now. */ /* Apply (and check) opener offer now. */
adjust_feerange(&feerange, offer[funder], funder); adjust_feerange(&feerange, offer[opener], opener);
/* Now any extra rounds required. */ /* Now any extra rounds required. */
while (!amount_sat_eq(offer[LOCAL], offer[REMOTE])) { while (!amount_sat_eq(offer[LOCAL], offer[REMOTE])) {
@@ -747,7 +747,7 @@ int main(int argc, char *argv[])
send_offer(pps, chainparams, &channel_id, send_offer(pps, chainparams, &channel_id,
funding_pubkey, funding_pubkey,
scriptpubkey, &funding_txid, funding_txout, scriptpubkey, &funding_txid, funding_txout,
funding, out, funder, funding, out, opener,
our_dust_limit, our_dust_limit,
offer[LOCAL]); offer[LOCAL]);
} else { } else {
@@ -762,7 +762,7 @@ int main(int argc, char *argv[])
funding_wscript, funding_wscript,
scriptpubkey, &funding_txid, scriptpubkey, &funding_txid,
funding_txout, funding, funding_txout, funding,
out, funder, out, opener,
our_dust_limit, our_dust_limit,
min_fee_to_accept, min_fee_to_accept,
&closing_txid); &closing_txid);

View File

@@ -6,24 +6,24 @@
/* If we're the finder, it's like an HTLC we added, if they are, it's like /* If we're the finder, it's like an HTLC we added, if they are, it's like
* a HTLC they added. */ * a HTLC they added. */
enum htlc_state first_fee_state(enum side funder) enum htlc_state first_fee_state(enum side opener)
{ {
if (funder == LOCAL) if (opener == LOCAL)
return SENT_ADD_HTLC; return SENT_ADD_HTLC;
else else
return RCVD_ADD_HTLC; return RCVD_ADD_HTLC;
} }
enum htlc_state last_fee_state(enum side funder) enum htlc_state last_fee_state(enum side opener)
{ {
if (funder == LOCAL) if (opener == LOCAL)
return SENT_ADD_ACK_REVOCATION; return SENT_ADD_ACK_REVOCATION;
else else
return RCVD_ADD_ACK_REVOCATION; return RCVD_ADD_ACK_REVOCATION;
} }
struct fee_states *new_fee_states(const tal_t *ctx, struct fee_states *new_fee_states(const tal_t *ctx,
enum side funder, enum side opener,
const u32 *feerate_per_kw) const u32 *feerate_per_kw)
{ {
struct fee_states *fee_states = tal(ctx, struct fee_states); struct fee_states *fee_states = tal(ctx, struct fee_states);
@@ -32,7 +32,7 @@ struct fee_states *new_fee_states(const tal_t *ctx,
for (size_t i = 0; i < ARRAY_SIZE(fee_states->feerate); i++) for (size_t i = 0; i < ARRAY_SIZE(fee_states->feerate); i++)
fee_states->feerate[i] = NULL; fee_states->feerate[i] = NULL;
if (feerate_per_kw) if (feerate_per_kw)
fee_states->feerate[last_fee_state(funder)] fee_states->feerate[last_fee_state(opener)]
= tal_dup(fee_states, u32, feerate_per_kw); = tal_dup(fee_states, u32, feerate_per_kw);
return fee_states; return fee_states;
} }
@@ -54,12 +54,12 @@ struct fee_states *dup_fee_states(const tal_t *ctx,
} }
u32 get_feerate(const struct fee_states *fee_states, u32 get_feerate(const struct fee_states *fee_states,
enum side funder, enum side opener,
enum side side) enum side side)
{ {
/* The first non-NULL feerate committed to this side is current */ /* The first non-NULL feerate committed to this side is current */
for (enum htlc_state i = first_fee_state(funder); for (enum htlc_state i = first_fee_state(opener);
i <= last_fee_state(funder); i <= last_fee_state(opener);
i++) { i++) {
if (!fee_states->feerate[i]) if (!fee_states->feerate[i])
continue; continue;
@@ -73,10 +73,10 @@ u32 get_feerate(const struct fee_states *fee_states,
} }
void start_fee_update(struct fee_states *fee_states, void start_fee_update(struct fee_states *fee_states,
enum side funder, enum side opener,
u32 feerate_per_kw) u32 feerate_per_kw)
{ {
enum htlc_state start = first_fee_state(funder); enum htlc_state start = first_fee_state(opener);
/* BOLT #2: /* BOLT #2:
* Unlike an HTLC, `update_fee` is never closed but simply replaced. * Unlike an HTLC, `update_fee` is never closed but simply replaced.
@@ -135,11 +135,11 @@ void towire_fee_states(u8 **pptr, const struct fee_states *fee_states)
} }
} }
/* FIXME: we don't know funder inside fromwire_fee_states, so can't do /* FIXME: we don't know opener inside fromwire_fee_states, so can't do
* this there :( */ * this there :( */
bool fee_states_valid(const struct fee_states *fee_states, enum side funder) bool fee_states_valid(const struct fee_states *fee_states, enum side opener)
{ {
return fee_states->feerate[last_fee_state(funder)] != NULL; return fee_states->feerate[last_fee_state(opener)] != NULL;
} }
static const char *fmt_fee_states(const tal_t *ctx, static const char *fmt_fee_states(const tal_t *ctx,

View File

@@ -18,11 +18,11 @@ struct fee_states {
/** /**
* new_fee_states: Initialize a fee_states structure as at open-of-channel. * new_fee_states: Initialize a fee_states structure as at open-of-channel.
* @ctx: the tal ctx to allocate off * @ctx: the tal ctx to allocate off
* @funder: which side funded the channel (and thus, proposes fee updates). * @opener: which side opened the channel (and thus, proposes fee updates).
* @feerate_per_kw: the initial feerate (if any). * @feerate_per_kw: the initial feerate (if any).
*/ */
struct fee_states *new_fee_states(const tal_t *ctx, struct fee_states *new_fee_states(const tal_t *ctx,
enum side funder, enum side opener,
const u32 *feerate_per_kw); const u32 *feerate_per_kw);
/** /**
@@ -36,33 +36,33 @@ struct fee_states *dup_fee_states(const tal_t *ctx,
/** /**
* get_feerate: Get the current feerate * get_feerate: Get the current feerate
* @fee_states: the fee state machine * @fee_states: the fee state machine
* @funder: which side funded the channel (and thus, proposes fee updates). * @opener: which side opened the channel (and thus, proposes fee updates).
* @side: which side to get the feerate for * @side: which side to get the feerate for
*/ */
u32 get_feerate(const struct fee_states *fee_states, u32 get_feerate(const struct fee_states *fee_states,
enum side funder, enum side opener,
enum side side); enum side side);
/** /**
* first_fee_state: get the initial fee state. * first_fee_state: get the initial fee state.
* @funder: which side funded the channel (and thus, proposes fee updates). * @opener: which side opened the channel (and thus, proposes fee updates).
*/ */
enum htlc_state first_fee_state(enum side funder); enum htlc_state first_fee_state(enum side opener);
/** /**
* last_fee_state: get the final fee state. * last_fee_state: get the final fee state.
* @funder: which side funded the channel (and thus, proposes fee updates). * @opener: which side opened the channel (and thus, proposes fee updates).
*/ */
enum htlc_state last_fee_state(enum side funder); enum htlc_state last_fee_state(enum side opener);
/** /**
* start_fee_update: feed a new fee update into state machine. * start_fee_update: feed a new fee update into state machine.
* @fee_states: the fee state machine * @fee_states: the fee state machine
* @funder: which side funded the channel (and thus, proposes fee updates). * @opener: which side opened the channel (and thus, proposes fee updates).
* @feerate_per_kw: the new feerate. * @feerate_per_kw: the new feerate.
*/ */
void start_fee_update(struct fee_states *fee_states, void start_fee_update(struct fee_states *fee_states,
enum side funder, enum side opener,
u32 feerate_per_kw); u32 feerate_per_kw);
/** /**
@@ -82,7 +82,7 @@ struct fee_states *fromwire_fee_states(const tal_t *ctx,
const u8 **cursor, size_t *max); const u8 **cursor, size_t *max);
/** /**
* Is this fee_state struct valid for this funding side? * Is this fee_state struct valid for this side?
*/ */
bool fee_states_valid(const struct fee_states *fee_states, enum side funder); bool fee_states_valid(const struct fee_states *fee_states, enum side opener);
#endif /* LIGHTNING_COMMON_FEE_STATES_H */ #endif /* LIGHTNING_COMMON_FEE_STATES_H */

View File

@@ -24,7 +24,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
const struct pubkey *local_funding_pubkey, const struct pubkey *local_funding_pubkey,
const struct pubkey *remote_funding_pubkey, const struct pubkey *remote_funding_pubkey,
bool option_static_remotekey, bool option_static_remotekey,
enum side funder) enum side opener)
{ {
struct channel *channel = tal(ctx, struct channel); struct channel *channel = tal(ctx, struct channel);
struct amount_msat remote_msatoshi; struct amount_msat remote_msatoshi;
@@ -37,7 +37,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
channel->funding, local_msatoshi)) channel->funding, local_msatoshi))
return tal_free(channel); return tal_free(channel);
channel->funder = funder; channel->opener = opener;
channel->config[LOCAL] = *local; channel->config[LOCAL] = *local;
channel->config[REMOTE] = *remote; channel->config[REMOTE] = *remote;
channel->funding_pubkey[LOCAL] = *local_funding_pubkey; channel->funding_pubkey[LOCAL] = *local_funding_pubkey;
@@ -58,8 +58,8 @@ struct channel *new_initial_channel(const tal_t *ctx,
channel->basepoints[REMOTE] = *remote_basepoints; channel->basepoints[REMOTE] = *remote_basepoints;
channel->commitment_number_obscurer channel->commitment_number_obscurer
= commit_number_obscurer(&channel->basepoints[funder].payment, = commit_number_obscurer(&channel->basepoints[opener].payment,
&channel->basepoints[!funder].payment); &channel->basepoints[!opener].payment);
channel->option_static_remotekey = option_static_remotekey; channel->option_static_remotekey = option_static_remotekey;
return channel; return channel;
@@ -95,7 +95,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
&channel->funding_txid, &channel->funding_txid,
channel->funding_txout, channel->funding_txout,
channel->funding, channel->funding,
channel->funder, channel->opener,
/* They specify our to_self_delay and v.v. */ /* They specify our to_self_delay and v.v. */
channel->config[!side].to_self_delay, channel->config[!side].to_self_delay,
&keyset, &keyset,
@@ -111,7 +111,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
u32 channel_feerate(const struct channel *channel, enum side side) u32 channel_feerate(const struct channel *channel, enum side side)
{ {
return get_feerate(channel->fee_states, channel->funder, side); return get_feerate(channel->fee_states, channel->opener, side);
} }
static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view)
@@ -128,12 +128,12 @@ static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view)
static char *fmt_channel(const tal_t *ctx, const struct channel *channel) static char *fmt_channel(const tal_t *ctx, const struct channel *channel)
{ {
return tal_fmt(ctx, "{ funding=%s," return tal_fmt(ctx, "{ funding=%s,"
" funder=%s," " opener=%s,"
" local=%s," " local=%s,"
" remote=%s }", " remote=%s }",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
&channel->funding), &channel->funding),
side_to_str(channel->funder), side_to_str(channel->opener),
fmt_channel_view(ctx, &channel->view[LOCAL]), fmt_channel_view(ctx, &channel->view[LOCAL]),
fmt_channel_view(ctx, &channel->view[REMOTE])); fmt_channel_view(ctx, &channel->view[REMOTE]));
} }

View File

@@ -39,7 +39,7 @@ struct channel {
u32 minimum_depth; u32 minimum_depth;
/* Who is paying fees. */ /* Who is paying fees. */
enum side funder; enum side opener;
/* Limits and settings on this channel. */ /* Limits and settings on this channel. */
struct channel_config config[NUM_SIDES]; struct channel_config config[NUM_SIDES];
@@ -78,7 +78,7 @@ struct channel {
* @remote_basepoints: remote basepoints. * @remote_basepoints: remote basepoints.
* @local_fundingkey: local funding key * @local_fundingkey: local funding key
* @remote_fundingkey: remote funding key * @remote_fundingkey: remote funding key
* @funder: which side initiated it. * @opener: which side initiated it.
* *
* Returns channel, or NULL if malformed. * Returns channel, or NULL if malformed.
*/ */
@@ -96,7 +96,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
const struct pubkey *local_funding_pubkey, const struct pubkey *local_funding_pubkey,
const struct pubkey *remote_funding_pubkey, const struct pubkey *remote_funding_pubkey,
bool option_static_remotekey, bool option_static_remotekey,
enum side funder); enum side opener);
/** /**

View File

@@ -30,22 +30,22 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
return be64_to_cpu(obscurer); return be64_to_cpu(obscurer);
} }
bool try_subtract_fee(enum side funder, enum side side, bool try_subtract_fee(enum side opener, enum side side,
struct amount_sat base_fee, struct amount_sat base_fee,
struct amount_msat *self, struct amount_msat *self,
struct amount_msat *other) struct amount_msat *other)
{ {
struct amount_msat *funder_amount; struct amount_msat *opener_amount;
if (funder == side) if (opener == side)
funder_amount = self; opener_amount = self;
else else
funder_amount = other; opener_amount = other;
if (amount_msat_sub_sat(funder_amount, *funder_amount, base_fee)) if (amount_msat_sub_sat(opener_amount, *opener_amount, base_fee))
return true; return true;
*funder_amount = AMOUNT_MSAT(0); *opener_amount = AMOUNT_MSAT(0);
return false; return false;
} }
@@ -62,7 +62,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
enum side funder, enum side opener,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u32 feerate_per_kw, u32 feerate_per_kw,
@@ -104,7 +104,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
* 3. Subtract this base fee from the funder (either `to_local` or * 3. Subtract this base fee from the funder (either `to_local` or
* `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)). * `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)).
*/ */
if (!try_subtract_fee(funder, side, base_fee, &self_pay, &other_pay)) { if (!try_subtract_fee(opener, side, base_fee, &self_pay, &other_pay)) {
/* BOLT #2: /* BOLT #2:
* *
* The receiving node MUST fail the channel if: * The receiving node MUST fail the channel if:

View File

@@ -76,7 +76,7 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
* initial_commit_tx: create (unsigned) commitment tx to spend the funding tx output * initial_commit_tx: create (unsigned) commitment tx to spend the funding tx output
* @ctx: context to allocate transaction and @htlc_map from. * @ctx: context to allocate transaction and @htlc_map from.
* @funding_txid, @funding_out, @funding: funding outpoint. * @funding_txid, @funding_out, @funding: funding outpoint.
* @funder: is the LOCAL or REMOTE paying the fee? * @opener: is the LOCAL or REMOTE paying the fee?
* @keyset: keys derived for this commit tx. * @keyset: keys derived for this commit tx.
* @feerate_per_kw: feerate to use * @feerate_per_kw: feerate to use
* @dust_limit: dust limit below which to trim outputs. * @dust_limit: dust limit below which to trim outputs.
@@ -95,7 +95,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
enum side funder, enum side opener,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u32 feerate_per_kw, u32 feerate_per_kw,
@@ -107,8 +107,8 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
enum side side, enum side side,
char** err_reason); char** err_reason);
/* try_subtract_fee - take away this fee from the funder (and return true), or all if insufficient (and return false). */ /* try_subtract_fee - take away this fee from the opener (and return true), or all if insufficient (and return false). */
bool try_subtract_fee(enum side funder, enum side side, bool try_subtract_fee(enum side opener, enum side side,
struct amount_sat base_fee, struct amount_sat base_fee,
struct amount_msat *self, struct amount_msat *self,
struct amount_msat *other); struct amount_msat *other);

View File

@@ -7,7 +7,7 @@ lightning-fundchannel_cancel - Command for completing channel establishment
.SH DESCRIPTION .SH DESCRIPTION
\fBfundchannel_cancel\fR is a lower level RPC command\. It allows channel funder \fBfundchannel_cancel\fR is a lower level RPC command\. It allows channel opener
to cancel a channel before funding broadcast with a connected peer\. to cancel a channel before funding broadcast with a connected peer\.

View File

@@ -9,7 +9,7 @@ SYNOPSIS
DESCRIPTION DESCRIPTION
----------- -----------
`fundchannel_cancel` is a lower level RPC command. It allows channel funder `fundchannel_cancel` is a lower level RPC command. It allows channel opener
to cancel a channel before funding broadcast with a connected peer. to cancel a channel before funding broadcast with a connected peer.
*id* is the node id of the remote peer with which to cancel. *id* is the node id of the remote peer with which to cancel.

View File

@@ -145,7 +145,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
/* NULL or stolen */ /* NULL or stolen */
struct wallet_shachain *their_shachain, struct wallet_shachain *their_shachain,
enum channel_state state, enum channel_state state,
enum side funder, enum side opener,
/* NULL or stolen */ /* NULL or stolen */
struct log *log, struct log *log,
const char *transient_billboard TAKES, const char *transient_billboard TAKES,
@@ -204,7 +204,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
shachain_init(&channel->their_shachain.chain); shachain_init(&channel->their_shachain.chain);
} }
channel->state = state; channel->state = state;
channel->funder = funder; channel->opener = opener;
channel->owner = NULL; channel->owner = NULL;
memset(&channel->billboard, 0, sizeof(channel->billboard)); memset(&channel->billboard, 0, sizeof(channel->billboard));
channel->billboard.transient = tal_strdup(channel, transient_billboard); channel->billboard.transient = tal_strdup(channel, transient_billboard);
@@ -427,7 +427,7 @@ void channel_fail_forget(struct channel *channel, const char *fmt, ...)
char *why; char *why;
struct channel_id cid; struct channel_id cid;
assert(channel->funder == REMOTE && assert(channel->opener == REMOTE &&
channel->state == CHANNELD_AWAITING_LOCKIN); channel->state == CHANNELD_AWAITING_LOCKIN);
va_start(ap, fmt); va_start(ap, fmt);
why = tal_vfmt(tmpctx, fmt, ap); why = tal_vfmt(tmpctx, fmt, ap);

View File

@@ -34,7 +34,7 @@ struct channel {
enum channel_state state; enum channel_state state;
/* Which side offered channel? */ /* Which side offered channel? */
enum side funder; enum side opener;
/* Is there a single subdaemon responsible for us? */ /* Is there a single subdaemon responsible for us? */
struct subd *owner; struct subd *owner;
@@ -135,7 +135,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
/* NULL or stolen */ /* NULL or stolen */
struct wallet_shachain *their_shachain STEALS, struct wallet_shachain *their_shachain STEALS,
enum channel_state state, enum channel_state state,
enum side funder, enum side opener,
/* NULL or stolen */ /* NULL or stolen */
struct log *log STEALS, struct log *log STEALS,
const char *transient_billboard TAKES, const char *transient_billboard TAKES,

View File

@@ -481,7 +481,7 @@ void peer_start_channeld(struct channel *channel,
&channel->channel_info.theirbase, &channel->channel_info.theirbase,
&channel->channel_info.remote_per_commit, &channel->channel_info.remote_per_commit,
&channel->channel_info.old_remote_per_commit, &channel->channel_info.old_remote_per_commit,
channel->funder, channel->opener,
channel->feerate_base, channel->feerate_base,
channel->feerate_ppm, channel->feerate_ppm,
channel->our_msat, channel->our_msat,
@@ -523,7 +523,7 @@ void peer_start_channeld(struct channel *channel,
subd_send_msg(channel->owner, take(initmsg)); subd_send_msg(channel->owner, take(initmsg));
/* On restart, feerate might not be what we expect: adjust now. */ /* On restart, feerate might not be what we expect: adjust now. */
if (channel->funder == LOCAL) if (channel->opener == LOCAL)
try_update_feerates(ld, channel); try_update_feerates(ld, channel);
} }
@@ -583,7 +583,7 @@ is_fundee_should_forget(struct lightningd *ld,
*/ */
/* Only applies if we are fundee. */ /* Only applies if we are fundee. */
if (channel->funder == LOCAL) if (channel->opener == LOCAL)
return false; return false;
/* Does not apply if we already saw the funding tx. */ /* Does not apply if we already saw the funding tx. */
@@ -746,7 +746,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
buffer + cidtok->start); buffer + cidtok->start);
} }
if (cancel_channel->funder == REMOTE) if (cancel_channel->opener == REMOTE)
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Cannot cancel channel that was " "Cannot cancel channel that was "
"initiated by peer"); "initiated by peer");

View File

@@ -217,7 +217,7 @@ void peer_start_closingd(struct channel *channel,
* [BOLT #3](03-transactions.md#fee-calculation). * [BOLT #3](03-transactions.md#fee-calculation).
*/ */
final_commit_feerate = get_feerate(channel->channel_info.fee_states, final_commit_feerate = get_feerate(channel->channel_info.fee_states,
channel->funder, LOCAL); channel->opener, LOCAL);
feelimit = commit_tx_base_fee(final_commit_feerate, 0); feelimit = commit_tx_base_fee(final_commit_feerate, 0);
/* Pick some value above slow feerate (or min possible if unknown) */ /* Pick some value above slow feerate (or min possible if unknown) */
@@ -283,7 +283,7 @@ void peer_start_closingd(struct channel *channel,
channel->funding, channel->funding,
&channel->local_funding_pubkey, &channel->local_funding_pubkey,
&channel->channel_info.remote_fundingkey, &channel->channel_info.remote_fundingkey,
channel->funder, channel->opener,
amount_msat_to_sat_round_down(channel->our_msat), amount_msat_to_sat_round_down(channel->our_msat),
amount_msat_to_sat_round_down(their_msat), amount_msat_to_sat_round_down(their_msat),
channel->our_config.dust_limit, channel->our_config.dust_limit,

View File

@@ -51,7 +51,7 @@ struct config {
/* How long between changing commit and sending COMMIT message. */ /* How long between changing commit and sending COMMIT message. */
u32 commit_time_ms; u32 commit_time_ms;
/* Do we let the funder set any fee rate they want */ /* Do we let the opener set any fee rate they want */
bool ignore_fee_limits; bool ignore_fee_limits;
/* Number of blocks to rescan from the current head, or absolute /* Number of blocks to rescan from the current head, or absolute

View File

@@ -560,7 +560,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
channel->shutdown_scriptpubkey[LOCAL], channel->shutdown_scriptpubkey[LOCAL],
channel->shutdown_scriptpubkey[REMOTE], channel->shutdown_scriptpubkey[REMOTE],
&final_key, &final_key,
channel->funder, channel->opener,
&channel->local_basepoints, &channel->local_basepoints,
&channel->channel_info.theirbase, &channel->channel_info.theirbase,
tx, tx,

View File

@@ -64,7 +64,7 @@ struct uncommitted_channel {
/* These are *not* filled in by new_uncommitted_channel: */ /* These are *not* filled in by new_uncommitted_channel: */
/* Minimum funding depth (if funder == REMOTE). */ /* Minimum funding depth (if opener == REMOTE). */
u32 minimum_depth; u32 minimum_depth;
/* Our channel config. */ /* Our channel config. */

View File

@@ -424,7 +424,7 @@ void channel_errmsg(struct channel *channel,
/* We should immediately forget the channel if we receive error during /* We should immediately forget the channel if we receive error during
* CHANNELD_AWAITING_LOCKIN if we are fundee. */ * CHANNELD_AWAITING_LOCKIN if we are fundee. */
if (!err_for_them && channel->funder == REMOTE if (!err_for_them && channel->opener == REMOTE
&& channel->state == CHANNELD_AWAITING_LOCKIN) && channel->state == CHANNELD_AWAITING_LOCKIN)
channel_fail_forget(channel, "%s: %s ERROR %s", channel_fail_forget(channel, "%s: %s ERROR %s",
channel->owner->name, channel->owner->name,
@@ -453,7 +453,7 @@ static void json_add_htlcs(struct lightningd *ld,
const struct htlc_out *hout; const struct htlc_out *hout;
struct htlc_out_map_iter outi; struct htlc_out_map_iter outi;
u32 local_feerate = get_feerate(channel->channel_info.fee_states, u32 local_feerate = get_feerate(channel->channel_info.fee_states,
channel->funder, LOCAL); channel->opener, LOCAL);
/* FIXME: Add more fields. */ /* FIXME: Add more fields. */
json_array_start(response, "htlcs"); json_array_start(response, "htlcs");
@@ -526,7 +526,7 @@ static struct amount_sat commit_txfee(const struct channel *channel,
struct lightningd *ld = channel->peer->ld; struct lightningd *ld = channel->peer->ld;
size_t num_untrimmed_htlcs = 0; size_t num_untrimmed_htlcs = 0;
u32 feerate = get_feerate(channel->channel_info.fee_states, u32 feerate = get_feerate(channel->channel_info.fee_states,
channel->funder, side); channel->opener, side);
struct amount_sat dust_limit; struct amount_sat dust_limit;
if (side == LOCAL) if (side == LOCAL)
dust_limit = channel->our_config.dust_limit; dust_limit = channel->our_config.dust_limit;
@@ -656,7 +656,7 @@ static void json_add_channel(struct lightningd *ld,
// FIXME @conscott : Modify this when dual-funded channels // FIXME @conscott : Modify this when dual-funded channels
// are implemented // are implemented
json_object_start(response, "funding_allocation_msat"); json_object_start(response, "funding_allocation_msat");
if (channel->funder == LOCAL) { if (channel->opener == LOCAL) {
json_add_u64(response, node_id_to_hexstr(tmpctx, &p->id), 0); json_add_u64(response, node_id_to_hexstr(tmpctx, &p->id), 0);
json_add_u64(response, node_id_to_hexstr(tmpctx, &ld->id), json_add_u64(response, node_id_to_hexstr(tmpctx, &ld->id),
channel->funding.satoshis * 1000); /* Raw: raw JSON field */ channel->funding.satoshis * 1000); /* Raw: raw JSON field */
@@ -668,7 +668,7 @@ static void json_add_channel(struct lightningd *ld,
json_object_end(response); json_object_end(response);
json_object_start(response, "funding_msat"); json_object_start(response, "funding_msat");
if (channel->funder == LOCAL) { if (channel->opener == LOCAL) {
json_add_sat_only(response, json_add_sat_only(response,
node_id_to_hexstr(tmpctx, &p->id), node_id_to_hexstr(tmpctx, &p->id),
AMOUNT_SAT(0)); AMOUNT_SAT(0));
@@ -735,8 +735,8 @@ static void json_add_channel(struct lightningd *ld,
/* Take away any currently-offered HTLCs. */ /* Take away any currently-offered HTLCs. */
subtract_offered_htlcs(channel, &spendable); subtract_offered_htlcs(channel, &spendable);
/* If we're funder, subtract txfees we'll need to spend this */ /* If we're opener, subtract txfees we'll need to spend this */
if (channel->funder == LOCAL) { if (channel->opener == LOCAL) {
if (!amount_msat_sub_sat(&spendable, spendable, if (!amount_msat_sub_sat(&spendable, spendable,
commit_txfee(channel, spendable, commit_txfee(channel, spendable,
LOCAL))) LOCAL)))
@@ -767,8 +767,8 @@ static void json_add_channel(struct lightningd *ld,
/* Take away any currently-offered HTLCs. */ /* Take away any currently-offered HTLCs. */
subtract_received_htlcs(channel, &receivable); subtract_received_htlcs(channel, &receivable);
/* If they're funder, subtract txfees they'll need to spend this */ /* If they're opener, subtract txfees they'll need to spend this */
if (channel->funder == REMOTE) { if (channel->opener == REMOTE) {
if (!amount_msat_sub_sat(&receivable, receivable, if (!amount_msat_sub_sat(&receivable, receivable,
commit_txfee(channel, commit_txfee(channel,
receivable, REMOTE))) receivable, REMOTE)))

View File

@@ -1676,7 +1676,7 @@ void peer_sending_commitsig(struct channel *channel, const u8 *msg)
&fee_states, &fee_states,
&changed_htlcs, &changed_htlcs,
&commit_sig, &htlc_sigs) &commit_sig, &htlc_sigs)
|| !fee_states_valid(fee_states, channel->funder)) { || !fee_states_valid(fee_states, channel->opener)) {
channel_internal_error(channel, "bad channel_sending_commitsig %s", channel_internal_error(channel, "bad channel_sending_commitsig %s",
tal_hex(channel, msg)); tal_hex(channel, msg));
return; return;
@@ -1716,7 +1716,7 @@ void peer_sending_commitsig(struct channel *channel, const u8 *msg)
channel->channel_info.fee_states = tal_steal(channel, fee_states); channel->channel_info.fee_states = tal_steal(channel, fee_states);
adjust_channel_feerate_bounds(channel, adjust_channel_feerate_bounds(channel,
get_feerate(fee_states, get_feerate(fee_states,
channel->funder, channel->opener,
REMOTE)); REMOTE));
if (!peer_save_commitsig_sent(channel, commitnum)) if (!peer_save_commitsig_sent(channel, commitnum))
@@ -1871,7 +1871,7 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
&failed, &failed,
&changed, &changed,
&tx) &tx)
|| !fee_states_valid(fee_states, channel->funder)) { || !fee_states_valid(fee_states, channel->opener)) {
channel_internal_error(channel, channel_internal_error(channel,
"bad fromwire_channel_got_commitsig %s", "bad fromwire_channel_got_commitsig %s",
tal_hex(channel, msg)); tal_hex(channel, msg));
@@ -1901,7 +1901,7 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
log_debug(channel->log, log_debug(channel->log,
"got commitsig %"PRIu64 "got commitsig %"PRIu64
": feerate %u, %zu added, %zu fulfilled, %zu failed, %zu changed", ": feerate %u, %zu added, %zu fulfilled, %zu failed, %zu changed",
commitnum, get_feerate(fee_states, channel->funder, LOCAL), commitnum, get_feerate(fee_states, channel->opener, LOCAL),
tal_count(added), tal_count(fulfilled), tal_count(added), tal_count(fulfilled),
tal_count(failed), tal_count(changed)); tal_count(failed), tal_count(changed));
@@ -1934,7 +1934,7 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
channel->channel_info.fee_states = tal_steal(channel, fee_states); channel->channel_info.fee_states = tal_steal(channel, fee_states);
adjust_channel_feerate_bounds(channel, adjust_channel_feerate_bounds(channel,
get_feerate(fee_states, get_feerate(fee_states,
channel->funder, channel->opener,
LOCAL)); LOCAL));
/* Since we're about to send revoke, bump state again. */ /* Since we're about to send revoke, bump state again. */
@@ -1982,7 +1982,7 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
&next_per_commitment_point, &next_per_commitment_point,
&fee_states, &fee_states,
&changed) &changed)
|| !fee_states_valid(fee_states, channel->funder)) { || !fee_states_valid(fee_states, channel->opener)) {
channel_internal_error(channel, "bad fromwire_channel_got_revoke %s", channel_internal_error(channel, "bad fromwire_channel_got_revoke %s",
tal_hex(channel, msg)); tal_hex(channel, msg));
return; return;

View File

@@ -133,7 +133,7 @@ u32 get_block_height(const struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "get_block_height called!\n"); abort(); } { fprintf(stderr, "get_block_height called!\n"); abort(); }
/* Generated stub for get_feerate */ /* Generated stub for get_feerate */
u32 get_feerate(const struct fee_states *fee_states UNNEEDED, u32 get_feerate(const struct fee_states *fee_states UNNEEDED,
enum side funder UNNEEDED, enum side opener UNNEEDED,
enum side side UNNEEDED) enum side side UNNEEDED)
{ fprintf(stderr, "get_feerate called!\n"); abort(); } { fprintf(stderr, "get_feerate called!\n"); abort(); }
/* Generated stub for htlc_is_trimmed */ /* Generated stub for htlc_is_trimmed */

View File

@@ -27,7 +27,7 @@ msgdata,onchain_init,remote_scriptpubkey_len,u16,
msgdata,onchain_init,remote_scriptpubkey,u8,remote_scriptpubkey_len msgdata,onchain_init,remote_scriptpubkey,u8,remote_scriptpubkey_len
msgdata,onchain_init,ourwallet_pubkey,pubkey, msgdata,onchain_init,ourwallet_pubkey,pubkey,
# We need these two for commit number obscurer # We need these two for commit number obscurer
msgdata,onchain_init,funder,enum side, msgdata,onchain_init,opener,enum side,
msgdata,onchain_init,local_basepoints,basepoints, msgdata,onchain_init,local_basepoints,basepoints,
msgdata,onchain_init,remote_basepoints,basepoints, msgdata,onchain_init,remote_basepoints,basepoints,
msgdata,onchain_init,tx,bitcoin_tx, msgdata,onchain_init,tx,bitcoin_tx,
1 #include <common/derive_basepoints.h>
27 msgdata,onchain_init,ourwallet_pubkey,pubkey,
28 # We need these two for commit number obscurer
29 msgdata,onchain_init,funder,enum side, msgdata,onchain_init,opener,enum side,
30 msgdata,onchain_init,local_basepoints,basepoints,
31 msgdata,onchain_init,remote_basepoints,basepoints,
32 msgdata,onchain_init,tx,bitcoin_tx,
33 msgdata,onchain_init,tx_blockheight,u32,

View File

@@ -705,7 +705,7 @@ static void unknown_spend(struct tracked_output *out,
} }
static u64 unmask_commit_number(const struct bitcoin_tx *tx, static u64 unmask_commit_number(const struct bitcoin_tx *tx,
enum side funder, enum side opener,
const struct pubkey *local_payment_basepoint, const struct pubkey *local_payment_basepoint,
const struct pubkey *remote_payment_basepoint) const struct pubkey *remote_payment_basepoint)
{ {
@@ -718,7 +718,7 @@ static u64 unmask_commit_number(const struct bitcoin_tx *tx,
* *
* The 48-bit commitment number is obscured by `XOR` with the lower 48 bits of... * The 48-bit commitment number is obscured by `XOR` with the lower 48 bits of...
*/ */
obscurer = commit_number_obscurer(keys[funder], keys[!funder]); obscurer = commit_number_obscurer(keys[opener], keys[!opener]);
/* BOLT #3: /* BOLT #3:
* *
@@ -2648,7 +2648,7 @@ int main(int argc, char *argv[])
const tal_t *ctx = tal(NULL, char); const tal_t *ctx = tal(NULL, char);
u8 *msg; u8 *msg;
struct pubkey remote_per_commit_point, old_remote_per_commit_point; struct pubkey remote_per_commit_point, old_remote_per_commit_point;
enum side funder; enum side opener;
struct basepoints basepoints[NUM_SIDES]; struct basepoints basepoints[NUM_SIDES];
struct shachain shachain; struct shachain shachain;
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
@@ -2686,7 +2686,7 @@ int main(int argc, char *argv[])
&scriptpubkey[LOCAL], &scriptpubkey[LOCAL],
&scriptpubkey[REMOTE], &scriptpubkey[REMOTE],
&our_wallet_pubkey, &our_wallet_pubkey,
&funder, &opener,
&basepoints[LOCAL], &basepoints[LOCAL],
&basepoints[REMOTE], &basepoints[REMOTE],
&tx, &tx,
@@ -2763,7 +2763,7 @@ int main(int argc, char *argv[])
* *latest commitment transaction*. * *latest commitment transaction*.
*/ */
struct secret revocation_preimage; struct secret revocation_preimage;
commit_num = unmask_commit_number(tx, funder, commit_num = unmask_commit_number(tx, opener,
&basepoints[LOCAL].payment, &basepoints[LOCAL].payment,
&basepoints[REMOTE].payment); &basepoints[REMOTE].payment);

View File

@@ -129,8 +129,8 @@ static u8 *dev_upfront_shutdown_script(const tal_t *ctx)
} }
/*~ If we can't agree on parameters, we fail to open the channel. If we're /*~ If we can't agree on parameters, we fail to open the channel. If we're
* the funder, we need to tell lightningd, otherwise it never really notices. */ * the opener, we need to tell lightningd, otherwise it never really notices. */
static void negotiation_aborted(struct state *state, bool am_funder, static void negotiation_aborted(struct state *state, bool am_opener,
const char *why) const char *why)
{ {
status_debug("aborted opening negotiation: %s", why); status_debug("aborted opening negotiation: %s", why);
@@ -143,7 +143,7 @@ static void negotiation_aborted(struct state *state, bool am_funder,
peer_billboard(true, why); peer_billboard(true, why);
/* If necessary, tell master that funding failed. */ /* If necessary, tell master that funding failed. */
if (am_funder) { if (am_opener) {
u8 *msg = towire_opening_funder_failed(NULL, why); u8 *msg = towire_opening_funder_failed(NULL, why);
wire_sync_write(REQ_FD, take(msg)); wire_sync_write(REQ_FD, take(msg));
} }
@@ -161,7 +161,7 @@ static void negotiation_aborted(struct state *state, bool am_funder,
} }
/*~ For negotiation failures: we tell them the parameter we didn't like. */ /*~ For negotiation failures: we tell them the parameter we didn't like. */
static void negotiation_failed(struct state *state, bool am_funder, static void negotiation_failed(struct state *state, bool am_opener,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -176,7 +176,7 @@ static void negotiation_failed(struct state *state, bool am_funder,
"You gave bad parameters: %s", errmsg); "You gave bad parameters: %s", errmsg);
sync_crypto_write(state->pps, take(msg)); sync_crypto_write(state->pps, take(msg));
negotiation_aborted(state, am_funder, errmsg); negotiation_aborted(state, am_opener, errmsg);
} }
/*~ This is the key function that checks that their configuration is reasonable: /*~ This is the key function that checks that their configuration is reasonable:
@@ -184,7 +184,7 @@ static void negotiation_failed(struct state *state, bool am_funder,
* they've accepted our open. */ * they've accepted our open. */
static bool check_config_bounds(struct state *state, static bool check_config_bounds(struct state *state,
const struct channel_config *remoteconf, const struct channel_config *remoteconf,
bool am_funder) bool am_opener)
{ {
struct amount_sat capacity; struct amount_sat capacity;
struct amount_sat reserve; struct amount_sat reserve;
@@ -196,7 +196,7 @@ static bool check_config_bounds(struct state *state,
* - `to_self_delay` is unreasonably large. * - `to_self_delay` is unreasonably large.
*/ */
if (remoteconf->to_self_delay > state->max_to_self_delay) { if (remoteconf->to_self_delay > state->max_to_self_delay) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"to_self_delay %u larger than %u", "to_self_delay %u larger than %u",
remoteconf->to_self_delay, remoteconf->to_self_delay,
state->max_to_self_delay); state->max_to_self_delay);
@@ -219,7 +219,7 @@ static bool check_config_bounds(struct state *state,
if (!amount_sat_add(&reserve, if (!amount_sat_add(&reserve,
remoteconf->channel_reserve, remoteconf->channel_reserve,
state->localconf.channel_reserve)) { state->localconf.channel_reserve)) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"channel_reserve_satoshis %s" "channel_reserve_satoshis %s"
" too large", " too large",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
@@ -229,7 +229,7 @@ static bool check_config_bounds(struct state *state,
/* If reserves are larger than total sat, we fail. */ /* If reserves are larger than total sat, we fail. */
if (!amount_sat_sub(&capacity, state->funding, reserve)) { if (!amount_sat_sub(&capacity, state->funding, reserve)) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"channel_reserve_satoshis %s" "channel_reserve_satoshis %s"
" and %s too large for funding %s", " and %s too large for funding %s",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
@@ -250,7 +250,7 @@ static bool check_config_bounds(struct state *state,
/* If the minimum htlc is greater than the capacity, the channel is /* If the minimum htlc is greater than the capacity, the channel is
* useless. */ * useless. */
if (amount_msat_greater_sat(remoteconf->htlc_minimum, capacity)) { if (amount_msat_greater_sat(remoteconf->htlc_minimum, capacity)) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"htlc_minimum_msat %s" "htlc_minimum_msat %s"
" too large for funding %s" " too large for funding %s"
" capacity_msat %s", " capacity_msat %s",
@@ -267,7 +267,7 @@ static bool check_config_bounds(struct state *state,
* set by lightningd, don't bother opening it. */ * set by lightningd, don't bother opening it. */
if (amount_msat_greater_sat(state->min_effective_htlc_capacity, if (amount_msat_greater_sat(state->min_effective_htlc_capacity,
capacity)) { capacity)) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"channel capacity with funding %s," "channel capacity with funding %s,"
" reserves %s/%s," " reserves %s/%s,"
" max_htlc_value_in_flight_msat is %s," " max_htlc_value_in_flight_msat is %s,"
@@ -289,7 +289,7 @@ static bool check_config_bounds(struct state *state,
/* We don't worry about how many HTLCs they accept, as long as > 0! */ /* We don't worry about how many HTLCs they accept, as long as > 0! */
if (remoteconf->max_accepted_htlcs == 0) { if (remoteconf->max_accepted_htlcs == 0) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"max_accepted_htlcs %u invalid", "max_accepted_htlcs %u invalid",
remoteconf->max_accepted_htlcs); remoteconf->max_accepted_htlcs);
return false; return false;
@@ -302,7 +302,7 @@ static bool check_config_bounds(struct state *state,
* - `max_accepted_htlcs` is greater than 483. * - `max_accepted_htlcs` is greater than 483.
*/ */
if (remoteconf->max_accepted_htlcs > 483) { if (remoteconf->max_accepted_htlcs > 483) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"max_accepted_htlcs %u too large", "max_accepted_htlcs %u too large",
remoteconf->max_accepted_htlcs); remoteconf->max_accepted_htlcs);
return false; return false;
@@ -316,7 +316,7 @@ static bool check_config_bounds(struct state *state,
*/ */
if (amount_sat_greater(remoteconf->dust_limit, if (amount_sat_greater(remoteconf->dust_limit,
remoteconf->channel_reserve)) { remoteconf->channel_reserve)) {
negotiation_failed(state, am_funder, negotiation_failed(state, am_opener,
"dust_limit_satoshis %s" "dust_limit_satoshis %s"
" too large for channel_reserve_satoshis %s", " too large for channel_reserve_satoshis %s",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
@@ -367,7 +367,7 @@ static void temporary_channel_id(struct channel_id *channel_id)
/*~ Handle random messages we might get during opening negotiation, (eg. gossip) /*~ Handle random messages we might get during opening negotiation, (eg. gossip)
* returning the first non-handled one, or NULL if we aborted negotiation. */ * returning the first non-handled one, or NULL if we aborted negotiation. */
static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
bool am_funder) bool am_opener)
{ {
/* This is an event loop of its own. That's generally considered poor /* This is an event loop of its own. That's generally considered poor
* form, but we use it in a very limited way. */ * form, but we use it in a very limited way. */
@@ -429,7 +429,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
} }
/* Close connection on all_channels error. */ /* Close connection on all_channels error. */
if (all_channels) { if (all_channels) {
if (am_funder) { if (am_opener) {
msg = towire_opening_funder_failed(NULL, msg = towire_opening_funder_failed(NULL,
err); err);
wire_sync_write(REQ_FD, take(msg)); wire_sync_write(REQ_FD, take(msg));
@@ -437,7 +437,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
peer_failed_received_errmsg(state->pps, err, peer_failed_received_errmsg(state->pps, err,
NULL, false); NULL, false);
} }
negotiation_aborted(state, am_funder, negotiation_aborted(state, am_opener,
tal_fmt(tmpctx, "They sent error %s", tal_fmt(tmpctx, "They sent error %s",
err)); err));
/* Return NULL so caller knows to stop negotiating. */ /* Return NULL so caller knows to stop negotiating. */
@@ -507,7 +507,7 @@ static bool setup_channel_funder(struct state *state)
return true; return true;
} }
/* We start the 'fund a channel' negotation with the supplied peer, but /* We start the 'open a channel' negotation with the supplied peer, but
* stop when we get to the part where we need the funding txid */ * stop when we get to the part where we need the funding txid */
static u8 *funder_channel_start(struct state *state, u8 channel_flags) static u8 *funder_channel_start(struct state *state, u8 channel_flags)
{ {
@@ -1065,7 +1065,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
return NULL; return NULL;
} }
/* These checks are the same whether we're funder or fundee... */ /* These checks are the same whether we're opener or accepter... */
if (!check_config_bounds(state, &state->remoteconf, false)) if (!check_config_bounds(state, &state->remoteconf, false))
return NULL; return NULL;

View File

@@ -362,32 +362,32 @@ def test_closing_specified_destination(node_factory, bitcoind, chainparams):
def closing_negotiation_step(node_factory, bitcoind, chainparams, opts): def closing_negotiation_step(node_factory, bitcoind, chainparams, opts):
rate = 29006 # closing fee negotiation starts at 21000 rate = 29006 # closing fee negotiation starts at 21000
funder = node_factory.get_node(feerates=(rate, rate, rate, rate)) opener = node_factory.get_node(feerates=(rate, rate, rate, rate))
rate = 27625 # closing fee negotiation starts at 20000 rate = 27625 # closing fee negotiation starts at 20000
fundee = node_factory.get_node(feerates=(rate, rate, rate, rate)) peer = node_factory.get_node(feerates=(rate, rate, rate, rate))
funder_id = funder.info['id'] opener_id = opener.info['id']
fundee_id = fundee.info['id'] peer_id = peer.info['id']
fund_amount = 10**6 fund_amount = 10**6
funder.rpc.connect(fundee_id, 'localhost', fundee.port) opener.rpc.connect(peer_id, 'localhost', peer.port)
funder.fund_channel(fundee, fund_amount) opener.fund_channel(peer, fund_amount)
assert bitcoind.rpc.getmempoolinfo()['size'] == 0 assert bitcoind.rpc.getmempoolinfo()['size'] == 0
if opts['close_initiated_by'] == 'funder': if opts['close_initiated_by'] == 'opener':
funder.rpc.close(peer_id=fundee_id, fee_negotiation_step=opts['fee_negotiation_step']) opener.rpc.close(peer_id=peer_id, fee_negotiation_step=opts['fee_negotiation_step'])
else: else:
assert opts['close_initiated_by'] == 'fundee' assert opts['close_initiated_by'] == 'peer'
fundee.rpc.close(peer_id=funder_id, fee_negotiation_step=opts['fee_negotiation_step']) peer.rpc.close(peer_id=opener_id, fee_negotiation_step=opts['fee_negotiation_step'])
# Get the proclaimed closing fee from the two nodes' statuses # Get the proclaimed closing fee from the two nodes' statuses
status_agreed_regex = re.compile("agreed on a closing fee of ([0-9]+) satoshi") status_agreed_regex = re.compile("agreed on a closing fee of ([0-9]+) satoshi")
# [fee_from_funder_status, fee_from_fundee_status] # [fee_from_opener_status, fee_from_peer_status]
fees_from_status = [None, None] fees_from_status = [None, None]
def get_fee_from_status(node, peer_id, i): def get_fee_from_status(node, peer_id, i):
@@ -399,8 +399,8 @@ def closing_negotiation_step(node_factory, bitcoind, chainparams, opts):
fees_from_status[i] = int(m.group(1)) fees_from_status[i] = int(m.group(1))
return True return True
wait_for(lambda: get_fee_from_status(funder, fundee_id, 0)) wait_for(lambda: get_fee_from_status(opener, peer_id, 0))
wait_for(lambda: get_fee_from_status(fundee, funder_id, 1)) wait_for(lambda: get_fee_from_status(peer, opener_id, 1))
assert opts['expected_close_fee'] == fees_from_status[0] assert opts['expected_close_fee'] == fees_from_status[0]
assert opts['expected_close_fee'] == fees_from_status[1] assert opts['expected_close_fee'] == fees_from_status[1]
@@ -429,11 +429,11 @@ def test_closing_negotiation_step_30pct(node_factory, bitcoind, chainparams):
opts = {} opts = {}
opts['fee_negotiation_step'] = '30%' opts['fee_negotiation_step'] = '30%'
opts['close_initiated_by'] = 'funder' opts['close_initiated_by'] = 'opener'
opts['expected_close_fee'] = 20537 if not chainparams['elements'] else 33870 opts['expected_close_fee'] = 20537 if not chainparams['elements'] else 33870
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
opts['close_initiated_by'] = 'fundee' opts['close_initiated_by'] = 'peer'
opts['expected_close_fee'] = 20233 if not chainparams['elements'] else 33366 opts['expected_close_fee'] = 20233 if not chainparams['elements'] else 33366
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
@@ -443,11 +443,11 @@ def test_closing_negotiation_step_50pct(node_factory, bitcoind, chainparams):
opts = {} opts = {}
opts['fee_negotiation_step'] = '50%' opts['fee_negotiation_step'] = '50%'
opts['close_initiated_by'] = 'funder' opts['close_initiated_by'] = 'opener'
opts['expected_close_fee'] = 20334 if not chainparams['elements'] else 33533 opts['expected_close_fee'] = 20334 if not chainparams['elements'] else 33533
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
opts['close_initiated_by'] = 'fundee' opts['close_initiated_by'] = 'peer'
opts['expected_close_fee'] = 20334 if not chainparams['elements'] else 33533 opts['expected_close_fee'] = 20334 if not chainparams['elements'] else 33533
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
@@ -457,16 +457,16 @@ def test_closing_negotiation_step_100pct(node_factory, bitcoind, chainparams):
opts = {} opts = {}
opts['fee_negotiation_step'] = '100%' opts['fee_negotiation_step'] = '100%'
opts['close_initiated_by'] = 'funder' opts['close_initiated_by'] = 'opener'
opts['expected_close_fee'] = 20001 if not chainparams['elements'] else 32985 opts['expected_close_fee'] = 20001 if not chainparams['elements'] else 32985
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
# The close fee of 20499 looks strange in this case - one would expect # The close fee of 20499 looks strange in this case - one would expect
# to have a number close to 21000. This is because # to have a number close to 21000. This is because
# * the range is initially set to [20000 (fundee), 21000 (funder)] # * the range is initially set to [20000 (peer), 21000 (opener)]
# * the funder is always first to propose, he uses 50% step, so he proposes 20500 # * the opener is always first to propose, he uses 50% step, so he proposes 20500
# * the range is narrowed to [20001, 20499] and the fundee proposes 20499 # * the range is narrowed to [20001, 20499] and the peer proposes 20499
opts['close_initiated_by'] = 'fundee' opts['close_initiated_by'] = 'peer'
opts['expected_close_fee'] = 20499 if not chainparams['elements'] else 33808 opts['expected_close_fee'] = 20499 if not chainparams['elements'] else 33808
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
@@ -476,11 +476,11 @@ def test_closing_negotiation_step_1sat(node_factory, bitcoind, chainparams):
opts = {} opts = {}
opts['fee_negotiation_step'] = '1' opts['fee_negotiation_step'] = '1'
opts['close_initiated_by'] = 'funder' opts['close_initiated_by'] = 'opener'
opts['expected_close_fee'] = 20989 if not chainparams['elements'] else 34621 opts['expected_close_fee'] = 20989 if not chainparams['elements'] else 34621
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
opts['close_initiated_by'] = 'fundee' opts['close_initiated_by'] = 'peer'
opts['expected_close_fee'] = 20010 if not chainparams['elements'] else 32995 opts['expected_close_fee'] = 20010 if not chainparams['elements'] else 32995
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
@@ -490,11 +490,11 @@ def test_closing_negotiation_step_700sat(node_factory, bitcoind, chainparams):
opts = {} opts = {}
opts['fee_negotiation_step'] = '700' opts['fee_negotiation_step'] = '700'
opts['close_initiated_by'] = 'funder' opts['close_initiated_by'] = 'opener'
opts['expected_close_fee'] = 20151 if not chainparams['elements'] else 33459 opts['expected_close_fee'] = 20151 if not chainparams['elements'] else 33459
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
opts['close_initiated_by'] = 'fundee' opts['close_initiated_by'] = 'peer'
opts['expected_close_fee'] = 20499 if not chainparams['elements'] else 33746 opts['expected_close_fee'] = 20499 if not chainparams['elements'] else 33746
closing_negotiation_step(node_factory, bitcoind, chainparams, opts) closing_negotiation_step(node_factory, bitcoind, chainparams, opts)
@@ -686,7 +686,7 @@ def test_penalty_outhtlc(node_factory, bitcoind, executor, chainparams):
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_onchain_first_commit(node_factory, bitcoind): def test_onchain_first_commit(node_factory, bitcoind):
"""Onchain handling where funder immediately drops to chain""" """Onchain handling where opener immediately drops to chain"""
# HTLC 1->2, 1 fails just after funding. # HTLC 1->2, 1 fails just after funding.
disconnects = ['+WIRE_FUNDING_LOCKED', 'permfail'] disconnects = ['+WIRE_FUNDING_LOCKED', 'permfail']

View File

@@ -161,11 +161,11 @@ def test_opening_tiny_channel(node_factory):
dustlimit = 546 dustlimit = 546
reserves = 2 * dustlimit reserves = 2 * dustlimit
min_commit_tx_fees = 5430 min_commit_tx_fees = 5430
min_for_funder = min_commit_tx_fees + dustlimit + 1 min_for_opener = min_commit_tx_fees + dustlimit + 1
l1_min_capacity = 1000 # 1k old default, too small but used at l1 to allow small incoming channels l1_min_capacity = 1000 # 1k old default, too small but used at l1 to allow small incoming channels
l2_min_capacity = reserves # just enough to get past capacity filter l2_min_capacity = reserves # just enough to get past capacity filter
l3_min_capacity = min_for_funder # the absolute technical minimum l3_min_capacity = min_for_opener # the absolute technical minimum
l4_min_capacity = 10000 # the current default l4_min_capacity = 10000 # the current default
l5_min_capacity = 20000 # a server with more than default minimum l5_min_capacity = 20000 # a server with more than default minimum
@@ -184,7 +184,7 @@ def test_opening_tiny_channel(node_factory):
with pytest.raises(RpcError, match=r'channel_reserve_satoshis .*sat and .*sat too large for funding .*sat'): with pytest.raises(RpcError, match=r'channel_reserve_satoshis .*sat and .*sat too large for funding .*sat'):
l1.fund_channel(l2, l2_min_capacity - 1) l1.fund_channel(l2, l2_min_capacity - 1)
# Open a channel with exactly the minimal amount for the fundee, # Open a channel with exactly the minimal amount for the fundee,
# This will raise an exception at l1, as the funder cannot afford fees for initial_commit_tx. # This will raise an exception at l1, as the opener cannot afford fees for initial_commit_tx.
# Note: The old default of 1k sat is below the technical minimum when accounting for dust reserves and fees # Note: The old default of 1k sat is below the technical minimum when accounting for dust reserves and fees
# This is why this must fail, for this reason the default will be raised to 10k sat. # This is why this must fail, for this reason the default will be raised to 10k sat.
with pytest.raises(RpcError, match=r'Funder cannot afford fee on initial commitment transaction'): with pytest.raises(RpcError, match=r'Funder cannot afford fee on initial commitment transaction'):
@@ -247,8 +247,8 @@ def test_disconnect(node_factory):
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_disconnect_funder(node_factory): def test_disconnect_opener(node_factory):
# Now error on funder side duringchannel open. # Now error on opener side during channel open.
disconnects = ['-WIRE_OPEN_CHANNEL', disconnects = ['-WIRE_OPEN_CHANNEL',
'@WIRE_OPEN_CHANNEL', '@WIRE_OPEN_CHANNEL',
'+WIRE_OPEN_CHANNEL', '+WIRE_OPEN_CHANNEL',
@@ -303,7 +303,7 @@ def test_disconnect_fundee(node_factory):
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_disconnect_half_signed(node_factory): def test_disconnect_half_signed(node_factory):
# Now, these are the corner cases. Fundee sends funding_signed, # Now, these are the corner cases. Fundee sends funding_signed,
# but funder doesn't receive it. # but opener doesn't receive it.
disconnects = ['@WIRE_FUNDING_SIGNED'] disconnects = ['@WIRE_FUNDING_SIGNED']
l1 = node_factory.get_node() l1 = node_factory.get_node()
l2 = node_factory.get_node(disconnect=disconnects) l2 = node_factory.get_node(disconnect=disconnects)
@@ -314,7 +314,7 @@ def test_disconnect_half_signed(node_factory):
with pytest.raises(RpcError): with pytest.raises(RpcError):
l1.rpc.fundchannel(l2.info['id'], 20000) l1.rpc.fundchannel(l2.info['id'], 20000)
# Fundee remembers, funder doesn't. # Peer remembers, opener doesn't.
assert l1.rpc.getpeer(l2.info['id']) is None assert l1.rpc.getpeer(l2.info['id']) is None
assert l2.rpc.getpeer(l1.info['id'])['id'] == l1.info['id'] assert l2.rpc.getpeer(l1.info['id'])['id'] == l1.info['id']
@@ -348,7 +348,7 @@ def test_reconnect_signed(node_factory):
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1") @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_reconnect_openingd(node_factory): def test_reconnect_openingd(node_factory):
# Openingd thinks we're still opening; funder reconnects.. # Openingd thinks we're still opening; opener reconnects..
disconnects = ['0WIRE_ACCEPT_CHANNEL'] disconnects = ['0WIRE_ACCEPT_CHANNEL']
l1 = node_factory.get_node(may_reconnect=True) l1 = node_factory.get_node(may_reconnect=True)
l2 = node_factory.get_node(disconnect=disconnects, l2 = node_factory.get_node(disconnect=disconnects,
@@ -1649,13 +1649,13 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind):
# could time out before lightningd processes all the # could time out before lightningd processes all the
# blocks. # blocks.
blocks = 200 blocks = 200
# funder # opener
l1 = node_factory.get_node() l1 = node_factory.get_node()
# fundee # peer
l2 = node_factory.get_node(options={"dev-max-funding-unconfirmed-blocks": blocks}) l2 = node_factory.get_node(options={"dev-max-funding-unconfirmed-blocks": blocks})
l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
# Give funder some funds. # Give opener some funds.
l1.fundwallet(10**7) l1.fundwallet(10**7)
# Let blocks settle. # Let blocks settle.
time.sleep(1) time.sleep(1)
@@ -1663,11 +1663,11 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind):
def mock_sendrawtransaction(r): def mock_sendrawtransaction(r):
return {'id': r['id'], 'error': {'code': 100, 'message': 'sendrawtransaction disabled'}} return {'id': r['id'], 'error': {'code': 100, 'message': 'sendrawtransaction disabled'}}
# Prevent funder from broadcasting funding tx (any tx really). # Prevent opener from broadcasting funding tx (any tx really).
l1.daemon.rpcproxy.mock_rpc('sendrawtransaction', mock_sendrawtransaction) l1.daemon.rpcproxy.mock_rpc('sendrawtransaction', mock_sendrawtransaction)
# Fund the channel. # Fund the channel.
# The process will complete, but funder will be unable # The process will complete, but opener will be unable
# to broadcast and confirm funding tx. # to broadcast and confirm funding tx.
with pytest.raises(RpcError, match=r'sendrawtransaction disabled'): with pytest.raises(RpcError, match=r'sendrawtransaction disabled'):
l1.rpc.fundchannel(l2.info['id'], 10**6) l1.rpc.fundchannel(l2.info['id'], 10**6)
@@ -1764,7 +1764,7 @@ def test_no_fee_estimate(node_factory, bitcoind, executor):
@unittest.skipIf(not DEVELOPER, "needs --dev-disconnect") @unittest.skipIf(not DEVELOPER, "needs --dev-disconnect")
def test_funder_feerate_reconnect(node_factory, bitcoind): def test_opener_feerate_reconnect(node_factory, bitcoind):
# l1 updates fees, then reconnect so l2 retransmits commitment_signed. # l1 updates fees, then reconnect so l2 retransmits commitment_signed.
disconnects = ['-WIRE_COMMITMENT_SIGNED*3'] disconnects = ['-WIRE_COMMITMENT_SIGNED*3']
l1 = node_factory.get_node(may_reconnect=True, l1 = node_factory.get_node(may_reconnect=True,
@@ -1788,7 +1788,7 @@ def test_funder_feerate_reconnect(node_factory, bitcoind):
l1.pay(l2, 200000000) l1.pay(l2, 200000000)
def test_funder_simple_reconnect(node_factory, bitcoind): def test_opener_simple_reconnect(node_factory, bitcoind):
"""Sanity check that reconnection works with completely unused channels""" """Sanity check that reconnection works with completely unused channels"""
# Set fees even so it doesn't send any commitments. # Set fees even so it doesn't send any commitments.
l1 = node_factory.get_node(may_reconnect=True, l1 = node_factory.get_node(may_reconnect=True,
@@ -2127,7 +2127,7 @@ def test_change_chaining(node_factory, bitcoind):
def test_feerate_spam(node_factory, chainparams): def test_feerate_spam(node_factory, chainparams):
l1, l2 = node_factory.line_graph(2) l1, l2 = node_factory.line_graph(2)
# We constrain the value the funder has at its disposal so we get the # We constrain the value the opener has at its disposal so we get the
# REMOTE feerate we are looking for below. This may be fragile and depends # REMOTE feerate we are looking for below. This may be fragile and depends
# on the transactions we generate. # on the transactions we generate.
slack = 45000000 if not chainparams['elements'] else 68000000 slack = 45000000 if not chainparams['elements'] else 68000000

View File

@@ -1566,22 +1566,22 @@ def test_pay_variants(node_factory):
def test_pay_retry(node_factory, bitcoind, executor, chainparams): def test_pay_retry(node_factory, bitcoind, executor, chainparams):
"""Make sure pay command retries properly. """ """Make sure pay command retries properly. """
def exhaust_channel(funder, fundee, scid, already_spent=0): def exhaust_channel(opener, peer, scid, already_spent=0):
"""Spend all available capacity (10^6 - 1%) of channel """Spend all available capacity (10^6 - 1%) of channel
""" """
peer = funder.rpc.listpeers(fundee.info['id'])['peers'][0] peer_node = opener.rpc.listpeers(peer.info['id'])['peers'][0]
chan = peer['channels'][0] chan = peer_node['channels'][0]
maxpay = chan['spendable_msatoshi'] maxpay = chan['spendable_msatoshi']
lbl = ''.join(random.choice(string.ascii_letters) for _ in range(20)) lbl = ''.join(random.choice(string.ascii_letters) for _ in range(20))
inv = fundee.rpc.invoice(maxpay, lbl, "exhaust_channel") inv = peer.rpc.invoice(maxpay, lbl, "exhaust_channel")
routestep = { routestep = {
'msatoshi': maxpay, 'msatoshi': maxpay,
'id': fundee.info['id'], 'id': peer.info['id'],
'delay': 10, 'delay': 10,
'channel': scid 'channel': scid
} }
funder.rpc.sendpay([routestep], inv['payment_hash']) opener.rpc.sendpay([routestep], inv['payment_hash'])
funder.rpc.waitsendpay(inv['payment_hash']) opener.rpc.waitsendpay(inv['payment_hash'])
# We connect every node to l5; in a line and individually. # We connect every node to l5; in a line and individually.
# Keep fixed fees so we can easily calculate exhaustion # Keep fixed fees so we can easily calculate exhaustion
@@ -2344,7 +2344,7 @@ def test_channel_spendable_receivable_capped(node_factory, bitcoind):
def test_lockup_drain(node_factory, bitcoind): def test_lockup_drain(node_factory, bitcoind):
"""Try to get channel into a state where funder can't afford fees on additional HTLC, so fundee can't add HTLC""" """Try to get channel into a state where opener can't afford fees on additional HTLC, so peer can't add HTLC"""
l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True}) l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True})
# l1 sends all the money to l2 until even 1 msat can't get through. # l1 sends all the money to l2 until even 1 msat can't get through.

View File

@@ -1039,8 +1039,8 @@ static bool channelseq(struct channel *c1, struct channel *c2)
CHECK(pubkey_eq(&ci1->remote_per_commit, &ci2->remote_per_commit)); CHECK(pubkey_eq(&ci1->remote_per_commit, &ci2->remote_per_commit));
CHECK(pubkey_eq(&ci1->old_remote_per_commit, &ci2->old_remote_per_commit)); CHECK(pubkey_eq(&ci1->old_remote_per_commit, &ci2->old_remote_per_commit));
CHECK(ci1->their_config.id != 0 && ci1->their_config.id == ci2->their_config.id); CHECK(ci1->their_config.id != 0 && ci1->their_config.id == ci2->their_config.id);
CHECK(fee_states_valid(ci1->fee_states, c1->funder)); CHECK(fee_states_valid(ci1->fee_states, c1->opener));
CHECK(fee_states_valid(ci2->fee_states, c2->funder)); CHECK(fee_states_valid(ci2->fee_states, c2->opener));
for (enum htlc_state i = 0; i < ARRAY_SIZE(ci1->fee_states->feerate); for (enum htlc_state i = 0; i < ARRAY_SIZE(ci1->fee_states->feerate);
i++) { i++) {
if (ci1->fee_states->feerate[i] == NULL) { if (ci1->fee_states->feerate[i] == NULL) {
@@ -1125,7 +1125,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk); pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
node_id_from_pubkey(&id, &pk); node_id_from_pubkey(&id, &pk);
feerate = 31337; feerate = 31337;
ci->fee_states = new_fee_states(w, c1.funder, &feerate); ci->fee_states = new_fee_states(w, c1.opener, &feerate);
mempat(scriptpubkey, tal_count(scriptpubkey)); mempat(scriptpubkey, tal_count(scriptpubkey));
c1.first_blocknum = 1; c1.first_blocknum = 1;
parse_wireaddr_internal("localhost:1234", &addr, 0, false, false, false, parse_wireaddr_internal("localhost:1234", &addr, 0, false, false, false,

View File

@@ -817,7 +817,7 @@ fail:
static struct fee_states *wallet_channel_fee_states_load(struct wallet *w, static struct fee_states *wallet_channel_fee_states_load(struct wallet *w,
const u64 id, const u64 id,
enum side funder) enum side opener)
{ {
struct fee_states *fee_states; struct fee_states *fee_states;
struct db_stmt *stmt; struct db_stmt *stmt;
@@ -827,7 +827,7 @@ static struct fee_states *wallet_channel_fee_states_load(struct wallet *w,
db_query_prepared(stmt); db_query_prepared(stmt);
/* Start with blank slate. */ /* Start with blank slate. */
fee_states = new_fee_states(w, funder, NULL); fee_states = new_fee_states(w, opener, NULL);
while (db_step(stmt)) { while (db_step(stmt)) {
enum htlc_state hstate = db_column_int(stmt, 0); enum htlc_state hstate = db_column_int(stmt, 0);
u32 feerate = db_column_int(stmt, 1); u32 feerate = db_column_int(stmt, 1);
@@ -843,7 +843,7 @@ static struct fee_states *wallet_channel_fee_states_load(struct wallet *w,
} }
tal_free(stmt); tal_free(stmt);
if (fee_states && !fee_states_valid(fee_states, funder)) { if (fee_states && !fee_states_valid(fee_states, opener)) {
log_broken(w->log, log_broken(w->log,
"invalid channel_feerates for id %"PRIu64, id); "invalid channel_feerates for id %"PRIu64, id);
fee_states = tal_free(fee_states); fee_states = tal_free(fee_states);
@@ -1359,7 +1359,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
else else
db_bind_null(stmt, 1); db_bind_null(stmt, 1);
db_bind_int(stmt, 2, chan->state); db_bind_int(stmt, 2, chan->state);
db_bind_int(stmt, 3, chan->funder); db_bind_int(stmt, 3, chan->opener);
db_bind_int(stmt, 4, chan->channel_flags); db_bind_int(stmt, 4, chan->channel_flags);
db_bind_int(stmt, 5, chan->minimum_depth); db_bind_int(stmt, 5, chan->minimum_depth);