From 4a9ea53f03bba58afc13cda4381cf1e6939a115e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:40:48 -0400 Subject: [PATCH] chore: add OE Abort rate debug flag (backport #2366) (#2401) Co-authored-by: Teddy Ding --- protocol/app/app.go | 14 +++++++++++++- protocol/app/flags/flags.go | 28 ++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/protocol/app/app.go b/protocol/app/app.go index aafdc3d49b..256efb1314 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -3,6 +3,7 @@ package app import ( "context" "encoding/json" + "fmt" "io" "math/big" "net/http" @@ -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" @@ -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...) diff --git a/protocol/app/flags/flags.go b/protocol/app/flags/flags.go index 9a49d4c15c..aadc805696 100644 --- a/protocol/app/flags/flags.go +++ b/protocol/app/flags/flags.go @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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 }