From 45072f3f4354f7116d9046a0fb888bbefb4ca21f Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Tue, 14 Feb 2023 19:43:45 -0600 Subject: [PATCH] chore: simplify addition and rename --- config/config.go | 28 ++++++++++------------------ config/config_test.go | 4 ++-- config/toml.go | 2 +- consensus/state.go | 5 ++--- go.mod | 7 +++++-- test/maverick/consensus/state.go | 5 ++--- 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/config/config.go b/config/config.go index cfbca2db30..5dd5c0d5d7 100644 --- a/config/config.go +++ b/config/config.go @@ -928,11 +928,10 @@ type ConsensusConfig struct { TimeoutPrecommit time.Duration `mapstructure:"timeout_precommit"` // How much the timeout_precommit increases with each round TimeoutPrecommitDelta time.Duration `mapstructure:"timeout_precommit_delta"` - // How long we wait after committing a block, before starting on the new - // height (this gives us a chance to receive some more precommits, even - // though we already have +2/3). - // NOTE: when modifying, make sure to update time_iota_ms genesis parameter - TargetRoundDuration time.Duration `mapstructure:"target_round_duration"` + // The TargetHeigtDuration is used to determine how long we wait after a + // block is committed. If this time is shorter than the actual time to reach + // consensus for that height, then we do not wait at all. + TargetHeightDuration time.Duration `mapstructure:"target_round_duration"` // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"` @@ -958,7 +957,7 @@ func DefaultConsensusConfig() *ConsensusConfig { TimeoutPrevoteDelta: 500 * time.Millisecond, TimeoutPrecommit: 1000 * time.Millisecond, TimeoutPrecommitDelta: 500 * time.Millisecond, - TargetRoundDuration: 3500 * time.Millisecond, + TargetHeightDuration: 3500 * time.Millisecond, SkipTimeoutCommit: false, CreateEmptyBlocks: true, CreateEmptyBlocksInterval: 0 * time.Second, @@ -978,7 +977,7 @@ func TestConsensusConfig() *ConsensusConfig { cfg.TimeoutPrecommit = 10 * time.Millisecond cfg.TimeoutPrecommitDelta = 1 * time.Millisecond // NOTE: when modifying, make sure to update time_iota_ms (testGenesisFmt) in toml.go - cfg.TargetRoundDuration = 70 * time.Millisecond + cfg.TargetHeightDuration = 70 * time.Millisecond cfg.SkipTimeoutCommit = true cfg.PeerGossipSleepDuration = 5 * time.Millisecond cfg.PeerQueryMaj23SleepDuration = 250 * time.Millisecond @@ -1012,16 +1011,9 @@ func (cfg *ConsensusConfig) Precommit(round int32) time.Duration { ) * time.Nanosecond } -// Commit returns the amount of time to wait for straggler votes after receiving -// +2/3 precommits for a single block (ie. a commit). This has been modified -// from upstream tendermint to be dynamic, where we account for the amount of -// time already taken in a round. -func (cfg *ConsensusConfig) Commit(t time.Time, elapsed time.Duration) time.Time { - remaining := cfg.TargetRoundDuration - elapsed - if remaining < time.Millisecond*1 { - remaining = time.Millisecond * 1 - } - return t.Add(remaining) +// NextStartTime adds the TargetHeightDuration to the provided starting time. +func (cfg *ConsensusConfig) NextStartTime(t time.Time) time.Time { + return t.Add(cfg.TargetHeightDuration) } // WalFile returns the full path to the write-ahead log file @@ -1058,7 +1050,7 @@ func (cfg *ConsensusConfig) ValidateBasic() error { if cfg.TimeoutPrecommitDelta < 0 { return errors.New("timeout_precommit_delta can't be negative") } - if cfg.TargetRoundDuration < 0 { + if cfg.TargetHeightDuration < 0 { return errors.New("target round duration can't be negative") } if cfg.CreateEmptyBlocksInterval < 0 { diff --git a/config/config_test.go b/config/config_test.go index 1bde4bd20f..ab3212b509 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -157,8 +157,8 @@ func TestConsensusConfig_ValidateBasic(t *testing.T) { "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true}, "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false}, "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true}, - "TargetRoundDuration": {func(c *ConsensusConfig) { c.TargetRoundDuration = time.Second }, false}, - "TargetRoundDuration negative": {func(c *ConsensusConfig) { c.TargetRoundDuration = -1 }, true}, + "TargetHeightDuration": {func(c *ConsensusConfig) { c.TargetHeightDuration = time.Second }, false}, + "TargetHeightDuration negative": {func(c *ConsensusConfig) { c.TargetHeightDuration = -1 }, true}, "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false}, "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true}, "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false}, diff --git a/config/toml.go b/config/toml.go index 1516128a36..1b1ed5ab67 100644 --- a/config/toml.go +++ b/config/toml.go @@ -461,7 +461,7 @@ timeout_precommit_delta = "{{ .Consensus.TimeoutPrecommitDelta }}" # How long we wait after committing a block, before starting on the new # height (this gives us a chance to receive some more precommits, even # though we already have +2/3). -target_round_duration = "{{ .Consensus.TargetRoundDuration }}" +target_round_duration = "{{ .Consensus.TargetHeightDuration }}" # How many blocks to look back to check existence of the node's consensus votes before joining consensus # When non-zero, the node will panic upon restart diff --git a/consensus/state.go b/consensus/state.go index c90096aaea..228ed6ddd7 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -652,10 +652,9 @@ func (cs *State) updateToState(state sm.State) { // to be gathered for the first block. // And alternative solution that relies on clocks: // cs.StartTime = state.LastBlockTime.Add(timeoutCommit) - cs.StartTime = cs.config.Commit(tmtime.Now(), time.Millisecond) + cs.StartTime = cs.config.NextStartTime(tmtime.Now()) } else { - elapsedTime := cs.CommitTime.Sub(cs.StartTime) - cs.StartTime = cs.config.Commit(cs.CommitTime, elapsedTime) + cs.StartTime = cs.config.NextStartTime(cs.StartTime) } cs.Validators = validators diff --git a/go.mod b/go.mod index d02b9e2f4f..03dfec2676 100644 --- a/go.mod +++ b/go.mod @@ -90,7 +90,6 @@ require ( github.com/containerd/typeurl v1.0.2 // indirect github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/creachadair/taskgroup v0.3.2 github.com/curioswitch/go-reassign v0.2.0 // indirect github.com/daixiang0/gci v0.8.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -203,7 +202,6 @@ require ( github.com/polyfloyd/go-errorlint v1.0.5 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect - github.com/prometheus/procfs v0.8.0 // indirect github.com/quasilyte/go-ruleguard v0.3.18 // indirect github.com/quasilyte/gogrep v0.0.0-20220828223005-86e4605de09f // indirect github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95 // indirect @@ -272,3 +270,8 @@ require ( mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect mvdan.cc/unparam v0.0.0-20220706161116-678bad134442 // indirect ) + +require ( + github.com/creachadair/taskgroup v0.3.2 + github.com/prometheus/procfs v0.8.0 // indirect +) diff --git a/test/maverick/consensus/state.go b/test/maverick/consensus/state.go index 83097ef373..543f7fb372 100644 --- a/test/maverick/consensus/state.go +++ b/test/maverick/consensus/state.go @@ -900,10 +900,9 @@ func (cs *State) updateToState(state sm.State) { // to be gathered for the first block. // And alternative solution that relies on clocks: // cs.StartTime = state.LastBlockTime.Add(timeoutCommit) - cs.StartTime = cs.config.Commit(tmtime.Now(), time.Millisecond) + cs.StartTime = cs.config.NextStartTime(tmtime.Now()) } else { - elapsedTime := cs.CommitTime.Sub(cs.StartTime) - cs.StartTime = cs.config.Commit(cs.CommitTime, elapsedTime) + cs.StartTime = cs.config.NextStartTime(cs.StartTime) } cs.Validators = validators