Skip to content

Commit

Permalink
feat: override timeout commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Dec 9, 2024
1 parent f11a169 commit 0ab3f1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 20 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -188,6 +193,7 @@ func New(
invCheckPeriod uint,
encodingConfig encoding.Config,
upgradeHeightV2 int64,
timeoutCommit time.Duration,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
Expand All @@ -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])
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
9 changes: 7 additions & 2 deletions cmd/celestia-appd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0ab3f1e

Please sign in to comment.