Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splice: Script for complex splices #6980

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

ddustin
Copy link
Collaborator

@ddustin ddustin commented Jan 6, 2024

PR reviewers: It might be good to start here to learn the splice script syntax: https://github.com/ddustin/lightning/blob/ddustin/splice_script/doc/lightning-splice.7.md

New compiler for splice scripts that parses splice scripts, validates them, converts them to json and back again.

A test is included that puts some advanced and complex scripts into the parser and validates the results that come out.

Changelog-Added: Splice script parser — takes a custom splice query language to bundle multiple complex splices into a single task in a simple way.

Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

Mh What do you mean by "Scripts"? and why now we need a "compiler" for splicing? 😕

I feel that I am missing somethings?

@ddustin
Copy link
Collaborator Author

ddustin commented Jan 8, 2024

Mh What do you mean by "Scripts"? and why now we need a "compiler" for splicing? 😕

I feel that I am missing somethings?

Proper documentation is coming but here's a quick summary:

The script isn't required to be used -- there will also be a json option and, of course, the lower level api is available.

When doing splices across multiple channels it quickly becomes unwieldy for users. Using the script is a nice shorthand to make it easier -- and also allows you to do "dry runs" and confirm it's doing what you'd like.

Say you wanted to take 50% of funds and splice them into three other channels, in splice script it's quite simple:

84ff50 -> 50%;
* -> cecf35;
* -> 4fe310;
* -> c14f60;

While working on it, it made sense to add a bunch of other useful things like being able to specify amounts as whole numbers, percentages, or * (split amount among all *s); channel queries; onchain bitcoin addresses; and the onchain wallet.

By building this more powerful part first it becomes trivial to implement the simpler splice commands. For instance:

Splice out 10 million sats

84ff50 -> 10M;

Splice in 10 million sats

wallet -> 10M;
* -> 84ff50;

Cross splice 10 million sats

84ff50 -> 10M;
* -> cecf35;

Pay 10M sats onchain using channel funds

84ff50 -> 10M+fee;
10M -> 1JfbZRwdDHKZmuiZgYArJZhcuuzuw2HuMu;

@ddustin ddustin added this to the v24.02 milestone Jan 13, 2024
@ddustin ddustin force-pushed the ddustin/splice_script branch 5 times, most recently from 731048c to ab31aa7 Compare January 22, 2024 22:12
@ddustin ddustin marked this pull request as ready for review January 22, 2024 22:13
@ddustin ddustin force-pushed the ddustin/splice_script branch 7 times, most recently from 8105050 to 737ffc2 Compare January 24, 2024 22:43
@ddustin ddustin mentioned this pull request May 30, 2024
70 tasks
@ddustin ddustin force-pushed the ddustin/splice_script branch 2 times, most recently from 2f774db to 479c654 Compare May 30, 2024 22:55
ddustin added 20 commits May 30, 2024 19:22
New compiler for splice scripts that parses splice scripts, validates them, converts them to json and back again.

Changelog-Added: Splice script parser — takes a custom splice query language to bundle multiple complex splices into a single task in a simple way.
A test that puts some advanced and complex scripts into the parser and validates the results that come out.
A routine for getting a signature back out of an input’s list of pending signatures via pubkey search.

This is needed for certain kinds of restarts as we lose our peer’s signature from memory but a copy is kept in the PSBT.
Stores an array of channel_ids into the PSBT globals area.

Changelog-None
`splice_signed` now searchs the PSBT for channel ids

Changelog-Changed: `splice_signed` parameters are switched in order to make `channel_id` an optional parameter, enabling multi-splice-signatures.
This is needed to all multi-channel splices. When channeld can return the signatures to the user (based on signing order precedent), it now does from splice_update.

Additionally, we move sending of the initial psbt from splice_init down to splice_update. This is also necessary for correct psbt diff detection during multi-channel splices.

Changelog-Changed: splice_update can in some cases now return the remotely partiall signed psbt to the user, if so `signtures_secured` will be true.
On certain well timed restarts we lose their siganture from memory and don’t receive it from them. In these cases we can extract it from the PSBT directly.
The ability to stfu channels in bulk is required to do complex multi channel operations. When stfu’ing in this manner, the available funds at the moment of stfu is returned to the user.

In order to cancel the stfu we also add a bulk tx_abort command.

Changelog-Added: `stfu_channels` and `abort_channels` are added for bulk multi-channel splice commands. These allow the user to pause (and resume) multiple channels in place.
This is the sister command of addpsbtoutput.

Adds inputs equal to or greater than the amount requests, reservers them, and reports important information back out to the user.

Changelog-Added: New low-level RPC command addpsbtinput to fund PSBTs directly and help with complex splices & dual-opens.
When set this flag tells addpsbtoutput to add the intiator serial_id to the added output.

Changelog-Changed: addpsbtoutput now allows serial_id to be set while adding which is needed for splicing and dual.
The command called “splice” can take a json payload or a ‘splice script’, process it into a list of ‘actions’ and then execute those actions.

These actions include or will include everything you would want to do with a splice:
* Splice into a channel
* Splice out of a channel
* Fund from wallet
* Deposit to wallet
* Send funds to bitcoin address

Changelog-Added: A new magic “splice” command is added that can take a ‘splice script’ or json payload and perform any complex splice across multiple channels merging the result into a single transaction. Some features are disabled and will be added in time.
Adding schema and documentatino for how to use the scripting portion of the “splice” RPC command.
The fee maximum is used to issue a warning to the user their feerate is high in case they accidentally make a large donation to miners.

During python testing the feerates are high on purpose so we raise the warning level to at least the penality feerate.
Tests that splice-in and splice-out work through the scripting process and confirm the resulting balances are correct.
If the user does not supply enough funds treat it as an abort instead of a channel warning.

Also clean up some indentation while we’re there.
@ddustin ddustin force-pushed the ddustin/splice_script branch 5 times, most recently from 9b9a15c to cfc9293 Compare May 31, 2024 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants