Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(abci): Backport: move timeout_commit into FinalizeBlockResponse #34

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
455 changes: 256 additions & 199 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
// Set timeout to 0 so `skipTimeoutCommit = true` during test.
thisConfig.Consensus.TimeoutCommit = 0
defer os.RemoveAll(thisConfig.RootDir)
ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0o700) // dir for wal
app := appFunc()
Expand Down
5 changes: 5 additions & 0 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ func randConsensusNet(t *testing.T, nValidators int, testName string, tickerFunc
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
// Set timeout to 0 so `skipTimeoutCommit = true` during test.
thisConfig.Consensus.TimeoutCommit = 0
configRootDirs = append(configRootDirs, thisConfig.RootDir)
for _, opt := range configOpts {
opt(thisConfig)
Expand Down Expand Up @@ -822,6 +824,9 @@ func randConsensusNetWithPeers(
t.Cleanup(func() { _ = stateStore.Close() })
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
// Set timeout to 0 so `skipTimeoutCommit = true` during test.
thisConfig.Consensus.TimeoutCommit = 0

configRootDirs = append(configRootDirs, thisConfig.RootDir)
ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0o700) // dir for wal
if i == 0 {
Expand Down
3 changes: 3 additions & 0 deletions consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func TestReactorWithEvidence(t *testing.T) {
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
// Set timeout to 0 so `skipTimeoutCommit = true` during test.
thisConfig.Consensus.TimeoutCommit = 0
defer os.RemoveAll(thisConfig.RootDir)
ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0o700) // dir for wal
app := appFunc()
Expand Down Expand Up @@ -448,6 +450,7 @@ func TestReactorVotingPowerChange(t *testing.T) {
"consensus_voting_power_changes_test",
newMockTickerFunc(true),
newPersistentKVStore)

defer cleanup()
reactors, blocksSubs, eventBuses := startConsensusNet(t, css, nVals)
defer stopConsensusNet(logger, reactors, eventBuses)
Expand Down
25 changes: 16 additions & 9 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,20 @@ func (cs *State) updateToState(state sm.State) {
cs.updateHeight(height)
cs.updateRoundStep(0, cstypes.RoundStepNewHeight)

timeoutCommit := state.NextBlockDelay
// If the ABCI app didn't set a delay, use the deprecated config value.
if timeoutCommit == 0 {
timeoutCommit = cs.config.TimeoutCommit //nolint:staticcheck
}
if cs.CommitTime.IsZero() {
// "Now" makes it easier to sync up dev nodes.
// We add timeoutCommit to allow transactions
// 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(cmttime.Now())
//
// We add timeoutCommit to allow transactions to be gathered for
// the first block. An alternative solution that relies on clocks:
// `cs.StartTime = state.LastBlockTime.Add(timeoutCommit)`
cs.StartTime = cmttime.Now().Add(timeoutCommit)
} else {
cs.StartTime = cs.config.Commit(cs.CommitTime)
cs.StartTime = cs.CommitTime.Add(timeoutCommit)
}

cs.Validators = validators
Expand Down Expand Up @@ -1042,7 +1047,7 @@ func (cs *State) handleTxsAvailable() {

// Enter: `timeoutNewHeight` by startTime (commitTime+timeoutCommit),
//
// or, if SkipTimeoutCommit==true, after receiving all precommits from (height,round-1)
// or, if NextBlockDelay==0, after receiving all precommits from (height,round-1)
//
// Enter: `timeoutPrecommits` after any +2/3 precommits from (height,round-1)
// Enter: +2/3 precommits for nil at (height,round-1)
Expand Down Expand Up @@ -2217,7 +2222,8 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error
cs.evsw.FireEvent(types.EventVote, vote)

// if we can skip timeoutCommit and have all the votes now,
if cs.config.SkipTimeoutCommit && cs.LastCommit.HasAll() {
skipTimeoutCommit := cs.state.NextBlockDelay == 0 && cs.config.TimeoutCommit == 0 //nolint:staticcheck
if skipTimeoutCommit && cs.LastCommit.HasAll() {
// go straight to new round (skip timeout commit)
// cs.scheduleTimeout(time.Duration(0), cs.Height, 0, cstypes.RoundStepNewHeight)
cs.enterNewRound(cs.Height, 0)
Expand Down Expand Up @@ -2383,7 +2389,8 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error

if !blockID.IsNil() {
cs.enterCommit(height, vote.Round)
if cs.config.SkipTimeoutCommit && precommits.HasAll() {
skipTimeoutCommit := cs.state.NextBlockDelay == 0 && cs.config.TimeoutCommit == 0 //nolint:staticcheck
if skipTimeoutCommit && precommits.HasAll() {
cs.enterNewRound(cs.Height, 0)
}
} else {
Expand Down
7 changes: 7 additions & 0 deletions proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "tendermint/types/params.proto";
import "tendermint/types/validator.proto";
import "google/protobuf/timestamp.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";

// NOTE: When using custom types, mind the warnings.
// https://github.com/cosmos/gogoproto/blob/master/custom_types.md#warnings-and-issues
Expand Down Expand Up @@ -363,6 +364,12 @@ message ResponseFinalizeBlock {
tendermint.types.ConsensusParams consensus_param_updates = 4;
// app_hash is the hash of the applications' state which is used to confirm that execution of the transactions was deterministic. It is up to the application to decide which algorithm to use.
bytes app_hash = 5;
// delay between the time when this block is committed and the next height is started.
// previously `timeout_commit` in config.toml
google.protobuf.Duration next_block_delay = 6 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
}

//----------------------------------------
Expand Down
Loading
Loading