Skip to content

Commit

Permalink
Merge pull request #1925 from kaloudis/embedded-lnd-db-compaction
Browse files Browse the repository at this point in the history
Embedded LND: Settings: DB compaction + Neutrino file deletion
  • Loading branch information
kaloudis committed Dec 30, 2023
2 parents 0080364 + 32ca193 commit 09a4a92
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 268 deletions.
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import LNDLogs from './views/Settings/EmbeddedNode/LNDLogs';
import Peers from './views/Settings/EmbeddedNode/Peers';
import NeutrinoPeers from './views/Settings/EmbeddedNode/Peers/NeutrinoPeers';
import ZeroConfPeers from './views/Settings/EmbeddedNode/Peers/ZeroConfPeers';
import Advanced from './views/Settings/EmbeddedNode/Advanced';

// Routing
import Routing from './views/Routing/Routing';
Expand Down Expand Up @@ -370,6 +371,9 @@ const AppScenes = {
ZeroConfPeers: {
screen: ZeroConfPeers
},
EmbeddedNodeSettingsAdvanced: {
screen: Advanced
},
LSPSettings: {
screen: LSP
},
Expand Down
13 changes: 13 additions & 0 deletions android/app/src/main/java/com/zeus/LndMobileTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,19 @@ public void DEBUG_deleteSpeedloaderDgraphDirectory(Promise promise) {
promise.resolve(null);
}

@ReactMethod
public void DEBUG_deleteNeutrinoFiles(String network, Promise promise) {
String chainFolder = getReactApplicationContext().getFilesDir().toString() + "/data/chain/bitcoin/" + network;

String neutrinoDb = chainFolder + "/neutrino.db";
String blockHeadersBin = chainFolder + "/block_headers.bin";
String regHeadersBin = chainFolder + "/reg_filter_headers.bin";
File neutrinoDbFile = new File(neutrinoDb);
File blockHeadersBinFile = new File(blockHeadersBin);
File regHeadersBinFiles = new File(regHeadersBin);
promise.resolve(neutrinoDbFile.delete() && blockHeadersBinFile.delete() && regHeadersBinFiles.delete());
}

@ReactMethod
public void DEBUG_listProcesses(Promise promise) {
String processes = "";
Expand Down
6 changes: 6 additions & 0 deletions ios/LndMobile/LndMobileTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ @interface RCT_EXTERN_MODULE(LndMobileTools, RCTEventEmitter)
rejecter: (RCTPromiseRejectBlock)reject
)

RCT_EXTERN_METHOD(
DEBUG_deleteNeutrinoFiles: (NSString)network
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject
)

RCT_EXTERN_METHOD(
checkApplicationSupportExists: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject
Expand Down
25 changes: 25 additions & 0 deletions ios/LndMobile/LndMobileTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,31 @@ class LndMobileTools: RCTEventEmitter {
resolve(nil)
}

@objc(DEBUG_deleteNeutrinoFiles:resolver:rejecter:)
func DEBUG_deleteNeutrinoFiles(network: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
let applicationSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
let chainPath = applicationSupport.appendingPathComponent("lnd", isDirectory: true)
.appendingPathComponent("data", isDirectory: true)
.appendingPathComponent("chain", isDirectory: true)
.appendingPathComponent("bitcoin", isDirectory: true)
.appendingPathComponent(network ?? "mainnet", isDirectory: true)

let neutrinoDbPath = chainPath.appendingPathComponent("neutrino.db")
let blockHeadersBinPath = chainPath.appendingPathComponent("block_headers.bin")
let regFiltersHeadersBinPath = chainPath.appendingPathComponent("reg_filter_headers.bin")

do {
try FileManager.default.removeItem(at: neutrinoDbPath)
try FileManager.default.removeItem(at: blockHeadersBinPath)
try FileManager.default.removeItem(at: regFiltersHeadersBinPath)
} catch {
reject("error", error.localizedDescription, error)
return
}

resolve(true)
}

@objc(checkApplicationSupportExists:rejecter:)
func checkApplicationSupportExists(resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
let applicationSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
Expand Down
1 change: 1 addition & 0 deletions lndmobile/LndMobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface ILndMobileTools {
DEBUG_getWalletPasswordFromKeychain(): Promise<string>;
DEBUG_deleteSpeedloaderLastrunFile(): boolean;
DEBUG_deleteSpeedloaderDgraphDirectory(): null;
DEBUG_deleteNeutrinoFiles(network: string): boolean;

// Android-specific
getIntentStringData(): Promise<string | null>;
Expand Down
9 changes: 9 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
"general.reset": "Reset",
"general.other": "Other",
"general.reorder": "Reorder",
"general.yes": "Yes",
"general.no": "No",
"general.advanced": "Advanced",
"restart.title": "Restart required",
"restart.msg": "ZEUS has to be restarted before the new configuration is applied.",
"restart.msg1": "Would you like to restart now?",
"views.Settings.Support.title": "Support ZEUS",
"views.Settings.Support.titleAlt": "Merch and Support",
"views.Settings.SocialMedia.title": "Social media",
Expand Down Expand Up @@ -768,6 +774,9 @@
"views.Settings.EmbeddedNode.waitForGraphSync.subtitle": "Waiting for the lightning network graph to sync will increase your probability of payment success.",
"views.Settings.EmbeddedNode.rescan": "Rescan wallet",
"views.Settings.EmbeddedNode.rescan.subtitle": "Rescan blockchain for your on-chain transactions. Restart the app to take effect. Will be unset upon completion.",
"views.Settings.EmbeddedNode.compactDb": "Compact databases",
"views.Settings.EmbeddedNode.compactDb.subtitle": "Whether the databases used within LND should automatically be compacted on startup. This is disabled by default because it increases startup time and requires additional disk space to be available during the compaction that is freed afterwards. In general compaction leads to smaller database files.",
"views.Settings.EmbeddedNode.stopLndDeleteNeutrino": "Stop LND and delete Neutrino files",
"views.Settings.EmbeddedNode.restart": "Restart to take effect.",
"views.Settings.EmbeddedNode.embeddedTor.subtitle": "Run your LND node with Tor.",
"views.Settings.EmbeddedNode.embeddedTor.clearnetWarning": "Note that calls to rates and Mempool.space endpoints will still be made on clearnet.",
Expand Down
2 changes: 2 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface Settings {
neutrinoPeers: Array<string>;
zeroConfPeers: Array<string>;
rescan: boolean;
compactDb: boolean;
recovery: boolean;
initialLoad: boolean;
embeddedTor: boolean;
Expand Down Expand Up @@ -781,6 +782,7 @@ export default class SettingsStore {
neutrinoPeers: [],
zeroConfPeers: [],
rescan: false,
compactDb: false,
recovery: false,
initialLoad: true,
embeddedTor: false,
Expand Down
18 changes: 15 additions & 3 deletions utils/LndMobileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export function checkLndStreamErrorResponse(
return null;
}

const writeLndConfig = async (isTestnet?: boolean, rescan?: boolean) => {
const writeLndConfig = async (
isTestnet?: boolean,
rescan?: boolean,
compactDb?: boolean
) => {
const { writeConfig } = lndMobile.index;

const peerMode = stores.settingsStore?.settings?.dontAllowOtherPeers
Expand Down Expand Up @@ -90,6 +94,10 @@ const writeLndConfig = async (isTestnet?: boolean, rescan?: boolean) => {
[db]
db.no-graph-cache=false
[bolt]
db.bolt.auto-compact=${compactDb ? 'true' : 'false'}
${compactDb ? 'db.bolt.auto-compact-min-age=0' : ''}
[Routing]
routing.assumechanvalid=1
Expand Down Expand Up @@ -180,10 +188,14 @@ export async function expressGraphSync() {
return;
}

export async function initializeLnd(isTestnet?: boolean, rescan?: boolean) {
export async function initializeLnd(
isTestnet?: boolean,
rescan?: boolean,
compactDb?: boolean
) {
const { initialize } = lndMobile.index;

await writeLndConfig(isTestnet, rescan);
await writeLndConfig(isTestnet, rescan, compactDb);
await initialize();
}

Expand Down
33 changes: 33 additions & 0 deletions utils/RestartUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Alert, NativeModules, Platform } from 'react-native';
import { localeString } from './LocaleUtils';

const restartNeeded = () => {
const title = localeString('restart.title');
const message = localeString('restart.msg');
if (Platform.OS === 'android') {
Alert.alert(title, message + '\n' + localeString('restart.msg1'), [
{
style: 'cancel',
text: localeString('general.no')
},
{
style: 'default',
text: localeString('general.yes'),
onPress: async () => {
try {
// await NativeModules.ZeusTor.stopTor();
await NativeModules.LndMobile.stopLnd();
await NativeModules.LndMobileTools.killLnd();
} catch (e) {
console.log(e);
}
NativeModules.LndMobileTools.restartApp();
}
}
]);
} else {
Alert.alert(title, message);
}
};

export { restartNeeded };

0 comments on commit 09a4a92

Please sign in to comment.