• Time to read 2 minutes
Syncing Geth in 2018

Syncing Geth in 2018

It's been 6 months since my last post and much has changed in the Cryptocurrency space. I conducted my first Cryptocurrency class 'A Beginner's Introduction to Blockchain Technology with Ethereum and Solidity Smart Contract' to a group of participants from various backgrounds - developers, lawyers, engineers and crypto-enthusiasts. One of the greatest early challenges that I encounter when I started working with Ethereum is syncing it to the Blockchain. I believe this hasn't changed for many people who are just starting out. In fact, the single of popular post on this blog, and on my Medium.com account is the instructions on syncing to the Ethereum blockchain. Light-sync, which is the technique of letting Geth download the minimal amount of transaction blocks, and checking with peers that you are connected to whenever your node needs information about transactions is now relatively stable. It is possible to connect your Geth instance onto the Ethereum blockchain in as little as 15 minutes. 

For me, this is a godsend because no participants of my workshop will hang around and wait for a day just so that their Geth instance is well synced. This is how I do it.

Starting Geth

Start by installing Geth. This set of instructions assumes that you are running Linux.

sudo apt-get install ethereum

Start Geth with the following command

geth --testnet --syncmode "light" --rpc --rpcapi db,eth,net,web3,personal,admin --cache=1024  --rpcport 8545 

Here, I am assuming that you are connect to the Ropsten testnet. The keyword here is --syncmode "light". This tells Geth that you are performing a light sync. 

Geth now starts syncing.

Checking Geth

Open a new window. Bring up your Geth console.

geth attach http://<your geth ip address>:8545 (e.g. http://127.0.0.1:8545)

Now run this command:

web3.eth.syncing

Seeing this means your Geth instance is still in the middle of syncing:

{ 
    currentBlock: 1600000,
    highestBlock: 1700000,
    knownStates: 1190000,
    pulledStates: 1140000,
    startingBlock: 1730000
}

In the example above, the highest block is currently 1,700,000. Our Geth node has currently synced up to 1,600,000 and thus has another 100,000 blocks to go before it syncs completely with the Ethereum Blockchain. When syncing is completed you should see:

false

Specifying Peers

A common problem you may encounter when syncing in light mode on Ropsten is that syncing just does not happen. 

While syncing in light mode, we are connecting to multiple peer nodes that provides us with the transactions that we need to reference. However, some nodes on the Ethereum Blockchian network will not let you sync, create contracts or execute transaction successfully. Here are some symptoms that you may encounter.

  • Connection keeps dropping
  • Unable to execute transactions
  • Unable to execute smart contracts
  • Syncing does not proceed

When such cases occur, attach to the Geth console with the following command:

geth attach <your geth ip address>:8545 (e.g. http://127.0.0.1:8545)

Execute the following commands to attach to 3 peers which have been tested to work properly:

admin.addPeer("enode://1d1a996a7cc0398e551441d646a2490157390e6efcaed2eb4745df1600706d1eab8d8eb4e6aec5b7fcffb46f468edc9b5366a01e214fd46cba28a3ce08d25431@136.243.41.67:30304")

admin.addPeer("enode://30b7ab30a01c124a6cceca36863ece12c4f5fa68e3ba9b0b51407ccc002eeed3b3102d20a88f1c1d3c3154e2449317b8ef95090e77b312d5cc39354f86d5d606@52.176.7.10:30303")

admin.addPeer("enode://af34d7c451ffd99a5ff81bc4bac72ef4b033590875959b046aaa23e4d35195695dabaa46731d8bbe857f7202e6517d164e340c0df14ea0f04fe065f0e3e48d72@52.208.46.161:30311")

As at the time of writing this blog post, the three Geth peers above accepts connections from light nodes.

You may also search the internet with the keyword “ropsten peers” to find new peers to add to your Geth node.

Photo by Gabriel Gusmao on Unsplash