Skip to content
Closed
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
8 changes: 6 additions & 2 deletions server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"github.com/evstack/ev-node/pkg/config"
)

// Deprecated: FlagAttesterMode is no longer needed. Attester mode is now
// auto-detected by probing the network module at startup.
const FlagAttesterMode = config.FlagPrefixEvnode + "attester-mode"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK attester needs to be a flag, as not all nodes are attesters


// AddFlags adds Evolve specific configuration options to cobra Command.
func AddFlags(cmd *cobra.Command) {
// Add ev-node flags
config.AddFlags(cmd)

// Add network flags
cmd.Flags().Bool(FlagAttesterMode, false, "enable attester mode (soft confirmation by the validator network)")
// Deprecated: attester mode is auto-detected via the network module.
// The flag is kept for backward compatibility but has no effect.
cmd.Flags().Bool(FlagAttesterMode, false, "deprecated: attester mode is now auto-detected")
_ = cmd.Flags().MarkDeprecated(FlagAttesterMode, "attester mode is now auto-detected via the network module")
}
50 changes: 46 additions & 4 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
cmtcfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/mempool"
cmtp2p "github.com/cometbft/cometbft/p2p"
Expand Down Expand Up @@ -55,6 +56,7 @@ import (
"github.com/evstack/ev-node/pkg/store"
rollkittypes "github.com/evstack/ev-node/types"

"github.com/evstack/ev-abci/modules/network/types"
"github.com/evstack/ev-abci/pkg/adapter"
"github.com/evstack/ev-abci/pkg/rpc"
"github.com/evstack/ev-abci/pkg/rpc/core"
Expand Down Expand Up @@ -470,17 +472,21 @@ func setupNodeAndExecutor(
return nil, nil, cleanupFn, err
}

// Auto-detect attester mode by probing the network module via ABCI query.
// This makes the --attester-mode flag obsolete.
attesterMode := detectNetworkModule(ctx, app, sdkLogger)

// Choose ValidatorHasherProvider based on attester mode (network soft confirmation)
var validatorHasherProvider func(proposerAddress []byte, pubKey crypto.PubKey) (rollkittypes.Hash, error)
if srvCtx.Viper.GetBool(FlagAttesterMode) {
if attesterMode {
// Attester mode: use validators from ABCI store
abciStore := execstore.NewExecABCIStore(database)
validatorHasherProvider = adapter.ValidatorHasherFromStoreProvider(abciStore)
sdkLogger.Info("using attester mode: validators will be read from ABCI store")
sdkLogger.Info("attester mode enabled: validators will be read from ABCI store")
} else {
// Sequencer mode: single validator
validatorHasherProvider = adapter.ValidatorHasherProvider()
sdkLogger.Info("using sequencer mode: single validator")
sdkLogger.Info("sequencer mode: single validator (network module not detected)")
}

rolllkitNode, err = node.NewNode(
Expand Down Expand Up @@ -523,7 +529,7 @@ func setupNodeAndExecutor(
Logger: servercmtlog.CometLoggerWrapper{Logger: sdkLogger},
RPCConfig: *cfg.RPC,
EVNodeConfig: evcfg,
AttesterMode: srvCtx.Viper.GetBool(FlagAttesterMode),
AttesterMode: attesterMode,
})

// Pass the created handler to the RPC server constructor
Expand All @@ -547,6 +553,42 @@ func setupNodeAndExecutor(
return rolllkitNode, executor, cleanupFn, nil
}

// networkParamsQueryPath is the gRPC query path for the network module's Params endpoint.
const networkParamsQueryPath = "/evabci.network.v1.Query/Params"

// abciQuerier is a minimal interface for ABCI Query used by detectNetworkModule.
type abciQuerier interface {
Query(context.Context, *abci.RequestQuery) (*abci.ResponseQuery, error)
}

// detectNetworkModule probes the ABCI application with a Params query for the
// network module. If the module is registered the query succeeds (code 0) and
// the function returns true, enabling attester mode automatically.
func detectNetworkModule(ctx context.Context, app abciQuerier, logger log.Logger) bool {
req := &types.QueryParamsRequest{}
reqBytes, err := req.Marshal()
if err != nil {
logger.Error("failed to marshal network module probe request", "error", err)
return false
}

resp, err := app.Query(ctx, &abci.RequestQuery{
Path: networkParamsQueryPath,
Data: reqBytes,
})
if err != nil {
logger.Debug("network module not detected (query error)", "error", err)
return false
}
if resp.Code != 0 {
logger.Debug("network module not detected (non-zero response code)", "code", resp.Code)
return false
}

logger.Info("network module detected, enabling attester mode automatically")
return true
}

// createSequencer creates a sequencer based on the configuration.
// If BasedSequencer is enabled, it creates a based sequencer that fetches transactions from DA.
// Otherwise, it creates a single (traditional) sequencer.
Expand Down
47 changes: 47 additions & 0 deletions server/start_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package server

import (
"context"
_ "embed"
"errors"
"strings"
"testing"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
sdkserver "github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/spf13/viper"
Expand All @@ -13,6 +17,49 @@ import (
"github.com/evstack/ev-node/pkg/genesis"
)

// mockQuerier implements abciQuerier for testing.
type mockQuerier struct {
resp *abci.ResponseQuery
err error
}

func (m *mockQuerier) Query(_ context.Context, _ *abci.RequestQuery) (*abci.ResponseQuery, error) {
return m.resp, m.err
}

func TestDetectNetworkModule(t *testing.T) {
nopLogger := log.NewNopLogger()

tests := []struct {
name string
querier abciQuerier
expected bool
}{
{
name: "module present - returns true",
querier: &mockQuerier{resp: &abci.ResponseQuery{Code: 0, Value: []byte("params")}, err: nil},
expected: true,
},
{
name: "module absent - non-zero code",
querier: &mockQuerier{resp: &abci.ResponseQuery{Code: 1, Log: "unknown query path"}, err: nil},
expected: false,
},
{
name: "query error",
querier: &mockQuerier{resp: nil, err: errors.New("app not ready")},
expected: false,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := detectNetworkModule(context.Background(), tc.querier, nopLogger)
require.Equal(t, tc.expected, result)
})
}
}

func TestParseDAStartHeightFromGenesis(t *testing.T) {
testCases := []struct {
name string
Expand Down
1 change: 0 additions & 1 deletion tests/integration/gm_gaia_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ func (s *DockerIntegrationTestSuite) getGmChain(ctx context.Context) *cosmos.Cha
"--evnode.da.data_namespace", "ev-data",
"--evnode.p2p.listen_address", "/ip4/0.0.0.0/tcp/36656",
"--rpc.laddr", "tcp://0.0.0.0:26657",
"--evnode.attester-mode", "true",
"--grpc.address", "0.0.0.0:9090",
"--api.enable",
"--minimum-gas-prices", "0.001stake",
Expand Down
Loading