MCPcopy Create free account
hub / github.com/ElementsProject/lightning / on_openchannel

Function on_openchannel

plugins/lsps-plugin/src/client.rs:662–722  ·  view source on GitHub ↗

Allows `zero_conf` channels to the client if the LSP is on the allowlist.

(
    p: cln_plugin::Plugin<State>,
    v: serde_json::Value,
)

Source from the content-addressed store, hash-verified

660
661/// Allows `zero_conf` channels to the client if the LSP is on the allowlist.
662async fn on_openchannel(
663 p: cln_plugin::Plugin<State>,
664 v: serde_json::Value,
665) -> Result<serde_json::Value, anyhow::Error> {
666 let req: OpenChannelRequest = ok_or_continue!(
667 serde_json::from_value(v).context("failed to deserialize open_channel request JSON")
668 );
669
670 // Fixme: Check that channel parameters are as negotiated.
671
672 let dir = p.configuration().lightning_dir;
673 let rpc_path = Path::new(&dir).join(&p.configuration().rpc_file);
674 let mut cln_client = ok_or_continue!(
675 cln_rpc::ClnRpc::new(rpc_path.clone())
676 .await
677 .context("failed to connect to core-lightning")
678 );
679
680 let ds_req = ListdatastoreRequest {
681 key: Some(vec![
682 "lsps".to_string(),
683 "client".to_string(),
684 req.openchannel.id.clone(),
685 ]),
686 };
687 let ds_res = ok_or_continue!(
688 cln_client
689 .call_typed(&ds_req)
690 .await
691 .context("failed to get datastore record")
692 );
693
694 if let Some(_rec) = ds_res.datastore.iter().next() {
695 info!(
696 "Allowing zero-conf channel from LSP {}",
697 &req.openchannel.id
698 );
699 let ds_req = DeldatastoreRequest {
700 generation: None,
701 key: vec![
702 "lsps".to_string(),
703 "client".to_string(),
704 req.openchannel.id.clone(),
705 ],
706 };
707 if let Some(err) = cln_client.call_typed(&ds_req).await.err() {
708 // We can do nothing but report that there was an issue deleting the
709 // datastore record.
710 warn!("Failed to delete LSP record from datastore: {}", err);
711 }
712 // Fixme: Check that we actually use client-trusts-LSP mode - can be
713 // found in the ds record.
714 return Ok(serde_json::json!({
715 "result": "continue",
716 "mindepth": 0,
717 }));
718 } else {
719 // Not a requested JIT-channel opening, continue.

Callers

nothing calls this directly

Calls 3

configurationMethod · 0.80
joinMethod · 0.80
call_typedMethod · 0.80

Tested by

no test coverage detected