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.

169 lines
6.7 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. }
  55. // ManifestNode represents a node in a testnet manifest.
  56. type ManifestNode struct {
  57. // Mode specifies the type of node: "validator", "full", "light" or "seed".
  58. // Defaults to "validator". Full nodes do not get a signing key (a dummy key
  59. // is generated), and seed nodes run in seed mode with the PEX reactor enabled.
  60. Mode string `toml:"mode"`
  61. // Seeds is the list of node names to use as P2P seed nodes. Defaults to none.
  62. Seeds []string `toml:"seeds"`
  63. // PersistentPeers is a list of node names to maintain persistent P2P
  64. // connections to. If neither seeds nor persistent peers are specified,
  65. // this defaults to all other nodes in the network. For light clients,
  66. // this relates to the providers the light client is connected to.
  67. PersistentPeers []string `toml:"persistent_peers"`
  68. // Database specifies the database backend: "goleveldb", "cleveldb",
  69. // "rocksdb", "boltdb", or "badgerdb". Defaults to goleveldb.
  70. Database string `toml:"database"`
  71. // ABCIProtocol specifies the protocol used to communicate with the ABCI
  72. // application: "unix", "tcp", "grpc", or "builtin". Defaults to unix.
  73. // builtin will build a complete Tendermint node into the application and
  74. // launch it instead of launching a separate Tendermint process.
  75. ABCIProtocol string `toml:"abci_protocol"`
  76. // PrivvalProtocol specifies the protocol used to sign consensus messages:
  77. // "file", "unix", "tcp", or "grpc". Defaults to "file". For tcp and unix, the ABCI
  78. // application will launch a remote signer client in a separate goroutine.
  79. // For grpc the ABCI application will launch a remote signer server.
  80. // Only nodes with mode=validator will actually make use of this.
  81. PrivvalProtocol string `toml:"privval_protocol"`
  82. // StartAt specifies the block height at which the node will be started. The
  83. // runner will wait for the network to reach at least this block height.
  84. StartAt int64 `toml:"start_at"`
  85. // FastSync specifies the fast sync mode: "" (disable), "v0" or "v2".
  86. // Defaults to disabled.
  87. FastSync string `toml:"fast_sync"`
  88. // StateSync enables state sync. The runner automatically configures trusted
  89. // block hashes and RPC servers. At least one node in the network must have
  90. // SnapshotInterval set to non-zero, and the state syncing node must have
  91. // StartAt set to an appropriate height where a snapshot is available.
  92. StateSync bool `toml:"state_sync"`
  93. // PersistInterval specifies the height interval at which the application
  94. // will persist state to disk. Defaults to 1 (every height), setting this to
  95. // 0 disables state persistence.
  96. PersistInterval *uint64 `toml:"persist_interval"`
  97. // SnapshotInterval specifies the height interval at which the application
  98. // will take state sync snapshots. Defaults to 0 (disabled).
  99. SnapshotInterval uint64 `toml:"snapshot_interval"`
  100. // RetainBlocks specifies the number of recent blocks to retain. Defaults to
  101. // 0, which retains all blocks. Must be greater that PersistInterval,
  102. // SnapshotInterval and EvidenceAgeHeight.
  103. RetainBlocks uint64 `toml:"retain_blocks"`
  104. // Perturb lists perturbations to apply to the node after it has been
  105. // started and synced with the network:
  106. //
  107. // disconnect: temporarily disconnects the node from the network
  108. // kill: kills the node with SIGKILL then restarts it
  109. // pause: temporarily pauses (freezes) the node
  110. // restart: restarts the node, shutting it down with SIGTERM
  111. Perturb []string `toml:"perturb"`
  112. // Log level sets the log level of the specific node i.e. "info".
  113. // This is helpful when debugging a specific problem. This overrides the network
  114. // level.
  115. LogLevel string `toml:"log_level"`
  116. // UseNewP2P enables use of the new p2p layer for this node.
  117. DisableLegacyP2P bool `toml:"disable_legacy_p2p"`
  118. // QueueType describes the type of queue that the p2p layer
  119. // uses internally.
  120. QueueType string `toml:"queue_type"`
  121. }
  122. // Save saves the testnet manifest to a file.
  123. func (m Manifest) Save(file string) error {
  124. f, err := os.Create(file)
  125. if err != nil {
  126. return fmt.Errorf("failed to create manifest file %q: %w", file, err)
  127. }
  128. return toml.NewEncoder(f).Encode(m)
  129. }
  130. // LoadManifest loads a testnet manifest from a file.
  131. func LoadManifest(file string) (Manifest, error) {
  132. manifest := Manifest{}
  133. _, err := toml.DecodeFile(file, &manifest)
  134. if err != nil {
  135. return manifest, fmt.Errorf("failed to load testnet manifest %q: %w", file, err)
  136. }
  137. return manifest, nil
  138. }