bitbucket.org/number571/tendermint@v0.8.14/test/e2e/pkg/manifest.go (about)

     1  package e2e
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/BurntSushi/toml"
     8  )
     9  
    10  // Manifest represents a TOML testnet manifest.
    11  type Manifest struct {
    12  	// IPv6 uses IPv6 networking instead of IPv4. Defaults to IPv4.
    13  	IPv6 bool `toml:"ipv6"`
    14  
    15  	// InitialHeight specifies the initial block height, set in genesis. Defaults to 1.
    16  	InitialHeight int64 `toml:"initial_height"`
    17  
    18  	// InitialState is an initial set of key/value pairs for the application,
    19  	// set in genesis. Defaults to nothing.
    20  	InitialState map[string]string `toml:"initial_state"`
    21  
    22  	// Validators is the initial validator set in genesis, given as node names
    23  	// and power:
    24  	//
    25  	// validators = { validator01 = 10; validator02 = 20; validator03 = 30 }
    26  	//
    27  	// Defaults to all nodes that have mode=validator at power 100. Explicitly
    28  	// specifying an empty set will start with no validators in genesis, and
    29  	// the application must return the validator set in InitChain via the
    30  	// setting validator_update.0 (see below).
    31  	Validators *map[string]int64 `toml:"validators"`
    32  
    33  	// ValidatorUpdates is a map of heights to validator names and their power,
    34  	// and will be returned by the ABCI application. For example, the following
    35  	// changes the power of validator01 and validator02 at height 1000:
    36  	//
    37  	// [validator_update.1000]
    38  	// validator01 = 20
    39  	// validator02 = 10
    40  	//
    41  	// Specifying height 0 returns the validator update during InitChain. The
    42  	// application returns the validator updates as-is, i.e. removing a
    43  	// validator must be done by returning it with power 0, and any validators
    44  	// not specified are not changed.
    45  	ValidatorUpdates map[string]map[string]int64 `toml:"validator_update"`
    46  
    47  	// Nodes specifies the network nodes. At least one node must be given.
    48  	Nodes map[string]*ManifestNode `toml:"node"`
    49  
    50  	// KeyType sets the curve that will be used by validators.
    51  	// Options are gost512 & gost256
    52  	KeyType string `toml:"key_type"`
    53  
    54  	// Evidence indicates the amount of evidence that will be injected into the
    55  	// testnet via the RPC endpoint of a random node. Default is 0
    56  	Evidence int `toml:"evidence"`
    57  
    58  	// LogLevel sets the log level of the entire testnet. This can be overridden
    59  	// by individual nodes.
    60  	LogLevel string `toml:"log_level"`
    61  
    62  	// DisableLegacyP2P enables use of the new p2p layer for all nodes in a test.
    63  	DisableLegacyP2P bool `toml:"disable_legacy_p2p"`
    64  
    65  	// QueueType describes the type of queue that the system uses internally
    66  	QueueType string `toml:"queue_type"`
    67  
    68  	// Number of bytes per tx. Default is 1kb (1024)
    69  	TxSize int64
    70  }
    71  
    72  // ManifestNode represents a node in a testnet manifest.
    73  type ManifestNode struct {
    74  	// Mode specifies the type of node: "validator", "full", "light" or "seed".
    75  	// Defaults to "validator". Full nodes do not get a signing key (a dummy key
    76  	// is generated), and seed nodes run in seed mode with the PEX reactor enabled.
    77  	Mode string `toml:"mode"`
    78  
    79  	// Seeds is the list of node names to use as P2P seed nodes. Defaults to none.
    80  	Seeds []string `toml:"seeds"`
    81  
    82  	// PersistentPeers is a list of node names to maintain persistent P2P
    83  	// connections to. If neither seeds nor persistent peers are specified,
    84  	// this defaults to all other nodes in the network. For light clients,
    85  	// this relates to the providers the light client is connected to.
    86  	PersistentPeers []string `toml:"persistent_peers"`
    87  
    88  	// Database specifies the database backend: "goleveldb", "cleveldb",
    89  	// "rocksdb", "boltdb", or "badgerdb". Defaults to goleveldb.
    90  	Database string `toml:"database"`
    91  
    92  	// ABCIProtocol specifies the protocol used to communicate with the ABCI
    93  	// application: "unix", "tcp", "grpc", or "builtin". Defaults to unix.
    94  	// builtin will build a complete Tendermint node into the application and
    95  	// launch it instead of launching a separate Tendermint process.
    96  	ABCIProtocol string `toml:"abci_protocol"`
    97  
    98  	// PrivvalProtocol specifies the protocol used to sign consensus messages:
    99  	// "file", "unix", "tcp", or "grpc". Defaults to "file". For tcp and unix, the ABCI
   100  	// application will launch a remote signer client in a separate goroutine.
   101  	// For grpc the ABCI application will launch a remote signer server.
   102  	// Only nodes with mode=validator will actually make use of this.
   103  	PrivvalProtocol string `toml:"privval_protocol"`
   104  
   105  	// StartAt specifies the block height at which the node will be started. The
   106  	// runner will wait for the network to reach at least this block height.
   107  	StartAt int64 `toml:"start_at"`
   108  
   109  	// FastSync specifies the fast sync mode: "" (disable), "v0" or "v2".
   110  	// Defaults to disabled.
   111  	FastSync string `toml:"fast_sync"`
   112  
   113  	// Mempool specifies which version of mempool to use. Either "v0" or "v1"
   114  	Mempool string `toml:"mempool_version"`
   115  
   116  	// StateSync enables state sync. The runner automatically configures trusted
   117  	// block hashes and RPC servers. At least one node in the network must have
   118  	// SnapshotInterval set to non-zero, and the state syncing node must have
   119  	// StartAt set to an appropriate height where a snapshot is available.
   120  	StateSync bool `toml:"state_sync"`
   121  
   122  	// PersistInterval specifies the height interval at which the application
   123  	// will persist state to disk. Defaults to 1 (every height), setting this to
   124  	// 0 disables state persistence.
   125  	PersistInterval *uint64 `toml:"persist_interval"`
   126  
   127  	// SnapshotInterval specifies the height interval at which the application
   128  	// will take state sync snapshots. Defaults to 0 (disabled).
   129  	SnapshotInterval uint64 `toml:"snapshot_interval"`
   130  
   131  	// RetainBlocks specifies the number of recent blocks to retain. Defaults to
   132  	// 0, which retains all blocks. Must be greater that PersistInterval,
   133  	// SnapshotInterval and EvidenceAgeHeight.
   134  	RetainBlocks uint64 `toml:"retain_blocks"`
   135  
   136  	// Perturb lists perturbations to apply to the node after it has been
   137  	// started and synced with the network:
   138  	//
   139  	// disconnect: temporarily disconnects the node from the network
   140  	// kill:       kills the node with SIGKILL then restarts it
   141  	// pause:      temporarily pauses (freezes) the node
   142  	// restart:    restarts the node, shutting it down with SIGTERM
   143  	Perturb []string `toml:"perturb"`
   144  
   145  	// Log level sets the log level of the specific node i.e. "info".
   146  	// This is helpful when debugging a specific problem. This overrides the network
   147  	// level.
   148  	LogLevel string `toml:"log_level"`
   149  
   150  	// UseNewP2P enables use of the new p2p layer for this node.
   151  	DisableLegacyP2P bool `toml:"disable_legacy_p2p"`
   152  }
   153  
   154  // Save saves the testnet manifest to a file.
   155  func (m Manifest) Save(file string) error {
   156  	f, err := os.Create(file)
   157  	if err != nil {
   158  		return fmt.Errorf("failed to create manifest file %q: %w", file, err)
   159  	}
   160  	return toml.NewEncoder(f).Encode(m)
   161  }
   162  
   163  // LoadManifest loads a testnet manifest from a file.
   164  func LoadManifest(file string) (Manifest, error) {
   165  	manifest := Manifest{}
   166  	_, err := toml.DecodeFile(file, &manifest)
   167  	if err != nil {
   168  		return manifest, fmt.Errorf("failed to load testnet manifest %q: %w", file, err)
   169  	}
   170  	return manifest, nil
   171  }