-
Notifications
You must be signed in to change notification settings - Fork 224
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
Conversation
@@ -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" |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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))?; |
There was a problem hiding this comment.
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 ...
Re-reading #69 I think I still need to initialize the plugin to write RPC requests to stdout instead of the rpc socket ... |
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 |
|
||
let mut app = tide::with_state(state); | ||
app.at("/pay_invoice").post(pay_invoice); | ||
app.listen("27.0.0.1:8080").await?; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm yes
I'm going to close this and open a new pull request with the core lightning plugin ... |
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 ...