Skip to content

Commit

Permalink
chore: add OE Abort rate debug flag (backport #2366) (#2401)
Browse files Browse the repository at this point in the history
Co-authored-by: Teddy Ding <[email protected]>
  • Loading branch information
mergify[bot] and teddyding authored Sep 30, 2024
1 parent f39b3e9 commit 4a9ea53
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
14 changes: 13 additions & 1 deletion protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"encoding/json"
"fmt"
"io"
"math/big"
"net/http"
Expand Down Expand Up @@ -33,6 +34,7 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/baseapp/oe"
"github.com/cosmos/cosmos-sdk/client"
cosmosflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
Expand Down Expand Up @@ -413,7 +415,17 @@ func New(
// Enable optimistic block execution.
if appFlags.OptimisticExecutionEnabled {
logger.Info("optimistic execution is enabled.")
baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution())
if appFlags.OptimisticExecutionTestAbortRate > 0 {
logger.Warn(fmt.Sprintf(
"Test flag optimistic-execution-test-abort-rate is set: %v\n",
appFlags.OptimisticExecutionTestAbortRate,
))
}
baseAppOptions = append(
baseAppOptions,
baseapp.SetOptimisticExecution(
oe.WithAbortRate(int(appFlags.OptimisticExecutionTestAbortRate)),
))
}

bApp := baseapp.NewBaseApp(appconstants.AppName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
Expand Down
28 changes: 22 additions & 6 deletions protocol/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type Flags struct {

VEOracleEnabled bool // Slinky Vote Extensions
// Optimistic block execution
OptimisticExecutionEnabled bool
OptimisticExecutionEnabled bool
OptimisticExecutionTestAbortRate uint16
}

// List of CLI flags.
Expand All @@ -58,7 +59,8 @@ const (
VEOracleEnabled = "slinky-vote-extension-oracle-enabled"

// Enable optimistic block execution.
OptimisticExecutionEnabled = "optimistic-execution-enabled"
OptimisticExecutionEnabled = "optimistic-execution-enabled"
OptimisticExecutionTestAbortRate = "optimistic-execution-test-abort-rate"
)

// Default values.
Expand All @@ -76,8 +78,10 @@ const (
DefaultWebsocketStreamingPort = 9092
DefaultFullNodeStreamingSnapshotInterval = 0

DefaultVEOracleEnabled = true
DefaultOptimisticExecutionEnabled = false
DefaultVEOracleEnabled = true

DefaultOptimisticExecutionEnabled = false
DefaultOptimisticExecutionTestAbortRate = 0
)

// AddFlagsToCmd adds flags to app initialization.
Expand Down Expand Up @@ -152,6 +156,11 @@ func AddFlagsToCmd(cmd *cobra.Command) {
DefaultOptimisticExecutionEnabled,
"Whether to enable optimistic block execution",
)
cmd.Flags().Uint16(
OptimisticExecutionTestAbortRate,
DefaultOptimisticExecutionTestAbortRate,
"[Test only] Abort rate for optimistic execution",
)
}

// Validate checks that the flags are valid.
Expand Down Expand Up @@ -210,8 +219,9 @@ func GetFlagValuesFromOptions(
WebsocketStreamingPort: DefaultWebsocketStreamingPort,
FullNodeStreamingSnapshotInterval: DefaultFullNodeStreamingSnapshotInterval,

VEOracleEnabled: true,
OptimisticExecutionEnabled: DefaultOptimisticExecutionEnabled,
VEOracleEnabled: true,
OptimisticExecutionEnabled: DefaultOptimisticExecutionEnabled,
OptimisticExecutionTestAbortRate: DefaultOptimisticExecutionTestAbortRate,
}

// Populate the flags if they exist.
Expand Down Expand Up @@ -304,5 +314,11 @@ func GetFlagValuesFromOptions(
result.OptimisticExecutionEnabled = v
}
}

if option := appOpts.Get(OptimisticExecutionTestAbortRate); option != nil {
if v, err := cast.ToUint16E(option); err == nil {
result.OptimisticExecutionTestAbortRate = v
}
}
return result
}

0 comments on commit 4a9ea53

Please sign in to comment.