Skip to content

Commit

Permalink
feat: use a dynamic timeout commit modelled on the size of the block
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwaters committed May 6, 2024
1 parent a1bcb0d commit d3544a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,21 @@ func (cfg *ConsensusConfig) Precommit(round int32) time.Duration {

// Commit returns the amount of time to wait for straggler votes after receiving +2/3 precommits
// for a single block (ie. a commit).
func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
return t.Add(cfg.TimeoutCommit)
func (cfg *ConsensusConfig) Commit(t time.Time, blockSizeBytes int64) time.Time {
// adjust the timeout based on how large the block size is for a total of
// 8MB which would decrease the timeout commit by roughly 4 seconds
perByteDelay := time.Duration(time.Microsecond / 2)

Check failure on line 1048 in config/config.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)
maxBlockSize := int64(8 * 1024 * 1024)
if blockSizeBytes > maxBlockSize {
blockSizeBytes = maxBlockSize
}

timeoutCommit := cfg.TimeoutCommit - (time.Duration(blockSizeBytes) * perByteDelay)
// make sure timeout is not negative
if timeoutCommit < 0 {
timeoutCommit = time.Millisecond
}
return t.Add(timeoutCommit)
}

// WalFile returns the full path to the write-ahead log file
Expand Down
4 changes: 2 additions & 2 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,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(cmttime.Now())
cs.StartTime = cs.config.Commit(cmttime.Now(), 0)
} else {
cs.StartTime = cs.config.Commit(cs.CommitTime)
cs.StartTime = cs.config.Commit(cs.CommitTime, cs.ProposalBlockParts.ByteSize())
}

cs.Validators = validators
Expand Down
4 changes: 2 additions & 2 deletions test/maverick/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +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(cmttime.Now())
cs.StartTime = cs.config.Commit(cmttime.Now(), 0)
} else {
cs.StartTime = cs.config.Commit(cs.CommitTime)
cs.StartTime = cs.config.Commit(cs.CommitTime, cs.ProposalBlockParts.ByteSize())
}

cs.Validators = validators
Expand Down

0 comments on commit d3544a5

Please sign in to comment.