Skip to content

Commit

Permalink
[CT-850] add flag to enable optimistic block execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed May 23, 2024
1 parent 07f18c3 commit 3394785
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 34 deletions.
5 changes: 5 additions & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ func New(
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

// Enable optimistic block execution.
if appFlags.OptimisticExecutionEnabled {
baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution())
}

bApp := baseapp.NewBaseApp(appconstants.AppName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
Expand Down
30 changes: 25 additions & 5 deletions protocol/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ type Flags struct {

// Grpc Streaming
GrpcStreamingEnabled bool
VEOracleEnabled bool // Slinky Vote Extensions

// Slinky Vote Extensions
VEOracleEnabled bool

// Optimistic block execution
OptimisticExecutionEnabled bool
}

// List of CLI flags.
Expand All @@ -41,6 +46,9 @@ const (

// Slinky VEs enabled
VEOracleEnabled = "slinky-vote-extension-oracle-enabled"

// Enable optimistic block execution.
OptimisticExecutionEnabled = "optimistic-execution-enabled"
)

// Default values.
Expand All @@ -50,8 +58,9 @@ const (
DefaultNonValidatingFullNode = false
DefaultDdErrorTrackingFormat = false

DefaultGrpcStreamingEnabled = false
DefaultVEOracleEnabled = true
DefaultGrpcStreamingEnabled = false
DefaultVEOracleEnabled = true
DefaultOptimisticExecutionEnabled = false
)

// AddFlagsToCmd adds flags to app initialization.
Expand Down Expand Up @@ -90,6 +99,11 @@ func AddFlagsToCmd(cmd *cobra.Command) {
DefaultVEOracleEnabled,
"Whether to run on-chain oracle via slinky vote extensions",
)
cmd.Flags().Bool(
OptimisticExecutionEnabled,
DefaultOptimisticExecutionEnabled,
"Whether to enable optimistic block execution",
)
}

// Validate checks that the flags are valid.
Expand Down Expand Up @@ -124,8 +138,9 @@ func GetFlagValuesFromOptions(
GrpcAddress: config.DefaultGRPCAddress,
GrpcEnable: true,

GrpcStreamingEnabled: DefaultGrpcStreamingEnabled,
VEOracleEnabled: true,
GrpcStreamingEnabled: DefaultGrpcStreamingEnabled,
VEOracleEnabled: true,
OptimisticExecutionEnabled: DefaultOptimisticExecutionEnabled,
}

// Populate the flags if they exist.
Expand Down Expand Up @@ -177,5 +192,10 @@ func GetFlagValuesFromOptions(
}
}

if option := appOpts.Get(OptimisticExecutionEnabled); option != nil {
if v, err := cast.ToBoolE(option); err == nil {
result.OptimisticExecutionEnabled = v
}
}
return result
}
73 changes: 44 additions & 29 deletions protocol/app/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func TestAddFlagsToCommand(t *testing.T) {
fmt.Sprintf("Has %s flag", flags.GrpcStreamingEnabled): {
flagName: flags.GrpcStreamingEnabled,
},
fmt.Sprintf("Has %s flag", flags.OptimisticExecutionEnabled): {
flagName: flags.OptimisticExecutionEnabled,
},
}

for name, tc := range tests {
Expand All @@ -48,11 +51,12 @@ func TestValidate(t *testing.T) {
}{
"success (default values)": {
flags: flags.Flags{
NonValidatingFullNode: flags.DefaultNonValidatingFullNode,
DdAgentHost: flags.DefaultDdAgentHost,
DdTraceAgentPort: flags.DefaultDdTraceAgentPort,
GrpcAddress: config.DefaultGRPCAddress,
GrpcEnable: true,
NonValidatingFullNode: flags.DefaultNonValidatingFullNode,
DdAgentHost: flags.DefaultDdAgentHost,
DdTraceAgentPort: flags.DefaultDdTraceAgentPort,
GrpcAddress: config.DefaultGRPCAddress,
GrpcEnable: true,
OptimisticExecutionEnabled: false,
},
},
"success - full node & gRPC disabled": {
Expand All @@ -68,6 +72,13 @@ func TestValidate(t *testing.T) {
GrpcStreamingEnabled: true,
},
},
"success - optimistic execution": {
flags: flags.Flags{
NonValidatingFullNode: false,
GrpcEnable: true,
OptimisticExecutionEnabled: true,
},
},
"failure - gRPC disabled": {
flags: flags.Flags{
GrpcEnable: false,
Expand Down Expand Up @@ -101,36 +112,40 @@ func TestGetFlagValuesFromOptions(t *testing.T) {
optsMap map[string]any

// Expectations.
expectedNonValidatingFullNodeFlag bool
expectedDdAgentHost string
expectedDdTraceAgentPort uint16
expectedGrpcAddress string
expectedGrpcEnable bool
expectedGrpcStreamingEnable bool
expectedNonValidatingFullNodeFlag bool
expectedDdAgentHost string
expectedDdTraceAgentPort uint16
expectedGrpcAddress string
expectedGrpcEnable bool
expectedGrpcStreamingEnable bool
expectedOptimisticExecutionEnabled bool
}{
"Sets to default if unset": {
expectedNonValidatingFullNodeFlag: false,
expectedDdAgentHost: "",
expectedDdTraceAgentPort: 8126,
expectedGrpcAddress: "localhost:9090",
expectedGrpcEnable: true,
expectedGrpcStreamingEnable: false,
expectedNonValidatingFullNodeFlag: false,
expectedDdAgentHost: "",
expectedDdTraceAgentPort: 8126,
expectedGrpcAddress: "localhost:9090",
expectedGrpcEnable: true,
expectedGrpcStreamingEnable: false,
expectedOptimisticExecutionEnabled: false,
},
"Sets values from options": {
optsMap: map[string]any{
flags.NonValidatingFullNodeFlag: true,
flags.DdAgentHost: "agentHostTest",
flags.DdTraceAgentPort: uint16(777),
flags.GrpcEnable: false,
flags.GrpcAddress: "localhost:9091",
flags.GrpcStreamingEnabled: "true",
flags.NonValidatingFullNodeFlag: true,
flags.DdAgentHost: "agentHostTest",
flags.DdTraceAgentPort: uint16(777),
flags.GrpcEnable: false,
flags.GrpcAddress: "localhost:9091",
flags.GrpcStreamingEnabled: "true",
flags.OptimisticExecutionEnabled: "true",
},
expectedNonValidatingFullNodeFlag: true,
expectedDdAgentHost: "agentHostTest",
expectedDdTraceAgentPort: 777,
expectedGrpcEnable: false,
expectedGrpcAddress: "localhost:9091",
expectedGrpcStreamingEnable: true,
expectedNonValidatingFullNodeFlag: true,
expectedDdAgentHost: "agentHostTest",
expectedDdTraceAgentPort: 777,
expectedGrpcEnable: false,
expectedGrpcAddress: "localhost:9091",
expectedGrpcStreamingEnable: true,
expectedOptimisticExecutionEnabled: true,
},
}

Expand Down

0 comments on commit 3394785

Please sign in to comment.