mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
channeld: --ignore-fee-limits as a hack for fee disparities.
This, of course, should never be used. But it helps maintain connections for the moment while we dig deeper into feerates. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
e91a8dff12
commit
79dc44713b
@@ -624,6 +624,9 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
|
||||
&peer->channel_id,
|
||||
"update_fee from non-funder?");
|
||||
|
||||
status_trace("update_fee %u, range %u-%u",
|
||||
feerate, peer->feerate_min, peer->feerate_max);
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A receiving node SHOULD fail the channel if the `update_fee` is too
|
||||
|
||||
@@ -71,6 +71,9 @@ struct config {
|
||||
|
||||
/* Channel update interval */
|
||||
u32 channel_update_interval;
|
||||
|
||||
/* Do we let the funder set any fee rate they want */
|
||||
bool ignore_fee_limits;
|
||||
};
|
||||
|
||||
struct lightningd {
|
||||
|
||||
@@ -204,6 +204,9 @@ static char *opt_set_fee_rates(const char *arg, struct chain_topology *topo)
|
||||
|
||||
static void config_register_opts(struct lightningd *ld)
|
||||
{
|
||||
opt_register_arg("--ignore-fee-limits", opt_set_bool_arg, opt_show_bool,
|
||||
&ld->config.ignore_fee_limits,
|
||||
"(DANGEROUS) allow peer to set any feerate");
|
||||
opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32,
|
||||
&ld->config.locktime_blocks,
|
||||
"Blocks before peer can unilaterally spend funds");
|
||||
@@ -346,6 +349,9 @@ static const struct config testnet_config = {
|
||||
|
||||
/* Send a keepalive update at least every week, prune every twice that */
|
||||
.channel_update_interval = 1209600/2,
|
||||
|
||||
/* Testnet sucks */
|
||||
.ignore_fee_limits = true,
|
||||
};
|
||||
|
||||
/* aka. "Dude, where's my coins?" */
|
||||
@@ -407,6 +413,9 @@ static const struct config mainnet_config = {
|
||||
|
||||
/* Send a keepalive update at least every week, prune every twice that */
|
||||
.channel_update_interval = 1209600/2,
|
||||
|
||||
/* Mainnet should have more stable fees */
|
||||
.ignore_fee_limits = false,
|
||||
};
|
||||
|
||||
static void check_config(struct lightningd *ld)
|
||||
|
||||
@@ -1938,6 +1938,29 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 feerate_min(struct lightningd *ld)
|
||||
{
|
||||
if (ld->config.ignore_fee_limits)
|
||||
return 1;
|
||||
|
||||
/* Set this to average of slow and normal.*/
|
||||
return (get_feerate(ld->topology, FEERATE_SLOW)
|
||||
+ get_feerate(ld->topology, FEERATE_NORMAL)) / 2;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
if (ld->config.ignore_fee_limits)
|
||||
return UINT_MAX;
|
||||
|
||||
return get_feerate(ld->topology, FEERATE_IMMEDIATE) * 5;
|
||||
}
|
||||
|
||||
static bool peer_start_channeld(struct peer *peer,
|
||||
const struct crypto_state *cs,
|
||||
u64 gossip_index,
|
||||
@@ -2019,6 +2042,10 @@ static bool peer_start_channeld(struct peer *peer,
|
||||
|
||||
num_revocations = revocations_received(&peer->their_shachain.chain);
|
||||
|
||||
/* Warn once. */
|
||||
if (peer->ld->config.ignore_fee_limits)
|
||||
log_unusual(peer->log, "Ignoring fee limits!");
|
||||
|
||||
initmsg = towire_channel_init(tmpctx,
|
||||
&get_chainparams(peer->ld)
|
||||
->genesis_blockhash,
|
||||
@@ -2028,8 +2055,8 @@ static bool peer_start_channeld(struct peer *peer,
|
||||
&peer->our_config,
|
||||
&peer->channel_info->their_config,
|
||||
peer->channel_info->feerate_per_kw,
|
||||
get_feerate(peer->ld->topology, FEERATE_NORMAL),
|
||||
get_feerate(peer->ld->topology, FEERATE_IMMEDIATE) * 5,
|
||||
feerate_min(peer->ld),
|
||||
feerate_max(peer->ld),
|
||||
peer->last_sig,
|
||||
cs, gossip_index,
|
||||
&peer->channel_info->remote_fundingkey,
|
||||
|
||||
@@ -220,4 +220,9 @@ void setup_listeners(struct lightningd *ld);
|
||||
void activate_peers(struct lightningd *ld);
|
||||
|
||||
void free_htlcs(struct lightningd *ld, const struct peer *peer);
|
||||
|
||||
/* Get range of feerates to insist other side abide by for normal channels. */
|
||||
u32 feerate_min(struct lightningd *ld);
|
||||
u32 feerate_max(struct lightningd *ld);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */
|
||||
|
||||
@@ -1501,15 +1501,11 @@ void notify_feerate_change(struct lightningd *ld)
|
||||
if (!peer->owner)
|
||||
continue;
|
||||
|
||||
/* FIXME: low bound is probably too low. */
|
||||
msg = towire_channel_feerates(peer,
|
||||
get_feerate(ld->topology,
|
||||
FEERATE_IMMEDIATE),
|
||||
get_feerate(ld->topology,
|
||||
FEERATE_NORMAL) / 2,
|
||||
get_feerate(ld->topology,
|
||||
FEERATE_IMMEDIATE)
|
||||
* 5);
|
||||
feerate_min(ld),
|
||||
feerate_max(ld));
|
||||
subd_send_msg(peer->owner, take(msg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2709,6 +2709,36 @@ class LightningDTests(BaseLightningDTests):
|
||||
l1.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
|
||||
|
||||
def test_fee_limits(self):
|
||||
# FIXME: Test case where opening denied.
|
||||
l1, l2 = self.connect()
|
||||
self.fund_channel(l1, l2, 10**6)
|
||||
|
||||
# L1 asks for stupid low fees
|
||||
l1.rpc.dev_setfees(15)
|
||||
|
||||
l1.daemon.wait_for_log('STATUS_FAIL_PEER_BAD')
|
||||
|
||||
# Restore to normal.
|
||||
l1.rpc.dev_setfees(15000)
|
||||
|
||||
# Try with node which sets --ignore-fee-limits
|
||||
l3 = self.node_factory.get_node(options=['--ignore-fee-limits=true'])
|
||||
l1.rpc.connect(l3.info['id'], 'localhost', l3.info['port'])
|
||||
|
||||
self.fund_channel(l1, l3, 10**6)
|
||||
|
||||
# Try stupid high fees
|
||||
l1.rpc.dev_setfees(15000 * 10)
|
||||
|
||||
l3.daemon.wait_for_log('peer_in WIRE_UPDATE_FEE')
|
||||
l3.daemon.wait_for_log('peer_in WIRE_COMMITMENT_SIGNED')
|
||||
|
||||
# Now shutdown cleanly.
|
||||
l1.rpc.close(l3.info['id'])
|
||||
l1.daemon.wait_for_log('-> CLOSINGD_COMPLETE')
|
||||
l3.daemon.wait_for_log('-> CLOSINGD_COMPLETE')
|
||||
|
||||
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
|
||||
def test_update_fee_reconnect(self):
|
||||
# Disconnect after first commitsig.
|
||||
|
||||
@@ -244,7 +244,8 @@ class LightningD(TailableProc):
|
||||
'--lightning-dir={}'.format(lightning_dir),
|
||||
'--port={}'.format(port),
|
||||
'--override-fee-rates=15000/7500/1000',
|
||||
'--network=regtest'
|
||||
'--network=regtest',
|
||||
'--ignore-fee-limits=false'
|
||||
]
|
||||
if DEVELOPER:
|
||||
self.cmd_line += ['--dev-broadcast-interval=1000']
|
||||
|
||||
Reference in New Issue
Block a user