Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34045,6 +34045,73 @@
}
]
},
"splicein.json": {
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"added": "v26.04",
"rpc": "splicein",
"title": "Command to splice funds into a channel",
"warning": "experimental-splicing only",
"description": [
"`splicein` is the command to move funds into a channel."
],
"request": {
"required": [
"channel",
"amount"
],
"properties": {
"channel": {
"type": "string",
"description": [
"channel identifier or channel query. Format is the same as is used in `dev-splice`."
]
},
"amount": {
"type": "string",
"description": [
"Amount in satoshis taken from the internal wallet and add to the channel. Format is the same as is used in `dev-splice`."
]
}
}
},
"response": {
"required": [],
"properties": {
"psbt": {
"type": "string",
"description": [
"The final psbt"
]
},
"tx": {
"type": "string",
"description": [
"The final transaction in hex"
]
},
"txid": {
"type": "string",
"description": [
"The txid of the final transaction"
]
}
}
},
"usage": [
"`splicein` is the command to add funds to a channel. It takes `amount` funds from your onchain wallet and places them into `channel`."
],
"author": [
"Dusty [@dusty_daemon](mailto:@dustydaemon) is mainly responsible."
],
"see_also": [
"lightning-dev-splice(7)"
],
"resources": [
"Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
]
},
"sql-template.json": {
"$schema": "../rpc-schema-draft.json",
"type": "object",
Expand Down
8 changes: 8 additions & 0 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,14 @@ def splice(self, script_or_json, dryrun=None, force_feerate=None, debug_log=None
}
return self.call("dev-splice", payload)

def splicein(self, channel, amount):
""" Execute a splice """
payload = {
"channel": channel,
"amount": amount,
}
return self.call("splicein", payload)

def stfu_channels(self, channel_ids):
""" STFU multiple channels """
payload = {
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ MARKDOWNPAGES := doc/addgossip.7 \
doc/signmessage.7 \
doc/signmessagewithkey.7 \
doc/signpsbt.7 \
doc/splicein.7 \
doc/splice_init.7 \
doc/splice_signed.7 \
doc/splice_update.7 \
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Core Lightning Documentation
splice_init <splice_init.7.md>
splice_signed <splice_signed.7.md>
splice_update <splice_update.7.md>
splicein <splicein.7.md>
sql <sql.7.md>
staticbackup <staticbackup.7.md>
stop <stop.7.md>
Expand Down
67 changes: 67 additions & 0 deletions doc/schemas/splicein.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"added": "v26.04",
"rpc": "splicein",
"title": "Command to splice funds into a channel",
"warning": "experimental-splicing only",
"description": [
"`splicein` is the command to move funds into a channel."
],
"request": {
"required": [
"channel",
"amount"
],
"properties": {
"channel": {
"type": "string",
"description": [
"channel identifier or channel query. Format is the same as is used in `dev-splice`."
]
},
"amount": {
"type": "string",
"description": [
"Amount in satoshis taken from the internal wallet and add to the channel. Format is the same as is used in `dev-splice`."
]
}
}
},
"response": {
"required": [],
"properties": {
"psbt": {
"type": "string",
"description": [
"The final psbt"
]
},
"tx": {
"type": "string",
"description": [
"The final transaction in hex"
]
},
"txid": {
"type": "string",
"description": [
"The txid of the final transaction"
]
}
}
},
"usage": [
"`splicein` is the command to add funds to a channel. It takes `amount` funds from your onchain wallet and places them into `channel`."
],
"author": [
"Dusty [@dusty_daemon](mailto:@dustydaemon) is mainly responsible."
],
"see_also": [
"lightning-dev-splice(7)"
],
"resources": [
"Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
]
}
47 changes: 47 additions & 0 deletions plugins/spender/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -2203,10 +2203,57 @@ json_splice(struct command *cmd, const char *buf, const jsmntok_t *params)
return send_outreq(req);
}

static struct command_result *
json_splicein(struct command *cmd, const char *buf, const jsmntok_t *params)
{
struct out_req *req;
const char *channel, *amount;
struct splice_cmd *splice_cmd;
char *script;

if (!param(cmd, buf, params,
p_req("channel", param_string, &channel),
p_req("amount", param_string, &amount),
NULL))
return command_param_failed();

script = tal_fmt(NULL,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is it! what we've been waiting for!

"wallet -> %s + fee; %s -> %s",
amount, amount, channel);

splice_cmd = tal(cmd, struct splice_cmd);

splice_cmd->cmd = cmd;
splice_cmd->script = tal_steal(splice_cmd, script);
splice_cmd->psbt = create_psbt(splice_cmd, 0, 0, 0);
splice_cmd->dryrun = false;
splice_cmd->wetrun = false;
splice_cmd->feerate_per_kw = 0;
splice_cmd->force_feerate = false;
splice_cmd->wallet_inputs_to_signed = 0;
splice_cmd->fee_calculated = false;
splice_cmd->initial_funds = AMOUNT_SAT(0);
splice_cmd->emergency_sat = AMOUNT_SAT(0);
splice_cmd->debug_log = NULL;
splice_cmd->debug_counter = 0;
splice_cmd->needed_funds = AMOUNT_SAT(0);
memset(&splice_cmd->final_txid, 0, sizeof(splice_cmd->final_txid));

req = jsonrpc_request_start(cmd, "listpeerchannels",
listpeerchannels_get_result,
splice_error, splice_cmd);

return send_outreq(req);
}

const struct plugin_command splice_commands[] = {
{
"dev-splice",
json_splice
},
{
"splicein",
json_splicein
},
};
const size_t num_splice_commands = ARRAY_SIZE(splice_commands);
39 changes: 39 additions & 0 deletions tests/test_splice.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,45 @@ def test_script_two_chan_splice_inout(node_factory, bitcoind):
l2.rpc.pay(inv['bolt11'])


@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
def test_easy_splice_in(node_factory, bitcoind, chainparams):
fundamt = 1000000

coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py"
l1, l2 = node_factory.line_graph(2, fundamount=fundamt, wait_for_announce=True,
opts={'experimental-splicing': None,
'plugin': coin_mvt_plugin})

# Splice in 100k sats into first channel
spliceamt = 100000

l1.rpc.splicein("*:?", f"{spliceamt}")
p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
assert p1['inflight'][0]['splice_amount'] == spliceamt
assert p1['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000
assert p1['inflight'][0]['our_funding_msat'] == fundamt * 1000
assert p2['inflight'][0]['splice_amount'] == 0
assert p2['inflight'][0]['total_funding_msat'] == (fundamt + spliceamt) * 1000
assert p2['inflight'][0]['our_funding_msat'] == 0
bitcoind.generate_block(6, wait_for_mempool=1)
l2.daemon.wait_for_log(r'lightningd, splice_locked clearing inflights')

p1 = only_one(l1.rpc.listpeerchannels(peer_id=l2.info['id'])['channels'])
p2 = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
assert p1['to_us_msat'] == (fundamt + spliceamt) * 1000
assert p1['total_msat'] == (fundamt + spliceamt) * 1000
assert p2['to_us_msat'] == 0
assert p2['total_msat'] == (fundamt + spliceamt) * 1000
assert 'inflight' not in p1
assert 'inflight' not in p2

wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1)
wait_for(lambda: len(l1.rpc.listfunds()['channels']) == 1)


# Makes channels going from node 1 -> 2, 2 -> 3, etc up to 'qty' number channels.
# If balanced is True, than each channel will be balanced -- otherwise the lower
# index channel will have funds in the channel to the higher indexed one.
Expand Down
Loading