Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove TimeIotaMs from ABCI consensus params #3403

Merged
merged 7 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Special thanks to external contributors on this release:
mempool's current `txs_total_bytes` is exposed via `total_bytes` field in
`/num_unconfirmed_txs` and `/unconfirmed_txs` RPC endpoints.
- [config] \#2920 Remove `consensus.blocktime_iota` parameter
- [genesis] \#2920 Add `time_iota_ms` to block's consensus parameters
- [genesis] \#2920 Add `time_iota_ms` to block's consensus parameters (not exposed to the application)
- [genesis] \#2920 Rename `consensus_params.block_size` to `consensus_params.block`

### IMPROVEMENTS:
Expand All @@ -40,8 +40,6 @@ Special thanks to external contributors on this release:
- leveldb.alivesnaps
- leveldb.aliveiters

CI/CD: * [\#3396](https://github.com/tendermint/tendermint/pull/3396)

### BUG FIXES:

- [p2p/conn] \#3347 Reject all-zero shared secrets in the Diffie-Hellman step of secret-connection
Expand Down
414 changes: 185 additions & 229 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions abci/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ message BlockParams {
int64 max_bytes = 1;
// Note: must be greater or equal to -1
int64 max_gas = 2;
// Note: must be greater than 0
int64 time_iota_ms = 3;
}

// EvidenceParams contains limits on the evidence.
Expand Down
7 changes: 6 additions & 1 deletion consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,12 @@ func (h *Handshaker) ReplayBlocks(
}

if res.ConsensusParams != nil {
state.ConsensusParams = types.PB2TM.ConsensusParams(res.ConsensusParams)
// Preserve TimeIotaMs since it's not exposed to the application.
timeIotaMs := state.ConsensusParams.Block.TimeIotaMs
{
state.ConsensusParams = types.PB2TM.ConsensusParams(res.ConsensusParams)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like a better approach would be to build this into the PB2TM.ConsensusParams method. Then we know we'll never forget to do this

Copy link
Contributor

Choose a reason for hiding this comment

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

Openned #3432

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the extra {}-brackets? The new scope doesn't introduce / separate anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2019-03-11 at 22 05 33

It separates reading from state.ConsensusParams and rewriting it with ABCI cs params

state.ConsensusParams.Block.TimeIotaMs = timeIotaMs
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not verify that this is the only place where we do not want ABCI params to potentially overwrite TimeIotaMs. Was this caught by a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, me executing

 rg "PB2TM.ConsensusParams"
consensus/replay.go
328:                            state.ConsensusParams = types.PB2TM.ConsensusParams(res.ConsensusParams)

types/protobuf_test.go
67:     cp2 := PB2TM.ConsensusParams(abciCP)

}
sm.SaveState(h.stateDB, state)
}
Expand Down
2 changes: 0 additions & 2 deletions docs/spec/abci/abci.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ Commit are included in the header of the next block.
- NOTE: blocks that violate this may be committed if there are Byzantine proposers.
It's the application's responsibility to handle this when processing a
block!
- `TimeIotaMs (int64)`: Minimum time increment between consecutive blocks (in milliseconds).


### EvidenceParams

Expand Down
7 changes: 3 additions & 4 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,11 @@ func TestApplyUpdates(t *testing.T) {
2: {initParams,
abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 44,
MaxGas: 55,
TimeIotaMs: 66,
MaxBytes: 44,
MaxGas: 55,
},
},
makeParams(44, 55, 66, 4)},
makeParams(44, 55, 3, 4)},
3: {initParams,
abci.ConsensusParams{
Evidence: &abci.EvidenceParams{
Expand Down
2 changes: 1 addition & 1 deletion types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type BlockParams struct {
MaxBytes int64 `json:"max_bytes"`
MaxGas int64 `json:"max_gas"`
// Minimum time increment between consecutive blocks (in milliseconds)
// Not exposed to the application.
TimeIotaMs int64 `json:"time_iota_ms"`
}

Expand Down Expand Up @@ -169,7 +170,6 @@ func (params ConsensusParams) Update(params2 *abci.ConsensusParams) ConsensusPar
if params2.Block != nil {
res.Block.MaxBytes = params2.Block.MaxBytes
res.Block.MaxGas = params2.Block.MaxGas
res.Block.TimeIotaMs = params2.Block.TimeIotaMs
}
if params2.Evidence != nil {
res.Evidence.MaxAge = params2.Evidence.MaxAge
Expand Down
9 changes: 4 additions & 5 deletions types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ func TestConsensusParamsUpdate(t *testing.T) {
makeParams(1, 2, 10, 3, valEd25519),
&abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 100,
MaxGas: 200,
TimeIotaMs: 300,
MaxBytes: 100,
MaxGas: 200,
},
Evidence: &abci.EvidenceParams{
MaxAge: 400,
MaxAge: 300,
},
Validator: &abci.ValidatorParams{
PubKeyTypes: valSecp256k1,
},
},
makeParams(100, 200, 300, 400, valSecp256k1),
makeParams(100, 200, 10, 300, valSecp256k1),
},
}
for _, tc := range testCases {
Expand Down
16 changes: 9 additions & 7 deletions types/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate {
func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams {
return &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
TimeIotaMs: params.Block.TimeIotaMs,
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
},
Evidence: &abci.EvidenceParams{
MaxAge: params.Evidence.MaxAge,
Expand Down Expand Up @@ -223,14 +222,17 @@ func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error)
}

func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams {
params := ConsensusParams{}
params := ConsensusParams{
Block: BlockParams{},
Evidence: EvidenceParams{},
Validator: ValidatorParams{},
}

// we must defensively consider any structs may be nil
if csp.Block != nil {
params.Block = BlockParams{
MaxBytes: csp.Block.MaxBytes,
MaxGas: csp.Block.MaxGas,
TimeIotaMs: csp.Block.TimeIotaMs,
MaxBytes: csp.Block.MaxBytes,
MaxGas: csp.Block.MaxGas,
}
}

Expand Down
2 changes: 2 additions & 0 deletions types/protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ 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

assert.Equal(t, *cp, cp2)
}
Expand Down