From 8c0af729875d0552de2fe558925d12cc3109c265 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 17 Dec 2020 10:32:42 -0600 Subject: [PATCH] consensus: deprecate time iota ms (#5792) time_iota_ms is intended to ensure that an honest validator always generates timestamps with time increasing monotonically. For this purpose, it always suffices to have this parameter set to `1ms`. Allowing users to choose different numbers increases bug surface area. Thus the code now ignores the user provided time_iota_ms parameter (marking it as unused), and uses 1ms internally. --- CHANGELOG_PENDING.md | 1 + config/config.go | 2 -- consensus/state.go | 7 ++++++- docs/tendermint-core/using-tendermint.md | 4 +--- proto/tendermint/types/params.proto | 5 +---- types/params.go | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 6bb8d946c..6201b9a56 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -43,6 +43,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [blockchain/v0] \#5741 Relax termination conditions and increase sync timeout (@melekes) - [cli] \#5772 `gen_node_key` output now contains node ID (`id` field) (@melekes) - [blockchain/v2] \#5774 Send status request when new peer joins (@melekes) +- [consensus] \#5792 Deprecates the `time_iota_ms` consensus parameter, to reduce the bug surface. The parameter is no longer used. (@valardragon) ### BUG FIXES diff --git a/config/config.go b/config/config.go index 26b2a5d97..3db13b54d 100644 --- a/config/config.go +++ b/config/config.go @@ -825,7 +825,6 @@ type ConsensusConfig struct { // 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 TimeoutCommit time.Duration `mapstructure:"timeout-commit"` // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) @@ -871,7 +870,6 @@ func TestConsensusConfig() *ConsensusConfig { cfg.TimeoutPrevoteDelta = 1 * time.Millisecond 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.TimeoutCommit = 10 * time.Millisecond cfg.SkipTimeoutCommit = true cfg.PeerGossipSleepDuration = 5 * time.Millisecond diff --git a/consensus/state.go b/consensus/state.go index 6f3ae2a3f..045c5dd53 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -2098,12 +2098,17 @@ func (cs *State) signVote( return vote, err } +// voteTime ensures monotonicity of the time a validator votes on. +// It ensures that for a prior block with a BFT-timestamp of T, +// any vote from this validator will have time at least time T + 1ms. +// This is needed, as monotonicity of time is a guarantee that BFT time provides. func (cs *State) voteTime() time.Time { now := tmtime.Now() minVoteTime := now + // Minimum time increment between blocks + const timeIota = time.Millisecond // TODO: We should remove next line in case we don't vote for v in case cs.ProposalBlock == nil, // even if cs.LockedBlock != nil. See https://docs.tendermint.com/master/spec/. - timeIota := time.Duration(cs.state.ConsensusParams.Block.TimeIotaMs) * time.Millisecond if cs.LockedBlock != nil { // See the BFT time spec https://docs.tendermint.com/master/spec/consensus/bft-time.html minVoteTime = cs.LockedBlock.Time.Add(timeIota) diff --git a/docs/tendermint-core/using-tendermint.md b/docs/tendermint-core/using-tendermint.md index 8eb847305..749c0dc4b 100644 --- a/docs/tendermint-core/using-tendermint.md +++ b/docs/tendermint-core/using-tendermint.md @@ -53,9 +53,7 @@ definition](https://github.com/tendermint/tendermint/blob/master/types/genesis.g - `block` - `max_bytes`: Max block size, in bytes. - `max_gas`: Max gas per block. - - `time_iota_ms`: Minimum time increment between consecutive blocks (in - milliseconds). If the block header timestamp is ahead of the system clock, - decrease this value. + - `time_iota_ms`: Unused. This has been deprecated and will be removed in a future version. - `evidence` - `max_age_num_blocks`: Max age of evidence, in blocks. The basic formula for calculating this is: MaxAgeDuration / {average block time}. diff --git a/proto/tendermint/types/params.proto b/proto/tendermint/types/params.proto index 0de7d846f..bfe933676 100644 --- a/proto/tendermint/types/params.proto +++ b/proto/tendermint/types/params.proto @@ -25,10 +25,7 @@ message BlockParams { // Max gas per block. // Note: must be greater or equal to -1 int64 max_gas = 2; - // Minimum time increment between consecutive blocks (in milliseconds) If the - // block header timestamp is ahead of the system clock, decrease this value. - // - // Not exposed to the application. + // This parameter is unused. int64 time_iota_ms = 3; } diff --git a/types/params.go b/types/params.go index 16c85aa55..697d8e38b 100644 --- a/types/params.go +++ b/types/params.go @@ -36,7 +36,7 @@ func DefaultBlockParams() tmproto.BlockParams { return tmproto.BlockParams{ MaxBytes: 22020096, // 21MB MaxGas: -1, - TimeIotaMs: 1000, // 1s + TimeIotaMs: 1, // 1s, parameter is now unused } }