Skip to content

Commit

Permalink
ci(e2e): support custom genesis upgrade (#2646)
Browse files Browse the repository at this point in the history
Adds the `EphemeralGenesisBinary` field to manifest. This adds support
to reset ephemeral networks to start genesis from arbitrary network
upgrade. This ensures we can skip old upgrades already performed on
protected networks.

issue: #2517
  • Loading branch information
corverroos authored Dec 9, 2024
1 parent f8816bf commit b75153f
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 40 deletions.
9 changes: 7 additions & 2 deletions e2e/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/omni-network/omni/e2e/netman/pingpong"
"github.com/omni-network/omni/e2e/solve"
"github.com/omni-network/omni/e2e/types"
haloapp "github.com/omni-network/omni/halo/app"
"github.com/omni-network/omni/halo/genutil/evm/predeploys"
"github.com/omni-network/omni/lib/contracts"
"github.com/omni-network/omni/lib/errors"
Expand Down Expand Up @@ -403,10 +404,14 @@ func maybeSubmitNetworkUpgrade(ctx context.Context, def Definition) error {
height = uint64(def.Manifest.NetworkUpgradeHeight)
}

log.Info(ctx, "Planning upgrade", "height", height, "name", latestUpgrade)
upgrade, err := haloapp.NextUpgrade(def.Manifest.EphemeralGenesisBinary)
if err != nil {
return err
}
log.Info(ctx, "Planning upgrade", "height", height, "name", upgrade)

tx, err := contract.PlanUpgrade(txOpts, bindings.UpgradePlan{
Name: latestUpgrade,
Name: upgrade,
Height: height,
Info: "e2e triggered upgrade",
})
Expand Down
10 changes: 6 additions & 4 deletions e2e/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/omni-network/omni/e2e/app/static"
"github.com/omni-network/omni/e2e/types"
"github.com/omni-network/omni/e2e/vmcompose"
uluwatu1 "github.com/omni-network/omni/halo/app/upgrades/uluwatu"
haloapp "github.com/omni-network/omni/halo/app"
halocmd "github.com/omni-network/omni/halo/cmd"
halocfg "github.com/omni-network/omni/halo/config"
"github.com/omni-network/omni/halo/genutil"
Expand Down Expand Up @@ -50,8 +50,6 @@ const (

PrivvalKeyFile = "config/priv_validator_key.json"
PrivvalStateFile = "data/priv_validator_state.json"

latestUpgrade = uluwatu1.UpgradeName
)

// Setup sets up the testnet configuration.
Expand Down Expand Up @@ -89,9 +87,13 @@ func Setup(ctx context.Context, def Definition, depCfg DeployConfig) error {
valPrivKeys = append(valPrivKeys, val.PrivvalKey)
}

// Network upgrade to include in genesis (applied at height=1)
var upgrade string
if def.Manifest.NetworkUpgradeHeight == 0 {
upgrade = latestUpgrade // Genesis upgrade.
upgrade, err = haloapp.NextUpgrade(def.Manifest.EphemeralGenesisBinary)
if err != nil {
return err
}
}

cosmosGenesis, err := genutil.MakeGenesis(
Expand Down
1 change: 1 addition & 0 deletions e2e/docker/compose.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
- 6060 # Pprof
volumes:
- ./{{ .Name }}:/halo
environment: [{{ if $.EphemeralGenesisBinary}}COSMOVISOR_CUSTOM_GENESIS={{$.EphemeralGenesisBinary}}{{ end }}]
logging:
driver: local
networks:
Expand Down
44 changes: 23 additions & 21 deletions e2e/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,21 @@ func (p *Provider) Setup() error {
}

def := ComposeDef{
Network: true,
NetworkName: p.testnet.Name,
NetworkCIDR: p.testnet.IP.String(),
BindAll: false,
UpgradeVersion: p.testnet.UpgradeVersion,
Nodes: p.testnet.Nodes,
OmniEVMs: p.testnet.OmniEVMs,
Anvils: p.testnet.AnvilChains,
Relayer: true,
Prometheus: p.testnet.Prometheus,
Monitor: true,
Solver: true,
GethVerbosity: 3, // Info
GethInitTags: gethInitTags,
Network: true,
NetworkName: p.testnet.Name,
NetworkCIDR: p.testnet.IP.String(),
BindAll: false,
UpgradeVersion: p.testnet.UpgradeVersion,
Nodes: p.testnet.Nodes,
OmniEVMs: p.testnet.OmniEVMs,
Anvils: p.testnet.AnvilChains,
Relayer: true,
Prometheus: p.testnet.Prometheus,
Monitor: true,
Solver: true,
GethVerbosity: 3, // Info
GethInitTags: gethInitTags,
EphemeralGenesisBinary: p.testnet.Manifest.EphemeralGenesisBinary,
}
def = SetImageTags(def, p.testnet.Manifest, p.omniTag)

Expand Down Expand Up @@ -180,13 +181,14 @@ func (p *Provider) StartNodes(ctx context.Context, nodes ...*e2e.Node) error {
}

type ComposeDef struct {
Network bool
NetworkName string
NetworkCIDR string
BindAll bool
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.
Network bool
NetworkName string
NetworkCIDR string
BindAll bool
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.
EphemeralGenesisBinary string // Optional network upgrade to use from genesis

Nodes []*e2e.Node
OmniEVMs []types.OmniEVM
Expand Down
1 change: 1 addition & 0 deletions e2e/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func TestComposeTemplate(t *testing.T) {
// If the network is empheral, we use the devnet configuration.
if test.isEmpheral {
testnet.Network = netconf.Devnet
testnet.Manifest.EphemeralGenesisBinary = "ephemeral_upgrade_99"
}

if test.upgrade != "" {
Expand Down
1 change: 1 addition & 0 deletions e2e/docker/testdata/TestComposeTemplate_commit.golden
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
- 6060 # Pprof
volumes:
- ./node0:/halo
environment: []
logging:
driver: local
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
- 6060 # Pprof
volumes:
- ./node0:/halo
environment: [COSMOVISOR_CUSTOM_GENESIS=ephemeral_upgrade_99]
logging:
driver: local
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
- 6060 # Pprof
volumes:
- ./node0:/halo
environment: [COSMOVISOR_CUSTOM_GENESIS=ephemeral_upgrade_99]
logging:
driver: local
networks:
Expand Down
7 changes: 6 additions & 1 deletion e2e/types/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ type Manifest struct {
// This overrides the --omni-image-tag if non-empty.
PinnedRelayerTag string `toml:"pinned_relayer_tag"`

// NetworkUpgradeHeight defines the network upgrade height, default is genesis, negative is disabled.
// NetworkUpgradeHeight defines the network upgrade height, default=0, negative is disabled.
// Note that it might be scheduled at a later height.
NetworkUpgradeHeight int64 `toml:"network_upgrade_height"`

// EphemeralGenesisBinary defines halovisor binary (network upgrade) to use from genesis onwards.
// The subsequent network upgrade will be planned at NetworkUpgradeHeight.
// This is only applicable to ephemeral networks.
EphemeralGenesisBinary string `toml:"ephemeral_genesis_binary"`

// FeatureFlags defines the feature flags to enable.
FeatureFlags feature.Flags `toml:"feature_flags"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- 6060 # Pprof
volumes:
- ./validator01:/halo
environment: []
logging:
driver: local
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- 6060 # Pprof
volumes:
- ./validator02:/halo
environment: []
logging:
driver: local
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- 6060 # Pprof
volumes:
- ./seed01:/halo
environment: []
logging:
driver: local
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- 6060 # Pprof
volumes:
- ./fullnode01:/halo
environment: []
logging:
driver: local
networks:
Expand Down
46 changes: 35 additions & 11 deletions halo/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,45 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
)

func (a App) setUpgradeHandlers() error {
upgrades := []struct {
Name string
Handler upgradetypes.UpgradeHandler
Store storetypes.StoreUpgrades
}{
{
Name: uluwatu1.UpgradeName,
Handler: uluwatu1.CreateUpgradeHandler(a.ModuleManager, a.Configurator(), a.SlashingKeeper),
Store: uluwatu1.StoreUpgrades,
// Upgrade defines a network upgrade.
type Upgrade struct {
Name string
HandlerFunc func(App) upgradetypes.UpgradeHandler
Store storetypes.StoreUpgrades
}

var upgrades = []Upgrade{
{
Name: uluwatu1.UpgradeName,
HandlerFunc: func(a App) upgradetypes.UpgradeHandler {
return uluwatu1.CreateUpgradeHandler(a.ModuleManager, a.Configurator(), a.SlashingKeeper)
},
Store: uluwatu1.StoreUpgrades,
},
}

// NextUpgrade returns the next upgrade name after the provided previous upgrade..
func NextUpgrade(prev string) (string, error) {
if prev == "" { // Return the first upgrade
return upgrades[0].Name, nil
}

for i, u := range upgrades {
if i == len(upgrades)-1 {
break
}

if u.Name == prev {
return upgrades[i+1].Name, nil
}
}

return "", errors.New("prev upgrade not found [BUG]")
}

func (a App) setUpgradeHandlers() error {
for _, u := range upgrades {
a.UpgradeKeeper.SetUpgradeHandler(u.Name, u.Handler)
a.UpgradeKeeper.SetUpgradeHandler(u.Name, u.HandlerFunc(a))
}

upgradeInfo, err := a.UpgradeKeeper.ReadUpgradeInfoFromDisk()
Expand Down
2 changes: 1 addition & 1 deletion scripts/halovisor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docker build args
ARG OMNI_COSMOVISOR_VERSION=v0.4.0
ARG OMNI_COSMOVISOR_VERSION=v0.5.0
ARG HALO_VERSION_0_GENESIS=v0.8.1
ARG HALO_VERSION_1_ULUWATU=main

Expand Down

0 comments on commit b75153f

Please sign in to comment.