From 0ab3f1ecca04ed94caba3cb5deae561ab7dc88c6 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 9 Dec 2024 15:39:48 -0500 Subject: [PATCH] feat: override timeout commit --- Makefile | 1 + README.md | 9 +++++++++ app/app.go | 23 ++++++++++++++++++++--- cmd/celestia-appd/cmd/root.go | 9 +++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c734b1e596..d09c0c9983 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ help: Makefile build: mod @cd ./cmd/celestia-appd @mkdir -p build/ + @echo "--> Building build/celestia-appd" @go build $(BUILD_FLAGS) -o build/ ./cmd/celestia-appd .PHONY: build diff --git a/README.md b/README.md index 44906140b4..451abcf46e 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,15 @@ celestia-appd tx blob pay-for-blob 0x00010203040506070809 0x48656c6c6f2c20576f72 If import celestia-app as a Go module, you may need to add some Go module `replace` directives to avoid type incompatibilities. Please see the `replace` directive in [go.mod](./go.mod) for inspiration. +### Usage in tests + +If you are running celestia-app in tests, you may want to override the `timeout_commit` to produce blocks faster. By default, a celestia-app chain with app version >= 3 will produce blocks every ~6 seconds. To produce blocks faster, you can override the `timeout_commit` with the `--timeout-commit` flag. + +```shell +# Start celestia-appd with a one second timeout commit. +celestia-appd start --timeout-commit 1s +``` + ## Contributing This repo attempts to conform to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) so PR titles should ideally start with `fix:`, `feat:`, `build:`, `chore:`, `ci:`, `docs:`, `style:`, `refactor:`, `perf:`, or `test:` because this helps with semantic versioning and changelog generation. It is especially important to include an `!` (e.g. `feat!:`) if the PR includes a breaking change. diff --git a/app/app.go b/app/app.go index eadd034ea1..777f4d2f00 100644 --- a/app/app.go +++ b/app/app.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "slices" + "time" "github.com/celestiaorg/celestia-app/v3/app/ante" "github.com/celestiaorg/celestia-app/v3/app/encoding" @@ -170,6 +171,10 @@ type App struct { // upgradeHeightV2 is used as a coordination mechanism for the height-based // upgrade from v1 to v2. upgradeHeightV2 int64 + // timeoutCommit is used to override the default timeoutCommit. This is + // useful for testing purposes and should not be used on public networks + // (Arabica, Mocha, or Mainnet Beta). + timeoutCommit time.Duration // MsgGateKeeper is used to define which messages are accepted for a given // app version. MsgGateKeeper *ante.MsgVersioningGateKeeper @@ -188,6 +193,7 @@ func New( invCheckPeriod uint, encodingConfig encoding.Config, upgradeHeightV2 int64, + timeoutCommit time.Duration, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { @@ -214,6 +220,7 @@ func New( tkeys: tkeys, memKeys: memKeys, upgradeHeightV2: upgradeHeightV2, + timeoutCommit: timeoutCommit, } app.ParamsKeeper = initParamsKeeper(appCodec, encodingConfig.Amino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) @@ -481,7 +488,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo app.SignalKeeper.ResetTally(ctx) } } - res.Timeouts.TimeoutCommit = appconsts.GetTimeoutCommit(currentVersion) + res.Timeouts.TimeoutCommit = app.getTimeoutCommit(currentVersion) res.Timeouts.TimeoutPropose = appconsts.GetTimeoutPropose(currentVersion) return res } @@ -539,8 +546,8 @@ func (app *App) Info(req abci.RequestInfo) abci.ResponseInfo { app.mountKeysAndInit(resp.AppVersion) } + resp.Timeouts.TimeoutCommit = app.getTimeoutCommit(resp.AppVersion) resp.Timeouts.TimeoutPropose = appconsts.GetTimeoutPropose(resp.AppVersion) - resp.Timeouts.TimeoutCommit = appconsts.GetTimeoutCommit(resp.AppVersion) return resp } @@ -565,7 +572,7 @@ func (app *App) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain app.SetInitialAppVersionInConsensusParams(ctx, appVersion) app.SetAppVersion(ctx, appVersion) } - res.Timeouts.TimeoutCommit = appconsts.GetTimeoutCommit(appVersion) + res.Timeouts.TimeoutCommit = app.getTimeoutCommit(appVersion) res.Timeouts.TimeoutPropose = appconsts.GetTimeoutPropose(appVersion) return res } @@ -849,3 +856,13 @@ func (app *App) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferS func isSupportedAppVersion(appVersion uint64) bool { return appVersion == v1 || appVersion == v2 || appVersion == v3 } + +// getTimeoutCommit returns the timeoutCommit if a user has overriden it via the +// --timeout-commit flag. Otherwise, it returns the default timeout commit based +// on the app version. +func (app *App) getTimeoutCommit(appVersion uint64) time.Duration { + if app.timeoutCommit != 0 { + return app.timeoutCommit + } + return appconsts.GetTimeoutCommit(appVersion) +} diff --git a/cmd/celestia-appd/cmd/root.go b/cmd/celestia-appd/cmd/root.go index 581ce3592e..78d0163479 100644 --- a/cmd/celestia-appd/cmd/root.go +++ b/cmd/celestia-appd/cmd/root.go @@ -37,6 +37,9 @@ const ( // UpgradeHeightFlag is the flag to specify the upgrade height for v1 to v2 // application upgrade. UpgradeHeightFlag = "v2-upgrade-height" + + // TimeoutCommit is a flag that can be used to override the timeout_commit. + TimeoutCommitFlag = "timeout-commit" ) // NewRootCmd creates a new root command for celestia-appd. @@ -125,7 +128,7 @@ func initRootCommand(rootCommand *cobra.Command, encodingConfig encoding.Config) ) // Add the following commands to the rootCommand: start, tendermint, export, version, and rollback. - addCommands(rootCommand, app.DefaultNodeHome, NewAppServer, appExporter, addModuleInitFlags) + addCommands(rootCommand, app.DefaultNodeHome, NewAppServer, appExporter, addStartFlags) } // setDefaultConsensusParams sets the default consensus parameters for the @@ -136,9 +139,11 @@ func setDefaultConsensusParams(command *cobra.Command) error { return server.SetCmdServerContext(command, ctx) } -func addModuleInitFlags(startCmd *cobra.Command) { +// addStartFlags adds flags to the start command. +func addStartFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) startCmd.Flags().Int64(UpgradeHeightFlag, 0, "Upgrade height to switch from v1 to v2. Must be coordinated amongst all validators") + startCmd.Flags().Duration(TimeoutCommitFlag, 0, "Override the application configured timeout_commit. Note: only for testing purposes.") } // replaceLogger optionally replaces the logger with a file logger if the flag