Skip to content

Commit

Permalink
Refactor config, properties, and instructions (#96)
Browse files Browse the repository at this point in the history
* Refactor config, properties, and instructions

* set sparko key to full-access

* update migration to set configured=true
  • Loading branch information
Dominion5254 authored Aug 30, 2023
1 parent 2ced1c3 commit fa5c266
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 111 deletions.
8 changes: 4 additions & 4 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ cat /root/.lightning/public/access.macaroon | basenc --base16 -w0 > /root/.ligh

lightning-cli getinfo > /root/.lightning/start9/lightningGetInfo

if [ "$(yq ".watchtowers.wt-client" /root/.lightning/start9/config.yaml)" = "true" ]; then
if [ "$(yq ".watchtowers.wt-client.enabled" /root/.lightning/start9/config.yaml)" = "enabled" ]; then
lightning-cli listtowers > /root/.lightning/start9/wtClientInfo
cat /root/.lightning/start9/wtClientInfo | jq -r 'to_entries[] | .key + "@" + (.value.net_addr | split("://")[1])' > /root/.lightning/start9/wt_old
cat /root/.lightning/start9/config.yaml | yq '.watchtowers.add-watchtowers | .[]' > /root/.lightning/start9/wt_new
Expand Down Expand Up @@ -216,9 +216,9 @@ else
echo "UI Password hash saved to config.json"
fi

SAVED_UI_PW_HASH=$(jq '.password' /app/apps/backend/$/root/.lightning/data/app/config.json)
if [ -e /app/apps/backend/$/root/.lightning/data/app/config.json && $UI_PASSWORD_HASH != $SAVED_UI_PW_HASH ]; then
jq ".password = $UI_PASSWORD" /app/apps/backend/$/root/.lightning/data/app/config.json
SAVED_UI_PW_HASH=$(cat /app/apps/backend/$/root/.lightning/data/app/config.json | jq -r '.password')
if [ -e /app/apps/backend/$/root/.lightning/data/app/config.json ] && [ $UI_PASSWORD_HASH != $SAVED_UI_PW_HASH ]; then
jq ".password = $UI_PASSWORD_HASH" /app/apps/backend/$/root/.lightning/data/app/config.json
echo "updated password hash saved to config.json"
fi

Expand Down
4 changes: 2 additions & 2 deletions docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ CLN can be connected to wallets supporting connecting over tor to the Sparko int

## User Interface

Your Core Lightning service comes with a featureful built in [UI](https://github.com/ElementsProject/cln-application/tree/d53e19548939641e7e12c756f43ef5fcf164225d). This interface can be used to deposit and withdraw bitcoin on chain, send and receive bitcoin over the lightning network, and even open or close channels! The password for your CLN UI can be found in the the `Config` menu.
Your Core Lightning service comes with a featureful built in [UI](https://github.com/ElementsProject/cln-application/tree/d53e19548939641e7e12c756f43ef5fcf164225d). This interface can be used to deposit and withdraw bitcoin on chain, send and receive bitcoin over the lightning network, and even open or close channels! The password for your CLN UI can be found in the `Config` and `Properties` menus.

**Note: If the password for the CLN UI is changed outside of the `Config` menu i.e. within the CLN UI, the password in your `Config` will not be updated!**
**Note: If the password for the CLN UI is changed outside of the `Config` menu i.e. within the CLN UI, the password in `Config` or `Properties` will not be updated!**

## CLBOSS

Expand Down
79 changes: 46 additions & 33 deletions scripts/procedures/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export const [getConfig, setConfigMatcher] = compat.getConfigAndMatcher({
multi: false,
selector: "$.rpc.password",
},
"ui-password": {
"type": "string",
"name": "UI Password",
"description": "The password for your CLN UI",
"nullable": false,
"copyable": true,
"masked": true,
"default": {
"charset": "a-z,A-Z,0-9",
"len": 22
}
},
"watchtowers": {
"type": "object",
"name": "Watchtowers",
Expand All @@ -102,28 +114,41 @@ export const [getConfig, setConfigMatcher] = compat.getConfigAndMatcher({
"default": false,
},
"wt-client": {
"type": "boolean",
"type": "union",
"name": "Enable Watchtower Client",
"description":
"Allow your node to subscribe to external watchtowers, which provides protection against misbehvaing channel peers",
"nullable": true,
"default": false,
},
"add-watchtowers": {
"type": "list",
"name": "Add Watchtowers",
"description":
"Add URIs of Watchtowers to connect to. Here's a list of altruistic public watchtowers, if you need some ideas: https://github.com/talaia-labs/rust-teos/discussions/158",
"range": "[0,*)",
"subtype": "string",
"spec": {
"masked": false,
"copyable": true,
"placeholder":
"02b4891f562c8b80571ddd2eeea48530471c30766295e1c78556ae4c4422d24436@recnedb7xfhzjdrcgxongzli3a6qyrv5jwgowoho3v5g3rwk7kkglrid.onion:9814",
tag: {
id: "enabled",
name: "Watchtower Client Enabled",
description: "- Disabled: Disable Watchtower Client\n-Enable Watchtower Client",
"variant-names": {
disabled: "Disabled",
enabled: "Enabled",
},
},
"nullable": true,
"default": Array<string>(),
default: "disabled",
variants: {
disabled: {},
enabled: {
"add-watchtowers": {
"type": "list",
"name": "Add Watchtowers",
"description":
"Add URIs of Watchtowers to connect to. Here's a list of altruistic public watchtowers, if you need some ideas: https://github.com/talaia-labs/rust-teos/discussions/158",
"range": "[1,*)",
"subtype": "string",
"spec": {
"masked": false,
"copyable": true,
"placeholder":
"02b4891f562c8b80571ddd2eeea48530471c30766295e1c78556ae4c4422d24436@recnedb7xfhzjdrcgxongzli3a6qyrv5jwgowoho3v5g3rwk7kkglrid.onion:9814",
},
"default": Array<string>(),
},
}
}
},
},
},
Expand Down Expand Up @@ -481,21 +506,21 @@ export const [getConfig, setConfigMatcher] = compat.getConfigAndMatcher({
spec: {
rebalance: {
type: "boolean",
name: "Enable Rebalance Plugin",
name: "Rebalance",
description:
"Enables the `rebalance` rpc command, which moves liquidity between your channels using circular payments.\nSee `help rebalance` on the CLI or in the Spark console for usage instructions.\n\nSource: https://github.com/lightningd/plugins/tree/master/rebalance\n",
default: false,
},
summary: {
type: "boolean",
name: "Enable Summary Plugin",
name: "Summary",
description:
"Enables the `summary` rpc command, which outputs a text summary of your node, including fiat amounts.\nCan be called via command line or the Spark console. \n\nSource: https://github.com/lightningd/plugins/tree/master/summary\n",
default: false,
},
rest: {
type: "boolean",
name: "Enable C-Lightning-REST Plugin",
name: "C-Lightning-REST",
description:
"This plugin exposes an LND-like REST API. It is required for Ride The Lighting to connect to Core Lightning.\n\nSource: https://github.com/Ride-The-Lightning/c-lightning-REST\n",
default: true,
Expand All @@ -507,7 +532,7 @@ export const [getConfig, setConfigMatcher] = compat.getConfigAndMatcher({
spec: {
enabled: {
"type": "boolean",
"name": "Enable Sparko Plugin",
"name": "Sparko",
"description":
"The famous Spark wallet repackaged as a single-binary lightningd plugin. This works as a full-blown HTTP-RPC bridge to your node that can be used to develop apps. \n\nSource: https://github.com/fiatjaf/sparko\n",
"default": true,
Expand Down Expand Up @@ -611,18 +636,6 @@ export const [getConfig, setConfigMatcher] = compat.getConfigAndMatcher({
},
},
},
"ui-password": {
"type": "string",
"name": "UI Password",
"description": "The password for your CLN UI",
"nullable": false,
"copyable": true,
"masked": true,
"default": {
"charset": "a-z,A-Z,0-9",
"len": 22
}
},
} as const,
);

Expand Down
53 changes: 43 additions & 10 deletions scripts/procedures/migrations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { literal, literals } from "https://deno.land/x/ts_matches@v5.2.0/mod.ts";
import { compat, matches, types as T } from "../deps.ts";

export const migration: T.ExpectedExports.migration =
Expand Down Expand Up @@ -201,19 +200,40 @@ export const migration: T.ExpectedExports.migration =
"23.02.2.7": {
up: compat.migrations.updateConfig(
(config) => {
if (
matches.shape({
advanced: matches.shape({
plugins: matches.shape({http: matches.any}, [ "http", ]
)
})
}).test(config)
config["ui-password"] = generateRandomString(22);
if (
matches.shape({
advanced: matches.shape({
plugins: matches.shape({http: matches.any}
)
})
}).test(config)
) {
delete config.advanced.plugins.http
}
}
if (
matches.shape({
advanced: matches.shape({
plugins: matches.any
})
}).test(config)
) {
config.advanced.plugins['sparko'] = {
enabled: true,
user: "sparko",
password: generateRandomString(22),
}
}
config.watchtowers = {
"wt-server": false,
"wt-client": {
enabled: "disabled",
"add-watchtowers": []
}
}
return config;
},
false,
true,
{ version: "23.02.2.7", type: "up" },
),
down: () => {
Expand All @@ -223,3 +243,16 @@ export const migration: T.ExpectedExports.migration =
},
"23.02.2.7",
);


function generateRandomString(length: number) {
const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let randomString = '';

for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
randomString += characters[randomIndex];
}

return randomString;
}
36 changes: 19 additions & 17 deletions scripts/procedures/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,29 +272,31 @@ export const properties: T.ExpectedExports.properties = async (
}

let wtClientProperties: T.PackagePropertiesV2 = {};
if (config.watchtowers["wt-client"]) {
if (config.watchtowers["wt-client"].enabled == "enabled") {
wtClientProperties = await effects
.readFile({
volumeId: "main",
path: "start9/wtClientInfo",
})
.then(JSON.parse)
.then((dataIn) => {
for (const tower of config.watchtowers["add-watchtowers"]) {
const [pubkey, url] = tower.split("@");
if (!(pubkey in dataIn)) {
dataIn[pubkey] = {
net_addr: url,
available_slots: 0,
subscription_start: 0,
subscription_expiry: 0,
status: "unreachable",
pending_appointments: [],
invalid_appointments: [],
};
if (config.watchtowers["wt-client"].enabled == "enabled" ) {
for (const tower of config.watchtowers["wt-client"]["add-watchtowers"]) {
const [pubkey, url] = tower.split("@");
if (!(pubkey in dataIn)) {
dataIn[pubkey] = {
net_addr: url,
available_slots: 0,
subscription_start: 0,
subscription_expiry: 0,
status: "unreachable",
pending_appointments: [],
invalid_appointments: [],
};
}
}
return dataIn;
}
return dataIn;
})
.then(Object.entries)
.then((xs) =>
Expand Down Expand Up @@ -382,7 +384,7 @@ export const properties: T.ExpectedExports.properties = async (
qr: true,
masked: true,
},
...(sparkoProperties
...(config.advanced.plugins.sparko.enabled
? {
"Sparko Properties": {
type: "object",
Expand All @@ -391,7 +393,7 @@ export const properties: T.ExpectedExports.properties = async (
}
}
: {}),
...(restProperties
...(config.advanced.plugins.rest
? {
"REST Properties": {
type: "object",
Expand All @@ -410,7 +412,7 @@ export const properties: T.ExpectedExports.properties = async (
},
}
: {}),
...(config.watchtowers["wt-client"]
...(config.watchtowers["wt-client"].enabled == "enabled"
? {
"Watchtower Client Properties": {
type: "object",
Expand Down
Loading

0 comments on commit fa5c266

Please sign in to comment.