Skip to content

Commit

Permalink
Merge pull request #51 from crytic/plan-generation
Browse files Browse the repository at this point in the history
Plan generation MVP
  • Loading branch information
bsamuels453 authored Jan 10, 2024
2 parents 05cee80 + b5acf03 commit 5366fe2
Show file tree
Hide file tree
Showing 22 changed files with 1,101 additions and 654 deletions.
4 changes: 3 additions & 1 deletion cmd/attacknet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {
log.Fatal(err)
os.Exit(1)
}
case "plan <path>":
case "plan <name> <path>":
config, err := plan.LoadPlannerConfigFromPath(CLI.Plan.Path)
if err != nil {
log.Fatal(err)
Expand All @@ -68,5 +68,7 @@ func main() {
log.Fatal(err)
os.Exit(1)
}
default:
log.Fatal("unrecognized arguments")
}
}
88 changes: 88 additions & 0 deletions network-configs/plan/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
participants:
- el_client_type: geth
el_client_image: ethereum/client-go:latest
cl_client_type: lighthouse
cl_client_image: sigp/lighthouse:latest
el_min_cpu: 1000
el_max_cpu: 1000
el_min_mem: 2048
el_max_mem: 2048
bn_min_cpu: 1000
bn_max_cpu: 1000
bn_min_mem: 2048
bn_max_mem: 2048
v_min_cpu: 1000
v_max_cpu: 1000
v_min_mem: 1024
v_max_mem: 1024
count: 1
- el_client_type: reth
el_client_image: ghcr.io/paradigmxyz/reth:v0.1.0-alpha.13
cl_client_type: teku
cl_client_image: consensys/teku:23.12.0
el_min_cpu: 1000
el_max_cpu: 1000
el_min_mem: 2048
el_max_mem: 2048
bn_min_cpu: 1000
bn_max_cpu: 1000
bn_min_mem: 2048
bn_max_mem: 2048
count: 1
- el_client_type: reth
el_client_image: ghcr.io/paradigmxyz/reth:v0.1.0-alpha.13
cl_client_type: lodestar
cl_client_image: chainsafe/lodestar:v1.12.1
el_min_cpu: 1000
el_max_cpu: 1000
el_min_mem: 2048
el_max_mem: 2048
bn_min_cpu: 1000
bn_max_cpu: 1000
bn_min_mem: 2048
bn_max_mem: 2048
v_min_cpu: 1000
v_max_cpu: 1000
v_min_mem: 1024
v_max_mem: 1024
count: 1
- el_client_type: reth
el_client_image: ghcr.io/paradigmxyz/reth:v0.1.0-alpha.13
cl_client_type: lighthouse
cl_client_image: sigp/lighthouse:latest
el_min_cpu: 1000
el_max_cpu: 1000
el_min_mem: 2048
el_max_mem: 2048
bn_min_cpu: 1000
bn_max_cpu: 1000
bn_min_mem: 2048
bn_max_mem: 2048
v_min_cpu: 1000
v_max_cpu: 1000
v_min_mem: 1024
v_max_mem: 1024
count: 1
- el_client_type: reth
el_client_image: ghcr.io/paradigmxyz/reth:v0.1.0-alpha.13
cl_client_type: prysm
cl_client_image: prysmaticlabs/prysm-beacon-chain:latest,prysmaticlabs/prysm-validator:latest
el_min_cpu: 1000
el_max_cpu: 1000
el_min_mem: 2048
el_max_mem: 2048
bn_min_cpu: 1000
bn_max_cpu: 1000
bn_min_mem: 2048
bn_max_mem: 2048
v_min_cpu: 1000
v_max_cpu: 1000
v_min_mem: 1024
v_max_mem: 1024
count: 1
network_params:
num_validator_keys_per_node: 32
additional_services:
- prometheus_grafana
- dora
parallel_keystore_generation: false
4 changes: 2 additions & 2 deletions pkg/health/ethereum/network_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (e *EthNetworkChecker) RunAllChecks(ctx context.Context) ([]*types.CheckRes
rpcClients[i] = client
}

log.Info("Ready to query for health checks")
log.Debug("Ready to query for health checks")
latestResult, err := e.getBlockConsensus(ctx, rpcClients, "latest", 3)
if err != nil {
return nil, err
Expand Down Expand Up @@ -113,7 +113,7 @@ func (e *EthNetworkChecker) getBlockConsensus(ctx context.Context, clients []*Ex
consensusBlockNum, wrongBlockNum, consensusBlockHash, wrongBlockHash := determineForkConsensus(forkChoice)
if len(wrongBlockNum) > 0 {
if maxAttempts > 0 {
log.Infof("Nodes not at consensus for %s block. Waiting and re-trying in case we're on block propagation boundary. Attempts left: %d", blockType, maxAttempts-1)
log.Debugf("Nodes not at consensus for %s block. Waiting and re-trying in case we're on block propagation boundary. Attempts left: %d", blockType, maxAttempts-1)
time.Sleep(2 * time.Second)
return e.getBlockConsensus(ctx, clients, blockType, maxAttempts-1)
} else {
Expand Down
26 changes: 13 additions & 13 deletions pkg/plan/config.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package plan

import (
planTypes "attacknet/cmd/pkg/plan/types"
"attacknet/cmd/pkg/plan/suite"
"github.com/kurtosis-tech/stacktrace"
"gopkg.in/yaml.v3"
"os"
)

func validatePlannerFaultConfiguration(c planTypes.PlannerConfig) error {
func validatePlannerFaultConfiguration(c PlannerConfig) error {
// fault type
_, ok := planTypes.FaultTypes[c.FaultConfig.FaultType]
_, ok := suite.FaultTypes[c.FaultConfig.FaultType]
if !ok {
faults := make([]planTypes.FaultTypeEnum, 0, len(planTypes.FaultTypes))
for k := range planTypes.FaultTypes {
faults := make([]suite.FaultTypeEnum, 0, len(suite.FaultTypes))
for k := range suite.FaultTypes {
faults = append(faults, k)
}
return stacktrace.NewError("the fault type '%s' is not supported. Supported faults: %v", c.FaultConfig.FaultType, faults)
Expand All @@ -26,10 +26,10 @@ func validatePlannerFaultConfiguration(c planTypes.PlannerConfig) error {

// targeting dimensions
for _, spec := range c.FaultConfig.TargetingDimensions {
_, ok := planTypes.TargetingSpecs[spec]
_, ok := suite.TargetingSpecs[spec]
if !ok {
specs := make([]planTypes.TargetingSpec, 0, len(planTypes.TargetingSpecs))
for k := range planTypes.TargetingSpecs {
specs := make([]suite.TargetingSpec, 0, len(suite.TargetingSpecs))
for k := range suite.TargetingSpecs {
specs = append(specs, k)
}
return stacktrace.NewError("the fault targeting dimension %s is not supported. Supported dimensions: %v", spec, specs)
Expand All @@ -38,10 +38,10 @@ func validatePlannerFaultConfiguration(c planTypes.PlannerConfig) error {

// attack size dimensions
for _, attackSize := range c.FaultConfig.AttackSizeDimensions {
_, ok := planTypes.AttackSizes[attackSize]
_, ok := suite.AttackSizes[attackSize]
if !ok {
sizes := make([]planTypes.AttackSize, 0, len(planTypes.AttackSizes))
for k := range planTypes.AttackSizes {
sizes := make([]suite.AttackSize, 0, len(suite.AttackSizes))
for k := range suite.AttackSizes {
sizes = append(sizes, k)
}
return stacktrace.NewError("the attack size dimension %s is not supported. Supported dimensions: %v", attackSize, sizes)
Expand All @@ -58,13 +58,13 @@ func validatePlannerFaultConfiguration(c planTypes.PlannerConfig) error {
return nil
}

func LoadPlannerConfigFromPath(path string) (*planTypes.PlannerConfig, error) {
func LoadPlannerConfigFromPath(path string) (*PlannerConfig, error) {
bs, err := os.ReadFile(path)
if err != nil {
return nil, stacktrace.Propagate(err, "could not planner config on path %s", path)
}

var config planTypes.PlannerConfig
var config PlannerConfig
err = yaml.Unmarshal(bs, &config)
if err != nil {
return nil, stacktrace.Propagate(err, "unable to unmarshal planner config from %s", path)
Expand Down
75 changes: 75 additions & 0 deletions pkg/plan/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package plan

import (
"fmt"
"github.com/kurtosis-tech/stacktrace"
"os"
"path/filepath"
)

func preparePaths(testName string) (netRefPath, netConfigPath, planConfigPath string, err error) {
dir, err := os.Getwd()
// initialize to empty string for error cases
netConfigPath = ""
planConfigPath = ""
if err != nil {
return
}

netRefPath = fmt.Sprintf("plan/%s.yaml", testName)
networkConfigName := fmt.Sprintf("network-configs/%s", netRefPath)
netConfigPath = filepath.Join(dir, networkConfigName)
if _, err = os.Stat(netConfigPath); err == nil {
// delete file
err = os.Remove(netConfigPath)
if err != nil {
err = stacktrace.Propagate(err, "unable to remove file")
return
}
}

suiteName := fmt.Sprintf("test-suites/plan/%s.yaml", testName)
planConfigPath = filepath.Join(dir, suiteName)
if _, err = os.Stat(planConfigPath); err == nil {
// delete file
err = os.Remove(planConfigPath)
if err != nil {
err = stacktrace.Propagate(err, "unable to remove file")
return
}
}
err = nil
return
}

func writePlans(netConfigPath, suiteConfigPath string, netConfig, suiteConfig []byte) error {
f, err := os.Create(netConfigPath)
if err != nil {
return stacktrace.Propagate(err, "cannot open network types path %s", netConfigPath)
}
_, err = f.Write(netConfig)
if err != nil {
return stacktrace.Propagate(err, "could not write network types to file")
}

err = f.Close()
if err != nil {
return stacktrace.Propagate(err, "could not close network types file")
}

f, err = os.Create(suiteConfigPath)
if err != nil {
return stacktrace.Propagate(err, "cannot open suite types path %s", suiteConfigPath)
}
_, err = f.Write(suiteConfig)
if err != nil {
return stacktrace.Propagate(err, "could not write suite types to file")
}

err = f.Close()
if err != nil {
return stacktrace.Propagate(err, "could not close suite types file")
}

return nil
}
71 changes: 14 additions & 57 deletions pkg/plan/network/clients.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,25 @@
package network

import (
"attacknet/cmd/pkg/plan/types"
"strings"
"github.com/kurtosis-tech/stacktrace"
)

const default_el_cpu = 1000
const default_cl_cpu = 1000
const default_val_cpu = 1000

const default_el_mem = 1024
const default_cl_mem = 2048
const default_val_mem = 1024

func buildConsensusClient(config types.ClientVersion) *types.ConsensusClient {
image := config.Image
validatorImage := ""

if strings.Contains(config.Image, ",") {
images := strings.Split(config.Image, ",")
image = images[0]
validatorImage = images[1]
}
if config.HasSidecar {
return &types.ConsensusClient{
Type: config.Name,
Image: image,
HasValidatorSidecar: true,
ValidatorImage: validatorImage,
ExtraLabels: make(map[string]string),
CpuRequired: default_cl_cpu,
MemoryRequired: default_cl_mem,
SidecarCpuRequired: default_val_cpu,
SidecarMemoryRequired: default_val_mem,
}
} else {
return &types.ConsensusClient{
Type: config.Name,
Image: image,
HasValidatorSidecar: false,
ValidatorImage: validatorImage,
ExtraLabels: make(map[string]string),
CpuRequired: default_cl_cpu,
MemoryRequired: default_cl_mem,
SidecarCpuRequired: 0,
SidecarMemoryRequired: 0,
}
func buildNode(index int, execConf, consensusConf ClientVersion) *Node {
return &Node{
Index: index,
Execution: composeExecutionClient(execConf),
Consensus: composeConsensusClient(consensusConf),
}
}

func buildExecutionClient(config types.ClientVersion) *types.ExecutionClient {
return &types.ExecutionClient{
Type: config.Name,
Image: config.Image,
ExtraLabels: make(map[string]string),
CpuRequired: default_cl_cpu,
MemoryRequired: default_cl_mem,
func composeBootnode(execClients, consensusClients map[string]ClientVersion) (*Node, error) {
execConf, ok := execClients["geth"]
if !ok {
return nil, stacktrace.NewError("unable to load configuration for exec client geth")
}
}

func buildNode(index int, execConf, consensusConf types.ClientVersion) *types.Node {
return &types.Node{
Index: index,
Execution: buildExecutionClient(execConf),
Consensus: buildConsensusClient(consensusConf),
consConf, ok := consensusClients["lighthouse"]
if !ok {
return nil, stacktrace.NewError("unable to load configuration for exec client lighthouse")
}
return buildNode(0, execConf, consConf), nil
}
Loading

0 comments on commit 5366fe2

Please sign in to comment.