Skip to content

Commit

Permalink
chore: simplify addition and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Feb 15, 2023
1 parent e2ce341 commit 45072f3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
28 changes: 10 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
5 changes: 2 additions & 3 deletions test/maverick/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 45072f3

Please sign in to comment.