initialization

package
v2.0.0-alpha1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 41 Imported by: 0

README

initializaion package

Motivation

This package contains all logic necessary for initializing configuration data either for a new chain or a single node via Docker containers.

The motivation for doing this via Docker is to be able to initialize configs of any Chain4Energy version.

For example, while the latest Chain4Energy version is v1.2.0, we might want to spin up a chain of v1.1.0 and test the upgrade.

Additionally, there are known file permission errors when initializing configurations as non-root. This is troublesome both in CI and locally. Doing this via Docker instead, allows us to initialize these files as a root user, bypassing the file permission issues.

Structure

Each folder in tests/e2e/initialization corresponds to a standalone script. At the time of this writing, we have the following scripts/folders: - chain - for initializing a full chain - node - for initializing a single node

All initialization scripts share a common init.Dockerfile that takes an argument E2E_SCRIPT_NAME. By providing the desired script name to the Dockerfile, we are able to build the image that can run any of these local scripts

Scripts

Initializing a Chain

From root folder:

make docker-build-e2e-init-chain

This script will build a Docker image that runs a script in the chain package and initializes all configuration files necessary for starting up an e2e chain.

Running The Container

When running a container with the specified script, it must mount a folder on a volume to have all configuration files produced.

Additionally, it takes the following arguments:

  • --data-dir
    • the location of where the configuration data is written inside the container (string)
  • --chain-id
    • the id of the chain (string)
  • --config
    • serialized node configurats (e.g. Pruning and Snapshot options). These correspond to the stuct NodeConfig, located in tests/e2e/chain/config.go The number of initialized validators on the new chain corresponds to the number of NodeConfigs provided by this parameter
  • --voting-period
    • The configurable voting period duration for the chain
tmpDir, _ := os.MkdirTemp("", "chain4energyn-e2e-testnet-")

initResource, _ = s.dkrPool.RunWithOptions(
&dockertest.RunOptions{
 Name:       fmt.Sprintf("%s", chainId),
 Repository: s.dockerImages.InitRepository,
 Tag:        s.dockerImages.InitTag,
 NetworkID:  s.dkrNet.Network.ID,
 Cmd: []string{
  fmt.Sprintf("--data-dir=%s", tmpDir),
  fmt.Sprintf("--chain-id=%s", chainId),
  fmt.Sprintf("--config=%s", nodeConfigBytes),
  fmt.Sprintf("--voting-period=%v", votingPeriodDuration),
 },
 User: "root:root",
 Mounts: []string{
  fmt.Sprintf("%s:%s", tmpDir, tmpDir), 
 },
},
noRestart,
)
Container Output

Assumming that the container was correctly mounted on a volume, it produces the following:

  • chain4energy-test-< chain id >-encode file
    • This is encoded metadata about the newly created chain with its nodes
  • chain4energy-test-< chain id > folder
  • For every NodeCondig provided to the container, it will produce a folder with the respective node configs

Example:

$:/tmp/chain4energy-e2e-testnet-1167397304 $ ls
osmo-test-a  osmo-test-a-encode

$:/tmp/chain4energy-e2e-testnet-1167397304/c4e-chain-test-a $ cd  osmo-test-a

$:/tmp/chain4energy-e2e-testnet-1167397304/c4e-chain-test-a $ ls
c4e-chain-test-a-00  c4e-chain-test-a-11  c4e-chain-test-a-22  osmo-test-a-33

$:/tmp/chain4energy-e2e-testnet-1167397304/c4e-chain-test-a $ cd  c4e-chain-test-a-00

$:/tmp/chain4energy-e2e-testnet-1167397304/c4e-chain-test-a/c4e-chain-test-a-00 $ ls
config  data  keyring-test  wasm
  • Here we mounted the container on /tmp/chain4energy-e2e-testnet-1167397304/c4e-chain-testas a volume
  • < chain id > = "a"
  • 4 NodeConfigs were provided via the --config flag
  • c4e-chain-test-a-encode output file corresponds to the serialized Chain struct defined in tests/e2e/chain/chain.go
Initializing a Node
make docker-build-e2e-init-node

This script will build a Docker image that runs a script in the node package and initializes all data necessary for starting up a new node.

Documentation

Index

Constants

View Source
const (
	// common
	C4eDenom            = "uc4e"
	MinGasPrice         = "0.000"
	IbcSendAmount       = 3300000000
	ValidatorWalletName = "val"
	// chainA
	ChainAID      = "c4e-chain-test-a"
	C4eBalanceA   = 200000000000
	StakeBalanceA = 110000000000
	StakeAmountA  = 100000000000
	// chainB
	ChainBID      = "c4e-chain-test-b"
	C4eBalanceB   = 500000000000
	StakeBalanceB = 440000000000
	StakeAmountB  = 400000000000
)

Variables

View Source
var (
	StakeAmountIntA  = math.NewInt(StakeAmountA)
	StakeAmountCoinA = sdk.NewCoin(C4eDenom, StakeAmountIntA)
	StakeAmountIntB  = math.NewInt(StakeAmountB)
	StakeAmountCoinB = sdk.NewCoin(C4eDenom, StakeAmountIntB)

	InitBalanceStrA = fmt.Sprintf("%d%s", C4eBalanceA+StakeBalanceA, C4eDenom)
	InitBalanceStrB = fmt.Sprintf("%d%s", C4eBalanceB+StakeBalanceB, C4eDenom)
	C4eToken        = sdk.NewInt64Coin(C4eDenom, IbcSendAmount) // 3,300uosmo

)

Functions

This section is empty.

Types

type Chain

type Chain struct {
	ChainMeta ChainMeta `json:"chainMeta"`
	Nodes     []*Node   `json:"validators"`
}

func InitChain

func InitChain(id, dataDir string, nodeConfigs []*NodeConfig, votingPeriod, expeditedVotingPeriod time.Duration, forkHeight int, appState map[string]json.RawMessage) (*Chain, error)

type ChainMeta

type ChainMeta struct {
	DataDir string `json:"dataDir"`
	Id      string `json:"id"`
}

type Node

type Node struct {
	Name          string `json:"name"`
	ConfigDir     string `json:"configDir"`
	Mnemonic      string `json:"mnemonic"`
	PublicAddress string `json:"publicAddress"`
	PublicKey     string `json:"publicKey"`
	PeerId        string `json:"peerId"`
	IsValidator   bool   `json:"isValidator"`
}

func InitSingleNode

func InitSingleNode(chainId, dataDir string, existingGenesisDir string, nodeConfig *NodeConfig, trustHeight int64, trustHash string, stateSyncRPCServers []string, persistentPeers []string) (*Node, error)

type NodeConfig

type NodeConfig struct {
	Name               string // name of the config that will also be assigned to Docke container.
	Pruning            string // default, nothing, everything, or custom
	PruningKeepRecent  string // keep all of the last N states (only used with custom pruning)
	PruningInterval    string // delete old states from every Nth block (only used with custom pruning)
	SnapshotInterval   uint64 // statesync snapshot every Nth block (0 to disable)
	SnapshotKeepRecent uint32 // number of recent snapshots to keep and serve (0 to keep all)
	IsValidator        bool   // flag indicating whether a node should be a validator
}

NodeConfig is a confiuration for the node supplied from the test runner to initialization scripts. It should be backwards compatible with earlier versions. If this struct is updated, the change must be backported to earlier branches that might be used for upgrade testing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL