Skip to content

Commit

Permalink
refactor: timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Oct 29, 2024
1 parent ec29c4b commit c53ee35
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/test/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *PriorityTestSuite) SetupSuite() {
cfg := testnode.DefaultConfig().
WithFundedAccounts(s.accountNames...).
// use a long block time to guarantee that some transactions are included in the same block
WithBlockTime(time.Second)
WithTimeoutCommit(time.Second)

cctx, _, _ := testnode.NewNetwork(t, cfg)
s.cctx = cctx
Expand Down
2 changes: 1 addition & 1 deletion app/test/square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *SquareSizeIntegrationTest) SetupSuite() {

cfg := testnode.DefaultConfig().
WithModifiers(genesis.ImmediateProposals(s.ecfg.Codec)).
WithBlockTime(time.Second)
WithTimeoutCommit(time.Second)

cctx, rpcAddr, grpcAddr := testnode.NewNetwork(t, cfg)

Expand Down
6 changes: 0 additions & 6 deletions pkg/appconsts/versioned_consts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ func TestUpgradeHeightDelay(t *testing.T) {
version: v2.Version,
expectedUpgradeHeightDelay: v2.UpgradeHeightDelay,
},
{
name: "v2 upgrade delay on an arabica network other than arabica-11",
chainID: "arabica-11",
version: v2.Version,
expectedUpgradeHeightDelay: v3.UpgradeHeightDelay, // falls back to v3 because of arabica bug
},
{
name: "v2 upgrade delay on arabica",
chainID: "arabica-11",
Expand Down
4 changes: 2 additions & 2 deletions test/txsim/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestTxSimulator(t *testing.T) {
func Setup(t testing.TB) (keyring.Keyring, string, string) {
t.Helper()

cfg := testnode.DefaultConfig().WithBlockTime(300 * time.Millisecond).WithFundedAccounts("txsim-master")
cfg := testnode.DefaultConfig().WithTimeoutCommit(300 * time.Millisecond).WithFundedAccounts("txsim-master")

cctx, rpcAddr, grpcAddr := testnode.NewNetwork(t, cfg)

Expand All @@ -165,7 +165,7 @@ func TestTxSimUpgrade(t *testing.T) {
cp := app.DefaultConsensusParams()
cp.Version.AppVersion = v2.Version
cfg := testnode.DefaultConfig().
WithBlockTime(300 * time.Millisecond).
WithTimeoutCommit(300 * time.Millisecond).
WithConsensusParams(cp).
WithFundedAccounts("txsim-master")
cctx, _, grpcAddr := testnode.NewNetwork(t, cfg)
Expand Down
34 changes: 18 additions & 16 deletions test/util/testnode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,10 @@ func (c *Config) WithSuppressLogs(sl bool) *Config {
return c
}

// WithBlockTime sets the block time and returns the Config.
func (c *Config) WithBlockTime(d time.Duration) *Config {
c.TmConfig.Consensus.TimeoutCommit = d
creator := DefaultAppCreator(d)
c.WithAppCreator(creator)
return c
}

// Deprecated: use WithBlockTime instead. WithTimeoutCommit sets the timeout
// commit in the cometBFT config and returns the Config. Warning, this won't
// actually change the block time and is being deprecated.
// WithTimeoutCommit sets the timeout commit in the cometBFT config and returns
// the Config.
func (c *Config) WithTimeoutCommit(d time.Duration) *Config {
c.TmConfig.Consensus.TimeoutCommit = d
return c
return c.WithAppCreator(DefaultAppCreator(WithTimeoutCommit(d)))
}

// WithFundedAccounts sets the genesis accounts and returns the Config.
Expand Down Expand Up @@ -142,7 +132,7 @@ func DefaultConfig() *Config {
WithTendermintConfig(DefaultTendermintConfig()).
WithAppConfig(DefaultAppConfig()).
WithAppOptions(DefaultAppOptions()).
WithAppCreator(DefaultAppCreator(time.Millisecond * 30)).
WithTimeoutCommit(time.Millisecond * 30).
WithSuppressLogs(true)
}

Expand Down Expand Up @@ -181,7 +171,15 @@ func DefaultTendermintConfig() *tmconfig.Config {
return tmCfg
}

func DefaultAppCreator(blockTime time.Duration) srvtypes.AppCreator {
type AppCreationOptions func(app *app.App)

func WithTimeoutCommit(d time.Duration) AppCreationOptions {
return func(app *app.App) {
app.SetEndBlocker(wrapEndBlocker(app, d))
}
}

func DefaultAppCreator(opts ...AppCreationOptions) srvtypes.AppCreator {
return func(_ log.Logger, _ tmdb.DB, _ io.Writer, _ srvtypes.AppOptions) srvtypes.Application {
encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...)
app := app.New(
Expand All @@ -194,7 +192,11 @@ func DefaultAppCreator(blockTime time.Duration) srvtypes.AppCreator {
simapp.EmptyAppOptions{},
baseapp.SetMinGasPrices(fmt.Sprintf("%v%v", appconsts.DefaultMinGasPrice, app.BondDenom)),
)
app.SetEndBlocker(wrapEndBlocker(app, blockTime))

for _, opt := range opts {
opt(app)
}

return app
}
}
Expand Down

0 comments on commit c53ee35

Please sign in to comment.