-
Notifications
You must be signed in to change notification settings - Fork 30
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
Remove Legacy Lightning-RPC Client #579
Open
nepet
wants to merge
3
commits into
main
Choose a base branch
from
2508-fix-missing-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
use crate::config::Config; | ||
use crate::pb::{self, node_server::Node}; | ||
use crate::rpc::LightningClient; | ||
use crate::storage::StateStore; | ||
use crate::{messages, Event}; | ||
use crate::{stager, tramp}; | ||
|
@@ -13,7 +12,6 @@ use governor::{ | |
}; | ||
use lazy_static::lazy_static; | ||
use log::{debug, error, info, trace, warn}; | ||
use serde_json::json; | ||
use std::path::PathBuf; | ||
use std::sync::atomic::AtomicBool; | ||
use std::sync::{ | ||
|
@@ -54,7 +52,6 @@ lazy_static! { | |
pub struct PluginNodeServer { | ||
pub tls: ServerTlsConfig, | ||
pub stage: Arc<stager::Stage>, | ||
pub rpc: Arc<Mutex<LightningClient>>, | ||
rpc_path: PathBuf, | ||
events: tokio::sync::broadcast::Sender<super::Event>, | ||
signer_state: Arc<Mutex<State>>, | ||
|
@@ -78,8 +75,6 @@ impl PluginNodeServer { | |
rpc_path.push("lightning-rpc"); | ||
info!("Connecting to lightning-rpc at {:?}", rpc_path); | ||
|
||
let rpc = Arc::new(Mutex::new(LightningClient::new(rpc_path.clone()))); | ||
|
||
// Bridge the RPC_BCAST into the events queue | ||
let tx = events.clone(); | ||
tokio::spawn(async move { | ||
|
@@ -95,15 +90,12 @@ impl PluginNodeServer { | |
|
||
let ctx = crate::context::Context::new(); | ||
|
||
let rrpc = rpc.clone(); | ||
|
||
let s = PluginNodeServer { | ||
ctx, | ||
tls, | ||
rpc, | ||
stage, | ||
events, | ||
rpc_path, | ||
rpc_path: rpc_path.clone(), | ||
signer_state: Arc::new(Mutex::new(signer_state)), | ||
signer_state_store: Arc::new(Mutex::new(signer_state_store)), | ||
grpc_binding: config.node_grpc_binding, | ||
|
@@ -114,10 +106,11 @@ impl PluginNodeServer { | |
use tokio::time::{sleep, Duration}; | ||
|
||
// Move the lock into the closure so we can release it later. | ||
let rpc = rrpc.lock().await; | ||
let mut rpc = cln_rpc::ClnRpc::new(rpc_path.clone()).await.unwrap(); | ||
loop { | ||
let res: Result<crate::responses::GetInfo, crate::rpc::Error> = | ||
rpc.call("getinfo", json!({})).await; | ||
let res = rpc | ||
.call_typed(&cln_rpc::model::requests::GetinfoRequest {}) | ||
.await; | ||
match res { | ||
Ok(_) => break, | ||
Err(e) => { | ||
|
@@ -137,8 +130,7 @@ impl PluginNodeServer { | |
key: Some(vec!["glconf".to_string(), "request".to_string()]), | ||
}; | ||
|
||
let res: Result<cln_rpc::model::responses::ListdatastoreResponse, crate::rpc::Error> = | ||
rpc.call("listdatastore", list_datastore_req).await; | ||
let res = rpc.call_typed(&list_datastore_req).await; | ||
|
||
match res { | ||
Ok(list_datastore_res) => { | ||
|
@@ -177,11 +169,8 @@ impl PluginNodeServer { | |
limiter.until_ready().await | ||
} | ||
|
||
pub async fn get_rpc(&self) -> LightningClient { | ||
let rpc = self.rpc.lock().await; | ||
let r = rpc.clone(); | ||
drop(rpc); | ||
r | ||
pub async fn get_rpc(&self) -> Result<cln_rpc::ClnRpc> { | ||
cln_rpc::ClnRpc::new(self.rpc_path.clone()).await | ||
} | ||
} | ||
|
||
|
@@ -229,8 +218,8 @@ impl Node for PluginNodeServer { | |
// log entries are produced while we're streaming the | ||
// backlog out, but do we care? | ||
use tokio::io::{AsyncBufReadExt, BufReader}; | ||
// The nodelet uses its CWD, but CLN creates a network | ||
// subdirectory | ||
// The nodelet uses its CWD, but CLN creates a network | ||
// subdirectory | ||
let file = tokio::fs::File::open("../log").await?; | ||
let mut file = BufReader::new(file).lines(); | ||
|
||
|
@@ -475,10 +464,16 @@ impl Node for PluginNodeServer { | |
) -> Result<Response<pb::Empty>, Status> { | ||
self.limit().await; | ||
let gl_config = req.into_inner(); | ||
let rpc = self.get_rpc().await; | ||
let mut rpc = self.get_rpc().await.map_err(|e| { | ||
tonic::Status::new( | ||
tonic::Code::Internal, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is the error messages all "early calls" will run into. Not the best UX. |
||
format!("could not connect rpc client: {e}"), | ||
) | ||
})?; | ||
|
||
let res: Result<crate::responses::GetInfo, crate::rpc::Error> = | ||
rpc.call("getinfo", json!({})).await; | ||
let res = rpc | ||
.call_typed(&cln_rpc::model::requests::GetinfoRequest {}) | ||
.await; | ||
|
||
let network = match res { | ||
Ok(get_info_response) => match get_info_response.network.parse() { | ||
|
@@ -528,20 +523,14 @@ impl Node for PluginNodeServer { | |
.map(|r| r.into()) | ||
.collect(); | ||
let serialized_req = serde_json::to_string(&requests[0]).unwrap(); | ||
let datastore_res: Result< | ||
crate::cln_rpc::model::responses::DatastoreResponse, | ||
crate::rpc::Error, | ||
> = rpc | ||
.call( | ||
"datastore", | ||
json!({ | ||
"key": vec![ | ||
"glconf".to_string(), | ||
"request".to_string(), | ||
], | ||
"string": serialized_req, | ||
}), | ||
) | ||
let datastore_res = rpc | ||
.call_typed(&cln_rpc::model::requests::DatastoreRequest { | ||
key: vec!["glconf".to_string(), "request".to_string()], | ||
string: Some(serialized_req.clone()), | ||
hex: None, | ||
mode: None, | ||
generation: None, | ||
}) | ||
.await; | ||
|
||
match datastore_res { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We got a bit unlucky here: we use the
Mutex
to prevent incoming JSON-RPC calls, before the JSON-RPC socket is ready. This is done by acquiring the lock during startup and releasing it once the socket file is present. The internal use-cases are ok, since they by definition are invoked only after the node started and the socket is ready.The change below however breaks this, by not locking in
get_rpc
it is now possible for incoming grpc calls to be directly forwarded (not waiting behind a lock) and so they will fail. We will most likely notice this as the startup commands (i.e., the ones that caused the node to start) will fail in a large number of cases.Please leave the
Mutex
inget_rpc