How Ethereum protocol works with geth - blockchain

I am new to Ethereum and generally to blockchain. I learned that Ethereum blockchain works on Kademlia. The distributed hash table and its working was beautiful and nicely explained by Eleuth P2P.
Now I used geth to connect to the Ethereum Mainnet and it discovered 2 to 3 maximum peers in 5 to 6 minutes.
Now I know the algorithm but my concern is how the first peer is discovered? Because internet is just a big set of routers and different type of computers (server, computer, etc ) and if you broadcast the discovery like in ARP. The internet will be flooded with these peer discovery broadcast messages and this doesn't seems right. So how initially the connections are made? Also we cannot trust a single network for first time connection because this will make the system server and client based and not decentralised so how the initial connections and peer discovery happens?
Are the broadcast message like have TTL like to prevent the circular loop like in TCP I guess? But this also seems a horrible idea to me.
Please explain.

In order to get going initially, geth uses a set of bootstrap nodes whose endpoints are recorded in the source code.
Source: Geth docs
Here's the list of the bootstrap nodes hardcoded in the Geth source code: https://github.com/ethereum/go-ethereum/blob/v1.10.11/params/bootnodes.go#L23
The --bootnodes option allows you to overwrite this list with your own. Example from the above linked docs:
geth --bootnodes enode://pubkey1#ip1:port1,enode://pubkey2#ip2:port2,enode://pubkey3#ip3:port3

Related

Where to get rpc server ethereum

I am new to cryptocurrency development.Today I learned that the ETH transaction requires an RPC server. I found a list of RPC servers like Binance. But is there any official RPC server? Or do you need to create it yourself? What is the difference? Where to get the official exchange rate eth to USD? Many thanks.
There is no official centralised server, because peer-to-peer cryptocurrencies are about decentralisation. Creating single points of failure is bad.
Ethereum software-as-a-service node alternatives can found on:
https://ethereumnodes.com
I also recommend you to try to host the node yourself.

Blockchain - How do implementations do peer-to-peer discovery?

I'm currently learning how blockchain works, just out of personal curiosity. I'm going through this course and now I've setup the peer-to-peer connectivity using web sockets. Multiple instances of the blockchain application can now run and communicate with each other using these sockets.
The one downside of the course implementation is how the instances know how to find each other. Essentially they need to be explicitly configured to communicate. In my current project, I have it setup with 3 instances. One opens a socket on port 5001 and connects to nothing else. The other opens a socket on port 5002 and connects to the instance on 5001. And the third opens a socket on port 5003 and connects to the instances on 5002 and 5001.
The point is, all three are explicitly configured like that. All three must be started in exactly that order so they can properly connect to the others. While this is fine for a practice implementation, I know that's not how a real blockchain implementation must be working out there in the wild. There must be some mechanism of discovery that takes place which would allow any of these instances to locate whichever others are currently running.
Networking is not my area of expertise, so I'm at a loss on how this could be done.
P2P cryptocurrency clients usually have hardcoded list of peers. These peers are managed by community. If you start you client for the first time, these peers is all you have.
When you connect to another node, it saves your IP in its internal list. Any node can request this list from another node. In this way your client can discover other nodes. Client application saves list of nodes to disk. On the next startup you have hardcoded nodes and nodes you were connected last time. Some nodes may be offline, but this is ok.
More detailed explanation in case of Bitcoin: https://developer.bitcoin.org/devguide/p2p_network.html#peer-discovery

Data on Private Ethereum blockchain lost/disappears after couple of days

I am deploying a private ethereum blockchain (geth) on a virtual machine on Azure. Upon deploying my Solidity contracts on the blockchain and launching my NodeJS application to it, I am able to add data normally through web apis of the nodejs Loopback App and everything is working fine and I can see the added data using the GET apis.
However, after 1-2-3 days (random) I am not able to retrieve the data I added through my GET apis, while am still able to add new data which confirms that Geth is running fine and wasn't interrupted.
I am running geth using:
geth --datadir ./myDataDir --rpc --networkid 1441 console 2>> myEth.log
myEth.log isn't showing anything wrong, nodejs logs are clean as well.
eth.syncing shows false which means the network is synced.
size of myDataDir folder is still increasing so logically data should be somewhere there but it's not showing.
This is not a private blockchain!
--networkid 1441
This only says that you communicate with clients that also run a network with ID 1441. It might be unlikely, but if someone else runs a network with ID 1441, this node will connect to your node just fine. And in case, the other network with the same ID has a longer (more "heavier") chain, this overwrites your local chain.
To avoid this, try a more random network ID, maybe 7-9 digits, and disable discovery with
--nodiscovery
Or just use the --dev preset.

Is there any way to get data from blockchain of tendermint API

Is there any way to get data from blockchain of tendermint API?
tendermint
Of course. What data are you looking for? If you run the node with default settings and go to localhost:46657/ you see a list of end points.
If you want a block, try localhost:46657/block?height=42
The port number 46657 did not work for me, then I tried printing tendermint port and tried hitting http://localhost:57943/block?height=99.
Where 99 was the height of my 1st block in the blockchain
57943 is my tendermint port.
So may be it is taking port number dynamically.
The best way to access blockchain data from tendermint is using rpc endpoint.The rpc endpoint port can be configured in config.toml file.When you access the endpoint you can see various endpoints few which require arguments and few which don't.The default port was changed from 46657 to 266657 in later versions.

How can I add a node to an existing network?

I created a network with 4 peers using docker-compose and docker for Mac.
I deploy my blockchain on this network successfully.
Now I'm launching a 5th peer using another yml file using the details of one of the previous peer as discovery node.
It appears in the list returned by http://localhost:7050/network/peers however my blockchain is not deployed on this peer and I cannot use it to process transactions.
Do I have to deploy the chaincode again on this peer? Did I miss something?
This is limitation in Fabric’s versions 0.5 and 0.6
Network configuration cannot be changed in realtime. In case If you use PBFT consensus, network configuration is hardcoded in:
“fabric/consensus/pbft/config.yaml"
# Maximum number of validators/replicas we expect in the network
# Keep the "N" in quotes, or it will be interpreted as "false".
"N": 4
The challenge is in updating configuration on all peers synchronously, otherwise they will not be able to reach consensus.
In one of next Fabric versions this configuration’s parameter will be moved to blockchain and it will be possible to add new peers and modify consensus configuration on the fly.
Update for question in comment:
Saw only this high level Roadmap proposal: