Connecting two peers on different machines in a private network - blockchain

I am using geth to create a Private blockchain in my system which is connected to my office network.
I want to add another peer(different PC) to my blockchain network which is connected to the same network.
How can I do that??
Any suggestions on, creating an app which indeed does solve the above requirement.

The key change that would be needed is to start geth nodes on those machines using rpc mode
For example start geth node on Machine 1 and Machine 2 using the commands:
Machine 1 : geth --datadir "C:\ethereum\geth\data\01" --networkid 1234 --rpc --rpcport "8545" --rpcaddr "127.198.216.197" --rpccorsdomain "*"
Machine 2 : geth --datadir "C:\ethereum\geth\data\01" --networkid 1234 --rpc --rpcport "8545" --rpcaddr "127.198.216.198" --rpccorsdomain "*"
Now add Machine 2 as a peer to Machine 1 if you want to do it manually or use a Bootnode and start Geth using Bootnode. You can refer to the link if you want to use Boot nodes: https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster
Then you should be able to attach your console using the command: geth attach http://127.198.216.197:8545
One caveat: You need to open respective ports if they are blocked by your office network

When running the client daemon you can add the 'connect' parameter to specify the IP:Port of the computer you want to try to connect to when starting.
bitcoind --daemon -connect=127.0.0.1:9090
This usually has to be done when the ip's of nodes hard coded into your blockchain codebase have not been updated to the IP's where you have nodes running. Thus peers.dat does not know where to look for a connection to the blockchain.
You can also specify these in the config file with the addnode parameter. e.g.
server=1
rpcport=9090
rpcuser=bitcoinrpc
rpcpassword=3QtnxrB7P5y4EpBdad1MkCeB2RHmArvcarw7udgXsAce
addnode=10.0.0.2:8333

Related

Remix provider connectivity issue with custom RPC

I have setup Ethereum private site chain using geth with the following nodes and each node is running on a separate machine on aws.
abc.122.41.xyz admin(node1)
abc.73.38.xyz peer(node2)
abc.125.123.xyz RPC(node3)
This setup is working fine with these parameters in geth.
--http.vhosts '*'--http.corsdomain '*'
But, I want to restrict access to specific sites to use this RPC like REMIX and etc. Now, I run the below command in this way to restrict access and I read it from REMIX official site to pass parameters in this way. But, Remix is not going to connect to the RPC and throw this error.
Error while connecting to the provider, provider not connected
geth --datadir node01 --networkid 4444 --nat extip:xyz.31.2.xyz --port 30303 --mine --miner.gasprice 1000000 --miner.etherbase=0x35ef1cb0552cEfDEDc9cF1DA19199071274094Ab --keystore key01 --ethstats node01:s3cr3t#stats-localhost.batterychain.info:3000
geth --datadir node02 --networkid 4444 --port 30303 --mine --miner.gasprice 1000000 --keystore key02/ --ethstats Geth/v1.10.20-stable-8f2416a8/linux-amd64/go1.18.1:s3cr3t#stats-localhost.batterychain.info:3000
geth --datadir node03 --networkid 4444 --port 30303 --mine --miner.gasprice 1000000 --http --http.corsdomain 'https://remix.ethereum.org' --http.addr 0.0.0.0 --http.api personal,eth,net,web3 --keystore key03/ --ethstats Geth/v1.10.20-stable-8f2416a8/linux-amd64/go1.18.1:s3cr3t#stats-localhost.batterychain.info:3000
I try to explore this issue on the internet and found some solutions like changing the order of parameters, and also passing REMIX with HTTP instead of HTTPS like
http://remix.ethereum.org
But, each time I face the above same error.

What does PRIVATE_CONFIG=tm.ipc mean and how to generate tm.ipc file?

i have tried the below command using PRIVATE_CONFIG=ignore.Can anyone help me to find some explanation regarding how tm.ipc is generated and what is its use
PRIVATE_CONFIG=tm.ipc nohup geth --datadir new-node-1 --nodiscover --verbosity 5 --networkid 31337 --raft --raftport 50000 --rpc --rpcaddr 0.0.0.0 --rpcport 22000 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,raft --emitcheckpoints --port 21000 2>>node.log &
The tm.ipc socket file is created by the transaction manager (Constellation or Tessera).
It's used by Quorum to communicate with the transaction manager for private transactions and Quorum expects PRIVATE_CONFIG to specify the location of the sokcet file.
If you are only interested in public transactions then you don't need a transaction manager, hence the PRIVATE_CONFIG=ignore setting.
Documentation for this can be found here

which port I use when I want to connect remix to my local quorum network?

I want to deploy a smart contract on my local network.
I executed a local node via
PRIVATE_CONFIG=ignore nohup geth --datadir ./Node1/new-
node-1
--nodiscover --verbosity 5 --networkid 31337 --raft --
raftport 51001 --rpc --rpcaddr 0.0.0.0 --rpcport 22101 --
rpcapi
admin,db,eth,debug,miner,net,shh,txpool,personal,web3,
quorum,raft --emitcheckpoints --port 21101 2>>node1.log &
I have to use localhost:\127.0.0.1:21101 or 22101?
I want to know the difference betwwen the two ports and what are used for?
An other question if you don't mind:
When i use the port 21101, it fails to connect and when I consult the node log I find :
Failed RLPx handshake addr=[::1]:42552 conn=inbound
err="read tcp [::1]:21102->[::1]:42552: i/o timeout"
You need to use an RPC port number to connect the network.
For examples: http://localhost:22101
Difference between the Raft port and RPC port?
Quorum listens on port 50400 by default for the raft transport, but this is configurable with the --raftport flag.
You can start the HTTP JSON-RPC with the --rpc flag, to change the default port (8545) --rpcport <portnumber> If accessing the RPC from a browser, CORS will need to be enabled with the appropriate domain set. Otherwise, JavaScript calls are limit by the same-origin policy and requests will fail:
For examples: geth --rpc --rpccorsdomain "http://localhost:3000"
Try to use http://remix.ethereum.org/ for connecting local networks (unsecured networks). If Https certificate enabled then, you can use https://remix.ethereum.org/

How to set up a Private network and connect peers in geth?

I am trying to setup a private network and trying to connect peers. Currently I'm trying it on my laptop and desktop (both of them are connected to different internet).
I run the below command in first terminal(in both systems (data dir is different in both systems)):
geth --rpc --rpcaddr "0.0.0.0" --rpcport "8545" --rpccorsdomain "http://localhost:5000, http://localhost:6000" --port "2403" --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3" --networkid 1001201 --datadir "E:\User\priv\data" init "E:\User\priv\genesis.json"
then I run:
geth --datadir "E:\User\priv\data"
Now, in the second terminal:
geth attach ipc:\\.\pipe\geth.ipc
I get the same enode value on both the systems when i run admin.nodeInfo.enode
then on 1st PC,
admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a#[192.168.1.2]:30301");
on 2nd PC,
admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a#[13.75.117.156]:30302");
both of them return true.
But admin.peerCount returns 0.
Can somebody please help me to setup a private geth network?
Step1
geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 init PathOfGenesisFile
The above command is to initialise a Genesis File.
Note: All Peers willing to connect to a network should have a same Genesis File.
Step2
geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 console
The above command opens a Geth JavaScript console.
Do the above 2 steps in other system also.
Step3
In the system where you want to add other system as peer type the following command admin.addPeer("Argument") where Argument is the enode value of other node which is obtained by typing admin.nodeInfo() in other system.
Eg:admin.nodeInfo
{
enode: "enode://965dc2b0f39e199d3a07871293015d8a4ad9349834fc27b7ee5e87bea89547e4fafda3ce7982ae07c14b8770c87a6c14e3fe2f91ef0d0ca717eb6ae56aa3e74b#[::]:30330?discport=0",
//////////
}
where 30330 is the network id of other system.
copy upto 30330.You need to give the ip address of other system in place of
[::]
It returns true if that node is capable of acting as a peer but not mean that it is added to our network, to know that type net.peerCount. It returns 1, if added.
You can follow the step3 for adding more peers.
You can create a private blockchain without creating a Genesis File.If you opt for that, follow this link.
As outlined here, your --port and --rpcport variables should be different. The resulting EnodeURLs should also be different.
Also, when you run geth the second time, I'd include everything you used in the first run before init.

Setting up JMeter for Distributed testing in AWS with connectivity issues

I have to do distributed testing using JMeter. The objective is to have multiple remote servers in AWS controlled by one local server send a file download request to another server in AWS.
How can I set up the different servers in AWS?
How can I connect to them remotely?
Can someone provide some step by step instructions on how to do it?
I have tried several things but keep running into connectivity issues across networks.
We had a similar task and we ran into a bunch of issues as well. Here are the details of the whole process and what we did to resolve the issues we encountered. Hope it helps.
We needed to send requests from 5 servers located in various regions of the world. So we launched 5 micro instances in AWS, each in a different region. We chose the regions to be as geographically apart as possible.
Remote (server) JMeters config
Here is how we set up each instance.
Installed java:
$ sudo apt-get update
$ sudo apt-get install default-jre
Installed JMeter:
$ mkdir jmeter
$ cd jmeter;
$ wget ftp://apache.mirrors.pair.com//jmeter/binaries/apache-jmeter-2.9.tgz
$ gunzip apache-jmeter-2.9.tgz;tar xvf apache-jmeter-2.9.tar
Edited the jmeter.properties file in the /bin folder of the JMeter installation and uncomment the line containing the server.rmi.localport setting. We changed the port to 50000.
server.rmi.localport=50000
Started JMeter server. Make sure the address and the port the server reports listening to are correct.
$ cd ~/jmeter/apache-jmeter-2.9/bin
$ vi jmeter-server
Local (client) JMeter config
Then we set up JMeter to run tests remotely on these instances on our local client machine:
Ensured to use the same version of JMeter as was running on the servers. Installed Java and JMeter as described above.
Enabled remote testing by editing the jmeter.properties file that can be found in the bin folder of the JMeter installation. The parameter remote_hosts needed to be set with the public DNS of the remote servers we were connecting to.
remote_hosts=54.x.x.x,54.x.x.x,54.x.x.x,54.x.x.x,54.x.x.x
We were now able to tell our client JMeter instance to run tests on any or all of our specified remote servers.
Issues and resolutions
Here are the issues we encountered and how we resolved them:
The client failed with:
ERROR - jmeter.engine.ClientJMeterEngine: java.rmi.ConnectException: Connection - refused to host: 127.0.0.1
It was due to the server host returning the private IP address as its address because of Amazon NAT.
We fixed this by setting the parameter RMI_HOST_DEF that the /usr/local/jmeter/bin/jmeter-server script includes in starting the server:
RMI_HOST_DEF=-Djava.rmi.server.hostname=54.xx.xx.xx
Now, the AWS instance returned the server’s external IP, and we could start the test.
When the server node attempted to return the result and tried to connect to the client, the server tried to connect to the external IP address of my local machine. But it threw a connection refused error:
2013/05/16 12:23:37 ERROR - jmeter.samplers.RemoteListenerWrapper: testStarted(host) java.rmi.ConnectException: Connection refused to host: xxx.xxx.xxx.xx;
We resolved this issue by setting up reverse tunnels at the client side.
First, we edited the jmeter.properties file in the /bin folder of the JMeter installation and uncommented the line containing the client.rmi.localport setting. We changed the port to 60000:
client.rmi.localport=60000
Then we connected to each of the servers using SSH, and setup a reverse tunnel to port 60000 on the client.
$ ssh -i ~/.ssh/54-x-x-x.us-east.pem -R 60000:localhost:60000 ubuntu#54.x.x.x
We kept each of these sessions open, as the JMeter server needs to be able to deliver the test results to the client.
Then we set up the JVM_ARGS environment variable on the client, in the jmeter.sh file in the /bin folder:
export JVM_ARGS="-Djava.rmi.server.hostname=localhost"
By doing this, JMeter will tell the servers to connect to localhost:60000 for delivering their results. This ends up being tunneled back to the client.
The SSH connections to the servers kept dropping after staying idle for a little bit. To prevent that from happening, we added a parameter to each of the SSH tunnel set up directing the client to wait 60 seconds before sending a null packet to the server to keep the connection alive:
$ ssh -i ~/.ssh/54-x-x-x.us-east.pem -o ServerAliveInterval=60 -R 60000:localhost:60000 ubuntu#54.x.x.x
(.ssh/config version of all required SSH settings:
Host 54.x.x.x
HostName 54.x.x.x
Port 22
User ubuntu
ServerAliveInterval 60
RemoteForward 127.0.0.1:60000 127.0.0.1:60000
IdentityFile ~/.ssh/54-x-x-x.us-east.pem
IdentitiesOnly yes
Just use ssh 54.x.x.x after setting this up.
)
I just went though this on openstack and found the same issues... no idea why the jmeter remoting documentation only covers half the required steps. You can do it without tunnels or touching the properties files.
You need
All nodes to advertise their public IP - on AWS/OS this defaults to the private IP
Ingress rules for the RMI port which defaults to 1099 - I use this
Ingress rules for the RMI "local" port which defaults to dynamic. Below I use 4001 for the client and 4000 for servers. The port can be the same but note the properties are different.
If you are using your workstation as the client you probably still need tunnels. Above Archana Aggarwal has good tips for tunnels.
Remote servers
Set java.rmi.server.hostname and server.rmi.localport inline or in the properties file.
jmeter-server -Djava.rmi.server.hostname=publicip -Dserver.rmi.localport=4000
Sneaky server on client
You can also run one on the same machine as the client. For clarity I've set java.rmi.server.hostname but left server.rmi.localport as dynamic
jmeter-server -Djava.rmi.server.hostname=localip
Client
Set java.rmi.server.hostname and client.rmi.localport inline or in the properties file. Use -R etc like so:
jmeter -n -t Test.jmx -Rremotepublicip1,remotepublicip2 -Djava.rmi.server.hostname=clientpublicip -Dclient.rmi.localport=4001 -GmypropA=1 -GmypropB=2 -lresults.jtl
When you go for distributed testing using JMeter in AWS, I would suggest you to use docker - which will help us with jmeter test infrastructure very quickly. This way we can also ensure that same version of java and jmeter are installed in all the instances of amazon which is very important of JMeter distributed testing.
Ensure that - you set below properties and ports are open for jmeter-server. [they do not have to be 1099,50000 exactly]
server.rmi.localport=50000
server_port=1099
java.rmi.server.hostname=SERVER_IP
for client
client.rmi.localport=60000
java.rmi.server.hostname=SERVER_IP - this step is very important as the container in aws instance will have their own IP address in the docker network - so master and slave can not communicate. So we explicitly set this property
More info:
http://www.testautomationguru.com/jmeter-distributed-load-testing-using-docker-in-aws/