Skip to content

Commit

Permalink
ci(e2e): explicit supported geth versions (#2540)
Browse files Browse the repository at this point in the history
Add explicit supported geth versions. Ensure backwards compatibility in
backwards.toml.

issue: none
  • Loading branch information
corverroos authored Nov 22, 2024
1 parent c79954c commit 1e52033
Show file tree
Hide file tree
Showing 21 changed files with 33,158 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
rev: v4.6.0
hooks:
- id: check-added-large-files # No large files
exclude: "(lib/netconf/.*/.*|contracts/allocs/.*)"
exclude: "(lib/netconf/.*/.*|contracts/allocs/.*|halo/genutil/evm/testdata/.*)"
- id: trailing-whitespace # trims trailing whitespace
exclude: "testdata"
- id: end-of-file-fixer # ensures that a file is either empty, or ends with one newline
Expand Down
4 changes: 2 additions & 2 deletions e2e/app/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package geth

import (
"encoding/hex"
"encoding/json"
"os"
"path/filepath"
"time"

"github.com/omni-network/omni/e2e/types"
evmgenutil "github.com/omni-network/omni/halo/genutil/evm"
"github.com/omni-network/omni/lib/errors"

"github.com/ethereum/go-ethereum/core"
Expand All @@ -22,7 +22,7 @@ const snapshotCacheMB = 1024

// WriteAllConfig writes all the geth config files for all omniEVMs.
func WriteAllConfig(testnet types.Testnet, genesis core.Genesis) error {
gethGenesisBz, err := json.MarshalIndent(genesis, "", " ")
gethGenesisBz, err := evmgenutil.MarshallBackwardsCompatible(genesis)
if err != nil {
return errors.Wrap(err, "marshal genesis")
}
Expand Down
9 changes: 9 additions & 0 deletions e2e/app/geth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import (
// Version defines the geth version deployed to all networks.
const Version = "v1.14.12"

// SupportedVersions are the supported older geth versions.
// These are tested in backwards.toml.
var SupportedVersions = []string{
"v1.14.11",
"v1.14.8",
"v1.14.7",
"v1.14.6",
}

// Config is the configurable options for the standard omni geth config.
type Config struct {
// Moniker is the p2p node name.
Expand Down
15 changes: 15 additions & 0 deletions e2e/app/geth/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package geth_test

import (
"testing"

"github.com/omni-network/omni/e2e/app/geth"

"github.com/stretchr/testify/require"
)

func TestVersions(t *testing.T) {
t.Parallel()
require.Len(t, geth.SupportedVersions, 4) // Only support (max) 4 versions
require.NotContains(t, geth.SupportedVersions, geth.Version)
}
10 changes: 10 additions & 0 deletions e2e/app/perturb.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func perturbService(ctx context.Context, service string, testnetDir string, pert
if err := docker.ExecCompose(ctx, testnetDir, "exec", service, "wget", "-O-", "localhost:8545/fuzzy_disable"); err != nil {
return errors.Wrap(err, "disable fuzzy head")
}
case types.PerturbUpgrade:
if err := docker.ExecCompose(ctx, testnetDir, "down", service); err != nil {
return errors.Wrap(err, "down service")
}
if err := docker.ReplaceUpgradeImage(testnetDir, service); err != nil {
return errors.Wrap(err, "upgrade service")
}
if err := docker.ExecCompose(ctx, testnetDir, "up", "-d", service); err != nil {
return errors.Wrap(err, "up service")
}
default:
return errors.New("unknown service perturbation")
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Setup(ctx context.Context, def Definition, depCfg DeployConfig) error {
if err != nil {
return errors.Wrap(err, "make genesis")
}
gethGenesisBz, err := json.MarshalIndent(gethGenesis, "", " ")
gethGenesisBz, err := evmgenutil.MarshallBackwardsCompatible(gethGenesis)
if err != nil {
return errors.Wrap(err, "marshal genesis")
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/docker/compose.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ services:
{{- end}}

# Use geth as the omni EVMs.
{{- range .OmniEVMs }}
{{- range $i, $v := .OmniEVMs }}
{{ .InstanceName }}:
labels:
e2e: true
container_name: {{ .InstanceName }}
image: "ethereum/client-go:{{ $.GethTag }}"
image: ethereum/client-go:{{ $.InitialGethTag $i }}{{if $.UpgradeGeth $i}} # Upgrade {{ .InstanceName }}:ethereum/client-go:{{ $.UpgradeGethTag }}{{end}}
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
33 changes: 30 additions & 3 deletions e2e/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"sync"
"text/template"

Expand Down Expand Up @@ -77,6 +78,14 @@ func NewProvider(testnet types.Testnet, infd types.InfrastructureData, imgTag st
// Setup generates the docker-compose file and write it to disk, erroring if
// any of these operations fail.
func (p *Provider) Setup() error {
// Determine any geth upgrades based on configured perturbations.
gethInitTags := make(map[int]string)
for i, omniEVM := range p.testnet.OmniEVMs {
if slices.Contains(p.testnet.Manifest.Perturb[omniEVM.InstanceName], types.PerturbUpgrade) {
gethInitTags[i] = geth.SupportedVersions[i%len(geth.SupportedVersions)]
}
}

def := ComposeDef{
Network: true,
NetworkName: p.testnet.Name,
Expand All @@ -91,6 +100,7 @@ func (p *Provider) Setup() error {
Monitor: true,
Solver: true,
GethVerbosity: 3, // Info
GethInitTags: gethInitTags,
}
def = SetImageTags(def, p.testnet.Manifest, p.omniTag)

Expand Down Expand Up @@ -174,8 +184,9 @@ type ComposeDef struct {
NetworkName string
NetworkCIDR string
BindAll bool
UpgradeVersion string
GethVerbosity int // # Geth log level (1=error,2=warn,3=info(default),4=debug,5=trace)
UpgradeVersion string // Halo target upgrade version
GethVerbosity int // Geth log level (1=error,2=warn,3=info(default),4=debug,5=trace)
GethInitTags map[int]string // Optional geth initial tags. Defaults to latest if empty.

Nodes []*e2e.Node
OmniEVMs []types.OmniEVM
Expand All @@ -192,10 +203,26 @@ type ComposeDef struct {
AnvilProxyTag string
}

func (ComposeDef) GethTag() string {
// UpgradeGeth returns true if the geth nodes should be upgraded.
func (c ComposeDef) UpgradeGeth(index int) bool {
return c.InitialGethTag(index) != c.UpgradeGethTag()
}

// UpgradeGethTag returns the geth docker image tag to upgrade to.
func (ComposeDef) UpgradeGethTag() string {
return geth.Version
}

// InitialGethTag return the geth docker image tag to initially deploy.
func (c ComposeDef) InitialGethTag(index int) string {
tag, ok := c.GethInitTags[index]
if !ok {
return geth.Version
}

return tag
}

// NodeOmniEVMs returns a map of node name to OmniEVM instance name; map[node_name]omni_evm.
func (c ComposeDef) NodeOmniEVMs() map[string]string {
resp := make(map[string]string)
Expand Down
6 changes: 5 additions & 1 deletion e2e/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestComposeTemplate(t *testing.T) {
en := enode.NewV4(&key.PublicKey, ipNet.IP, 30303, 30303)

const node0 = "node0"
const evm0 = "omni_evm_0"
dir := t.TempDir()
testnet := types.Testnet{
Manifest: types.Manifest{
Expand All @@ -78,7 +79,7 @@ func TestComposeTemplate(t *testing.T) {
OmniEVMs: []types.OmniEVM{
{
Chain: types.OmniEVMByNetwork(netconf.Simnet),
InstanceName: "omni_evm_0",
InstanceName: evm0,
AdvertisedIP: ipNet.IP,
ProxyPort: 8000,
NodeKey: key,
Expand Down Expand Up @@ -116,6 +117,7 @@ func TestComposeTemplate(t *testing.T) {

if test.upgrade != "" {
testnet.UpgradeVersion = test.upgrade
testnet.Manifest.Perturb = map[string][]types.Perturb{evm0: {types.PerturbUpgrade}}
}

p := docker.NewProvider(testnet, types.InfrastructureData{}, test.tag)
Expand All @@ -137,6 +139,8 @@ func TestComposeTemplate(t *testing.T) {
}
require.NoError(t, err)

require.NoError(t, docker.ReplaceUpgradeImage(dir, evm0))

bz, err := os.ReadFile(filepath.Join(dir, "docker-compose.yaml"))
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion e2e/docker/testdata/TestComposeTemplate_commit.golden
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ services:
labels:
e2e: true
container_name: omni_evm_0
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ services:
labels:
e2e: true
container_name: omni_evm_0
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.11 # Upgrade omni_evm_0:ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ services:
labels:
e2e: true
container_name: omni_evm_0
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
6 changes: 6 additions & 0 deletions e2e/manifests/backwards.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ perturb = ["upgrade"]
[node.validator04]
version="omniops/halovisor:v0.9.0"
perturb = ["upgrade"]

[perturb]
validator01_evm = ["upgrade"]
validator02_evm = ["upgrade"]
validator03_evm = ["upgrade"]
validator04_evm = ["upgrade"]
3 changes: 2 additions & 1 deletion e2e/types/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const (
PerturbStopStart Perturb = "stopstart"
// PerturbRollback defines a perturbation that stops a halo node, performs a rollback, then starts it again.
PerturbRollback Perturb = "rollback"
// PerturbUpgrade defines a perturbation that upgrades a halo node to the latest image tag.
// PerturbUpgrade defines a perturbation that upgrades a geth node to the latest version.
// Note that halo upgrades are handled by CometBFT perturbations.
PerturbUpgrade Perturb = "upgrade"

// PerturbFuzzyHeadDropBlocks defines a perturbation that enables fuzzyhead dropping xblock for a while.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
labels:
e2e: true
container_name: validator01_evm
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
labels:
e2e: true
container_name: validator02_evm
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
labels:
e2e: true
container_name: seed01_evm
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
labels:
e2e: true
container_name: fullnode01_evm
image: "ethereum/client-go:v1.14.12"
image: ethereum/client-go:v1.14.12
restart: unless-stopped
command:
- --config=/geth/config.toml
Expand Down
41 changes: 41 additions & 0 deletions halo/genutil/evm/evm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evm

import (
"encoding/json"
"math/big"

"github.com/omni-network/omni/e2e/app/eoa"
Expand Down Expand Up @@ -49,6 +50,46 @@ func MakeGenesis(network netconf.ID) (core.Genesis, error) {
}, nil
}

// MarshallBackwardsCompatible marshals a genesis into a backwards compatible JSON format.
func MarshallBackwardsCompatible(genesis core.Genesis) ([]byte, error) {
// Geth version 1.14.12 removed TerminalTotalDifficultyPassed,
// but this is still required by older v1.14.* versions.
backwardsConfig := struct {
*params.ChainConfig // Extend latest chain config
TerminalTotalDifficultyPassed bool `json:"terminalTotalDifficultyPassed"`
}{
ChainConfig: genesis.Config,
TerminalTotalDifficultyPassed: true,
}
configBz, err := json.MarshalIndent(backwardsConfig, "", " ")
if err != nil {
return nil, errors.Wrap(err, "marshal backwards compatible config")
}

// Marshal new genesis
bz, err := json.MarshalIndent(genesis, "", " ")
if err != nil {
return nil, errors.Wrap(err, "marshal genesis")
}

// Unmarshal into generic map
temp1 := make(map[string]json.RawMessage)
if err := json.Unmarshal(bz, &temp1); err != nil {
return nil, errors.Wrap(err, "unmarshal genesis")
}

// Replace config with backwards compatible config
temp1["config"] = configBz

// Marshal backwards compatible genesis
bz, err = json.MarshalIndent(temp1, "", " ")
if err != nil {
return nil, errors.Wrap(err, "marshal backwards compatible genesis")
}

return bz, nil
}

// defaultChainConfig returns the default chain config for a network.
// See geth reference: https://github.com/ethereum/go-ethereum/blob/master/params/config.go#L65
func defaultChainConfig(network netconf.ID) *params.ChainConfig {
Expand Down
7 changes: 7 additions & 0 deletions halo/genutil/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ func TestMakeEVMGenesis(t *testing.T) {
genesis, err := evm.MakeGenesis(netconf.Staging)
require.NoError(t, err)
tutil.RequireGoldenJSON(t, genesis)

t.Run("backwards", func(t *testing.T) {
t.Parallel()
backwards, err := evm.MarshallBackwardsCompatible(genesis)
require.NoError(t, err)
tutil.RequireGoldenBytes(t, backwards)
})
}
33,020 changes: 33,020 additions & 0 deletions halo/genutil/evm/testdata/TestMakeEVMGenesis_backwards.golden

Large diffs are not rendered by default.

0 comments on commit 1e52033

Please sign in to comment.