Browse Source

moveonly: feerate_min and feerate_max belong in chaintopology.c

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 6 years ago
parent
commit
a260849870
  1. 51
      lightningd/chaintopology.c
  2. 5
      lightningd/chaintopology.h
  3. 51
      lightningd/peer_control.c
  4. 5
      lightningd/peer_control.h

51
lightningd/chaintopology.c

@ -706,6 +706,57 @@ u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate)
return topo->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 /* On shutdown, channels get deleted last. That frees from our list, so
* do it now instead. */ * do it now instead. */
static void destroy_chain_topology(struct chain_topology *topo) static void destroy_chain_topology(struct chain_topology *topo)

5
lightningd/chaintopology.h

@ -131,6 +131,11 @@ u32 get_block_height(const struct chain_topology *topo);
/* Get fee rate in satoshi per kiloweight, or 0 if unavailable! */ /* Get fee rate in satoshi per kiloweight, or 0 if unavailable! */
u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate); 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). /* Broadcast a single tx, and rebroadcast as reqd (copies tx).
* If failed is non-NULL, call that and don't rebroadcast. */ * If failed is non-NULL, call that and don't rebroadcast. */
void broadcast_tx(struct chain_topology *topo, void broadcast_tx(struct chain_topology *topo,

51
lightningd/peer_control.c

@ -189,57 +189,6 @@ u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx)
return scriptpubkey_p2wpkh(ctx, &shutdownkey); 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) static void sign_last_tx(struct channel *channel)
{ {
struct lightningd *ld = channel->peer->ld; struct lightningd *ld = channel->peer->ld;

5
lightningd/peer_control.h

@ -88,10 +88,5 @@ void activate_peers(struct lightningd *ld);
void drop_to_chain(struct lightningd *ld, struct channel *channel, bool cooperative); 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); void channel_watch_funding(struct lightningd *ld, struct channel *channel);
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */ #endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */

Loading…
Cancel
Save