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

chore(halo/evmstaking): return error on unexpected code path #2673

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ devnet-clean: ## Deletes devnet1 containers
.PHONY: e2e-ci
e2e-ci: ## Runs all e2e CI tests
@go install github.com/omni-network/omni/e2e
@cd e2e && ./run-multiple.sh manifests/devnet1.toml manifests/fuzzyhead.toml manifests/ci.toml manifests/backwards.toml
@cd e2e && ./run-multiple.sh manifests/devnet1.toml manifests/devnet2.toml manifests/fuzzyhead.toml manifests/ci.toml manifests/backwards.toml

.PHONY: e2e-run
e2e-run: ## Run specific e2e manifest (MANIFEST=single, MANIFEST=devnet1, etc). Note container remain running after the test.
Expand Down
1 change: 1 addition & 0 deletions halo/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func Start(ctx context.Context, cfg Config) (<-chan error, func(context.Context)

buildinfo.Instrument(ctx)

feature.SetGlobals(cfg.FeatureFlags)
ctx = feature.WithFlags(ctx, cfg.FeatureFlags)

tracerIDs := tracer.Identifiers{Network: cfg.Network, Service: "halo", Instance: cfg.Comet.Moniker}
Expand Down
7 changes: 7 additions & 0 deletions halo/evmstaking/evmstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/omni-network/omni/halo/genutil/evm/predeploys"
"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/k1util"
"github.com/omni-network/omni/lib/log"
evmenginetypes "github.com/omni-network/omni/octane/evmengine/types"
Expand Down Expand Up @@ -73,6 +74,9 @@ func New(

// Prepare returns all omni stake contract EVM event logs from the provided block hash.
func (p EventProcessor) Prepare(ctx context.Context, blockHash common.Hash) ([]evmenginetypes.EVMEvent, error) {
if feature.FlagEVMStakingModule.Enabled(ctx) {
return nil, errors.New("unexpected code path [BUG]")
}
logs, err := p.ethCl.FilterLogs(ctx, ethereum.FilterQuery{
BlockHash: &blockHash,
Addresses: p.Addresses(),
Expand Down Expand Up @@ -110,6 +114,9 @@ func (p EventProcessor) Addresses() []common.Address {
// - CreateValidator
// - Delegate.
func (p EventProcessor) Deliver(ctx context.Context, _ common.Hash, elog evmenginetypes.EVMEvent) error {
if feature.FlagEVMStakingModule.Enabled(ctx) {
return errors.New("unexpected code path [BUG]")
}
ethlog, err := elog.ToEthLog()
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions halo/evmstaking2/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/omni-network/omni/halo/genutil/evm/predeploys"
"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/k1util"
"github.com/omni-network/omni/lib/log"
evmenginetypes "github.com/omni-network/omni/octane/evmengine/types"
Expand Down Expand Up @@ -86,6 +87,10 @@ func NewKeeper(

// EndBlock delivers all pending EVM events on every `k.deliverInterval`'th block.
func (k *Keeper) EndBlock(ctx context.Context) error {
if !feature.FlagEVMStakingModule.Enabled(ctx) {
return errors.New("unexpected code path [BUG]")
}

blockHeight := sdk.UnwrapSDKContext(ctx).BlockHeight()

if blockHeight%k.deliverInterval != 0 {
Expand Down Expand Up @@ -122,6 +127,9 @@ func (k *Keeper) EndBlock(ctx context.Context) error {

// Prepare returns all omni stake contract EVM event logs from the provided block hash.
func (k Keeper) Prepare(ctx context.Context, blockHash common.Hash) ([]evmenginetypes.EVMEvent, error) {
if !feature.FlagEVMStakingModule.Enabled(ctx) {
return nil, errors.New("unexpected code path [BUG]")
}
logs, err := k.ethCl.FilterLogs(ctx, ethereum.FilterQuery{
BlockHash: &blockHash,
Addresses: k.Addresses(),
Expand Down Expand Up @@ -162,6 +170,9 @@ func (k Keeper) Addresses() []common.Address {
// first stored in keeper's state. Then all stored events are periodically delivered
// from `EndBlock` at once.
func (k Keeper) Deliver(ctx context.Context, _ common.Hash, elog evmenginetypes.EVMEvent) error {
if !feature.FlagEVMStakingModule.Enabled(ctx) {
return errors.New("unexpected code path [BUG]")
}
err := k.eventsTable.Insert(ctx, &EVMEvent{
Event: &elog,
})
Expand Down
4 changes: 3 additions & 1 deletion halo/evmstaking2/keeper/keeper_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/omni-network/omni/halo/evmstaking2/testutil"
"github.com/omni-network/omni/halo/evmstaking2/types"
"github.com/omni-network/omni/lib/ethclient"
"github.com/omni-network/omni/lib/feature"
"github.com/omni-network/omni/lib/netconf"
etypes "github.com/omni-network/omni/octane/evmengine/types"

Expand Down Expand Up @@ -302,7 +303,8 @@ func setupKeeper(

key := storetypes.NewKVStoreKey(types.ModuleName)
storeSvc := runtime.NewKVStoreService(key)
ctx := sdktestutil.DefaultContext(key, storetypes.NewTransientStoreKey("test_key"))
ctx := sdktestutil.DefaultContext(key, storetypes.NewTransientStoreKey("test_key")).
WithContext(feature.WithFlag(context.Background(), feature.FlagEVMStakingModule))
ctx = ctx.WithBlockHeight(1)
ctx = ctx.WithChainID(netconf.Simnet.Static().OmniConsensusChainIDStr())

Expand Down
17 changes: 15 additions & 2 deletions lib/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ const (
FlagEVMStakingModule Flag = "evm-staking-module"
)

var enabledFlags = make(map[Flag]bool)
chmllr marked this conversation as resolved.
Show resolved Hide resolved

var allFlags = map[Flag]bool{
FlagEVMStakingModule: true,
}

// Flag is a feature flag.
type Flag string

// Enabled returns true if the flag is enabled in the context.
// Enabled returns true if the flag is enabled in the context or globally.
func (f Flag) Enabled(ctx context.Context) bool {
return enabled(ctx, f)
}
Expand Down Expand Up @@ -53,8 +55,19 @@ func WithFlag(ctx context.Context, flag Flag) context.Context {
return WithFlags(ctx, Flags{string(flag)})
}

// enabled returns true if the given flag is enabled in the context.
// SetGlobals enables all given flags globally.
func SetGlobals(flags Flags) {
for _, flag := range flags {
enabledFlags[Flag(flag)] = true
}
}

// enabled returns true if the given flag is enabled globally or in the context.
func enabled(ctx context.Context, flag Flag) bool {
if enabledFlags[flag] {
return true
}

flags, ok := ctx.Value(key{}).([]Flag)
if !ok {
return false
Expand Down
Loading