Skip to content

Commit

Permalink
testutil/compose: add feature set flags (#607)
Browse files Browse the repository at this point in the history
Adds the ability to enable different feature sets to compose.

Also fix issue with teku vc config.

category: feature
ticket: #568
  • Loading branch information
corverroos committed May 25, 2022
1 parent 858032a commit 27414e7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
2 changes: 2 additions & 0 deletions testutil/compose/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ func newNewCmd() *cobra.Command {
buildLocal := cmd.Flags().Bool("build-local", conf.BuildLocal, "Enables building a local charon binary from source. Note this requires the CHARON_REPO env var.")
beaconNode := cmd.Flags().String("beacon-node", conf.BeaconNode, "Beacon node URL endpoint or 'mock' for simnet.")
splitKeys := cmd.Flags().String("split-keys-dir", conf.SplitKeysDir, "Directory containing keys to split for keygen==create, or empty not to split.")
featureSet := cmd.Flags().String("feature-set", conf.FeatureSet, "Minimum feature set to enable: alpha, beta, stable")

cmd.RunE = func(cmd *cobra.Command, _ []string) error {
conf.KeyGen = compose.KeyGen(*keygen)
conf.BuildLocal = *buildLocal
conf.BeaconNode = *beaconNode
conf.SplitKeysDir = *splitKeys
conf.FeatureSet = *featureSet

ctx := log.WithTopic(cmd.Context(), "new")
if err := compose.New(ctx, *dir, conf); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion testutil/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
defaultNumVals = 1
defaultNumNodes = 4
defaultThreshold = 3
defaultFeatureSet = "alpha"

charonImage = "ghcr.io/obolnetwork/charon"
localBinary = "/compose/charon"
Expand Down Expand Up @@ -95,6 +96,9 @@ type Config struct {

// VCs define the types of validator clients to use.
VCs []vcType `json:"validator_clients"`

// FeatureSet defines the minimum feature set to enable.
FeatureSet string `json:"feature_set"`
}

// entrypoint returns the path to the charon binary based on the BuildLocal field.
Expand All @@ -116,8 +120,8 @@ func NewDefaultConfig() Config {
ImageTag: defaultImageTag,
VCs: []vcType{vcTeku, vcLighthouse, vcMock},
KeyGen: defaultKeyGen,
SplitKeysDir: "",
BeaconNode: defaultBeaconNode,
Step: stepDefined,
FeatureSet: defaultFeatureSet,
}
}
2 changes: 1 addition & 1 deletion testutil/compose/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Define(ctx context.Context, dir string) error {
}
}

if !noPull && conf.ImageTag == "latest" {
if !noPull && !conf.BuildLocal && conf.ImageTag == "latest" {
if err := pullLatest(ctx); err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions testutil/compose/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Lock(ctx context.Context, dir string) error {

var nodes []node
for i := 0; i < conf.NumNodes; i++ {
n := node{EnvVars: newNodeEnvs(i, true, conf.BeaconNode)}
n := node{EnvVars: newNodeEnvs(i, true, conf.BeaconNode, conf.FeatureSet)}
nodes = append(nodes, n)
}

Expand Down Expand Up @@ -99,7 +99,7 @@ func Lock(ctx context.Context, dir string) error {
}

// newNodeEnvs returns the default node environment variable to run a charon docker container.
func newNodeEnvs(index int, validatorMock bool, beaconNode string) []kv {
func newNodeEnvs(index int, validatorMock bool, beaconNode string, featureSet string) []kv {
beaconMock := false
if beaconNode == "mock" {
beaconMock = true
Expand All @@ -122,6 +122,7 @@ func newNodeEnvs(index int, validatorMock bool, beaconNode string) []kv {
{"simnet_validator_mock", fmt.Sprintf(`"%v"`, validatorMock)},
{"simnet_beacon_mock", fmt.Sprintf(`"%v"`, beaconMock)},
{"log_level", "debug"},
{"feature_set", featureSet},
}
}

Expand Down
38 changes: 24 additions & 14 deletions testutil/compose/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package compose

import (
"context"
"fmt"
"io/fs"
"strings"

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
Expand All @@ -42,11 +44,11 @@ func Run(ctx context.Context, dir string) error {
vcs []vc
)
for i := 0; i < conf.NumNodes; i++ {
n := node{EnvVars: newNodeEnvs(i, true, conf.BeaconNode)}
n := node{EnvVars: newNodeEnvs(i, true, conf.BeaconNode, conf.FeatureSet)}
nodes = append(nodes, n)

typ := conf.VCs[i%len(conf.VCs)]
vcs = append(vcs, vcByType[typ])
vcs = append(vcs, getVC(typ, i))
}

data := tmplData{
Expand All @@ -66,19 +68,27 @@ func Run(ctx context.Context, dir string) error {
return writeDockerCompose(dir, data)
}

var vcByType = map[vcType]vc{
vcLighthouse: {
Label: string(vcLighthouse),
Build: "lighthouse",
},
vcTeku: {
Label: string(vcTeku),
Image: "consensys/teku:latest",
Command: `|
// getVC returns the validator client template data for the provided type and index.
func getVC(typ vcType, nodeIdx int) vc {
vcByType := map[vcType]vc{
vcLighthouse: {
Label: string(vcLighthouse),
Build: "lighthouse",
},
vcTeku: {
Label: string(vcTeku),
Image: "consensys/teku:latest",
Command: `|
validator-client
--network=auto
--beacon-node-api-endpoint="http://node1:16002"
--validator-keys="/compose/node1:/compose/node1"
--beacon-node-api-endpoint="http://node{{nodeIdx}}:16002"
--validator-keys="/compose/node{{nodeIdx}}:/compose/node{{nodeIdx}}"
--validators-proposer-default-fee-recipient="0x0000000000000000000000000000000000000000"`,
},
},
}

resp := vcByType[typ]
resp.Command = strings.ReplaceAll(resp.Command, "{{nodeIdx}}", fmt.Sprint(nodeIdx))

return resp
}
3 changes: 2 additions & 1 deletion testutil/compose/testdata/TestNewDefaultConfig.golden
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"teku",
"lighthouse",
"mock"
]
],
"feature_set": "alpha"
}
12 changes: 8 additions & 4 deletions testutil/compose/testdata/TestRunCompose.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
CHARON_LOG_LEVEL: debug
CHARON_FEATURE_SET: alpha

node1:
<<: *node-base
Expand All @@ -46,6 +47,7 @@ services:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
CHARON_LOG_LEVEL: debug
CHARON_FEATURE_SET: alpha

node2:
<<: *node-base
Expand All @@ -65,6 +67,7 @@ services:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
CHARON_LOG_LEVEL: debug
CHARON_FEATURE_SET: alpha

node3:
<<: *node-base
Expand All @@ -84,6 +87,7 @@ services:
CHARON_SIMNET_VALIDATOR_MOCK: "true"
CHARON_SIMNET_BEACON_MOCK: "true"
CHARON_LOG_LEVEL: debug
CHARON_FEATURE_SET: alpha

bootnode:
<<: *node-base
Expand All @@ -102,8 +106,8 @@ services:
command: |
validator-client
--network=auto
--beacon-node-api-endpoint="http://node1:16002"
--validator-keys="/compose/node1:/compose/node1"
--beacon-node-api-endpoint="http://node0:16002"
--validator-keys="/compose/node0:/compose/node0"
--validators-proposer-default-fee-recipient="0x0000000000000000000000000000000000000000"
networks: [compose]
depends_on: [node0]
Expand All @@ -126,8 +130,8 @@ services:
command: |
validator-client
--network=auto
--beacon-node-api-endpoint="http://node1:16002"
--validator-keys="/compose/node1:/compose/node1"
--beacon-node-api-endpoint="http://node3:16002"
--validator-keys="/compose/node3:/compose/node3"
--validators-proposer-default-fee-recipient="0x0000000000000000000000000000000000000000"
networks: [compose]
depends_on: [node3]
Expand Down

0 comments on commit 27414e7

Please sign in to comment.