Skip to content

Commit

Permalink
fix(cli/cmd): add feature flags to the joint-test (#2693)
Browse files Browse the repository at this point in the history
Adds feature flags to the join test

issue: #2525
  • Loading branch information
chmllr authored Dec 13, 2024
1 parent 444f9d0 commit 2071c22
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 13 deletions.
1 change: 1 addition & 0 deletions cli/cmd/compose.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
container_name: halo
image: omniops/halovisor:{{.HaloTag}}
restart: unless-stopped
environment: [{{ if .GenesisBinary}}COSMOVISOR_CUSTOM_GENESIS={{.GenesisBinary}}{{ end }}]
ports:
- 26656:26656 # CometBFT Consensus P2P
- 26657:26657 # CometBFT Consensus RPC
Expand Down
72 changes: 63 additions & 9 deletions cli/cmd/initnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"text/template"

"github.com/omni-network/omni/e2e/app/geth"
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/lib/buildinfo"
cprovider "github.com/omni-network/omni/lib/cchain/provider"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/feature"
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"

Expand All @@ -37,13 +39,14 @@ const (
)

type InitConfig struct {
Network netconf.ID
Home string
Moniker string
Clean bool
Archive bool
Debug bool
HaloTag string
Network netconf.ID
Home string
Moniker string
Clean bool
Archive bool
Debug bool
HaloTag string
HaloFeatureFlags feature.Flags
}

func (c InitConfig) Verify() error {
Expand Down Expand Up @@ -131,6 +134,7 @@ func InitNodes(ctx context.Context, cfg InitConfig) error {
TrustedSync: !cfg.Archive, // Don't state sync if archive
AddrBook: true,
HaloCfgFunc: func(haloCfg *halocfg.Config) {
haloCfg.FeatureFlags = cfg.HaloFeatureFlags
haloCfg.EngineEndpoint = "http://omni_evm:8551"
haloCfg.EngineJWTFile = "/geth/jwtsecret"
if cfg.Archive {
Expand Down Expand Up @@ -158,14 +162,62 @@ func InitNodes(ctx context.Context, cfg InitConfig) error {
return errors.Wrap(err, "init halo")
}

err = writeComposeFile(ctx, cfg)
var upgrade string
// For non-archive nodes, we want to detect the latest upgrade and start
// the local node with this binary, so that the consensus snapshot pulled
// from the network is compatible with the local binary.
if !cfg.Archive {
upgrade, err = detectCurrentUpgrade(ctx, cfg.Network)
if err != nil {
return errors.Wrap(err, "detect upgrade")
}
}

err = writeComposeFile(ctx, cfg, upgrade)
if err != nil {
return errors.Wrap(err, "write compose file")
}

return nil
}

// detectCurrentUpgrade detects the current upgrade applied on the network.
// Note it only detects known upgrades. It return empty string if no known upgrade is applied.
func detectCurrentUpgrade(ctx context.Context, network netconf.ID) (string, error) {
rpcServer := network.Static().ConsensusRPC()
rpcCl, err := rpchttp.New(rpcServer, "/websocket")
if err != nil {
return "", errors.Wrap(err, "create rpc client")
}
cprov := cprovider.NewABCI(rpcCl, network)

// Cosmos doesn't provide an API to simply query current applied upgrade.
// So we iterate through knowns and check which is active.
for _, upgrade := range haloapp.AllUpgrades() {
plan, ok, err := cprov.AppliedPlan(ctx, upgrade)
if err != nil {
return "", errors.Wrap(err, "fetching applied plan")
} else if !ok {
continue
} else if upgrade != plan.Name {
return "", errors.New("unexpected upgrade plan name", "expected", upgrade, "actual", plan.Name)
}

log.Info(ctx, "Detected activated network upgrade", "upgrade_name", plan.Name, "upgrade_height", plan.Height)

return upgrade, nil
}

// No known upgrade detected.
if network != netconf.Devnet { // This is only expected for devnet
return "", errors.New("failed to detect known network upgrade (use latest cli version)")
}

log.Info(ctx, "No known network upgrade detected")

return "", nil
}

// maybeDownloadGenesis downloads the genesis files via cprovider the network if they are not already set.
func maybeDownloadGenesis(ctx context.Context, network netconf.ID) error {
if network.IsProtected() {
Expand All @@ -191,7 +243,7 @@ func maybeDownloadGenesis(ctx context.Context, network netconf.ID) error {
return netconf.SetEphemeralGenesis(network, execution, consensus)
}

func writeComposeFile(ctx context.Context, cfg InitConfig) error {
func writeComposeFile(ctx context.Context, cfg InitConfig, upgrade string) error {
composeFile := filepath.Join(cfg.Home, "compose.yaml")

if cmtos.FileExists(composeFile) {
Expand Down Expand Up @@ -223,11 +275,13 @@ func writeComposeFile(ctx context.Context, cfg InitConfig) error {
GethTag string
GethVerbosity int
GethArchive bool
GenesisBinary string
}{
HaloTag: cfg.HaloTag,
GethTag: geth.Version,
GethVerbosity: verbosity,
GethArchive: cfg.Archive,
GenesisBinary: upgrade,
})
if err != nil {
return errors.Wrap(err, "execute template")
Expand Down
10 changes: 10 additions & 0 deletions halo/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ var upgrades = []Upgrade{
},
}

// AllUpgrades returns the names of all known upgrades.
func AllUpgrades() []string {
var resp []string
for _, u := range upgrades {
resp = append(resp, u.Name)
}

return resp
}

// NextUpgrade returns the next upgrade name after the provided previous upgrade..
func NextUpgrade(prev string) (string, error) {
if prev == "" { // Return the first upgrade
Expand Down
30 changes: 26 additions & 4 deletions scripts/join/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import (
"time"

clicmd "github.com/omni-network/omni/cli/cmd"
"github.com/omni-network/omni/e2e/manifests"
"github.com/omni-network/omni/e2e/types"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/ethclient"
"github.com/omni-network/omni/lib/feature"
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/tutil"
"github.com/omni-network/omni/lib/umath"

rpchttp "github.com/cometbft/cometbft/rpc/client/http"

"github.com/BurntSushi/toml"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -61,10 +65,11 @@ func TestJoinNetwork(t *testing.T) {
networkID := netconf.ID(*network)
haloTag := haloTag(t)
cfg := clicmd.InitConfig{
Network: networkID,
Home: home,
Moniker: t.Name(),
HaloTag: haloTag,
Network: networkID,
Home: home,
Moniker: t.Name(),
HaloTag: haloTag,
HaloFeatureFlags: maybeGetFeatureFlags(ctx, networkID),
}

tutil.RequireNoError(t, ensureHaloImage(cfg.HaloTag))
Expand Down Expand Up @@ -348,3 +353,20 @@ func getContainerStats(ctx context.Context) (stats, error) {

return resp, nil
}

func maybeGetFeatureFlags(ctx context.Context, network netconf.ID) feature.Flags {
if network.IsProtected() {
return make([]string, 0) // Protected networks never have feature flags
} else if network == netconf.Devnet {
panic("cannot join devnet")
}

var manifest types.Manifest
_, err := toml.Decode(string(manifests.Staging()), &manifest)
if err != nil {
log.Error(ctx, "failed to parse the manifest", err)
return make([]string, 0)
}

return manifest.FeatureFlags
}

0 comments on commit 2071c22

Please sign in to comment.