Bitcoin Forum
May 10, 2024, 11:06:20 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Connecting two local nodes in RegTest  (Read 740 times)
bytecoiner22 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
March 22, 2017, 03:24:57 PM
Merited by ABCbits (1)
 #1

I am trying to connect two local regtest nodes together. I am able to run one regtest node without any issues, and am also able to run the bitcoin-cli commands such as generate to create my own chain, however when I try to start a new node, I'm not able to connect them. This is what I do (sorry if there is a clear mistake).

Run node 1
./src/bitcoind -regtest -port=8333 -rpcport=8332 -datadir=/Documents/node1data -conf=Bitcoin/bitcoin.conf

Run node 2
./src/bitcoind -regtest -port=8330 -rpcport=8331 -datadir=/Documents/node2data -conf=/Bitcoin/bitcoin.conf
By now I seem to have two different chains, generating blocks on one node doesn't change the number of blocks in the other node. I would like to have these two nodes share a chain so that mining a block in one of the nodes updates the chain on both of them. However when I try to connect them using the following command:

./src/bitcoin-cli -regtest -port=8333 -rpcport=8332 -rpcuser=user -rpcpassword=password addnode "http://127.0.0.1:18332" "add"
The rpc call to addnode displays no errors and if I run it again I get: "Error: Node already added"

After this call, the command

./src/bitcoin-cli -regtest -port=8333 -rpcport=8332 -rpcuser=user -rpcpassword=password getconnectioncount
returns 0...

So, I see a lot of people using software such as dockers, etc. Why is this not working? Am I completely mistaken to think this could work, if so I would love to know where I'm failing. Ultimately, how can I achieve to have two or three nodes connected to each other?
My end goal is to have one miner that generates all the blocks, that way the BTC balance isn't affected on a secondary node. Since mining generates a lot of BTC it is hard for me to keep track of the transactions.

Thanks in advance to anyone who reads my question.
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715382380
Hero Member
*
Offline Offline

Posts: 1715382380

View Profile Personal Message (Offline)

Ignore
1715382380
Reply with quote  #2

1715382380
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
March 22, 2017, 03:45:38 PM
Merited by ABCbits (1)
 #2

Because both nodes have their own chains, they will not be able to connect. You will need to delete the blockchain for one node.

You should also use -connect=<ip:port> (without the angle brackets) in your startup command for one node in order to connect it to the other.

bytecoiner22 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
March 22, 2017, 04:38:42 PM
 #3

Because both nodes have their own chains, they will not be able to connect. You will need to delete the blockchain for one node.

You should also use -connect=<ip:port> (without the angle brackets) in your startup command for one node in order to connect it to the other.

Still a little confused,
1. I cleared
/Documents/node1data
/Documents/node2data
 to have two empty chains.
2. I started
./src/bitcoind -regtest -port=8330 -rpcport=8331 -datadir=/Documents/node2data -conf=/Bitcoin/bitcoin.conf
./src/bitcoind -regtest -port=8333 -rpcport=8332 -datadir=/Documents/node1data -conf=Bitcoin/bitcoin.conf -connect=http://127.0.0.1:8330
3. This command still outputs 0
./src/bitcoin-cli -regtest -port=8333 -rpcport=8332 -rpcuser=user -rpcpassword=password getconnectioncount

Is there no way to sync both chains? So that after node1 mines a block node2 gets notified and adds this to his datadir?
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
March 22, 2017, 05:27:50 PM
Merited by ABCbits (1)
 #4

You should not have http:// in your connect option. Http is not part of the IP address, it is a protocol, and having that there will confuse bitcoind. You should just have
Code:
-connect=127.0.0.1:8330

bytecoiner22 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 1


View Profile
March 22, 2017, 07:49:42 PM
 #5

Thanks a lot! Taking off the http fixed it
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!