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
I'm trying to automate this. Here is a link to what I had to far and the problem that I am facing http://unix.stackexchange.com/questions/332632/capturing-output-from-blocking-process-without-terminating
They apparently deleted the comment see below


I'm running the following commands in a shell script

ip=$(multichaind decibel -shortoutput=1 -miningrequirespeers=0 -discover -rpcuser=admin -rpcpassword=admin -daemon=1)

mkdir .multichain1

echo "ip address $ip"

addr=$(multichaind $ip -datadir=.multichain1)

echo "wallet $addr"

multichain-cli decibel -rpcuser=admin -rpcpassword=admin grant $addr connect,send,recieve

multichaind $ip -datadir=.multichain1 -daemon=1
The first line is a command

multichaind decibel -shortoutput=1 -miningrequirespeers=0 -discover -rpcuser=admin -rpcpassword=admin -daemon=1

that starts a process/ program and returns a result to the output. I then had to use the output result from this command to run the other command

multichaind *theipaddress* -datadir=.multichain1

Here theipaddress represents result from the first command. I use it to run the above the command which just returns a result to output

multichain-cli decibel -rpcuser=admin -rpcpassword=admin grant *address* connect,send,receive

Here address represents the output from the previous command. it doesn't start any processes/ programs

multichaind *theipaddress* -datadir=.multichain1 -daemon=1

Here theipaddress is the result from the very first command.

Usually these commands have to be run manually and I had to use multiple terminals to do it. I'm trying to now automate the tasks into a shell/ bash script but the problem I am facing is that the first command "blocks" the other processes from being executed.

I can't KILL the first process because it is needed by the 3rd task/ command

Is there a way to auto mate these tasks into one bash script without having to KILL the first command?
Is it possible to set the datadir of the first node itself?
Yes you can set the datadir of any node, including the first node, in the same way.
Having trouble adding the port and rpcport numbers to the .multichain-other/chaintest/multichain.conf. I'm getting a permission error. Is there anyway to do this from the command line?
Yes, you can run MultiChain with parameters -port=X -rpcport=Y – see this page for more information on runtime parameters: https://www.multichain.com/developers/runtime-parameters/
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
...