Skip to content

Commit

Permalink
feat(e2e): config flag for arbitrary CometBFT configurations (comet…
Browse files Browse the repository at this point in the history
…bft#3967)

Addresses cometbft#3832.

Introduces a flag `config` to the manifest. It is a list of strings that
should have the format `key = value`. Keys are any of the configuration
parameters included in a CometBFT configuration file.

The flag can be global, meaning that the configurations will be applied
for every node in the network, or specific for a given node, when
inserted in the section referring to that node. Local/specific
configurations are applied after the global ones, therefore overriding
them.

Example:

```
config = [
   "p2p.send_rate = 51200",
   "filter_peers = true",
]
```

The configurations are applying using `viper`, as I could not find
another way to load configuration parameters. They are always loaded as
a string, and this appears to work correctly.

Note: this PR is based atop cometbft#3964 for simplicity, but it does not need
to.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Andy Nogueira <me@andynogueira.dev>
  • Loading branch information
4 people authored Sep 4, 2024
1 parent 40c4b40 commit cea82b1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/e2e/pkg/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ type Manifest struct {
// -1 denotes it is set at genesis.
// 0 denotes it is set at InitChain.
PbtsUpdateHeight int64 `toml:"pbts_update_height"`

// Config is a set of key-value config entries to write to CometBFT's
// configuration files for all nodes. The format is "key = value".
// Example: "p2p.send_rate = 512000".
Config []string `toml:"config"`
}

// ManifestNode represents a node in a testnet manifest.
Expand Down Expand Up @@ -242,6 +247,11 @@ type ManifestNode struct {

// Simulated clock skew for this node
ClockSkew time.Duration `toml:"clock_skew"`

// Config is a set of key-value config entries to write to CometBFT's
// configuration files for this node. The format is "key = value".
// Example: "p2p.send_rate = 512000".
Config []string `toml:"config"`
}

// Save saves the testnet manifest to a file.
Expand Down
20 changes: 19 additions & 1 deletion test/e2e/pkg/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ func NewTestnetFromManifest(manifest Manifest, file string, ifd InfrastructureDa
} else if testnet.DefaultZone != "" {
node.Zone = ZoneID(testnet.DefaultZone)
}
// Configs are applied in order, so a local Config in Node
// should override a global config in Testnet.
if len(manifest.Config) > 0 {
node.Config = append(testnet.Config, node.Config...)
}

testnet.Nodes = append(testnet.Nodes, node)
}
Expand Down Expand Up @@ -394,6 +399,13 @@ func (t Testnet) Validate() error {
return fmt.Errorf("invalid node %q: %w", node.Name, err)
}
}
for _, entry := range t.Config {
tokens := strings.Split(entry, " = ")
if len(tokens) != 2 {
return fmt.Errorf("invalid config entry: \"%s\", "+
"expected \"key = value\"", entry)
}
}
return nil
}

Expand Down Expand Up @@ -521,7 +533,13 @@ func (n Node) Validate(testnet Testnet) error {
return fmt.Errorf("invalid perturbation %q", perturbation)
}
}

for _, entry := range n.Config {
tokens := strings.Split(entry, " = ")
if len(tokens) != 2 {
return fmt.Errorf("invalid config entry: \"%s\", "+
"expected \"key = value\"", entry)
}
}
return nil
}

Expand Down
16 changes: 16 additions & 0 deletions test/e2e/runner/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/spf13/viper"

"github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/crypto/ed25519"
Expand Down Expand Up @@ -316,6 +317,21 @@ func MakeConfig(node *e2e.Node) (*config.Config, error) {
if node.CompactionInterval != 0 && node.Compact {
cfg.Storage.CompactionInterval = node.CompactionInterval
}

// We currently need viper in order to parse config files.
if len(node.Config) > 0 {
viper.Reset()
for _, entry := range node.Config {
tokens := strings.Split(entry, " = ")
key, value := tokens[0], tokens[1]
logger.Debug("Applying Comet config", "node", node.Name, key, value)
viper.Set(key, value)
}
if err := viper.Unmarshal(cfg); err != nil {
return nil, err
}
}

return cfg, nil
}

Expand Down

0 comments on commit cea82b1

Please sign in to comment.