You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
6.8 KiB

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