mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
moveonly: feerate_min and feerate_max belong in chaintopology.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
c7c5affa3f
commit
a260849870
4 changed files with 56 additions and 56 deletions
|
@ -706,6 +706,57 @@ u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate)
|
|||
return topo->feerate[feerate];
|
||||
}
|
||||
|
||||
u32 feerate_min(struct lightningd *ld, bool *unknown)
|
||||
{
|
||||
u32 min;
|
||||
|
||||
if (unknown)
|
||||
*unknown = false;
|
||||
|
||||
/* We can't allow less than feerate_floor, since that won't relay */
|
||||
if (ld->config.ignore_fee_limits)
|
||||
min = 1;
|
||||
else {
|
||||
u32 feerate = try_get_feerate(ld->topology, FEERATE_SLOW);
|
||||
if (!feerate && unknown)
|
||||
*unknown = true;
|
||||
|
||||
/* Set this to half of slow rate (if unknown, will be floor) */
|
||||
min = feerate / 2;
|
||||
}
|
||||
|
||||
if (min < feerate_floor())
|
||||
return feerate_floor();
|
||||
return min;
|
||||
}
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* Given the variance in fees, and the fact that the transaction may be
|
||||
* spent in the future, it's a good idea for the fee payer to keep a good
|
||||
* margin (say 5x the expected fee requirement)
|
||||
*/
|
||||
u32 feerate_max(struct lightningd *ld, bool *unknown)
|
||||
{
|
||||
u32 feerate;
|
||||
|
||||
if (unknown)
|
||||
*unknown = false;
|
||||
|
||||
if (ld->config.ignore_fee_limits)
|
||||
return UINT_MAX;
|
||||
|
||||
/* If we don't know feerate, don't limit other side. */
|
||||
feerate = try_get_feerate(ld->topology, FEERATE_URGENT);
|
||||
if (!feerate) {
|
||||
if (unknown)
|
||||
*unknown = true;
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
return feerate * ld->config.max_fee_multiplier;
|
||||
}
|
||||
|
||||
/* On shutdown, channels get deleted last. That frees from our list, so
|
||||
* do it now instead. */
|
||||
static void destroy_chain_topology(struct chain_topology *topo)
|
||||
|
|
|
@ -131,6 +131,11 @@ u32 get_block_height(const struct chain_topology *topo);
|
|||
/* Get fee rate in satoshi per kiloweight, or 0 if unavailable! */
|
||||
u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate);
|
||||
|
||||
/* Get range of feerates to insist other side abide by for normal channels.
|
||||
* If we have to guess, sets *unknown to true, otherwise false. */
|
||||
u32 feerate_min(struct lightningd *ld, bool *unknown);
|
||||
u32 feerate_max(struct lightningd *ld, bool *unknown);
|
||||
|
||||
/* Broadcast a single tx, and rebroadcast as reqd (copies tx).
|
||||
* If failed is non-NULL, call that and don't rebroadcast. */
|
||||
void broadcast_tx(struct chain_topology *topo,
|
||||
|
|
|
@ -189,57 +189,6 @@ u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx)
|
|||
return scriptpubkey_p2wpkh(ctx, &shutdownkey);
|
||||
}
|
||||
|
||||
u32 feerate_min(struct lightningd *ld, bool *unknown)
|
||||
{
|
||||
u32 min;
|
||||
|
||||
if (unknown)
|
||||
*unknown = false;
|
||||
|
||||
/* We can't allow less than feerate_floor, since that won't relay */
|
||||
if (ld->config.ignore_fee_limits)
|
||||
min = 1;
|
||||
else {
|
||||
u32 feerate = try_get_feerate(ld->topology, FEERATE_SLOW);
|
||||
if (!feerate && unknown)
|
||||
*unknown = true;
|
||||
|
||||
/* Set this to half of slow rate (if unknown, will be floor) */
|
||||
min = feerate / 2;
|
||||
}
|
||||
|
||||
if (min < feerate_floor())
|
||||
return feerate_floor();
|
||||
return min;
|
||||
}
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* Given the variance in fees, and the fact that the transaction may be
|
||||
* spent in the future, it's a good idea for the fee payer to keep a good
|
||||
* margin (say 5x the expected fee requirement)
|
||||
*/
|
||||
u32 feerate_max(struct lightningd *ld, bool *unknown)
|
||||
{
|
||||
u32 feerate;
|
||||
|
||||
if (unknown)
|
||||
*unknown = false;
|
||||
|
||||
if (ld->config.ignore_fee_limits)
|
||||
return UINT_MAX;
|
||||
|
||||
/* If we don't know feerate, don't limit other side. */
|
||||
feerate = try_get_feerate(ld->topology, FEERATE_URGENT);
|
||||
if (!feerate) {
|
||||
if (unknown)
|
||||
*unknown = true;
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
return feerate * ld->config.max_fee_multiplier;
|
||||
}
|
||||
|
||||
static void sign_last_tx(struct channel *channel)
|
||||
{
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
|
|
|
@ -88,10 +88,5 @@ void activate_peers(struct lightningd *ld);
|
|||
|
||||
void drop_to_chain(struct lightningd *ld, struct channel *channel, bool cooperative);
|
||||
|
||||
/* Get range of feerates to insist other side abide by for normal channels.
|
||||
* If we have to guess, sets *unknown to true, otherwise false. */
|
||||
u32 feerate_min(struct lightningd *ld, bool *unknown);
|
||||
u32 feerate_max(struct lightningd *ld, bool *unknown);
|
||||
|
||||
void channel_watch_funding(struct lightningd *ld, struct channel *channel);
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue