how to run datadir in multichain

+4 votes
can anybody give one example command for using datadir to have two nodes in a single machine
asked Sep 29, 2016 by userven

1 Answer

+7 votes
 
Best answer

This assumes you are in your home directory - if not, type cd ~ before starting.

First create the chain in the default directory  (~/.multichain/) in the normal way:

multichain-util create chaintest

multichaind chaintest -daemon

For this example let's say the node address output was chaintest@12.34.56.78:9255

Now create the second node as follows, using a different datadir, port and rpcport:

mkdir .multichain-other

multichaind -datadir=.multichain-other -port=10255 -rpcport=10254 chaintest@12.34.56.78:9255

You will see the usual message about needing connect permissions, so assign these via the regular node:

multichain-cli chaintest grant [address-shown] connect

Now you can start up the second node again:

multichaind -datadir=.multichain-other -port=10255 -rpcport=10254 chaintest -daemon

You can send commands to the second node as follows:

multichain-cli -datadir=.multichain-other -rpcport=10254 chaintest

To make shorter command lines in future you can add the following lines to the configuration file .multichain-other/chaintest/multichain.conf for the second chain:

port=10255

rpcport=10254

Then in future you can just start up this chain using:

multichaind -datadir=.multichain-other chaintest -daemon

And access its command line using:

multichain-cli -datadir=.multichain-other chaintest

answered Oct 2, 2016 by MultiChain
edited Dec 15, 2016 by MultiChain
That's what I've been doing so far. My question was referring to adding the -port and -rcpport numbers in the .multichain-other/chaintest/multichain.conf file. I'm unable to add/change anything in the file because I do not have permissions to edit it. I wanted to know if there was another way to add the port and rpcport numbers to the file so I can reduce the length of the command line when starting up a node.
I have setup similar to this.
But if i login to the cli of node 2 and try to check the address,
I still see only the addresses of the 1st node.

Also even when i try to publish to a stream in the 1nd node cli still i see the strem publisher as Node 1 address.

Please let me know if anyone has come across the same issue and found some way.!!

Happy Multichaining :)
When I try this, I never get the usual message about needing connect permissions on the second node. Running multichain-cli -datadir=.multichain-other -rpcport=10254 chaintest1 gives me a "no credentials" error and recommends I add them to .multichain-other/chaintest1/multichain.conf, which does contain some credentials (but not the same as .multichain/chaintest1/multichain.conf.

MultiChain 2.0 beta 1 on Ubuntu 18.10.

Update: And the reason would be: anyone-can-connect = true
Dockerfile:
---------------------------------------------------------------
FROM ubuntu:18.04

WORKDIR /root
RUN apt-get update
RUN apt-get install -y wget
RUN wget https://www.multichain.com/download/multichain-2.1.2.tar.gz
RUN tar -xvzf multichain-2.1.2.tar.gz
WORKDIR /root/multichain-2.1.2
RUN mv multichaind multichain-cli multichain-util /usr/local/bin
WORKDIR /root

RUN multichain-util create chaintest

COPY start.sh .
RUN chmod +x start.sh

ENTRYPOINT ["/root/start.sh"]
---------------------------------------------------------------
start.sh:
---------------------------------------------------------------
#!/bin/bash

multichaind chaintest -daemon > node1_output.txt

node1_address=$(grep multichaind node1_output.txt | sed 's/multichaind //')

mkdir .multichain-other

multichaind -datadir=.multichain-other -port=10255 -rpcport=10254 $node1_address > node2_output.txt

grep multichain-cli node2_output.txt | grep connect,send,receive > connect_node2.sh

chmod +x connect_node2.sh

./connect_node2.sh > connect_node2.sh_output.txt

echo multichain-cli chaintest > node1_cli.sh
echo multichain-cli -datadir=.multichain-other -rpcport=10254 chaintest > node2_cli.sh
chmod +x node1_cli.sh node2_cli.sh

rm connect_node2.sh multichain-2.1.2.tar.gz node1_output.txt node2_output.txt start.sh

multichaind -datadir=.multichain-other -port=10255 -rpcport=10254 chaintest
---------------------------------------------------------------
How to use:
---------------------------------------------------------------
$ docker build -t my-image .
$ docker run --rm -it my-image
$ docker exec -it two /bin/bash
$ ./node2_cli.sh
$ getinfo
...