initialization

package
v11.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: Apache-2.0 Imports: 44 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 Osmosis version.

For example, while the latest Osmosis version is v9, we might want to spin up a chain of v8 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 (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("", "osmosis-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 a the container was correctly mounted on a volume, it produces the following:

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

Example:

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

$:/tmp/osmosis-e2e-testnet-1167397304/osmo-test-a $ cd  osmo-test-a

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

$:/tmp/osmosis-e2e-testnet-1167397304/osmo-test-a $ cd  osmo-test-a-osmosis-00

$:/tmp/osmosis-e2e-testnet-1167397304/osmo-test-a/osmo-test-a-osmosis-00 $ ls
config  data  keyring-test  wasm
  • Here we mounted the container on /tmp/osmosis-e2e-testnet-1167397304/osmo-testas a volume
  • < chain id > = "a"
  • 4 NodeConfigs were provided via the --config flag
  • osmo-test-a-encode output file corresponds to the serialized Chain struct defined in tests/e2e/chain/chain.go
Initializing a Node (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
	OsmoDenom           = "uosmo"
	StakeDenom          = "stake"
	OsmoIBCDenom        = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518"
	StakeIBCDenom       = "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B7787"
	MinGasPrice         = "0.000"
	IbcSendAmount       = 3300000000
	ValidatorWalletName = "val"
	// chainA
	ChainAID      = "osmo-test-a"
	OsmoBalanceA  = 200000000000
	StakeBalanceA = 110000000000
	StakeAmountA  = 100000000000
	// chainB
	ChainBID      = "osmo-test-b"
	OsmoBalanceB  = 500000000000
	StakeBalanceB = 440000000000
	StakeAmountB  = 400000000000
)

Variables

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

	InitBalanceStrA = fmt.Sprintf("%d%s,%d%s", OsmoBalanceA, OsmoDenom, StakeBalanceA, StakeDenom)
	InitBalanceStrB = fmt.Sprintf("%d%s,%d%s", OsmoBalanceB, OsmoDenom, StakeBalanceB, StakeDenom)
	OsmoToken       = sdk.NewInt64Coin(OsmoDenom, IbcSendAmount)  // 3,300uosmo
	StakeToken      = sdk.NewInt64Coin(StakeDenom, IbcSendAmount) // 3,300ustake

)

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) (*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, votingPeriod time.Duration, 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