github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/test/e2e/pkg/manifest.go (about) 1 package e2e 2 3 import ( 4 "fmt" 5 "os" 6 "time" 7 8 "github.com/BurntSushi/toml" 9 ) 10 11 // Manifest represents a TOML testnet manifest. 12 type Manifest struct { 13 // IPv6 uses IPv6 networking instead of IPv4. Defaults to IPv4. 14 IPv6 bool `toml:"ipv6"` 15 16 // InitialHeight specifies the initial block height, set in genesis. Defaults to 1. 17 InitialHeight int64 `toml:"initial_height"` 18 19 // InitialState is an initial set of key/value pairs for the application, 20 // set in genesis. Defaults to nothing. 21 InitialState map[string]string `toml:"initial_state"` 22 23 // Validators is the initial validator set in genesis, given as node names 24 // and power: 25 // 26 // validators = { validator01 = 10; validator02 = 20; validator03 = 30 } 27 // 28 // Defaults to all nodes that have mode=validator at power 100. Explicitly 29 // specifying an empty set will start with no validators in genesis, and 30 // the application must return the validator set in InitChain via the 31 // setting validator_update.0 (see below). 32 Validators *map[string]int64 `toml:"validators"` 33 34 // ValidatorUpdates is a map of heights to validator names and their power, 35 // and will be returned by the ABCI application. For example, the following 36 // changes the power of validator01 and validator02 at height 1000: 37 // 38 // [validator_update.1000] 39 // validator01 = 20 40 // validator02 = 10 41 // 42 // Specifying height 0 returns the validator update during InitChain. The 43 // application returns the validator updates as-is, i.e. removing a 44 // validator must be done by returning it with power 0, and any validators 45 // not specified are not changed. 46 ValidatorUpdates map[string]map[string]int64 `toml:"validator_update"` 47 48 // Nodes specifies the network nodes. At least one node must be given. 49 Nodes map[string]*ManifestNode `toml:"node"` 50 51 // KeyType sets the curve that will be used by validators. 52 // Options are ed25519 & secp256k1 53 KeyType string `toml:"key_type"` 54 55 // ABCIProtocol specifies the protocol used to communicate with the ABCI 56 // application: "unix", "tcp", "grpc", or "builtin". Defaults to builtin. 57 // builtin will build a complete Ostracon node into the application and 58 // launch it instead of launching a separate Ostracon process. 59 ABCIProtocol string `toml:"abci_protocol"` 60 61 // Add artificial delays to each of the main ABCI calls to mimic computation time 62 // of the application 63 PrepareProposalDelay time.Duration `toml:"prepare_proposal_delay"` 64 ProcessProposalDelay time.Duration `toml:"process_proposal_delay"` 65 CheckTxDelay time.Duration `toml:"check_tx_delay"` 66 // TODO: add vote extension and finalize block delay (@cmwaters) 67 68 LoadTxSizeBytes int `toml:"load_tx_size_bytes"` 69 LoadTxBatchSize int `toml:"load_tx_batch_size"` 70 LoadTxConnections int `toml:"load_tx_connections"` 71 } 72 73 // ManifestNode represents a node in a testnet manifest. 74 type ManifestNode struct { 75 // Mode specifies the type of node: "validator", "full", "light" or "seed". 76 // Defaults to "validator". Full nodes do not get a signing key (a dummy key 77 // is generated), and seed nodes run in seed mode with the PEX reactor enabled. 78 Mode string `toml:"mode"` 79 80 // Version specifies which version of Ostracon this node is. Specifying different 81 // versions for different nodes allows for testing the interaction of different 82 // node's compatibility. Note that in order to use a node at a particular version, 83 // there must be a docker image of the test app tagged with this version present 84 // on the machine where the test is being run. 85 Version string `toml:"version"` 86 87 // Seeds is the list of node names to use as P2P seed nodes. Defaults to none. 88 Seeds []string `toml:"seeds"` 89 90 // PersistentPeers is a list of node names to maintain persistent P2P 91 // connections to. If neither seeds nor persistent peers are specified, 92 // this defaults to all other nodes in the network. For light clients, 93 // this relates to the providers the light client is connected to. 94 PersistentPeers []string `toml:"persistent_peers"` 95 96 // Database specifies the database backend: "goleveldb", "cleveldb", 97 // "rocksdb", "boltdb", or "badgerdb". Defaults to goleveldb. 98 Database string `toml:"database"` 99 100 // PrivvalProtocol specifies the protocol used to sign consensus messages: 101 // "file", "unix", or "tcp". Defaults to "file". For unix and tcp, the ABCI 102 // application will launch a remote signer client in a separate goroutine. 103 // Only nodes with mode=validator will actually make use of this. 104 PrivvalProtocol string `toml:"privval_protocol"` 105 106 // StartAt specifies the block height at which the node will be started. The 107 // runner will wait for the network to reach at least this block height. 108 StartAt int64 `toml:"start_at"` 109 110 // FastSync specifies the fast sync mode: "" (disable), "v0", "v1", or "v2". 111 // Defaults to disabled. 112 FastSync string `toml:"fast_sync"` 113 114 // StateSync enables state sync. The runner automatically configures trusted 115 // block hashes and RPC servers. At least one node in the network must have 116 // SnapshotInterval set to non-zero, and the state syncing node must have 117 // StartAt set to an appropriate height where a snapshot is available. 118 StateSync bool `toml:"state_sync"` 119 120 // PersistInterval specifies the height interval at which the application 121 // will persist state to disk. Defaults to 1 (every height), setting this to 122 // 0 disables state persistence. 123 PersistInterval *uint64 `toml:"persist_interval"` 124 125 // SnapshotInterval specifies the height interval at which the application 126 // will take state sync snapshots. Defaults to 0 (disabled). 127 SnapshotInterval uint64 `toml:"snapshot_interval"` 128 129 // RetainBlocks specifies the number of recent blocks to retain. Defaults to 130 // 0, which retains all blocks. Must be greater that PersistInterval and 131 // SnapshotInterval. 132 RetainBlocks uint64 `toml:"retain_blocks"` 133 134 // Perturb lists perturbations to apply to the node after it has been 135 // started and synced with the network: 136 // 137 // disconnect: temporarily disconnects the node from the network 138 // kill: kills the node with SIGKILL then restarts it 139 // pause: temporarily pauses (freezes) the node 140 // restart: restarts the node, shutting it down with SIGTERM 141 Perturb []string `toml:"perturb"` 142 143 // SendNoLoad determines if the e2e test should send load to this node. 144 // It defaults to false so unless the configured, the node will 145 // receive load. 146 SendNoLoad bool `toml:"send_no_load"` 147 } 148 149 // Save saves the testnet manifest to a file. 150 func (m Manifest) Save(file string) error { 151 f, err := os.Create(file) 152 if err != nil { 153 return fmt.Errorf("failed to create manifest file %q: %w", file, err) 154 } 155 return toml.NewEncoder(f).Encode(m) 156 } 157 158 // LoadManifest loads a testnet manifest from a file. 159 func LoadManifest(file string) (Manifest, error) { 160 manifest := Manifest{} 161 _, err := toml.DecodeFile(file, &manifest) 162 if err != nil { 163 return manifest, fmt.Errorf("failed to load testnet manifest %q: %w", file, err) 164 } 165 return manifest, nil 166 }