df: Pass new feerate options through to plugin, set reasonable bounds

We let the plugin decide what feerate to accept/whether or not to add
funds to the open. To aid this decision, we also send the plugin what we
(c-lightning) currently have as our max and min acceptable feerates.

We also now use these as our default for max/min acceptable feerate
range when sending an openchannel offer to a peer.

In the future, it might be a good idea to make these more easily
changeable, either via a config setting (?) or a command param.
This commit is contained in:
niftynei
2020-10-26 12:48:42 -05:00
committed by neil saitug
parent 97fd18f0b5
commit 4ea9d9e928
6 changed files with 145 additions and 58 deletions

View File

@@ -44,13 +44,38 @@ def get_script(bech_addr):
return bytes([wit_ver + 0x50 if wit_ver > 0 else wit_ver, len(wprog)] + wprog)
def find_feerate(best, their_min, their_max, our_min, our_max):
if best >= our_min and best <= our_max:
return best
if their_max < our_min or their_min > our_max:
return False
if best < our_min:
return our_min
# best > our_max:
return our_max
@plugin.hook('openchannel2')
def on_openchannel(openchannel2, plugin, **kwargs):
# We mirror what the peer does, wrt to funding amount
# We mirror what the peer does, wrt to funding amount ...
amount = openchannel2['their_funding']
feerate = openchannel2['feerate_per_kw_funding']
locktime = openchannel2['locktime']
# ...unless they send us totally unacceptable feerates.
feerate = find_feerate(openchannel2['funding_feerate_best'],
openchannel2['funding_feerate_min'],
openchannel2['funding_feerate_max'],
openchannel2['feerate_our_min'],
openchannel2['feerate_our_max'])
# Their feerate range is out of bounds, we're not going to
# participate.
if not feerate:
return {'result': 'continue'}
funding = plugin.rpc.fundpsbt(amount, ''.join([str(feerate), 'perkw']), 0, reserve=True,
locktime=locktime)
psbt_obj = psbt_from_base64(funding['psbt'])
@@ -65,7 +90,8 @@ def on_openchannel(openchannel2, plugin, **kwargs):
psbt_add_output_at(psbt_obj, 0, 0, output)
return {'result': 'continue', 'psbt': psbt_to_base64(psbt_obj, 0),
'accepter_funding_msat': amount}
'accepter_funding_msat': amount,
'funding_feerate': feerate}
@plugin.hook('openchannel2_changed')