types: add new consensus params from proto (#7354)

This change adds the new TimingParams proto messages. These new messages were build using the wb/proposer-based-timestamps branch on the spec repo.
This change also adds validation that these values are positive when parsed and adds the new parameters into the existing tests.
This commit is contained in:
William Banfield
2021-12-05 19:20:37 -05:00
committed by GitHub
parent a9aab99b41
commit a9b2bbd70d
11 changed files with 658 additions and 136 deletions
+13 -13
View File
@@ -58,7 +58,7 @@ type pbtsTestHarness struct {
type pbtsTestConfiguration struct {
// The timestamp consensus parameters to be used by the state machine under test.
timestampParams types.TimestampParams
timingParams types.TimingParams
// The setting to use for the TimeoutPropose configuration parameter.
timeoutPropose time.Duration
@@ -80,7 +80,7 @@ func newPBTSTestHarness(ctx context.Context, t *testing.T, tc pbtsTestConfigurat
clock := new(tmtimemocks.Source)
cfg.Consensus.TimeoutPropose = tc.timeoutPropose
consensusParams := types.DefaultConsensusParams()
consensusParams.Timestamp = tc.timestampParams
consensusParams.Timing = tc.timingParams
state, privVals := makeGenesisState(cfg, genesisStateArgs{
Params: consensusParams,
@@ -240,9 +240,9 @@ func TestReceiveProposalWaitsForPreviousBlockTime(t *testing.T) {
defer cancel()
initialTime := time.Now().Add(50 * time.Millisecond)
cfg := pbtsTestConfiguration{
timestampParams: types.TimestampParams{
Precision: 100 * time.Millisecond,
MsgDelay: 500 * time.Millisecond,
timingParams: types.TimingParams{
Precision: 100 * time.Millisecond,
MessageDelay: 500 * time.Millisecond,
},
timeoutPropose: 50 * time.Millisecond,
genesisTime: initialTime,
@@ -256,7 +256,7 @@ func TestReceiveProposalWaitsForPreviousBlockTime(t *testing.T) {
// Check that the validator waited until after the proposer-based timestamp
// waitingTime bound.
assert.True(t, results.height2.prevoteIssuedAt.After(cfg.height2ProposalDeliverTime))
maxWaitingTime := cfg.genesisTime.Add(cfg.timestampParams.Precision).Add(cfg.timestampParams.MsgDelay)
maxWaitingTime := cfg.genesisTime.Add(cfg.timingParams.Precision).Add(cfg.timingParams.MessageDelay)
assert.True(t, results.height2.prevoteIssuedAt.Before(maxWaitingTime))
// Check that the validator did not prevote for nil.
@@ -275,9 +275,9 @@ func TestReceiveProposalTimesOutOnSlowDelivery(t *testing.T) {
defer cancel()
initialTime := time.Now()
cfg := pbtsTestConfiguration{
timestampParams: types.TimestampParams{
Precision: 100 * time.Millisecond,
MsgDelay: 500 * time.Millisecond,
timingParams: types.TimingParams{
Precision: 100 * time.Millisecond,
MessageDelay: 500 * time.Millisecond,
},
timeoutPropose: 50 * time.Millisecond,
genesisTime: initialTime,
@@ -290,7 +290,7 @@ func TestReceiveProposalTimesOutOnSlowDelivery(t *testing.T) {
// Check that the validator waited until after the proposer-based timestamp
// waitinTime bound.
maxWaitingTime := initialTime.Add(cfg.timestampParams.Precision).Add(cfg.timestampParams.MsgDelay)
maxWaitingTime := initialTime.Add(cfg.timingParams.Precision).Add(cfg.timingParams.MessageDelay)
assert.True(t, results.height2.prevoteIssuedAt.After(maxWaitingTime))
// Ensure that the validator issued a prevote for nil.
@@ -378,9 +378,9 @@ func TestProposalTimeout(t *testing.T) {
mockSource := new(tmtimemocks.Source)
mockSource.On("Now").Return(testCase.localTime)
tp := types.TimestampParams{
Precision: testCase.precision,
MsgDelay: testCase.msgDelay,
tp := types.TimingParams{
Precision: testCase.precision,
MessageDelay: testCase.msgDelay,
}
ti := proposalStepWaitingTime(mockSource, testCase.previousBlockTime, tp)
+5 -3
View File
@@ -816,7 +816,8 @@ func testHandshakeReplay(
}
// now start the app using the handshake - it should sync
genDoc, _ := sm.MakeGenesisDocFromFile(cfg.GenesisFile())
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile())
require.NoError(t, err)
handshaker := NewHandshaker(logger, stateStore, state, store, eventbus.NopEventBus{}, genDoc)
proxyApp := proxy.NewAppConns(clientCreator2, logger, proxy.NopMetrics())
if err := proxyApp.Start(ctx); err != nil {
@@ -825,7 +826,7 @@ func testHandshakeReplay(
t.Cleanup(func() { cancel(); proxyApp.Wait() })
err := handshaker.Handshake(ctx, proxyApp)
err = handshaker.Handshake(ctx, proxyApp)
if expectError {
require.Error(t, err)
return
@@ -1004,7 +1005,8 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {
require.NoError(t, err)
stateDB, state, store := stateAndStore(cfg, pubKey, appVersion)
stateStore := sm.NewStore(stateDB)
genDoc, _ := sm.MakeGenesisDocFromFile(cfg.GenesisFile())
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile())
require.NoError(t, err)
state.LastValidators = state.Validators.Copy()
// mode = 0 for committing all the blocks
blocks := sf.MakeBlocks(3, &state, privVal)
+3 -4
View File
@@ -1119,8 +1119,7 @@ func (cs *State) enterPropose(height int64, round int32) {
}
}()
//nolint: lll
waitingTime := proposalStepWaitingTime(tmtime.DefaultSource{}, cs.state.LastBlockTime, cs.state.ConsensusParams.Timestamp)
waitingTime := proposalStepWaitingTime(tmtime.DefaultSource{}, cs.state.LastBlockTime, cs.state.ConsensusParams.Timing) // nolint: lll
proposalTimeout := maxDuration(cs.config.Propose(round), waitingTime)
// If we don't get the proposal and all block parts quick enough, enterPrevote
@@ -2448,9 +2447,9 @@ func proposerWaitTime(lt tmtime.Source, bt time.Time) time.Duration {
// The result of proposalStepWaitingTime is compared with the configured `timeout-propose` duration,
// and the validator waits for whichever duration is larger before advancing to the next step
// and prevoting nil.
func proposalStepWaitingTime(lt tmtime.Source, bt time.Time, tp types.TimestampParams) time.Duration {
func proposalStepWaitingTime(lt tmtime.Source, bt time.Time, tp types.TimingParams) time.Duration {
t := lt.Now()
wt := bt.Add(tp.Precision).Add(tp.MsgDelay)
wt := bt.Add(tp.Precision).Add(tp.MessageDelay)
if t.After(wt) {
return 0
}