Skip to content

Commit 643dea1

Browse files
committed
feat: add Esplora blockchain backend to Embedded LND
1 parent 1f74a0f commit 643dea1

11 files changed

Lines changed: 674 additions & 317 deletions

File tree

App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ import DisasterRecoveryAdvanced from './views/Settings/EmbeddedNode/DisasterReco
157157
import Pathfinding from './views/Settings/EmbeddedNode/Pathfinding';
158158
import ExpressGraphSync from './views/Settings/EmbeddedNode/ExpressGraphSync';
159159
import LNDLogs from './views/Settings/EmbeddedNode/LNDLogs';
160-
import Peers from './views/Settings/EmbeddedNode/Peers';
160+
import BlockchainBackend from './views/Settings/EmbeddedNode/BlockchainBackend';
161161
import NeutrinoPeers from './views/Settings/EmbeddedNode/Peers/NeutrinoPeers';
162162
import ZeroConfPeers from './views/Settings/EmbeddedNode/Peers/ZeroConfPeers';
163163
import Advanced from './views/Settings/EmbeddedNode/Advanced';
@@ -911,8 +911,10 @@ export default class App extends React.PureComponent {
911911
component={LNDLogs}
912912
/>
913913
<Stack.Screen
914-
name="Peers" // @ts-ignore:next-line
915-
component={Peers}
914+
name="BlockchainBackend" // @ts-ignore:next-line
915+
component={
916+
BlockchainBackend
917+
}
916918
/>
917919
<Stack.Screen
918920
name="NeutrinoPeers" // @ts-ignore:next-line

locales/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,12 @@
11081108
"views.Settings.EmbeddedNode.NeutrinoPeers.optimize": "Optimize peers selection",
11091109
"views.Settings.EmbeddedNode.ZeroConfPeers.title": "Zero conf Peers",
11101110
"views.Settings.EmbeddedNode.ZeroConfPeers.subtitle": "Set the peers you would like to accept zero conf lightning channels from, other than the LSP.",
1111+
"views.Settings.EmbeddedNode.BlockchainBackend.title": "Blockchain backend",
1112+
"views.Settings.EmbeddedNode.BlockchainBackend.backend": "Backend",
1113+
"views.Settings.EmbeddedNode.BlockchainBackend.neutrino.subtitle": "Neutrino is a light client that downloads block headers from Bitcoin peers. It is privacy-preserving and does not require a trusted server.",
1114+
"views.Settings.EmbeddedNode.BlockchainBackend.esplora.subtitle": "Esplora fetches blockchain data from a server. It syncs faster but requires trusting the server operator.",
1115+
"views.Settings.EmbeddedNode.BlockchainBackend.esploraUrl": "Esplora URL",
1116+
"views.Settings.EmbeddedNode.BlockchainBackend.customEsploraUrl": "Custom Esplora URL",
11111117
"views.Settings.EmbeddedNode.ExpressGraphSync.title": "Express Graph Sync",
11121118
"views.Settings.EmbeddedNode.expressGraphSync": "Enable express graph sync (EGS)",
11131119
"views.Settings.EmbeddedNode.expressGraphSync.subtitle": "Download Lightning network's gossip data on startup. This will make pathfinding when trying to make a payment much more reliable. Restart the app to take effect. Also known as Speedloader.",

stores/SettingsStore.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,14 @@ export interface Settings {
187187
bimodalPathfinding: boolean;
188188
graphSyncPromptNeverAsk: boolean;
189189
graphSyncPromptIgnoreOnce: boolean;
190+
embeddedLndBackend: 'neutrino' | 'esplora';
190191
dontAllowOtherPeers: boolean;
191192
neutrinoPeersMainnet: Array<string>;
192193
neutrinoPeersTestnet: Array<string>;
193194
zeroConfPeers: Array<string>;
195+
esploraMainnet: string;
196+
esploraTestnet: string;
197+
customEsplora: string;
194198
rescan: boolean;
195199
compactDb: boolean;
196200
recovery: boolean;
@@ -1321,6 +1325,41 @@ export const DEFAULT_NEUTRINO_PEERS_MAINNET = [
13211325
'noad.sathoarder.com'
13221326
];
13231327

1328+
export const DEFAULT_ESPLORA_MAINNET = 'https://mempool.space/api';
1329+
export const DEFAULT_ESPLORA_TESTNET = 'https://mempool.space/testnet/api';
1330+
1331+
export const ESPLORA_MAINNET_KEYS = [
1332+
{
1333+
key: 'Mempool.space',
1334+
value: 'https://mempool.space/api'
1335+
},
1336+
{
1337+
key: 'Blockstream.info',
1338+
value: 'https://blockstream.info/api'
1339+
},
1340+
{
1341+
key: 'Custom',
1342+
translateKey: 'general.custom',
1343+
value: 'Custom'
1344+
}
1345+
];
1346+
1347+
export const ESPLORA_TESTNET_KEYS = [
1348+
{
1349+
key: 'Mempool.space',
1350+
value: 'https://mempool.space/testnet/api'
1351+
},
1352+
{
1353+
key: 'Blockstream.info',
1354+
value: 'https://blockstream.info/testnet/api'
1355+
},
1356+
{
1357+
key: 'Custom',
1358+
translateKey: 'general.custom',
1359+
value: 'Custom'
1360+
}
1361+
];
1362+
13241363
export const SECONDARY_NEUTRINO_PEERS_MAINNET = [
13251364
// friends
13261365
[
@@ -1425,10 +1464,14 @@ export default class SettingsStore {
14251464
bimodalPathfinding: true,
14261465
graphSyncPromptNeverAsk: false,
14271466
graphSyncPromptIgnoreOnce: false,
1467+
embeddedLndBackend: 'neutrino',
14281468
dontAllowOtherPeers: false,
14291469
neutrinoPeersMainnet: DEFAULT_NEUTRINO_PEERS_MAINNET,
14301470
neutrinoPeersTestnet: DEFAULT_NEUTRINO_PEERS_TESTNET,
14311471
zeroConfPeers: [],
1472+
esploraMainnet: DEFAULT_ESPLORA_MAINNET,
1473+
esploraTestnet: DEFAULT_ESPLORA_TESTNET,
1474+
customEsplora: '',
14321475
rescan: false,
14331476
compactDb: false,
14341477
recovery: false,

utils/LndMobileUtils.ts

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import {
3333
SECONDARY_NEUTRINO_PEERS_MAINNET,
3434
DEFAULT_NEUTRINO_PEERS_TESTNET,
3535
DEFAULT_FEE_ESTIMATOR,
36-
DEFAULT_SPEEDLOADER
36+
DEFAULT_SPEEDLOADER,
37+
DEFAULT_ESPLORA_MAINNET,
38+
DEFAULT_ESPLORA_TESTNET
3739
} from '../stores/SettingsStore';
3840

3941
import { lnrpc } from '../proto/lightning';
@@ -103,6 +105,9 @@ const writeLndConfig = async ({
103105
}) => {
104106
const { writeConfig } = lndMobile.index;
105107

108+
const backend = settingsStore?.settings?.embeddedLndBackend || 'neutrino';
109+
const isEsplora = backend === 'esplora';
110+
106111
const peerMode = settingsStore?.settings?.dontAllowOtherPeers
107112
? 'connect'
108113
: 'addpeer';
@@ -128,6 +133,50 @@ const writeLndConfig = async ({
128133
db.bolt.auto-compact=${compactDb ? 'true' : 'false'}
129134
${compactDb ? 'db.bolt.auto-compact-min-age=0' : ''}`;
130135

136+
// Get esplora URL
137+
const getEsploraUrl = () => {
138+
if (!isTestnet) {
139+
const mainnetUrl = settingsStore?.settings?.esploraMainnet;
140+
if (mainnetUrl === 'Custom') {
141+
return settingsStore?.settings?.customEsplora;
142+
}
143+
return mainnetUrl || DEFAULT_ESPLORA_MAINNET;
144+
} else {
145+
const testnetUrl = settingsStore?.settings?.esploraTestnet;
146+
if (testnetUrl === 'Custom') {
147+
return settingsStore?.settings?.customEsplora;
148+
}
149+
return testnetUrl || DEFAULT_ESPLORA_TESTNET;
150+
}
151+
};
152+
153+
// Backend-specific configuration
154+
const backendConfig = isEsplora
155+
? `[esplora]
156+
esplora.url=${getEsploraUrl()}`
157+
: `[Neutrino]
158+
${
159+
!isTestnet
160+
? settingsStore?.settings?.neutrinoPeersMainnet
161+
.map((peer) => `neutrino.${peerMode}=${peer}\n `)
162+
.join('')
163+
: settingsStore?.settings?.neutrinoPeersTestnet
164+
.map((peer) => `neutrino.${peerMode}=${peer}\n `)
165+
.join('')
166+
}
167+
${
168+
!isTestnet
169+
? 'neutrino.assertfilterheader=230000:1308d5cfc6462f877a5587fd77d7c1ab029d45e58d5175aaf8c264cee9bde760'
170+
: ''
171+
}
172+
${
173+
!isTestnet
174+
? 'neutrino.assertfilterheader=660000:08312375fabc082b17fa8ee88443feb350c19a34bb7483f94f7478fa4ad33032'
175+
: ''
176+
}
177+
neutrino.broadcasttimeout=11s
178+
neutrino.persistfilters=${persistFilters}`;
179+
131180
const config = `[Application Options]
132181
debuglevel=info
133182
maxbackoff=2s
@@ -141,7 +190,7 @@ const writeLndConfig = async ({
141190
${rescan ? 'reset-wallet-transactions=true' : ''}
142191
143192
${dbConfig}
144-
193+
145194
[Routing]
146195
routing.assumechanvalid=1
147196
routing.strictgraphpruning=false
@@ -150,31 +199,10 @@ const writeLndConfig = async ({
150199
bitcoin.active=1
151200
bitcoin.mainnet=${isTestnet ? 0 : 1}
152201
bitcoin.testnet=${isTestnet ? 1 : 0}
153-
bitcoin.node=neutrino
202+
bitcoin.node=${backend}
154203
bitcoin.defaultchanconfs=1
155204
156-
[Neutrino]
157-
${
158-
!isTestnet
159-
? settingsStore?.settings?.neutrinoPeersMainnet
160-
.map((peer) => `neutrino.${peerMode}=${peer}\n `)
161-
.join('')
162-
: settingsStore?.settings?.neutrinoPeersTestnet
163-
.map((peer) => `neutrino.${peerMode}=${peer}\n `)
164-
.join('')
165-
}
166-
${
167-
!isTestnet
168-
? 'neutrino.assertfilterheader=230000:1308d5cfc6462f877a5587fd77d7c1ab029d45e58d5175aaf8c264cee9bde760'
169-
: ''
170-
}
171-
${
172-
!isTestnet
173-
? 'neutrino.assertfilterheader=660000:08312375fabc082b17fa8ee88443feb350c19a34bb7483f94f7478fa4ad33032'
174-
: ''
175-
}
176-
neutrino.broadcasttimeout=11s
177-
neutrino.persistfilters=${persistFilters}
205+
${backendConfig}
178206
179207
[fee]
180208
fee.url=${

0 commit comments

Comments
 (0)