Can I run multiple nodes on one server connecting to the same chain (using different users)

+3 votes

Hi

I tried setting up two nodes on the same server, using two different usernames. So using terminal, I logged into the different users and try to connect to eachother.

I issued different port numbers for port and rpcport. Both nodes start, using different terminals/users.

On one user (initial user) the cli allows me to query through getinfo. The other gives an error:

{"method":"getinfo","params":[],"id":1,"chain_name":"chain1"}

error: incorrect rpcuser or rpcpassword (authorization failed)


The password of the rpcuser in ~/.multichain/chain1$ more multichain.conf  is different for both users, which is ok?

Anyway. Just needed thumbs up if it is possible to use only server to test multiple nodes. Or is the IP address some sort of unique key?

(tried google on your site, but couldnt find the answer)

asked Dec 11, 2015 by Tom

1 Answer

+1 vote

It should be possible and I'll ask the team about this. In the meantime another solution is the datadir option which lets you run multiple nodes even under one user.

answered Dec 11, 2015 by MultiChain
Hi

thanks for the answer.

I tried doing so using datadir. This is what I did:



* NODE 1 initial setup
mkdir /home/tom/node1
./multichain-util create chain1 -datadir=/home/tom/node1
./multichaind chain1 -daemon -datadir=/home/tom/node1
Take the address (chain1@10.240.115.183:4251) and move to NODE 2 actions

* NODE 2 setup of connection to NODE 1
mkdir /home/tom/node2
./multichaind chain1@10.240.115.183:4251 -datadir=/home/tom/node2
Take the wallet address and fill in below:
./multichain-cli chain1 -datadir=/home/tom/node1 grant 1SGyVpcGoJGRxrhZG48B33Dm7gE21gbhAEjhj connect

    RETURNDATA:{"method":"grant","params":["1SGyVpcGoJGRxrhZG48B33Dm7gE21gbhAEjhj","connect"],"id":1,"chain_name":"chain1"}
    93d4d87cfef6cdf37d87fb373edf6a2601fb2725db90c1e5847dc7ccd5d7acf4

When I then try to run the daemon on node 2, it gives me errors trying to bind to port

./multichaind chain1 -datadir=/home/tom/node2  -daemon

I tried adding the -rpcport=4333, but that gives the same error

./multichaind chain1 -datadir=/home/tom/node2 -rpcport=4333 -daemon


MultiChain Core Daemon build 1.0 alpha 12 protocol 10002

Multichain server starting
tom@tom-Latitude-6430U:~/blockchain/multichain-1.0-alpha-12$ Chain chain1 already exists, adding 10.240.115.183:4251 to list of peers

New users can connect to this blockchain using
multichaind chain1@10.240.115.183:4251

Error: Unable to bind to 0.0.0.0:4251 on this computer. Bitcoin Core is probably already running.
Error: Failed to listen on any port. Use -listen=0 if you want this


I am a bit lost here. How to setup node2 to connect correctly without complaining?

Regards

Tom
If you want to run two nodes on the same server, you need to use a different JSON-RPC port *and* peer-to-peer port for each node. Try setting the rpcport and port settings in the multichain.conf file for each node in its directory. More info here: http://www.multichain.com/developers/runtime-parameters/
Hi

Thx. This works using the following:

./multichaind chain1 -datadir=/home/tom/node2 -rpcport=4333 -port=4335 -daemon

And I need to include these ports all the time if I dont want issues with the other commands in getting started (or put them in the conf file!) - just for others to note

Example:

./multichain-cli chain1 -datadir=/home/tom/node2 -rpcport=4333 -port=4335 getinfo
Hi, here is my 'dumb ps-script' running on windows 10 to automate process:
you can get 5 nodes (or as you wish) created, granted on seed-node and run all of them automatically, FIRST you have to extract  https://www.multichain.com/download/multichain-windows-1.0.1.zip to system32 folder to get this ps working, SECOND open powershell_ise, copy paste into new script window, dont save, just execute (F5). Wait.. and you will get about 95,3MB for 5 nodes in %appdata%\MultiChain folder!!

$ip  = (Get-NetIPAddress -AddressFamily IPv4 -PrefixLength 24).IPAddress
$path= "$env:APPDATA\MultiChain"
#[int]$node_count = Read-Host "How much node chain do you want? "
[int]$node_count = 5
#$chainname = Read-Host "What chain's name (chain)? "
$chainname = 'node'
$name       = "main-"+$chainname
##Port
[int]$NetPort = 7001;
[int]$RPCPort = 7002;

$nodes = @()
#$params = [PSCustomObject]@{}
$params = [PSCustomObject]@{
            chainName = $name
            ipv4      = $ip
            netPort   = $NetPort
            rpcPort   = $RPCPort
            dataDir   = "$path\$name"
            localAddr = ''
}
$nodes +=$params

#Create main-node
Start-Process multichain-util -RedirectStandardOutput rso.txt -Wait -ArgumentList "create $name -default-network-port=7001 -default-rpc-port=7002"
Start-Process multichaind -RedirectStandardOutput $($name +".txt") -ArgumentList "$name -daemon"
Start-Sleep -s 5
$arg = ((Select-String .\main-node.txt -Pattern 'multichain').Line -split ' ')[1]

foreach ($i in 1..($node_count-1)){
    $RPCPort   += 10
    $NetPort   += 10
    $nodes += [PSCustomObject]@{
            chainName = $chainname+$i
            ipv4      = $ip
            netPort   = $NetPort
            rpcPort   = $RPCPort
            dataDir   = "$path\$chainname"+$i
            localAddr = ''
    }

    #create node
        md $nodes[$i].dataDir
    #copy params    
        (gc $($nodes[0].DataDir+"\params.dat")) -replace 'main-node',$nodes[$i].chainName ` -replace '7001',$nodes[$i].netPort ` -replace '7002',$nodes[$i].rpcPort | Out-File $($nodes[$i].dataDir+"\params.dat")

    #try to-connect
    

    Write-Host "========================="$nodes[$i].dataDir
    $arg = ((Select-String .\main-node.txt -Pattern 'multichain').Line -split ' ')[1]
    Start-Process multichaind -RedirectStandardOutput $($nodes[$i].chainName +".txt") -ArgumentList "$arg -datadir=`"$($nodes[$i].DataDir)`" -port=$($nodes[$i].netPort) -rpcport=$($nodes[$i].rpcPort)" -Wait
    $grant = (Select-String .\$($nodes[$i].chainName +".txt") -Pattern 'connect,send,receive').Line
    $nodes[$i].localAddr = ($grant -split ' ')[3]
    Invoke-Expression $grant
    
    Start-Process multichaind -ArgumentList "main-node stop" -Wait
    Start-Process multichaind -ArgumentList "main-node -daemon"
    Start-Sleep -s 3

    Start-Process multichaind -ArgumentList "$arg -datadir=`"$($nodes[$i].DataDir)`" -port=$($nodes[$i].netPort) -rpcport=$($nodes[$i].rpcPort)"
    
}
...