mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 23:04:35 +01:00
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:
committed by
Rusty Russell
parent
964a3583c4
commit
0e20e3c5e7
@@ -6,24 +6,24 @@
|
||||
|
||||
/* If we're the finder, it's like an HTLC we added, if they are, it's like
|
||||
* 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;
|
||||
else
|
||||
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;
|
||||
else
|
||||
return RCVD_ADD_ACK_REVOCATION;
|
||||
}
|
||||
|
||||
struct fee_states *new_fee_states(const tal_t *ctx,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
const u32 *feerate_per_kw)
|
||||
{
|
||||
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++)
|
||||
fee_states->feerate[i] = NULL;
|
||||
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);
|
||||
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,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
enum side side)
|
||||
{
|
||||
/* The first non-NULL feerate committed to this side is current */
|
||||
for (enum htlc_state i = first_fee_state(funder);
|
||||
i <= last_fee_state(funder);
|
||||
for (enum htlc_state i = first_fee_state(opener);
|
||||
i <= last_fee_state(opener);
|
||||
i++) {
|
||||
if (!fee_states->feerate[i])
|
||||
continue;
|
||||
@@ -73,10 +73,10 @@ u32 get_feerate(const struct fee_states *fee_states,
|
||||
}
|
||||
|
||||
void start_fee_update(struct fee_states *fee_states,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
u32 feerate_per_kw)
|
||||
{
|
||||
enum htlc_state start = first_fee_state(funder);
|
||||
enum htlc_state start = first_fee_state(opener);
|
||||
|
||||
/* BOLT #2:
|
||||
* 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 :( */
|
||||
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,
|
||||
|
||||
@@ -18,11 +18,11 @@ struct fee_states {
|
||||
/**
|
||||
* new_fee_states: Initialize a fee_states structure as at open-of-channel.
|
||||
* @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).
|
||||
*/
|
||||
struct fee_states *new_fee_states(const tal_t *ctx,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
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
|
||||
* @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
|
||||
*/
|
||||
u32 get_feerate(const struct fee_states *fee_states,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
enum side side);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @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.
|
||||
* @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.
|
||||
*/
|
||||
void start_fee_update(struct fee_states *fee_states,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
u32 feerate_per_kw);
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ struct fee_states *fromwire_fee_states(const tal_t *ctx,
|
||||
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 */
|
||||
|
||||
@@ -24,7 +24,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
||||
const struct pubkey *local_funding_pubkey,
|
||||
const struct pubkey *remote_funding_pubkey,
|
||||
bool option_static_remotekey,
|
||||
enum side funder)
|
||||
enum side opener)
|
||||
{
|
||||
struct channel *channel = tal(ctx, struct channel);
|
||||
struct amount_msat remote_msatoshi;
|
||||
@@ -37,7 +37,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
||||
channel->funding, local_msatoshi))
|
||||
return tal_free(channel);
|
||||
|
||||
channel->funder = funder;
|
||||
channel->opener = opener;
|
||||
channel->config[LOCAL] = *local;
|
||||
channel->config[REMOTE] = *remote;
|
||||
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->commitment_number_obscurer
|
||||
= commit_number_obscurer(&channel->basepoints[funder].payment,
|
||||
&channel->basepoints[!funder].payment);
|
||||
= commit_number_obscurer(&channel->basepoints[opener].payment,
|
||||
&channel->basepoints[!opener].payment);
|
||||
|
||||
channel->option_static_remotekey = option_static_remotekey;
|
||||
return channel;
|
||||
@@ -95,7 +95,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
||||
&channel->funding_txid,
|
||||
channel->funding_txout,
|
||||
channel->funding,
|
||||
channel->funder,
|
||||
channel->opener,
|
||||
/* They specify our to_self_delay and v.v. */
|
||||
channel->config[!side].to_self_delay,
|
||||
&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)
|
||||
{
|
||||
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)
|
||||
@@ -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)
|
||||
{
|
||||
return tal_fmt(ctx, "{ funding=%s,"
|
||||
" funder=%s,"
|
||||
" opener=%s,"
|
||||
" local=%s,"
|
||||
" remote=%s }",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&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[REMOTE]));
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ struct channel {
|
||||
u32 minimum_depth;
|
||||
|
||||
/* Who is paying fees. */
|
||||
enum side funder;
|
||||
enum side opener;
|
||||
|
||||
/* Limits and settings on this channel. */
|
||||
struct channel_config config[NUM_SIDES];
|
||||
@@ -78,7 +78,7 @@ struct channel {
|
||||
* @remote_basepoints: remote basepoints.
|
||||
* @local_fundingkey: local funding key
|
||||
* @remote_fundingkey: remote funding key
|
||||
* @funder: which side initiated it.
|
||||
* @opener: which side initiated it.
|
||||
*
|
||||
* 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 *remote_funding_pubkey,
|
||||
bool option_static_remotekey,
|
||||
enum side funder);
|
||||
enum side opener);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,22 +30,22 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
|
||||
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_msat *self,
|
||||
struct amount_msat *other)
|
||||
{
|
||||
struct amount_msat *funder_amount;
|
||||
struct amount_msat *opener_amount;
|
||||
|
||||
if (funder == side)
|
||||
funder_amount = self;
|
||||
if (opener == side)
|
||||
opener_amount = self;
|
||||
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;
|
||||
|
||||
*funder_amount = AMOUNT_MSAT(0);
|
||||
*opener_amount = AMOUNT_MSAT(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
struct amount_sat funding,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
u16 to_self_delay,
|
||||
const struct keyset *keyset,
|
||||
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
|
||||
* `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:
|
||||
*
|
||||
* The receiving node MUST fail the channel if:
|
||||
|
||||
@@ -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
|
||||
* @ctx: context to allocate transaction and @htlc_map from.
|
||||
* @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.
|
||||
* @feerate_per_kw: feerate to use
|
||||
* @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,
|
||||
unsigned int funding_txout,
|
||||
struct amount_sat funding,
|
||||
enum side funder,
|
||||
enum side opener,
|
||||
u16 to_self_delay,
|
||||
const struct keyset *keyset,
|
||||
u32 feerate_per_kw,
|
||||
@@ -107,8 +107,8 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
enum side side,
|
||||
char** err_reason);
|
||||
|
||||
/* try_subtract_fee - take away this fee from the funder (and return true), or all if insufficient (and return false). */
|
||||
bool try_subtract_fee(enum side funder, enum side side,
|
||||
/* 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 opener, enum side side,
|
||||
struct amount_sat base_fee,
|
||||
struct amount_msat *self,
|
||||
struct amount_msat *other);
|
||||
|
||||
Reference in New Issue
Block a user