Skip to content

Commit

Permalink
Allow tweaking bitcoin.conf directly from the UI
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Childs <[email protected]>
Co-authored-by: Mayank Chhabra <[email protected]>
Co-authored-by: Steven Briscoe <[email protected]>
  • Loading branch information
4 people committed Dec 21, 2022
1 parent 66c8896 commit cc5e1fd
Show file tree
Hide file tree
Showing 25 changed files with 9,862 additions and 8,409 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ lb_settings.json
.nyc_output
coverage
.todo
bitcoin
data/
.env.local
40 changes: 39 additions & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ var app = require('../app');
var debug = require('debug')('nodejs-regular-webapp2:server');
var http = require('http');

const diskLogic = require('../logic/disk');
const diskService = require('../services/disk');
const bitcoindLogic = require('../logic/bitcoind');
const constants = require('../utils/const');

/**
* Get port from environment and store in Express.
*/
Expand All @@ -29,6 +34,34 @@ server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Function to create default bitcoin core config files if they do not already exist.
*/

async function createConfFilesAndRestartBitcoind() {
console.log('umbrel-bitcoin.conf does not exist, creating config files with Umbrel default values');
const config = await diskLogic.getJsonStore();

// set torProxyForClearnet to false for existing installs
if (constants.BITCOIN_INITIALIZE_WITH_CLEARNET_OVER_TOR) config.torProxyForClearnet = true;

await diskLogic.applyCustomBitcoinConfig(config);

const MAX_TRIES = 60;
let tries = 0;

while (tries < MAX_TRIES) {
try {
await bitcoindLogic.stop();
break;
} catch (error) {
console.error(error);
tries++;
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
}

/**
* Normalize a port into a number, string, or false.
*/
Expand Down Expand Up @@ -81,11 +114,16 @@ function onError(error) {
* Event listener for HTTP server "listening" event.
*/

function onListening() {
async function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
console.log('Listening on ' + bind);

// if umbrel-bitcoin.conf does not exist, create default bitcoin core config files and restart bitcoind.
if (! await diskService.fileExists(constants.UMBREL_BITCOIN_CONF_FILEPATH)) {
createConfFilesAndRestartBitcoind();
}
}
68 changes: 62 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,84 @@
version: "3.7"

services:
i2pd_daemon:
container_name: i2pd_daemon
image: purplei2p/i2pd:release-2.44.0@sha256:d154a599793c393cf9c91f8549ba7ece0bb40e5728e1813aa6dd4c210aa606f6
user: "1000:1000"
command: --sam.enabled=true --sam.address=0.0.0.0 --sam.port=7656 --loglevel=error
restart: on-failure
volumes:
- ${PWD}/data/i2pd:/home/i2pd/data
networks:
default:
ipv4_address: "10.21.0.2"

tor_server:
container_name: tor_server
image: getumbrel/tor:0.4.7.8@sha256:2ace83f22501f58857fa9b403009f595137fa2e7986c4fda79d82a8119072b6a
user: "1000:1000"
restart: on-failure
entrypoint: /tor-entrypoint/tor-entrypoint.sh
volumes:
- ${PWD}/data/tor:/etc/tor
- ${PWD}/tor-entrypoint:/tor-entrypoint
environment:
HOME: "/tmp"
networks:
default:
ipv4_address: "10.21.0.3"

bitcoind:
image: lncm/bitcoind:v22.0@sha256:37a1adb29b3abc9f972f0d981f45e41e5fca2e22816a023faa9fdc0084aa4507
command: -regtest -rpcbind=0.0.0.0 -rpcallowip=0.0.0.0/0 -rpcauth=umbrel:5071d8b3ba93e53e414446ff9f1b7d7b$$375e9731abd2cd2c2c44d2327ec19f4f2644256fdeaf4fc5229bf98b778aafec
image: lncm/bitcoind:v24.0@sha256:db19fe46f30acd3854f4f0d239278137d828ce3728f925c8d92faaab1ba8556a
user: "1000:1000"
command: -port=8333 -rpcport=8332 -rpcbind=0.0.0.0 -rpcallowip=0.0.0.0/0 -rpcauth=umbrel:5071d8b3ba93e53e414446ff9f1b7d7b$$375e9731abd2cd2c2c44d2327ec19f4f2644256fdeaf4fc5229bf98b778aafec
volumes:
- ${PWD}/data/bitcoin:/data/.bitcoin
restart: on-failure
restart: unless-stopped
stop_grace_period: 15m30s
ports:
- "18443:18443" # regtest
- "8332:8332" # rpc
- "8333:8333" # p2p
networks:
default:
ipv4_address: "10.21.0.4"

server:
build: .
depends_on: [bitcoind]
command: ["npm", "start"]
restart: on-failure
ports:
- "3005:3005"
volumes:
- ${PWD}/data/app:/data # volume to persist advanced settings json
- ${PWD}/data/bitcoin:/bitcoin/.bitcoin # volume to persist umbrel-bitcoin.conf and bitcoin.conf
environment:
PORT: "3005"
BITCOIN_HOST: "bitcoind"
RPC_PORT: "18443" # - regtest
BITCOIN_P2P_PORT: 8333
BITCOIN_RPC_PORT: 8332
BITCOIN_DEFAULT_NETWORK: "regtest"
RPC_USER: "umbrel"
RPC_PASSWORD: "moneyprintergobrrr"
BITCOIN_RPC_HIDDEN_SERVICE: "somehiddenservice.onion"
BITCOIN_P2P_HIDDEN_SERVICE: "anotherhiddenservice.onion"
DEVICE_DOMAIN_NAME: "test.local"
DEVICE_DOMAIN_NAME: "test.local"
BITCOIND_IP: "10.21.0.4"
TOR_PROXY_IP: "10.21.0.3"
TOR_PROXY_PORT: "9050"
TOR_PROXY_CONTROL_PORT: "9051"
TOR_PROXY_CONTROL_PASSWORD: "umbrelisneat"
I2P_DAEMON_IP: "10.21.0.2"
I2P_DAEMON_PORT: "7656"
networks:
default:
ipv4_address: "10.21.0.5"

networks:
default:
name: advanced_settings_test_network
ipam:
driver: default
config:
- subnet: "10.21.0.0/16"
37 changes: 31 additions & 6 deletions logic/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@ async function getConnectionsCount() {

var outBoundConnections = 0;
var inBoundConnections = 0;
var clearnetConnections = 0;
var torConnections = 0;
var i2pConnections = 0;

peerInfo.result.forEach(function(peer) {
if (peer.inbound === false) {
outBoundConnections++;

return;
} else {
inBoundConnections++;
}
inBoundConnections++;

if (peer.network === "onion") {
torConnections++;
} else if (peer.network === "i2p") {
i2pConnections++;
} else {
// ipv4 and ipv6 are clearnet
clearnetConnections++;
}
});

const connections = {
total: inBoundConnections + outBoundConnections,
inbound: inBoundConnections,
outbound: outBoundConnections
outbound: outBoundConnections,
clearnet: clearnetConnections,
tor: torConnections,
i2p: i2pConnections
};

return connections;
Expand Down Expand Up @@ -72,12 +86,16 @@ async function getLocalSyncInfo() {
var blockCount = blockChainInfo.blocks;
var headerCount = blockChainInfo.headers;
var percent = blockChainInfo.verificationprogress;
var pruned = blockChainInfo.pruned;
var pruneTargetSize = blockChainInfo.pruneTargetSize;

return {
chain,
percent,
currentBlock: blockCount,
headerCount: headerCount // eslint-disable-line object-shorthand,
headerCount: headerCount, // eslint-disable-line object-shorthand,
pruned,
pruneTargetSize
};
}

Expand All @@ -92,6 +110,7 @@ async function getSyncStatus() {
return localSyncInfo;
}

// TODO - consider using getNetworkInfo for info on proxy for ipv4 and ipv6
async function getVersion() {
const networkInfo = await bitcoindService.getNetworkInfo();
const unformattedVersion = networkInfo.result.subversion;
Expand Down Expand Up @@ -259,6 +278,11 @@ async function nodeStatusSummary() {
};
}

async function stop() {
const stopResponse = await bitcoindService.stop();
return {stopResponse};
}

module.exports = {
getBlockHash,
getTransaction,
Expand All @@ -273,5 +297,6 @@ module.exports = {
getSyncStatus,
getVersion,
nodeStatusDump,
nodeStatusSummary
nodeStatusSummary,
stop
};
Loading

0 comments on commit cc5e1fd

Please sign in to comment.