BitcoinTalk
Running on a port other than 8333

Running on a port other than 8333

July 27, 2010, 02:08:17 PM

I've been working on adding -port= / -rpcport= command line / config file options to bitcoin. The idea is to let you run multiple copies of bitcoind on one machine; I need this because I'm planning on having at least two Bitcoin-related web services (the Bitcoin Faucet and a service to be named later), I want them to have completely separate wallets, but I don't want to rent multiple servers to host them.

Satoshi pointed out that allowing bitcoin/bitcoind to run on a non-standard port could be dangerous, because if misconfigured two bitcoins might both open and write to the same database. To prevent that, the <datadir>/db.log file is used as a lock so only one bitcoin can access the same datadir at a time (uses boost::interprocess::file_lock, which is purported to be cross-platform and well-behaved, even if bitcoin crashes).

Issues that came up as I was doing this:

I left a call to wxSingleInstanceChecker in the Windows GUI code, so no multiple-gui-bitcoins-listening-on-different-ports on Windows. I don't do Windows...

I didn't bother making the error handling graceful if you point two bitcoins at the same datadir (you get a runtime exception "Cannot lock db.log, is bitcoin already running?").

Re: Running on a port other than 8333

July 27, 2010, 02:42:23 PM

If I was a C++ programmer, I would make multiple instances of Bitcoin automatically talk to each other. But then again, I don't know how hard it is to do cross platform interprocess communication. If a data directory was already being used by one instance, then the new instance would be required to use a different data directory. Sure, you probably can make multiple instances share some or all the files in a data directory, but I think it's a bad idea since it the likelihood for little bugs is high, but the likelihood of the likelihood of those being discovered, researched, reported and fixed is low since the feature wouldn't get much exposure. Imagine the mess it will make if somebody starts half a dozen instances.

Re: Running on a port other than 8333

Satoshi pointed out that allowing bitcoin/bitcoind to run on a non-standard port could be dangerous, because if misconfigured two bitcoins might both open and write to the same database. To prevent that, the <datadir>/db.log file is used as a lock so only one bitcoin can access the same datadir at a time (uses boost::interprocess::file_lock, which is purported to be cross-platform and well-behaved, even if bitcoin crashes).

Re: Running on a port other than 8333

I've been working on adding -port= / -rpcport= command line / config file options to bitcoin

Nice. In addition it would be good to have an -ip= option for what address to bind the port. (rpcport binds to 127.0.0.1 but currently port binds to 0.0.0.0 which is all IP addresses on the machine. On my multi-homed system I'd like to bind bitcoin to the external address different from the bitcoin(s) that binds to the internal address(es).)