From 3394785df46c94665ed34129b53058637a1f73dd Mon Sep 17 00:00:00 2001 From: Jay Yu <103467857+jayy04@users.noreply.github.com> Date: Thu, 16 May 2024 15:23:52 -0400 Subject: [PATCH] [CT-850] add flag to enable optimistic block execution --- protocol/app/app.go | 5 +++ protocol/app/flags/flags.go | 30 ++++++++++--- protocol/app/flags/flags_test.go | 73 +++++++++++++++++++------------- 3 files changed, 74 insertions(+), 34 deletions(-) diff --git a/protocol/app/app.go b/protocol/app/app.go index 679f4e3e73..98e5cdacf3 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -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) diff --git a/protocol/app/flags/flags.go b/protocol/app/flags/flags.go index 22bf36243c..54b694c2d7 100644 --- a/protocol/app/flags/flags.go +++ b/protocol/app/flags/flags.go @@ -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. @@ -41,6 +46,9 @@ const ( // Slinky VEs enabled VEOracleEnabled = "slinky-vote-extension-oracle-enabled" + + // Enable optimistic block execution. + OptimisticExecutionEnabled = "optimistic-execution-enabled" ) // Default values. @@ -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. @@ -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. @@ -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. @@ -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 } diff --git a/protocol/app/flags/flags_test.go b/protocol/app/flags/flags_test.go index dd6f12db85..21bdcdd2b6 100644 --- a/protocol/app/flags/flags_test.go +++ b/protocol/app/flags/flags_test.go @@ -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 { @@ -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": { @@ -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, @@ -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, }, }