Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(e2e): add solver skeleton app #2367

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .goreleaser-official.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project_name: omni
# - Only linux/amd/arm docker images required
# - Tag images with {Tag} and latest
#
# relayer, monitor:
# relayer, monitor, solver:
# - Internal facing (not external)
# - Not released as binaries
# - Only linux/amd docker image required.
Expand Down Expand Up @@ -54,6 +54,15 @@ builds:
ldflags:
- -s -w -X github.com/omni-network/omni/lib/buildinfo.version={{.Tag}}

- id: solver
main: ./solver
binary: solver
env: [CGO_ENABLED=0]
goos: [linux]
goarch: [amd64]
ldflags:
- -s -w -X github.com/omni-network/omni/lib/buildinfo.version={{.Tag}}

dockers:
- id: halo-amd64
ids: [halo]
Expand Down Expand Up @@ -113,6 +122,13 @@ dockers:
image_templates:
- omniops/monitor:{{.Tag}}

- ids: [solver]
goos: linux
goarch: amd64
dockerfile: ./solver/Dockerfile
image_templates:
- omniops/solver:{{.Tag}}

docker_manifests:
- name_template: omniops/halo:{{.Tag}}
image_templates:
Expand Down
15 changes: 15 additions & 0 deletions .goreleaser-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ builds:
goos: [linux]
goarch: [amd64]

- id: solver
main: ./solver
binary: solver
env: [CGO_ENABLED=0]
goos: [linux]
goarch: [amd64]

- id: omni
main: ./cli/cmd/omni
binary: omni
Expand Down Expand Up @@ -74,6 +81,14 @@ dockers:
- omniops/monitor:{{ .ShortCommit }}
- omniops/monitor:main

- ids: [solver]
dockerfile: ./solver/Dockerfile
goos: linux
goarch: amd64
image_templates:
- omniops/solver:{{ .ShortCommit }}
- omniops/solver:main

- ids: [anvilproxy]
dockerfile: ./e2e/anvilproxy/Dockerfile
goos: linux
Expand Down
7 changes: 6 additions & 1 deletion e2e/app/agent/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func genPromConfig(ctx context.Context, testnet types.Testnet, secrets Secrets,
MetricsPath: "/metrics",
targets: []string{fmt.Sprintf("monitor:%d", promPort)},
},
{
JobName: "solver",
MetricsPath: "/metrics",
targets: []string{fmt.Sprintf("solver:%d", promPort)},
},
},
}

Expand Down Expand Up @@ -147,7 +152,7 @@ func (c promScrapConfig) Targets() string {
// It replaces the geth targets with provided.
// It replaces the host label.
func ConfigForHost(bz []byte, newHost string, halos []string, geths []string, services map[string]bool) []byte {
for _, service := range []string{"relayer", "monitor"} {
for _, service := range []string{"relayer", "monitor", "solver"} {
if services[service] {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/app/agent/prometheus_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestPromGen(t *testing.T) {
nodes: []string{"validator01", "validator02", "fullnode03"},
hostname: "vm",
newNodes: []string{"fullnode04"},
newServices: []string{"relayer", "monitor"},
newServices: []string{"relayer", "monitor", "solver"},
agentSecrets: true,
},
}
Expand Down
8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest1_gen.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ scrape_configs:
network: 'manifest1-localhost'
host: 'localhost'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [solver:26660] # solver targets
labels:
network: 'manifest1-localhost'
host: 'localhost'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest1_update.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ scrape_configs:
network: 'manifest1-localhost'
host: 'localhost-2'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [] # solver targets
labels:
network: 'manifest1-localhost'
host: 'localhost-2'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest2_gen.golden
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ scrape_configs:
network: 'staging'
host: 'vm'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [solver:26660] # solver targets
labels:
network: 'staging'
host: 'vm'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest2_update.golden
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ scrape_configs:
network: 'staging'
host: 'vm-2'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [] # solver targets
labels:
network: 'staging'
host: 'vm-2'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest3_gen.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ scrape_configs:
network: 'manifest3-localhost'
host: 'localhost'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [solver:26660] # solver targets
labels:
network: 'manifest3-localhost'
host: 'localhost'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest3_update.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ scrape_configs:
network: 'manifest3-localhost'
host: 'localhost-2'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [] # solver targets
labels:
network: 'manifest3-localhost'
host: 'localhost-2'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest4_gen.golden
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ scrape_configs:
network: 'staging'
host: 'vm'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [solver:26660] # solver targets
labels:
network: 'staging'
host: 'vm'

8 changes: 8 additions & 0 deletions e2e/app/agent/testdata/TestPromGen_manifest4_update.golden
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ scrape_configs:
network: 'staging'
host: 'vm-2'

- job_name: "solver"
metrics_path: "/metrics"
static_configs:
- targets: [solver:26660] # solver targets
labels:
network: 'staging'
host: 'vm-2'

2 changes: 1 addition & 1 deletion e2e/app/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestManifestServiceReference(t *testing.T) {
require.NoError(t, err)

services := keys(infraData.Instances)
services = append(services, "relayer", "monitor")
services = append(services, "relayer", "monitor", "solver")
sort.Strings(services)
ref[manifest.Network] = services
}
Expand Down
50 changes: 48 additions & 2 deletions e2e/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/omni-network/omni/lib/xchain"
monapp "github.com/omni-network/omni/monitor/app"
relayapp "github.com/omni-network/omni/relayer/app"
solverapp "github.com/omni-network/omni/solver/app"

"github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/crypto"
Expand All @@ -54,6 +55,8 @@ const (
)

// Setup sets up the testnet configuration.
//
//nolint:gocyclo // Just multiple sequential steps.
func Setup(ctx context.Context, def Definition, depCfg DeployConfig) error {
log.Info(ctx, "Setup testnet", "dir", def.Testnet.Dir)

Expand Down Expand Up @@ -114,6 +117,10 @@ func Setup(ctx context.Context, def Definition, depCfg DeployConfig) error {
return err
}

if err := writeSolverConfig(ctx, def, logCfg); err != nil {
return err
}

if err := writeAnvilState(def.Testnet); err != nil {
return err
}
Expand Down Expand Up @@ -492,6 +499,45 @@ func writeRelayerConfig(ctx context.Context, def Definition, logCfg log.Config)
return nil
}

func writeSolverConfig(_ context.Context, def Definition, logCfg log.Config) error {
confRoot := filepath.Join(def.Testnet.Dir, "solver")

const (
privKeyFile = "privatekey"
configFile = "solver.toml"
)

if err := os.MkdirAll(confRoot, 0o755); err != nil {
return errors.Wrap(err, "mkdir", "path", confRoot)
}

// Save network config
endpoints := internalEndpoints(def, "")
if def.Infra.GetInfrastructureData().Provider == vmcompose.ProviderName {
endpoints = ExternalEndpoints(def)
}

// TODO(corver): save proper private key
privKey, err := ethcrypto.GenerateKey()
if err != nil {
return errors.Wrap(err, "generate private key")
}
if err := ethcrypto.SaveECDSA(filepath.Join(confRoot, privKeyFile), privKey); err != nil {
return errors.Wrap(err, "write private key")
}

solverCfg := solverapp.DefaultConfig()
solverCfg.PrivateKey = privKeyFile
solverCfg.Network = def.Testnet.Network
solverCfg.RPCEndpoints = endpoints

if err := solverapp.WriteConfigTOML(solverCfg, logCfg, filepath.Join(confRoot, configFile)); err != nil {
return errors.Wrap(err, "write solver config")
}

return nil
}

func writeMonitorConfig(ctx context.Context, def Definition, logCfg log.Config, valPrivKeys []crypto.PrivKey) error {
confRoot := filepath.Join(def.Testnet.Dir, "monitor")

Expand Down Expand Up @@ -530,7 +576,7 @@ func writeMonitorConfig(ctx context.Context, def Definition, logCfg log.Config,
// Save private key
privKey, err := eoa.PrivateKey(ctx, def.Testnet.Network, eoa.RoleMonitor)
if err != nil {
return errors.Wrap(err, "get relayer key")
return errors.Wrap(err, "get monitor key")
}
if err := ethcrypto.SaveECDSA(filepath.Join(confRoot, privKeyFile), privKey); err != nil {
return errors.Wrap(err, "write private key")
Expand Down Expand Up @@ -568,7 +614,7 @@ func writeMonitorConfig(ctx context.Context, def Definition, logCfg log.Config,
cfg.XFeeMngr.CoinGeckoAPIKey = def.Cfg.CoinGeckoAPIKey

if err := monapp.WriteConfigTOML(cfg, logCfg, filepath.Join(confRoot, configFile)); err != nil {
return errors.Wrap(err, "write relayer config")
return errors.Wrap(err, "write monitor config")
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions e2e/app/testdata/TestManifestServiceReference.golden
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"seed01_evm",
"seed02",
"seed02_evm",
"solver",
"validator01",
"validator01_evm",
"validator02",
Expand All @@ -46,6 +47,7 @@
"relayer",
"seed01",
"seed01_evm",
"solver",
"validator01",
"validator01_evm",
"validator02",
Expand Down
16 changes: 16 additions & 0 deletions e2e/docker/compose.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ services:
{{ if $.Network }}ipv4_address: 10.186.73.201{{ end }}
{{ end }}

{{- if .Solver }}
solver:
labels:
e2e: true
container_name: solver
image: omniops/solver:{{or .SolverTag "main"}}
restart: unless-stopped
ports:
- 26660 # Prometheus and pprof
volumes:
- ./solver:/solver
networks:
{{ $.NetworkName }}:
{{ if $.Network }}ipv4_address: 10.186.73.203{{ end }}
{{ end }}

{{- if .Prometheus }}
prometheus:
labels:
Expand Down
21 changes: 13 additions & 8 deletions e2e/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (p *Provider) Setup() error {
Relayer: true,
Prometheus: p.testnet.Prometheus,
Monitor: true,
Solver: true,
GethVerbosity: 3, // Info
}
def = SetImageTags(def, p.testnet.Manifest, p.omniTag)
Expand Down Expand Up @@ -180,12 +181,15 @@ type ComposeDef struct {
OmniEVMs []types.OmniEVM
Anvils []types.AnvilChain

Monitor bool
AnvilProxyTag string
RelayerTag string
Monitor bool
Relayer bool
Solver bool
Prometheus bool

MonitorTag string
Relayer bool
Prometheus bool
RelayerTag string
SolverTag string
AnvilProxyTag string
}

func (ComposeDef) GethTag() string {
Expand All @@ -211,6 +215,7 @@ func (c ComposeDef) NodeOmniEVMs() map[string]string {
func SetImageTags(def ComposeDef, manifest types.Manifest, omniImgTag string) ComposeDef {
anvilProxyTag := omniImgTag

// TODO(corver): Remove pinned tags since they are not used.
monitorTag := omniImgTag
if manifest.PinnedMonitorTag != "" {
monitorTag = manifest.PinnedMonitorTag
Expand All @@ -224,6 +229,7 @@ func SetImageTags(def ComposeDef, manifest types.Manifest, omniImgTag string) Co
def.AnvilProxyTag = anvilProxyTag
def.MonitorTag = monitorTag
def.RelayerTag = relayerTag
def.SolverTag = omniImgTag

return def
}
Expand Down Expand Up @@ -300,15 +306,14 @@ func additionalServices(testnet types.Testnet) []string {
resp = append(resp, "prometheus")
}

resp = append(resp, "monitor")

for _, omniEVM := range testnet.OmniEVMs {
resp = append(resp, omniEVM.InstanceName)
}
for _, anvil := range testnet.AnvilChains {
resp = append(resp, anvil.Chain.Name)
}
resp = append(resp, "relayer")

resp = append(resp, "monitor", "relayer", "solver")

return resp
}
Expand Down
Loading
Loading