Browse Source

fundchannel/fundchannel_start: remove deprecated `satoshi` parameter

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: JSON: `fundchannel` and `fundchannel_start` `satoshi` parameter removed (renamed to `amount` in 0.7.3).
travis-debug
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
75838341a7
  1. 46
      lightningd/opening_control.c
  2. 44
      plugins/fundchannel.c
  3. 97
      tests/test_connection.py

46
lightningd/opening_control.c

@ -1133,43 +1133,15 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
fc->uc = NULL; fc->uc = NULL;
fc->inflight = false; fc->inflight = false;
/* For generating help, give new-style. */ if (!param(fc->cmd, buffer, params,
if (!params || !deprecated_apis || params->type == JSMN_ARRAY) { p_req("id", param_node_id, &id),
if (!param(fc->cmd, buffer, params, p_req("amount", param_sat, &amount),
p_req("id", param_node_id, &id), p_opt("feerate", param_feerate, &feerate_per_kw),
p_req("amount", param_sat, &amount), p_opt_def("announce", param_bool, &announce_channel, true),
p_opt("feerate", param_feerate, &feerate_per_kw), p_opt("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script),
p_opt_def("announce", param_bool, &announce_channel, true), p_opt("push_msat", param_msat, &push_msat),
p_opt("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script), NULL))
p_opt("push_msat", param_msat, &push_msat), return command_param_failed();
NULL))
return command_param_failed();
} else {
/* For json object type when allow deprecated api, 'check' command
* can't find the error if we don't set 'amount' nor 'satoshi'.
*/
struct amount_sat *satoshi;
if (!param(fc->cmd, buffer, params,
p_req("id", param_node_id, &id),
p_opt("amount", param_sat, &amount),
p_opt("satoshi", param_sat, &satoshi),
p_opt("feerate", param_feerate, &feerate_per_kw),
p_opt_def("announce", param_bool, &announce_channel, true),
p_opt("push_msat", param_msat, &push_msat),
NULL))
return command_param_failed();
if (!amount) {
if (satoshi)
amount = satoshi;
else
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Need set 'amount' field");
}
/* No upfront shutdown script option for deprecated API */
fc->our_upfront_shutdown_script = NULL;
}
if (amount_sat_greater(*amount, chainparams->max_funding)) if (amount_sat_greater(*amount, chainparams->max_funding))
return command_fail(cmd, FUND_MAX_EXCEEDED, return command_fail(cmd, FUND_MAX_EXCEEDED,

44
plugins/fundchannel.c

@ -393,40 +393,16 @@ static struct command_result *json_fundchannel(struct command *cmd,
{ {
struct funding_req *fr = tal(cmd, struct funding_req); struct funding_req *fr = tal(cmd, struct funding_req);
/* For generating help, give new-style. */ if (!param(cmd, buf, params,
if (!params || !deprecated_apis || params->type == JSMN_ARRAY) { p_req("id", param_node_id, &fr->id),
if (!param(cmd, buf, params, p_req("amount", param_string_check_sat, &fr->funding_str),
p_req("id", param_node_id, &fr->id), p_opt("feerate", param_string, &fr->feerate_str),
p_req("amount", param_string_check_sat, &fr->funding_str), p_opt_def("announce", param_bool, &fr->announce_channel, true),
p_opt("feerate", param_string, &fr->feerate_str), p_opt_def("minconf", param_number, &fr->minconf, 1),
p_opt_def("announce", param_bool, &fr->announce_channel, true), p_opt("utxos", param_string, &fr->utxo_str),
p_opt_def("minconf", param_number, &fr->minconf, 1), p_opt("push_msat", param_msat, &fr->push_msat),
p_opt("utxos", param_string, &fr->utxo_str), NULL))
p_opt("push_msat", param_msat, &fr->push_msat), return command_param_failed();
NULL))
return command_param_failed();
} else {
const char *satoshi_str;
if (!param(cmd, buf, params,
p_req("id", param_node_id, &fr->id),
p_opt("amount", param_string, &fr->funding_str),
p_opt("satoshi", param_string, &satoshi_str),
p_opt("feerate", param_string, &fr->feerate_str),
p_opt_def("announce", param_bool, &fr->announce_channel, true),
p_opt_def("minconf", param_number, &fr->minconf, 1),
p_opt("utxos", param_string, &fr->utxo_str),
p_opt("push_msat", param_msat, &fr->push_msat),
NULL))
return command_param_failed();
if (!fr->funding_str) {
if (satoshi_str)
fr->funding_str = satoshi_str;
else
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Need set 'amount' field");
}
}
fr->funding_all = streq(fr->funding_str, "all"); fr->funding_all = streq(fr->funding_str, "all");

97
tests/test_connection.py

@ -6,7 +6,7 @@ from flaky import flaky # noqa: F401
from pyln.client import RpcError from pyln.client import RpcError
from utils import ( from utils import (
DEVELOPER, only_one, wait_for, sync_blockheight, VALGRIND, TIMEOUT, DEVELOPER, only_one, wait_for, sync_blockheight, VALGRIND, TIMEOUT,
SLOW_MACHINE, COMPAT, expected_features SLOW_MACHINE, expected_features
) )
from bitcoin.core import CMutableTransaction, CMutableTxOut from bitcoin.core import CMutableTransaction, CMutableTxOut
@ -704,101 +704,6 @@ def test_shutdown_awaiting_lockin(node_factory, bitcoind):
wait_for(lambda: l2.rpc.listpeers()['peers'] == []) wait_for(lambda: l2.rpc.listpeers()['peers'] == [])
@unittest.skipIf(not COMPAT, "needs COMPAT=1")
def test_deprecated_fundchannel_start(node_factory, bitcoind):
"""Test the deprecated old-style:
fundchannel {id} {satoshi} {feerate} {announce}
"""
l1, l2 = node_factory.get_nodes(2, opts=[{'allow-deprecated-apis': True}, {}])
nodeid = l2.info['id']
# New style(object type)
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, amount=10**6, feerate='2000perkw', announce=True)
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, amount=10**6, announce=True)
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, amount=10**6, feerate='2000perkw')
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, amount=10**6)
# Array type
l1.rpc.call('check', ['fundchannel_start', nodeid, 10**6, '2000perkw', True])
l1.rpc.call('check', ['fundchannel_start', nodeid, 10**6, None, True])
l1.rpc.call('check', ['fundchannel_start', nodeid, 10**6, 'slow'])
l1.rpc.call('check', ['fundchannel_start', nodeid, 10**6])
# No 'amount' nor 'satoshi'(array type)
with pytest.raises(RpcError, match=r'missing required parameter: amount'):
l1.rpc.call('check', ['fundchannel_start', nodeid])
with pytest.raises(RpcError, match=r'.*should be a satoshi amount, not.*'):
l1.rpc.call('check', ['fundchannel_start', nodeid, '2000perkw'])
# Old style(object type)
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, satoshi=10**6, feerate='2000perkw', announce=False)
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, satoshi=10**6, feerate='slow')
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, satoshi=10**6, announce=True)
l1.rpc.check(command_to_check='fundchannel_start', id=nodeid, satoshi=10**6)
# For json object type when allow deprecated api, 'check' command can't find
# the error if we don't set 'amount' nor 'satoshi'.
l1.rpc.connect(nodeid, 'localhost', l2.port)
# No 'amount' nor 'satoshi'(object type)
with pytest.raises(RpcError, match=r'Need set \'amount\' field'):
l1.rpc.call('fundchannel_start', {'id': nodeid, 'feerate': '2000perkw'})
@unittest.skipIf(not COMPAT, "needs COMPAT=1")
def test_deprecated_fundchannel(node_factory, bitcoind):
"""Test the deprecated old-style:
fundchannel {id} {satoshi} {feerate} {announce} {minconf} {utxos}
"""
l1 = node_factory.get_node(options={'allow-deprecated-apis': True})
# FIXME: Use 'check' command after libplugin(C language) supports 'check' mode for command
nodes = node_factory.get_nodes(8)
amount = int(0.0005 * 10**8)
for n in nodes:
l1.rpc.connect(n.info['id'], 'localhost', n.port)
# Get 8 utxos
for i in range(8):
l1.fundwallet(10**8)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1])
wait_for(lambda: len(l1.rpc.listfunds()["outputs"]) == 8)
# No 'amount' nor 'satoshi'(array type)
with pytest.raises(RpcError, match=r'missing required parameter: amount'):
l1.rpc.call('fundchannel', [nodes[0].info['id']])
with pytest.raises(RpcError, match=r'.* should be a satoshi amount, not .*'):
l1.rpc.call('fundchannel', [nodes[0].info['id'], 'slow'])
def get_utxo(node):
"""Get an unspent but confirmed output
"""
outputs = node.rpc.listfunds()['outputs']
for o in outputs:
if o['status'] == 'confirmed':
return "{}:{}".format(o['txid'], o['output'])
# Array type
l1.rpc.call('fundchannel', [nodes[0].info['id'], amount, '2000perkw', False, 1, [get_utxo(l1)]])
l1.rpc.call('fundchannel', [nodes[1].info['id'], amount, '2000perkw', False, None, [get_utxo(l1)]])
l1.rpc.call('fundchannel', [nodes[2].info['id'], amount, '2000perkw', None, None, [get_utxo(l1)]])
l1.rpc.call('fundchannel', [nodes[3].info['id'], amount, '2000perkw', True, 1])
# No 'amount' nor 'satoshi'(object type)
with pytest.raises(RpcError, match=r'Need set \'amount\' field'):
l1.rpc.call('fundchannel', {'id': nodes[4].info['id'], 'feerate': '2000perkw'})
# Old style(object type)
l1.rpc.call('fundchannel', {'id': nodes[4].info['id'], 'satoshi': 'all', 'feerate': 'slow',
'announce': True, 'minconf': 1, 'utxos': [get_utxo(l1)]})
l1.rpc.call('fundchannel', {'id': nodes[5].info['id'], 'satoshi': 'all', 'feerate': 'slow', 'minconf': 1})
l1.rpc.call('fundchannel', {'id': nodes[6].info['id'], 'satoshi': 'all', 'feerate': 'slow'})
l1.rpc.call('fundchannel', {'id': nodes[7].info['id'], 'satoshi': 'all'})
def test_funding_change(node_factory, bitcoind): def test_funding_change(node_factory, bitcoind):
"""Add some funds, fund a channel, and make sure we remember the change """Add some funds, fund a channel, and make sure we remember the change
""" """

Loading…
Cancel
Save