Skip to content

Commit

Permalink
Embedded LND: Settings: DB compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Dec 29, 2023
1 parent 803aa2c commit ee65cf9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@
"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 the database",
"views.Settings.EmbeddedNode.compactDb.subtitle": "Whether the databases used within lnd should automatically be compacted on startup. This is disabled by default because it 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.resetMissionControl": "Reset payment routing profile",
"views.Settings.EmbeddedNode.resetMissionControl.subtitle": "This will reset the mission control state. Can be helpful if you are having issues finding routes while making payments.",
"views.Settings.EmbeddedNode.DisasterRecovery.title": "Disaster recovery",
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;
// LSP
Expand Down Expand Up @@ -780,6 +781,7 @@ export default class SettingsStore {
neutrinoPeers: [],
zeroConfPeers: [],
rescan: false,
compactDb: false,
recovery: false,
initialLoad: true,
// LSP
Expand Down
10 changes: 7 additions & 3 deletions utils/LndMobileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function checkLndStreamErrorResponse(
return null;
}

const writeLndConfig = async (isTestnet?: boolean, rescan?: boolean) => {
const writeLndConfig = async (isTestnet?: boolean, rescan?: boolean, compactDb?: boolean) => {

Check failure on line 63 in utils/LndMobileUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `isTestnet?:·boolean,·rescan?:·boolean,·compactDb?:·boolean` with `⏎····isTestnet?:·boolean,⏎····rescan?:·boolean,⏎····compactDb?:·boolean⏎`
const { writeConfig } = lndMobile.index;

const peerMode = stores.settingsStore?.settings?.dontAllowOtherPeers
Expand Down Expand Up @@ -90,6 +90,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 +184,10 @@ export async function expressGraphSync() {
return;
}

export async function initializeLnd(isTestnet?: boolean, rescan?: boolean) {
export async function initializeLnd(isTestnet?: boolean, rescan?: boolean, compactDb?: boolean) {

Check failure on line 187 in utils/LndMobileUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `isTestnet?:·boolean,·rescan?:·boolean,·compactDb?:·boolean` with `⏎····isTestnet?:·boolean,⏎····rescan?:·boolean,⏎····compactDb?:·boolean⏎`
const { initialize } = lndMobile.index;

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

Expand Down
62 changes: 59 additions & 3 deletions views/Settings/EmbeddedNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface EmbeddedNodeProps {

interface EmbeddedNodeState {
rescan: boolean | undefined;
compactDb: boolean | undefined;
}

@inject('SettingsStore')
Expand All @@ -28,21 +29,23 @@ export default class EmbeddedNode extends React.Component<
EmbeddedNodeState
> {
state = {
rescan: false
rescan: false,
compactDb: false
};

async UNSAFE_componentWillMount() {
const { SettingsStore } = this.props;
const { settings } = SettingsStore;

this.setState({
rescan: settings.rescan
rescan: settings.rescan,
compactDb: settings.compactDb
});
}

render() {
const { navigation, SettingsStore } = this.props;
const { rescan } = this.state;
const { rescan, compactDb } = this.state;
const { updateSettings, embeddedLndNetwork, settings }: any =
SettingsStore;
const {
Expand Down Expand Up @@ -287,6 +290,59 @@ export default class EmbeddedNode extends React.Component<
</Text>
</View>
</>
<>
<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent'
}}
>
<ListItem.Title
style={{
color: themeColor('text'),
fontFamily: 'PPNeueMontreal-Book'
}}
>
{localeString(
'views.Settings.EmbeddedNode.compactDb'
)}
</ListItem.Title>
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end'
}}
>
<Switch
value={compactDb}
onValueChange={async () => {
this.setState({
compactDb: !compactDb
});
await updateSettings({
compactDb: !compactDb
});
}}
/>
</View>
</ListItem>
<View
style={{
margin: 10
}}
>
<Text
style={{
color: themeColor('secondaryText')
}}
>
{localeString(
'views.Settings.EmbeddedNode.compactDb.subtitle'
)}
</Text>
</View>
</>
</ScrollView>
</View>
</Screen>
Expand Down
3 changes: 2 additions & 1 deletion views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
fiatEnabled,
pos,
rescan,
compactDb,
recovery,
lightningAddress,
initialLoad
Expand Down Expand Up @@ -345,7 +346,7 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {

if (implementation === 'embedded-lnd') {
if (connecting) {
await initializeLnd(embeddedLndNetwork === 'Testnet', rescan);
await initializeLnd(embeddedLndNetwork === 'Testnet', rescan, compactDb);

Check failure on line 349 in views/Wallet/Wallet.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `embeddedLndNetwork·===·'Testnet',·rescan,·compactDb` with `⏎····················embeddedLndNetwork·===·'Testnet',⏎····················rescan,⏎····················compactDb⏎················`

// on initial load, do not run EGS
if (initialLoad) {
Expand Down

0 comments on commit ee65cf9

Please sign in to comment.