types: refactor PB2TM.ConsensusParams to take BlockTimeIota as an arg (#3442)

See https://github.com/tendermint/tendermint/pull/3403/files#r266208947

In #3403 we unexposed BlockTimeIota from the ABCI, but it's still part
of the ConsensusParams struct, so we have to remember to add it back
after calling PB2TM.ConsensusParams. Instead, PB2TM.ConsensusParams
should take it as an argument

Fixes #3432
This commit is contained in:
Anton Kaliaev 2019-03-19 11:38:32 +04:00 committed by GitHub
parent 7457133307
commit 4162ebe8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 12 deletions

View File

@ -324,12 +324,7 @@ func (h *Handshaker) ReplayBlocks(
}
if res.ConsensusParams != nil {
// Preserve TimeIotaMs since it's not exposed to the application.
timeIotaMs := state.ConsensusParams.Block.TimeIotaMs
{
state.ConsensusParams = types.PB2TM.ConsensusParams(res.ConsensusParams)
}
state.ConsensusParams.Block.TimeIotaMs = timeIotaMs
state.ConsensusParams = types.PB2TM.ConsensusParams(res.ConsensusParams, state.ConsensusParams.Block.TimeIotaMs)
}
sm.SaveState(h.stateDB, state)
}

View File

@ -221,7 +221,9 @@ func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error)
return tmVals, nil
}
func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams {
// BlockParams.TimeIotaMs is not exposed to the application. Therefore a caller
// must provide it.
func (pb2tm) ConsensusParams(csp *abci.ConsensusParams, blockTimeIotaMs int64) ConsensusParams {
params := ConsensusParams{
Block: BlockParams{},
Evidence: EvidenceParams{},
@ -233,6 +235,7 @@ func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams {
params.Block = BlockParams{
MaxBytes: csp.Block.MaxBytes,
MaxGas: csp.Block.MaxGas,
TimeIotaMs: blockTimeIotaMs,
}
}

View File

@ -64,9 +64,7 @@ func TestABCIValidators(t *testing.T) {
func TestABCIConsensusParams(t *testing.T) {
cp := DefaultConsensusParams()
abciCP := TM2PB.ConsensusParams(cp)
cp2 := PB2TM.ConsensusParams(abciCP)
// TimeIotaMs is not exposed to the application.
cp2.Block.TimeIotaMs = cp.Block.TimeIotaMs
cp2 := PB2TM.ConsensusParams(abciCP, cp.Block.TimeIotaMs)
assert.Equal(t, *cp, cp2)
}