Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Optimistic Execution on v5.2.x (FNS not compatible) #2060

Open
wants to merge 10 commits into
base: release/protocol/v5.2.x
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/workflows/protocol-build-and-push-mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on: # yamllint disable-line rule:truthy
branches:
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
- 'td/*'

jobs:
build-and-push-mainnet:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/protocol-build-and-push-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on: # yamllint disable-line rule:truthy
branches:
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
- 'td/*'

jobs:
build-and-push-testnet:
Expand Down
10 changes: 8 additions & 2 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ func New(
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

// Enable optimistic block execution.
if appFlags.OptimisticExecutionEnabled {
logger.Info("optimistic execution is enabled.")
baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution())
}

bApp := baseapp.NewBaseApp(appconstants.AppName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
Expand Down Expand Up @@ -1654,8 +1660,6 @@ func (app *App) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
if err != nil {
return response, err
}
block := app.IndexerEventManager.ProduceBlock(ctx)
app.IndexerEventManager.SendOnchainData(block)
return response, err
}

Expand All @@ -1664,6 +1668,8 @@ func (app *App) Precommitter(ctx sdk.Context) {
if err := app.ModuleManager.Precommit(ctx); err != nil {
panic(err)
}
block := app.IndexerEventManager.ProduceBlock(ctx)
app.IndexerEventManager.SendOnchainData(block)
}

// PrepareCheckStater application updates after commit and before any check state is invoked.
Expand Down
25 changes: 23 additions & 2 deletions protocol/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Flags struct {
GrpcStreamingMaxChannelBufferSize uint32

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

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

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

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

// Default values.
Expand All @@ -62,7 +67,8 @@ const (
DefaultGrpcStreamingMaxBatchSize = 2000
DefaultGrpcStreamingMaxChannelBufferSize = 2000

DefaultVEOracleEnabled = true
DefaultVEOracleEnabled = true
DefaultOptimisticExecutionEnabled = false
)

// AddFlagsToCmd adds flags to app initialization.
Expand Down Expand Up @@ -116,6 +122,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 All @@ -127,6 +138,10 @@ func (f *Flags) Validate() error {

// Grpc streaming
if f.GrpcStreamingEnabled {
if f.OptimisticExecutionEnabled {
// TODO(OTE-456): Finish gRPC streaming x OE integration.
return fmt.Errorf("grpc streaming cannot be enabled together with optimistic execution")
}
if !f.GrpcEnable {
return fmt.Errorf("grpc.enable must be set to true - grpc streaming requires gRPC server")
}
Expand Down Expand Up @@ -164,7 +179,8 @@ func GetFlagValuesFromOptions(
GrpcStreamingMaxBatchSize: DefaultGrpcStreamingMaxBatchSize,
GrpcStreamingMaxChannelBufferSize: DefaultGrpcStreamingMaxChannelBufferSize,

VEOracleEnabled: true,
VEOracleEnabled: true,
OptimisticExecutionEnabled: DefaultOptimisticExecutionEnabled,
}

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

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

for name, tc := range tests {
Expand All @@ -57,11 +60,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 @@ -80,6 +84,22 @@ func TestValidate(t *testing.T) {
GrpcStreamingMaxChannelBufferSize: 2000,
},
},
"success - optimistic execution": {
flags: flags.Flags{
NonValidatingFullNode: false,
GrpcEnable: true,
OptimisticExecutionEnabled: true,
},
},
"failure - optimistic execution cannot be enabled with gRPC streaming": {
flags: flags.Flags{
NonValidatingFullNode: false,
GrpcEnable: true,
GrpcStreamingEnabled: true,
OptimisticExecutionEnabled: true,
},
expectedErr: fmt.Errorf("grpc streaming cannot be enabled together with optimistic execution"),
},
"failure - gRPC disabled": {
flags: flags.Flags{
GrpcEnable: false,
Expand Down Expand Up @@ -153,6 +173,7 @@ func TestGetFlagValuesFromOptions(t *testing.T) {
expectedGrpcStreamingFlushMs uint32
expectedGrpcStreamingBatchSize uint32
expectedGrpcStreamingMaxChannelBufferSize uint32
expectedOptimisticExecutionEnabled bool
}{
"Sets to default if unset": {
expectedNonValidatingFullNodeFlag: false,
Expand All @@ -164,6 +185,7 @@ func TestGetFlagValuesFromOptions(t *testing.T) {
expectedGrpcStreamingFlushMs: 50,
expectedGrpcStreamingBatchSize: 2000,
expectedGrpcStreamingMaxChannelBufferSize: 2000,
expectedOptimisticExecutionEnabled: false,
},
"Sets values from options": {
optsMap: map[string]any{
Expand All @@ -176,6 +198,7 @@ func TestGetFlagValuesFromOptions(t *testing.T) {
flags.GrpcStreamingFlushIntervalMs: uint32(408),
flags.GrpcStreamingMaxBatchSize: uint32(650),
flags.GrpcStreamingMaxChannelBufferSize: uint32(972),
flags.OptimisticExecutionEnabled: "true",
},
expectedNonValidatingFullNodeFlag: true,
expectedDdAgentHost: "agentHostTest",
Expand All @@ -186,6 +209,7 @@ func TestGetFlagValuesFromOptions(t *testing.T) {
expectedGrpcStreamingFlushMs: 408,
expectedGrpcStreamingBatchSize: 650,
expectedGrpcStreamingMaxChannelBufferSize: 972,
expectedOptimisticExecutionEnabled: true,
},
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ replace (
// Use dYdX fork of CometBFT
github.com/cometbft/cometbft => github.com/dydxprotocol/cometbft v0.38.6-0.20240426214049-c8beeeada40a
// Use dYdX fork of Cosmos SDK
github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20240606183841-18966898625f
github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20240807220600-7a2c45589d7c
github.com/cosmos/iavl => github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85
)

Expand Down
4 changes: 2 additions & 2 deletions protocol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dydxprotocol/cometbft v0.38.6-0.20240426214049-c8beeeada40a h1:KeQZZsYJQ/AKQ6lbP5lL3N/6aOclxxYG8pIm8zerwZw=
github.com/dydxprotocol/cometbft v0.38.6-0.20240426214049-c8beeeada40a/go.mod h1:EBEod7kZfNr4W0VooOrTEMSiXNrSyiQ/M2FL/rOcPCs=
github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20240606183841-18966898625f h1:OLmCAiUdKbz9KNYzNtrvl+Y8l5sNWeWqjN5U5h78ckw=
github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20240606183841-18966898625f/go.mod h1:NruCXox2SOkVq2ZC5Bs8s2sT+jjVqBEU59wXyZOkCkM=
github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20240807220600-7a2c45589d7c h1:xVjHUTNwabuapovByZ13Ei52pJLBhBTdWJHlm3bYEQo=
github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20240807220600-7a2c45589d7c/go.mod h1:NruCXox2SOkVq2ZC5Bs8s2sT+jjVqBEU59wXyZOkCkM=
github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d h1:HgLu1FD2oDFzlKW6/+SFXlH5Os8cwNTbplQIrQOWx8w=
github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d/go.mod h1:zMcD3hfNwd0WMTpdRUhS3QxoCoEtBXWeoKsu3iaLBbQ=
github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85 h1:5B/yGZyTBX/OZASQQMnk6Ms/TZja56MYd8OBaVc0Mho=
Expand Down
21 changes: 6 additions & 15 deletions protocol/mocks/ClobKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 6 additions & 15 deletions protocol/mocks/MemClobKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading