Skip to content

Commit

Permalink
cln-grpc: Do not start unless a grpc-port is specified
Browse files Browse the repository at this point in the history
For now we don't want to autostart.

Suggested-by: Rusty Russell <@rustyrussell>
  • Loading branch information
cdecker committed Mar 28, 2022
1 parent b748e88 commit 21385e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 5 additions & 1 deletion plugins/grpc-plugin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ async fn main() -> Result<()> {
let plugin = Builder::new(state.clone(), tokio::io::stdin(), tokio::io::stdout())
.option(options::ConfigOption::new(
"grpc-port",
options::Value::Integer(50051),
options::Value::Integer(-1),
"Which port should the grpc plugin listen for incoming connections?",
))
.start()
.await?;

let bind_port = match plugin.option("grpc-port") {
Some(options::Value::Integer(-1)) => {
log::info!("`grpc-port` option is not configured, exiting.");
return Ok(());
}
Some(options::Value::Integer(i)) => i,
None => return Err(anyhow!("Missing 'grpc-port' option")),
Some(o) => return Err(anyhow!("grpc-port is not a valid integer: {:?}", o)),
Expand Down
20 changes: 16 additions & 4 deletions tests/test_cln_rs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fixtures import * # noqa: F401,F403
from node_pb2_grpc import NodeStub
from pathlib import Path
from pyln.testing.utils import env, TEST_NETWORK
from pyln.testing.utils import env, TEST_NETWORK, wait_for
from ephemeral_port_reserve import reserve
import grpc
import node_pb2 as nodepb
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_plugin_start(node_factory):
def test_grpc_connect(node_factory):
"""Attempts to connect to the grpc interface and call getinfo"""
grpc_port = reserve()
bin_path = Path.cwd() / "target" / "debug" / "grpc-plugin"
bin_path = Path.cwd() / "target" / "debug" / "cln-grpc"
l1 = node_factory.get_node(options={"plugin": str(bin_path), "grpc-port": str(grpc_port)})

p = Path(l1.daemon.lightning_dir) / TEST_NETWORK
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_grpc_generate_certificate(node_factory):
- If we delete one cert or its key it should get regenerated.
"""
grpc_port = reserve()
bin_path = Path.cwd() / "target" / "debug" / "grpc-plugin"
bin_path = Path.cwd() / "target" / "debug" / "cln-grpc"
l1 = node_factory.get_node(options={
"plugin": str(bin_path),
"grpc-port": str(grpc_port),
Expand Down Expand Up @@ -139,14 +139,26 @@ def test_grpc_generate_certificate(node_factory):
assert contents[-1] != files[-1].open().read()


def test_grpc_no_auto_start(node_factory):
"""Ensure that we do not start cln-grpc unless a port is configured.
"""
bin_path = Path.cwd() / "target" / "debug" / "cln-grpc"
l1, = node_factory.get_nodes(1, opts={
"plugin": str(bin_path),
})

wait_for(lambda: [p for p in l1.rpc.plugin('list')['plugins'] if 'cln-grpc' in p['name']] == [])
assert l1.daemon.is_in_log(r'plugin-cln-grpc: Killing plugin: exited during normal operation')


def test_grpc_wrong_auth(node_factory):
"""An mTLS client certificate should only be usable with its node
We create two instances, each generates its own certs and keys,
and then we try to cross the wires.
"""
grpc_port = reserve()
bin_path = Path.cwd() / "target" / "debug" / "grpc-plugin"
bin_path = Path.cwd() / "target" / "debug" / "cln-grpc"
l1, l2 = node_factory.get_nodes(2, opts={
"plugin": str(bin_path),
"start": False,
Expand Down
2 changes: 1 addition & 1 deletion tools/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [ "$1" = "--inside-docker" ]; then
cd /build
./configure
make
make install DESTDIR=/"$VER"
make install DESTDIR=/"$VER" RUST_PROFILE=release
cd /"$VER" && tar cvfz /release/clightning-"$VER".tar.gz -- *
exit 0
fi
Expand Down

0 comments on commit 21385e2

Please sign in to comment.