Angel \”Java\” Lopez on Blog

June 11, 2017

Running an Ethereum/RSK Node

Filed under: Blockchain, Ethereum, Open Source Projects, RSK — ajlopez @ 2:43 pm

The RSK public testnet was launched, and the core source was opened. If don’t know what RSK is, please visit:

http://rsk.co/

Technically, it is a fork of Ethereum (Java source), with a 2-way peg with Bitcoin, and merge-mining capabilities. You can run your own node, alone, in your own network, or join it to the public testnet. There are instructions at thecore project github wiki:

https://github.com/rsksmart/rskj/wiki

In this post, I want to describe my usual workflow, to run experiments with RSK implementation and ideas (disclaimer:I’m a member of RSK development team, but this is a description of my personal experiments). First, you have to downloadthe source code from:

https://github.com/rsksmart/rskj

Currently, the most updated published version is at branch Ginger:

https://github.com/rsksmart/rskj/tree/ginger

Also, you can clone the repository into your own one. Once you have the source code, you can compile using IntelliJ  deaCommunity Edition, or use the command line:

.\gradlew build shadow -x testnet

(I’m usually work with Windows, in Linux, Mac, you must use the normal /). More details at:

https://github.com/rsksmart/rskj/wiki/Compile-and-run-a-RSK-node-locally

The shadow option is to build a jar with all the dependencies. The -x test skips the run of test from build step. The command generates a .jar file in one subdirectory. Then, you can execute

cd rskj-core\build\libs
java -Drsk.conf.file=<path> -cp rskj-core-0.2.0-GINGER-all.jar co.rsk.Start

What config file to use and to configure it? More info at:

https://github.com/rsksmart/rskj/wiki/How-to-initialize-RSK-node-configuration-file-settings

An initial config file at:

https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/resources/config/rsk-sample.conf

You must set a unique nodeId for your instance. You can generate a nodeId using the command line:

java -cp rskj-core-0.2.0-GINGER-all.jar co.rsk.GenNodeKeyId

It dumps a JSON file to console. You must copy the private key and the node id, to your config file:

# Private key of the peer
nodeId = 66cf57...
privateKey = 46f850...

You only need to copy the privateKey to run the node, but you can include the nodeId also for your own reference. The other line to configure is the coinbase secret:

# this string is computed
# to be eventually the address
# that get the miner reward
coinbase.secret = mytreasure

You must put an arbitrary string here.

To allow the CORS (Cross-Origin Resource Sharing) for your JSON RPC (Remote Procedure Call), set the cors property:

rpc {
    enabled = true		# you can disable rpc
    port = 4444
    
    cors = "*.rsk.co"    # you can put "localhost here"

The RPC capability is only used to query the node, and disabling it does not interfere with the normalwork of the node. How the node knows how to connect to the public Testnet? There is a list of bootstrap nodes:

peer {
	discovery = {
        # if peer discovery is off
        # the peer window will show
        # only what retrieved by active
        # peer [true/false]
        enabled = true

        # List of the peers to start
        # the search of the online peers
        # values: [ip:port]
        ip.list = [
            "bootstrap01.testnet.rsk.co:50505",
            "bootstrap02.testnet.rsk.co:50505",
            "bootstrap03.testnet.rsk.co:50505",
            "bootstrap04.testnet.rsk.co:50505"
        ]

to use in what is call the “peer discovery” process. You can disable them if you want only to use your own node in your network.

If you want to run MANY local nodes, you must have MANY configuration file. In these files, adjust also the properties:

    # Peer for server to listen for incoming connections
    # 50505 for testnet
    listen.port = 50505 # ie to 50506

and the already mentioned:

rpc {
    enabled = true
    port = 4444		# ie to 4445

Additionally, you can set your own network id, so your local o networked nodes only work for this network:

    # Network id
    networkId = 777  # ie to 42

You can also specify in each of your nodes the active nodes to connect, instead of using peer discovery and bootstrap public nodes:

    # Boot node list
    # Use to connect to specific nodes
    active = [    
        #{ 
        #    ip = 11.22.33.44
        #    port = 50505
        #    nodeId = e437a483...
        #}
    ]

As usual, you can set the machine name instead of IP number, using the same property ip.

If you want your node mine new blocks, change these properties to true:

# miner options
miner {
    server.enabled = false  # change to true
    client.enabled = false	# change to true

If you change only the server.enabled property to true, you can expose the new block to merge mining process, but this feature is beyond the scope of this post.

Any other question? You can visit the RSKJ gitter channel:

https://gitter.im/rsksmart/rskj

Enjoy!

RSK is hiring! Interested?

https://twitter.com/RSKsmart/status/872169805515718657

Stay tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

 

Create a free website or blog at WordPress.com.