From 2fb8ca812e73b9f933a7c19ed3780881b9543776 Mon Sep 17 00:00:00 2001 From: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:08:13 -0400 Subject: [PATCH] Add support for rpc polling in dev commands --- .vscode/settings.json | 4 + locales/en.json | 6 + src/state/Lightning.ts | 2 +- src/state/Settings.ts | 24 ++++ src/state/index.ts | 24 +++- src/windows/InitProcess/DEV_Commands.tsx | 1 + src/windows/Settings/Settings.tsx | 150 +++++++++++++++++++---- 7 files changed, 181 insertions(+), 30 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f82fc3965 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/locales/en.json b/locales/en.json index 3c9c4dd4c..60bf0952d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -742,6 +742,12 @@ "rpc": { "title": "Set bitcoind RPC Host" }, + "rpcuser": { + "title": "Set the bitcoind RPC User" + }, + "rpcpass": { + "title": "Set the bitcoind RPC Password" + }, "zmqRawBlock": { "title": "Set bitcoind ZMQ Raw Block Host" }, diff --git a/src/state/Lightning.ts b/src/state/Lightning.ts index 3f52f282b..d4d3af6f2 100644 --- a/src/state/Lightning.ts +++ b/src/state/Lightning.ts @@ -13,7 +13,7 @@ import logger from "./../utils/log"; const log = logger("Lightning"); -export type LndChainBackend = "neutrino" | "bitcoindWithZmq"; +export type LndChainBackend = "neutrino" | "bitcoindWithZmq" | "bitcoindWithRpcPolling"; interface ILightningPeer { peer: lnrpc.Peer; diff --git a/src/state/Settings.ts b/src/state/Settings.ts index aa1d62e9f..12000a9d0 100644 --- a/src/state/Settings.ts +++ b/src/state/Settings.ts @@ -67,6 +67,8 @@ export interface ISettingsModel { changeNeutrinoPeers: Thunk; changeZeroConfPeers: Thunk; changeBitcoindRpcHost: Thunk; + changeBitcoindRpcUser: Thunk; + changeBitcoindRpcPassword: Thunk; changeBitcoindPubRawBlock: Thunk; changeBitcoindPubRawTx: Thunk; changeDunderServer: Thunk; @@ -110,6 +112,8 @@ export interface ISettingsModel { setNeutrinoPeers: Action; setZeroConfPeers: Action; setBitcoindRpcHost: Action; + setBitcoindRpcUser: Action; + setBitcoindRpcPassword: Action; setBitcoindPubRawBlock: Action; setBitcoindPubRawTx: Action; setDunderServer: Action; @@ -152,6 +156,8 @@ export interface ISettingsModel { lndChainBackend: string; neutrinoPeers: string[]; bitcoindRpcHost: string; + bitcoindRpcUser: string; + bitcoindRpcPassword: string; bitcoindPubRawBlock: string; bitcoindPubRawTx: string; dunderServer: string; @@ -384,6 +390,16 @@ export const settings: ISettingsModel = { actions.setBitcoindRpcHost(payload); }), + changeBitcoindRpcUser: thunk(async (actions, payload) => { + await setItem(StorageItem.bitcoindRpcUser, payload); + actions.setBitcoindRpcHost(payload); + }), + + changeBitcoindRpcPassword: thunk(async (actions, payload) => { + await setItem(StorageItem.bitcoindRpcPass, payload); + actions.setBitcoindRpcHost(payload); + }), + changeBitcoindPubRawBlock: thunk(async (actions, payload) => { await setItem(StorageItem.bitcoindPubRawBlock, payload); actions.setBitcoindPubRawBlock(payload); @@ -547,6 +563,12 @@ export const settings: ISettingsModel = { setBitcoindRpcHost: action((state, payload) => { state.bitcoindRpcHost = payload; }), + setBitcoindRpcUser: action((state, payload) => { + state.bitcoindRpcUser = payload; + }), + setBitcoindRpcPassword: action((state, payload) => { + state.bitcoindRpcPassword = payload; + }), setBitcoindPubRawBlock: action((state, payload) => { state.bitcoindPubRawBlock = payload; }), @@ -626,6 +648,8 @@ export const settings: ISettingsModel = { neutrinoPeers: [], zeroConfPeers: [], bitcoindRpcHost: "", + bitcoindRpcUser: "", + bitcoindRpcPassword: "", bitcoindPubRawBlock: "", bitcoindPubRawTx: "", dunderServer: "", diff --git a/src/state/index.ts b/src/state/index.ts index 46499b231..fd7d592f3 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -9,7 +9,10 @@ import { DEFAULT_PATHFINDING_ALGORITHM, PLATFORM } from "../utils/constants"; import { Chain, VersionCode } from "../utils/build"; import { IBlixtLsp, blixtLsp } from "./BlixtLsp"; import { IChannelModel, channel } from "./Channel"; -import { IChannelAcceptanceManagerModel, channelAcceptanceManager } from "./ChannelAcceptanceManager"; +import { + IChannelAcceptanceManagerModel, + channelAcceptanceManager, +} from "./ChannelAcceptanceManager"; import { IClipboardManagerModel, clipboardManager } from "./ClipboardManager"; import { IContactsModel, contacts } from "./Contacts"; import { ILightningBoxModel, lightningBox } from "./LightningBox"; @@ -285,8 +288,11 @@ export const model: IStoreModel = { } } } - let persistentServicesEnabled = await getItemObjectAsyncStorage(StorageItem.persistentServicesEnabled) ?? false; - let persistentServicesWarningShown = await getItemObjectAsyncStorage(StorageItem.persistentServicesWarningShown) ?? false; + let persistentServicesEnabled = + (await getItemObjectAsyncStorage(StorageItem.persistentServicesEnabled)) ?? false; + let persistentServicesWarningShown = + (await getItemObjectAsyncStorage(StorageItem.persistentServicesWarningShown)) ?? + false; if (persistentServicesEnabled && !persistentServicesWarningShown) { await setItemObject(StorageItem.persistentServicesWarningShown, true); await NativeModules.BlixtTor.showMsg(); @@ -568,6 +574,18 @@ bitcoind.zmqpubrawtx=${bitcoindPubRawTx} : "" } +${ + lndChainBackend === "bitcoindWithRpcPolling" + ? ` +[Bitcoind] +bitcoind.rpchost=${bitcoindRpcHost} +bitcoind.rpcuser=${bitcoindRpcUser} +bitcoind.rpcpass=${bitcoindRpcPass} +bitcoind.rpcpolling=true +` + : "" +} + [autopilot] autopilot.active=0 autopilot.private=1 diff --git a/src/windows/InitProcess/DEV_Commands.tsx b/src/windows/InitProcess/DEV_Commands.tsx index 9fa0dd9f9..8478e8e10 100644 --- a/src/windows/InitProcess/DEV_Commands.tsx +++ b/src/windows/InitProcess/DEV_Commands.tsx @@ -561,6 +561,7 @@ console.log(x); + diff --git a/src/windows/Settings/Settings.tsx b/src/windows/Settings/Settings.tsx index a636cd75a..67a6f1aa6 100644 --- a/src/windows/Settings/Settings.tsx +++ b/src/windows/Settings/Settings.tsx @@ -797,6 +797,64 @@ ${t("LN.inbound.dialog.msg3")}`; ); }; + // bitcoind RPC user + const bitcoindRpcUser = useStoreState((store) => store.settings.bitcoindRpcUser); + const changeBitcoindRpcUser = useStoreActions((store) => store.settings.changeBitcoindRpcUser); + const onSetBitcoindRpcUserPress = async () => { + Alert.prompt( + t("bitcoinNetwork.rpcuser.title"), + "", + [ + { + text: t("buttons.cancel", { ns: namespaces.common }), + style: "cancel", + onPress: () => {}, + }, + { + text: t("buttons.save", { ns: namespaces.common }), + onPress: async (text) => { + if (text) { + await changeBitcoindRpcUser(text); + await writeConfig(); + } + }, + }, + ], + "plain-text", + bitcoindRpcUser ?? "", + ); + }; + + // bitcoind RPC password + const bitcoindRpcPassword = useStoreState((store) => store.settings.bitcoindRpcPassword); + const changeBitcoindRpcPassword = useStoreActions( + (store) => store.settings.changeBitcoindRpcPassword, + ); + const onSetBitcoindRpcPasswordPress = async () => { + Alert.prompt( + t("bitcoinNetwork.rpcpass.title"), + "", + [ + { + text: t("buttons.cancel", { ns: namespaces.common }), + style: "cancel", + onPress: () => {}, + }, + { + text: t("buttons.save", { ns: namespaces.common }), + onPress: async (text) => { + if (text) { + await changeBitcoindRpcPassword(text); + await writeConfig(); + } + }, + }, + ], + "plain-text", + bitcoindRpcPassword ?? "", + ); + }; + // bitcoind zmq block const bitcoindPubRawBlock = useStoreState((store) => store.settings.bitcoindPubRawBlock); const changeBitcoindPubRawBlock = useStoreActions( @@ -1333,16 +1391,24 @@ ${t("experimental.tor.disabled.msg2")}`; }; // Persistent services - const persistentServicesEnabled = useStoreState((store) => store.settings.persistentServicesEnabled); - const changePersistentServicesEnabled = useStoreActions((store) => store.settings.changePersistentServicesEnabled); + const persistentServicesEnabled = useStoreState( + (store) => store.settings.persistentServicesEnabled, + ); + const changePersistentServicesEnabled = useStoreActions( + (store) => store.settings.changePersistentServicesEnabled, + ); const changePersistentServicesEnabledPress = async () => { await changePersistentServicesEnabled(!persistentServicesEnabled); restartNeeded(); }; // Persistent services - const customInvoicePreimageEnabled = useStoreState((store) => store.settings.customInvoicePreimageEnabled); - const changeCustomInvoicePreimageEnabled = useStoreActions((store) => store.settings.changeCustomInvoicePreimageEnabled); + const customInvoicePreimageEnabled = useStoreState( + (store) => store.settings.customInvoicePreimageEnabled, + ); + const changeCustomInvoicePreimageEnabled = useStoreActions( + (store) => store.settings.changeCustomInvoicePreimageEnabled, + ); const onToggleCustomInvoicePreimageEnabled = async () => { await changeCustomInvoicePreimageEnabled(!customInvoicePreimageEnabled); }; @@ -1719,6 +1785,35 @@ ${t("experimental.tor.disabled.msg2")}`; )} + {lndChainBackend === "bitcoindWithRpcPolling" && ( + <> + + + + + + {t("bitcoinNetwork.rpc.title")} + + + + + + + + {t("bitcoinNetwork.rpcuser.title")} + + + + + + + + {t("bitcoinNetwork.rpcpass.title")} + + + + )} + @@ -1904,16 +1999,17 @@ ${t("experimental.tor.disabled.msg2")}`; )} - {scheduledGossipSyncEnabled && (PLATFORM === "android" || PLATFORM === "ios" || PLATFORM === "macos") && ( - copySpeedloaderLog()}> - - - - - {t("miscelaneous.speedloaderLog.title")} - - - )} + {scheduledGossipSyncEnabled && + (PLATFORM === "android" || PLATFORM === "ios" || PLATFORM === "macos") && ( + copySpeedloaderLog()}> + + + + + {t("miscelaneous.speedloaderLog.title")} + + + )} {t("debug.lndLog.title")} - {scheduledGossipSyncEnabled && + {scheduledGossipSyncEnabled && ( {t("debug.speedloaderLog.title")} - } + )} c.history.successAmtSat > 0).map((c) => { - return { - nodeFrom: hexToUint8Array(c.nodeFrom), - nodeTo: hexToUint8Array(c.nodeTo), - history: { - successAmtSat: Long.fromValue(c.history.successAmtSat), - successTime: Long.fromValue(c.history.successTime), - } - } - }); + const x: routerrpc.IXImportMissionControlRequest["pairs"] = json.pairs + .filter((c) => c.history.successAmtSat > 0) + .map((c) => { + return { + nodeFrom: hexToUint8Array(c.nodeFrom), + nodeTo: hexToUint8Array(c.nodeTo), + history: { + successAmtSat: Long.fromValue(c.history.successAmtSat), + successTime: Long.fromValue(c.history.successTime), + }, + }; + }); await xImportMissionControl(x); toast("Done");