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

Core lightning plugin to intercept HTLCs #101

Closed
wants to merge 8 commits into from

Conversation

justinmoon
Copy link
Contributor

@justinmoon justinmoon commented May 18, 2022

TLDR this PR turns ln_gateway into a core-lightning "plugin" so that it can intercept HTLCs using the htlc_accepted hook. In the future this will allow the gateway to buy the preimage from the federation and complete incoming lightning payments. Right now a preimage is hard-coded. I made a new file for this plugin since it's not really done yet ...

This PR also creates a new UserClient::create_invoice(amount) method to create a lightning invoice which will allow the gateway to receive payment and (eventually) figure out which preimage to buy from the federation.

Perhaps I should squash commits or break this up into a couple PRs? I'll leave some comments inline ...

@@ -26,3 +27,6 @@ tide = "0.16.0"
tracing = "0.1.26"
tracing-subscriber = { version = "0.3.1", features = [ "env-filter" ] }
tokio = {version = "1.0", features = ["full"]}

# FIXME: kept getting `Error: attempted to set a logger after the logging system was already initialized`
log = "0.4.17"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed like tracing and the cln_plugin logging system were in conflict somehow and I couldn't figure out exactly how. This is kind of weird because core-lightning plugins use stdin / stdout for IO and that might have something to do with it ...

// .with_env_filter(
// EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
// )
// .init();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just commented out the tracing code because we need to figure out how to get this working again and remove the log dependency I added for reasons mentioned above ...

{
let workdir = match plugin.option("minimint-cfg").expect("minimint-cfg missing") {
options::Value::String(workdir) => {
// FIXME: cln_plugin doesn't yet support optional parameters
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to add this to cln_plugin

.min_final_cltv_expiry(144)
.payee_pub_key(node_public_key)
.private_route(gateway_route_hint)
.build_signed(|hash| self.context.secp.sign_recoverable(hash, &node_secret_key))?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these parameters I just copied from examples in the docs. Don't know exactly what all of them mean ...

@elsirion elsirion linked an issue May 19, 2022 that may be closed by this pull request
@justinmoon
Copy link
Contributor Author

Re-reading #69 I think I still need to initialize the plugin to write RPC requests to stdout instead of the rpc socket ...

@elsirion
Copy link
Contributor

Yeah, that will make the rpc path in the GW config obsolete since cln will tell you where its RPC socket is on initialization (iirc).

@justinmoon
Copy link
Contributor Author

Yeah, that will make the rpc path in the GW config obsolete since cln will tell you where its RPC socket is on initialization (iirc).

This is correct. Core-lightning sends this in the "configuration" section of the "init" message that is sent while the plugin is intializing.

Problem is that cln_plugin doesn't save this while handling the "init" message. Made a PR to fix this.


let mut app = tide::with_state(state);
app.at("/pay_invoice").post(pay_invoice);
app.listen("27.0.0.1:8080").await?;
Copy link

Choose a reason for hiding this comment

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

Should this be 127.0.0.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm yes

@justinmoon
Copy link
Contributor Author

I'm going to close this and open a new pull request with the core lightning plugin ...

@justinmoon justinmoon closed this Jun 20, 2022
@justinmoon justinmoon deleted the 5-12-cln-plugin branch July 31, 2022 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make lightning gateway run a core lightning plugin
3 participants