Skip to content

Commit

Permalink
types: refactor PB2TM.ConsensusParams to take BlockTimeIota as an arg (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
melekes committed Mar 19, 2019
1 parent 7457133 commit 4162ebe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 1 addition & 6 deletions consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 6 additions & 3 deletions types/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -231,8 +233,9 @@ func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams {
// we must defensively consider any structs may be nil
if csp.Block != nil {
params.Block = BlockParams{
MaxBytes: csp.Block.MaxBytes,
MaxGas: csp.Block.MaxGas,
MaxBytes: csp.Block.MaxBytes,
MaxGas: csp.Block.MaxGas,
TimeIotaMs: blockTimeIotaMs,
}
}

Expand Down
4 changes: 1 addition & 3 deletions types/protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4162ebe

Please sign in to comment.