Skip to content

Adding support for your protocol

Vuong Nguyen edited this page Jun 14, 2019 · 10 revisions

1. Creating a compatible docker image

The first step to have a fully functional library which is compatible with the Genesis platform is creating a docker image. Be sure to include the following Debian dependencies inside the docker image : iperf3 openssh-server iputils-ping vim tmux software-properties-common. Keep in mind that smaller docker images are always better than larger ones, as downloading large images can slow down the initial build time for some users. More information about Docker.

2. Ensure the availability of your image by default

Create a pull request against the Whiteblock dockerfile repository which contains your Dockerfile.

3. Create the library in Genesis

a. Create the directories

Create a directory in the ./protocols directory and in the ./resources named after the protocol you wish to implement.

b. Define the parameters

Create a file called params.json in the new directory that is created inside of ./resources. Inside of this file, Define the custom parameters which will be used by your protocol library. If you do not know which parameters you will need for your library, leave the paramters empty, by writing only [] to the file. Parameters are formatted as a multi-dimensional array, the subarray will always consist of two elements : the name of the parameter and the type of the parameter. For instance, to configure the number of validators, include ["validators","int"] in the JSON array. The currently supported types are : "int","string","[]string", and "bool".

c. Define the default parameters

Create a file called defaults.json and place it in the directory you created inside of ./resources. Inside of this file, set the default values for the parameters in part b. It is highly recommended to define these default parameters even though it is not required. If you are not sure which parameters you will need for your library, leave the parameters empty by writing only {} to the file. The format for this file is simply a JSON object which maps the parameters to their default value. For example, if you wanted to define the default value for validators as 1, you would add "validators":1 to the JSON object.

d. Create the library

Here is a template to get you start, replace YOUR_PROTOCOL with the name of the protocol you are implementing

/*
	Copyright 2019 whiteblock Inc.
	This file is a part of the genesis.

	Genesis is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Genesis is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

//Package YOUR_PROTOCOL handles YOUR_PROTOCOL specific functionality
package YOUR_PROTOCOL

import (
	"github.com/whiteblock/genesis/db"
	"github.com/whiteblock/genesis/protocols/helpers"
	"github.com/whiteblock/genesis/protocols/registrar"
	"github.com/whiteblock/genesis/ssh"
	"github.com/whiteblock/genesis/testnet"
	"github.com/whiteblock/genesis/util"
)

var conf *util.Config = util.GetConfig()

const blockchain = "YOUR_PROTOCOL"

func init() {
	registrar.RegisterBuild(blockchain, build)
	registrar.RegisterAddNodes(blockchain, add)
	registrar.RegisterServices(blockchain,func() []helpers.Service { return nil })
	registrar.RegisterDefaults(blockchain, helpers.DefaultGetDefaultsFn(blockchain))
	registrar.RegisterParams(blockchain, helpers.DefaultGetParamsFn(blockchain))
}

// build builds out a fresh new YOUR_PROTOCOL test network
func build(tn *testnet.TestNet) error {
	tn.BuildState.SetBuildSteps(/**The number of times you will increment the build progress goes here*/)
	/**
	 * TODO implement adding nodes to the network
	 */
	return err
}

// Add handles adding a node to the YOUR_PROTOCOL testnet
func add(tn *testnet.TestNet) error {
	/**
	 * TODO implement adding nodes to the network.
	 */
	return nil
}

e. Define the build process

Define your Genesis ceremony in code! For further instruction, go here.

f. Ensure your library is compiled

Import the Github path to your library in the manager/manager.go file, as a side effect only library.