Skip to content

cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable#3928

Merged
melekes merged 9 commits intomasterfrom
anton/3908
Sep 10, 2019
Merged

cs: check for SkipTimeoutCommit or wait timeout in handleTxsAvailable#3928
melekes merged 9 commits intomasterfrom
anton/3908

Conversation

@melekes
Copy link
Contributor

@melekes melekes commented Aug 29, 2019

Previously, if create_empty_blocks was set to false, TM sometimes could
create 2 consecutive blocks without actually waiting for timeoutCommit
(1 sec. by default).

I[2019-08-29|07:32:43.874] Executed block                               module=state height=47 validTxs=10 invalidTxs=0
I[2019-08-29|07:32:43.876] Committed state                              module=state height=47 txs=10 appHash=F88C010000000000
I[2019-08-29|07:32:44.885] Executed block                               module=state height=48 validTxs=2 invalidTxs=0
I[2019-08-29|07:32:44.887] Committed state                              module=state height=48 txs=2 appHash=FC8C010000000000
I[2019-08-29|07:32:44.908] Executed block                               module=state height=49 validTxs=8 invalidTxs=0
I[2019-08-29|07:32:44.909] Committed state                              module=state height=49 txs=8 appHash=8C8D010000000000
I[2019-08-29|07:32:45.886] Executed block                               module=state height=50 validTxs=2 invalidTxs=0
I[2019-08-29|07:32:45.895] Committed state                              module=state height=50 txs=2 appHash=908D010000000000
I[2019-08-29|07:32:45.908] Executed block                               module=state height=51 validTxs=8 invalidTxs=0
I[2019-08-29|07:32:45.909] Committed state                              module=state height=51 txs=8 appHash=A08D010000000000

This commit fixes that by adding a check to handleTxsAvailable.

Fixes #3908

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

Previously, if create_empty_blocks was set to false, TM sometimes could
create 2 consecutive blocks without actually waiting for timeoutCommit
(1 sec. by default).

```
I[2019-08-29|07:32:43.874] Executed block                               module=state height=47 validTxs=10 invalidTxs=0
I[2019-08-29|07:32:43.876] Committed state                              module=state height=47 txs=10 appHash=F88C010000000000
I[2019-08-29|07:32:44.885] Executed block                               module=state height=48 validTxs=2 invalidTxs=0
I[2019-08-29|07:32:44.887] Committed state                              module=state height=48 txs=2 appHash=FC8C010000000000
I[2019-08-29|07:32:44.908] Executed block                               module=state height=49 validTxs=8 invalidTxs=0
I[2019-08-29|07:32:44.909] Committed state                              module=state height=49 txs=8 appHash=8C8D010000000000
I[2019-08-29|07:32:45.886] Executed block                               module=state height=50 validTxs=2 invalidTxs=0
I[2019-08-29|07:32:45.895] Committed state                              module=state height=50 txs=2 appHash=908D010000000000
I[2019-08-29|07:32:45.908] Executed block                               module=state height=51 validTxs=8 invalidTxs=0
I[2019-08-29|07:32:45.909] Committed state                              module=state height=51 txs=8 appHash=A08D010000000000
```

This commit fixes that by adding a check to handleTxsAvailable.

Fixes #3908
@melekes melekes requested review from ebuchman and xla as code owners August 29, 2019 09:12
or SkipTimeoutCommit=true && we DON'T have all the votes
@melekes melekes removed the WIP label Aug 29, 2019
@melekes
Copy link
Contributor Author

melekes commented Aug 29, 2019

TestReactorCreatesBlockWhenEmptyBlocksFalse is failing

Copy link
Contributor

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 🍖

@b00f
Copy link
Contributor

b00f commented Sep 3, 2019

Thumb up! Thanks

@melekes melekes self-assigned this Sep 3, 2019
@codecov-io
Copy link

codecov-io commented Sep 5, 2019

Codecov Report

Merging #3928 into master will increase coverage by 0.1%.
The diff coverage is 60%.

@@            Coverage Diff            @@
##           master    #3928     +/-   ##
=========================================
+ Coverage   66.91%   67.01%   +0.1%     
=========================================
  Files         219      219             
  Lines       18478    18486      +8     
=========================================
+ Hits        12364    12389     +25     
+ Misses       5192     5177     -15     
+ Partials      922      920      -2
Impacted Files Coverage Δ
consensus/state.go 79.9% <60%> (-0.05%) ⬇️
consensus/reactor.go 78.42% <0%> (+0.11%) ⬆️
p2p/pex/pex_reactor.go 83.76% <0%> (+1.15%) ⬆️
blockchain/v0/pool.go 82.62% <0%> (+1.96%) ⬆️
blockchain/v0/reactor.go 81.6% <0%> (+3.77%) ⬆️

Copy link
Contributor

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

now := tmtime.Now()
if cs.StartTime.After(now) {
timeoutCommit := cs.StartTime.Sub(now)
cs.scheduleTimeout(timeoutCommit, cs.Height, 0, cstypes.RoundStepNewHeight)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this.

}

now := tmtime.Now()
if cs.StartTime.After(now) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we more concretely assert that we're in the timeout commit phase here using the state/step rather than the time?

// we only need to do this for round 0
cs.enterNewRound(cs.Height, 0)
cs.enterPropose(cs.Height, 0)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First thing we should check is if we're in the timeout commit period.

If so, and this stuff is true, go then go to the next round.

If so, and this stuff is not true, then schedule the round timeout.

Otherwise, go to the round.


switch cs.Step {
case cstypes.RoundStepNewHeight: // timeoutCommit phase
if cs.needProofBlock(cs.Height) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't like that we're loading block meta here, but I guess it's fine for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree - why did we need to check if needProofBlock here? And what happened to checking SkipTimeoutCommit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needProofBlock to avoid race between this func and enterNewRound https://github.com/tendermint/tendermint/blob/master/consensus/state.go#L835

SkipTimeoutCommit I've realized that we don't need it here since

a) if we're in timeoutCommit phase, it means we haven't received all the votes (https://github.com/tendermint/tendermint/blob/master/consensus/state.go#L1574) and it's ok to wait
b) if we're in propose phase, we don't need to check SkipTimeoutCommit and can enterPropose as we do right now

}

// +1ms to ensure RoundStepNewRound timeout always happens after RoundStepNewHeight
timeoutCommit := cs.StartTime.Sub(tmtime.Now()) + 1*time.Millisecond
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use time.Now() here and when calculating StartTime to ensure monotonic time! tmtime strips monotonic component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating 1 block per Tx when create_empty_block flag set to false

5 participants