Running on a port other than 8333

8 messages BitcoinTalk Gavin Andresen, agaumoney, lachesis, Jeff Garzik, Satoshi Nakamoto, MoneyTree July 27, 2010 — January 19, 2011
Gavin Andresen July 27, 2010 14:08 UTC Source ·

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.

Usage looks like this:

$ ./bitcoind getbalance  # The TEST network Faucet bitcoind
40616.66159265000
$ ./bitcoind -datadir=/home/bitcoin/.bitcoinTEST2 getbalance
1000.000000000000
$ cat /home/bitcoin/.bitcoinTEST2/bitcoin.conf
rpcpassword=.....
port=18666
rpcport=18665

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 /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?”).

Patches are at http://pastebin.com/2e4hfXSS; I’ve only tested on Linux so far, anybody willing to try this on Windows?

agaumoney July 27, 2010 19:00 UTC Source ·
Quote from: gavinandresen on July 27, 2010, 5:08:17 AM UTC

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).)

lachesis August 10, 2010 15:24 UTC Source ·

Do you have an updated version of this patch for SVN revision 125? Also, does Bitcoin open the BerkeleyDB as exclusive, precluding the need for a file lock?It does not — did my own tests.

Jeff Garzik (jgarzik) August 10, 2010 17:07 UTC Source ·
Quote from: lachesis on August 10, 2010, 6:24:55 AM UTC

Do you have an updated version of this patch for SVN revision 125? Also, does Bitcoin open the BerkeleyDB as exclusive, precluding the need for a file lock?It does not — did my own tests.

It does open with DB_PRIVATE.

http://www.oracle.com/technology/documentation/berkeley-db/db/api_reference/C/envopen.html

Satoshi Nakamoto September 12, 2010 17:40 UTC Source ·
Quote from: lachesis on August 10, 2010, 6:24:55 AM UTC

Also, does Bitcoin open the BerkeleyDB as exclusive, precluding the need for a file lock?It does not — did my own tests.

Is there a way to open BerkeleyDB exclusive?

DB_PRIVATE is the worst of both worlds.  DB_PRIVATE is not exclusive, but it does make it get screwed up if another process tries to access it at the same time.

I’ve dropped the DB_PRIVATE flag in rev 153.

Jeff Garzik (jgarzik) September 12, 2010 20:50 UTC Source ·
Quote from: satoshi on September 12, 2010, 5:40:20 PM UTC

Is there a way to open BerkeleyDB exclusive?

What is your intended goal?

If it is to prevent two bitcoin clients from actively using the same database, you’ll need to employ application-level protection. Crude methods of this include a lockfile or “lock” database entry.

If the intention is to prevent all other access, I’d suggest giving up on that goal 😊 It is highly useful to permit db4 tools to access db4 databases:Code:db46_archive db46_deadlock db46_load db46_stat db46_checkpoint db46_dump db46_printlog db46_upgrade db46_codegen db46_hotbackup db46_recover db46_verify and just as useful to permit read-only accesses by tools such as gavin’s bitcointools.

MoneyTree January 19, 2011 23:41 UTC Source ·
Quote from: gavinandresen on July 27, 2010, 2:08:17 PM UTC

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.

Same here. I have managed to create 2 wallets and two instances of a bitcoin.conf.

both have a different rcport specified in the config (8332 and 8333)

I can start either one of them and it works fine, the web sites using the wallet can connect.

However… If I start the second bitcoin instance (I’m on windows) the second process grows to about 6 Mb and then just dies… So each of them wallets runs just fine alone but not together.

Is there any way I can debug to see what happened? I tried switching on options in the config (like noirc and the connect only to…) but it does not seem to make a difference.

Kind regards,

MoneyTree

http://doubletrouble.bitcoinbet.com/

Jeff Garzik (jgarzik) January 19, 2011 23:42 UTC Source ·
Quote from: MoneyTree on January 19, 2011, 11:41:59 PM UTC

both have a different rcport specified in the config (8332 and 8333)

8333 is the hardcoded P2P port.