mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +01:00
df-tests: add setacceptmaxfunding to df_accepter plugin
Method for setting a ceiling on the fund matching capabilities of df_accepter. Setting it to zero means we don't fund the channel anymore.
This commit is contained in:
committed by
Christian Decker
parent
ea1895fc1e
commit
f822a93cf4
@@ -85,12 +85,34 @@ def find_inputs(b64_psbt):
|
|||||||
return input_idxs
|
return input_idxs
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.init()
|
||||||
|
def init(configuration, options, plugin):
|
||||||
|
# this is the max channel size, pre-wumbo
|
||||||
|
plugin.max_fund = Millisatoshi((2 ** 24 - 1) * 1000)
|
||||||
|
plugin.log('max funding set to {}'.format(plugin.max_fund))
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.method("setacceptfundingmax")
|
||||||
|
def set_accept_funding_max(plugin, max_sats, **kwargs):
|
||||||
|
plugin.max_fund = Millisatoshi(max_sats)
|
||||||
|
|
||||||
|
return {'accepter_max_funding': plugin.max_fund}
|
||||||
|
|
||||||
|
|
||||||
@plugin.hook('openchannel2')
|
@plugin.hook('openchannel2')
|
||||||
def on_openchannel(openchannel2, plugin, **kwargs):
|
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']
|
amount = Millisatoshi(openchannel2['their_funding'])
|
||||||
locktime = openchannel2['locktime']
|
locktime = openchannel2['locktime']
|
||||||
|
|
||||||
|
if amount > plugin.max_fund:
|
||||||
|
plugin.log("amount adjusted from {} to {}".format(amount, plugin.max_fund))
|
||||||
|
amount = plugin.max_fund
|
||||||
|
|
||||||
|
if amount == 0:
|
||||||
|
plugin.log("accepter_max_funding set to zero")
|
||||||
|
return {'result': 'continue'}
|
||||||
|
|
||||||
# ...unless they send us totally unacceptable feerates.
|
# ...unless they send us totally unacceptable feerates.
|
||||||
feerate = find_feerate(openchannel2['funding_feerate_best'],
|
feerate = find_feerate(openchannel2['funding_feerate_best'],
|
||||||
openchannel2['funding_feerate_min'],
|
openchannel2['funding_feerate_min'],
|
||||||
@@ -101,12 +123,15 @@ def on_openchannel(openchannel2, plugin, **kwargs):
|
|||||||
# Their feerate range is out of bounds, we're not going to
|
# Their feerate range is out of bounds, we're not going to
|
||||||
# participate.
|
# participate.
|
||||||
if not feerate:
|
if not feerate:
|
||||||
|
plugin.log("Declining to fund, no feerate found.")
|
||||||
return {'result': 'continue'}
|
return {'result': 'continue'}
|
||||||
|
|
||||||
funding = plugin.rpc.fundpsbt(amount,
|
funding = plugin.rpc.fundpsbt(int(amount.to_satoshi()),
|
||||||
'{}perkw'.format(feerate),
|
'{}perkw'.format(feerate),
|
||||||
0, reserve=True,
|
0, # because we're the accepter!!
|
||||||
|
reserve=True,
|
||||||
locktime=locktime,
|
locktime=locktime,
|
||||||
|
minconf=0,
|
||||||
min_witness_weight=110)
|
min_witness_weight=110)
|
||||||
psbt_obj = psbt_from_base64(funding['psbt'])
|
psbt_obj = psbt_from_base64(funding['psbt'])
|
||||||
|
|
||||||
@@ -119,6 +144,7 @@ def on_openchannel(openchannel2, plugin, **kwargs):
|
|||||||
output = tx_output_init(change.to_whole_satoshi(), get_script(addr))
|
output = tx_output_init(change.to_whole_satoshi(), get_script(addr))
|
||||||
psbt_add_output_at(psbt_obj, 0, 0, output)
|
psbt_add_output_at(psbt_obj, 0, 0, output)
|
||||||
|
|
||||||
|
plugin.log("contributing {} at feerate {}".format(amount, feerate))
|
||||||
return {'result': 'continue', 'psbt': psbt_to_base64(psbt_obj, 0),
|
return {'result': 'continue', 'psbt': psbt_to_base64(psbt_obj, 0),
|
||||||
'accepter_funding_msat': amount,
|
'accepter_funding_msat': amount,
|
||||||
'funding_feerate': feerate}
|
'funding_feerate': feerate}
|
||||||
|
|||||||
Reference in New Issue
Block a user