Skip to content

Commit

Permalink
Add additional lnd.conf options to Advanced Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nmfretz committed Nov 2, 2023
1 parent 5ce08be commit b9f67e7
Show file tree
Hide file tree
Showing 5 changed files with 843 additions and 19 deletions.
96 changes: 94 additions & 2 deletions logic/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,39 @@ const GB_TO_MiB = 953.674;
const MB_TO_MiB = 0.953674;

const DEFAULT_ADVANCED_SETTINGS = {
// Peer Settings
clearnet: true,
torProxyForClearnet: false,
tor: true,
i2p: true,
incomingConnections: false,
peerblockfilters: true,
peerbloomfilters: false,
bantime: 86400,
maxconnections: 125,
maxreceivebuffer: 5000,
maxsendbuffer: 1000,
maxtimeadjustment: 4200,
peertimeout: 60,
timeout: 5000,
maxuploadtarget: 0,
// Optimization
cacheSizeMB: 450,
mempoolFullRbf: false,
rest: false,
prune: {
enabled: false,
pruneSizeGB: 300,
},
blockfilterindex: true,
maxmempool: 300,
mempoolexpiry: 336,
persistmempool: true,
maxorphantx: 100,
reindex: false,
// RPC/REST
rest: false,
rpcworkqueue: 128,
// Network Selection
network: constants.BITCOIN_DEFAULT_NETWORK
}

Expand Down Expand Up @@ -116,13 +136,36 @@ function settingsToMultilineConfString(settings) {
const txindexEnabled = settings.prune.enabled ? '0' : '1';
umbrelBitcoinConfig.push(`txindex=${txindexEnabled}`);

// blockfilterindex
if (settings.blockfilterindex) {
umbrelBitcoinConfig.push("# Enable all compact filters.");
umbrelBitcoinConfig.push('blockfilterindex=1');
}

// maxmempool
umbrelBitcoinConfig.push("# Keep the transaction memory pool below this many megabytes.");
umbrelBitcoinConfig.push(`maxmempool=${settings.maxmempool}`);

// mempoolexpiry
umbrelBitcoinConfig.push("# Do not keep transactions in the mempool longer than this many hours.");
umbrelBitcoinConfig.push(`mempoolexpiry=${settings.mempoolexpiry}`);

// persistmempool
if (settings.persistmempool) {
umbrelBitcoinConfig.push("# Save the mempool on shutdown and load on restart.");
umbrelBitcoinConfig.push('persistmempool=1');
}

// maxorphantx
umbrelBitcoinConfig.push("# Maximum number of orphan transactions to be kept in memory.");
umbrelBitcoinConfig.push(`maxorphantx=${settings.maxorphantx}`);

// reindex
if (settings.reindex) {
umbrelBitcoinConfig.push('# Rebuild chain state and block index from the blk*.dat files on disk.');
umbrelBitcoinConfig.push('reindex=1');
}


// [NETWORK]
umbrelBitcoinConfig.push("");
umbrelBitcoinConfig.push("# [network]");
Expand Down Expand Up @@ -167,14 +210,63 @@ function settingsToMultilineConfString(settings) {
umbrelBitcoinConfig.push(`# Whitelist peers connecting from local Umbrel IP range. Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool.`);
umbrelBitcoinConfig.push(`whitelist=10.21.0.0/16`);

// peerblockfilters
if (settings.peerblockfilters) {
umbrelBitcoinConfig.push("# Serve compact block filters to peers per BIP 157.");
umbrelBitcoinConfig.push('peerblockfilters=1');
}

// peerbloomfilters
if (settings.peerbloomfilters) {
umbrelBitcoinConfig.push("# Support filtering of blocks and transactions with bloom filters.");
umbrelBitcoinConfig.push('peerbloomfilters=1');
}

// bantime
umbrelBitcoinConfig.push("# Number of seconds to keep misbehaving peers from reconnecting.");
umbrelBitcoinConfig.push(`bantime=${settings.bantime}`);

// maxconnections
umbrelBitcoinConfig.push("# Maintain at most this many connections to peers.");
umbrelBitcoinConfig.push(`maxconnections=${settings.maxconnections}`);

// maxreceivebuffer
umbrelBitcoinConfig.push("# Maximum per-connection receive buffer in KB.");
umbrelBitcoinConfig.push(`maxreceivebuffer=${settings.maxreceivebuffer}`);

// maxsendbuffer
umbrelBitcoinConfig.push("# Maximum per-connection send buffer in KB.");
umbrelBitcoinConfig.push(`maxsendbuffer=${settings.maxsendbuffer}`);

// maxtimeadjustment
umbrelBitcoinConfig.push("# Maximum allowed median peer time offset adjustment.");
umbrelBitcoinConfig.push(`maxtimeadjustment=${settings.maxtimeadjustment}`);

// peertimeout
umbrelBitcoinConfig.push("# The amount of time (in seconds) a peer may be inactive before the connection to it is dropped.");
umbrelBitcoinConfig.push(`peertimeout=${settings.peertimeout}`);

// timeout
umbrelBitcoinConfig.push("# Initial peer connection timeout in milliseconds.");
umbrelBitcoinConfig.push(`timeout=${settings.timeout}`);

// maxuploadtarget
umbrelBitcoinConfig.push("# Maximum total upload target in MB per 24hr period.");
umbrelBitcoinConfig.push(`maxuploadtarget=${settings.maxuploadtarget}`);

// [RPC]
umbrelBitcoinConfig.push("");
umbrelBitcoinConfig.push("# [rpc]");
// rest
if (settings.rest) {
umbrelBitcoinConfig.push("# Accept public REST requests.");
umbrelBitcoinConfig.push('rest=1');
}

// rpcworkqueue
umbrelBitcoinConfig.push("# Depth of the work queue to service RPC calls.");
umbrelBitcoinConfig.push(`rpcworkqueue=${settings.rpcworkqueue}`);

umbrelBitcoinConfig.push("");
umbrelBitcoinConfig.push(`# Required to configure Tor control port properly`);
umbrelBitcoinConfig.push(`[${settings.network}]`);
Expand Down
6 changes: 6 additions & 0 deletions routes/v1/bitcoind/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const systemLogic = require('logic/system.js');
const configLogic = require('logic/config');
const bitcoindLogic = require('logic/bitcoind.js');
const safeHandler = require('utils/safeHandler');
const validateSettingsRequest = require('utils/validateSettingsRequest');

router.get('/bitcoin-p2p-connection-details', safeHandler(async(req, res) => {
const connectionDetails = systemLogic.getBitcoinP2PConnectionDetails();
Expand All @@ -29,6 +30,11 @@ router.post('/update-bitcoin-config', safeHandler(async(req, res) => {
// store old bitcoinConfig in memory to revert to in case of errors setting new config and restarting bitcoind
const oldBitcoinConfig = await configLogic.getJsonStore();
const newBitcoinConfig = req.body.bitcoinConfig;

const validationErrors = validateSettingsRequest(newBitcoinConfig);
if (validationErrors.length > 0) {
return res.status(400).json({success: false, validationErrors});
}

try {
await configLogic.applyCustomBitcoinConfig(newBitcoinConfig);
Expand Down
Loading

0 comments on commit b9f67e7

Please sign in to comment.