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

evidence: cap evidence to an absolute number #4780

Merged
merged 22 commits into from
May 11, 2020
Merged

Conversation

cmwaters
Copy link
Contributor

Description

Added the consensus param MaxNumEvidence to dictate the maximum number of evidence to be committed to a block. It is defaulted at 50

There was some discussion around making it proportional to the validator set size which although makes sense has eventually been decided as something that the application can choose to do if they want.

Closes: #2590

@cmwaters cmwaters requested review from melekes and tessr as code owners April 30, 2020 05:05
@auto-comment
Copy link

auto-comment bot commented Apr 30, 2020

👋 Thanks for creating a PR!

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Wrote tests
  • Updated CHANGELOG_PENDING.md
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments
  • Re-reviewed Files changed in the Github PR explorer
  • Applied Appropriate Labels

Thank you for your contribution to Tendermint! 🚀

@cmwaters
Copy link
Contributor Author

I'm not too sure how I feel about some of these tests - they seem to quite arbitrarily be testing basic math operations involving constants and I think serve mainly as a check when one of these constants change.

@cmwaters cmwaters added C:evidence Component: Evidence T:breaking Type: Breaking Change labels Apr 30, 2020
types/params.go Outdated
params.Evidence.MaxNumEvidence)
}

if params.Evidence.MaxNumEvidence > params.Block.MaxBytes {
Copy link
Contributor

Choose a reason for hiding this comment

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

aren't these different things? pieces vs bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes correct, do you think I should have some sort of catch here to stop people from picking a maxnum that multiplied by the max num of bytes ends up being greater than the block max bytes

types/params.go Outdated
@@ -67,6 +67,11 @@ type EvidenceParams struct {
// mechanism for handling [Nothing-At-Stake
// attacks](https://github.com/ethereum/wiki/wiki/Proof-of-Stake-FAQ#what-is-the-nothing-at-stake-problem-and-how-can-it-be-fixed).
MaxAgeDuration time.Duration `json:"max_age_duration"`

// Ratio for the max amount of evidence relative to the amount of validators to be included in a block
Copy link
Contributor

Choose a reason for hiding this comment

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

not a ratio

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops I went from first trying as a ratio to switching it to just an absolute number so forgot to update the commenting

types/params.go Outdated
// Ratio for the max amount of evidence relative to the amount of validators to be included in a block
// i.e. MaxNumEvidence = ValSize * MaxEvidenceToValidatorsRatio
// where MaxNumEvidence is always rounded up. Default is 1/3 of validator size
MaxNumEvidence int64 `json:"max_num_evidence"`
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 make this uint16?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I agree - does that mean I can remove the greater than 0 catch as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the only problem I see with uint16 is that there will most likely need to be quite a few conversions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I just discovered this:

json: cannot unmarshal string into Go value of type uint16)

Copy link
Contributor

Choose a reason for hiding this comment

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

uint32 should work. could we try this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure I can give it a go

Copy link
Contributor

Choose a reason for hiding this comment

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

this should be added to the abci consensusparams as well https://github.com/tendermint/tendermint/blob/master/abci/types/types.proto#L298

@cmwaters
Copy link
Contributor Author

Two questions: should I be changing the abci ConsensusParams type as well and should the minimum number of evidence be 0 or 1 (being able to set 0 effectively bypasses the use of evidence)

@cmwaters cmwaters changed the title Callum/2590 cap evidence evidence: cap evidence to an absolute number Apr 30, 2020
@@ -98,8 +98,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
maxBytes := state.ConsensusParams.Block.MaxBytes
maxGas := state.ConsensusParams.Block.MaxGas

// Fetch a limited amount of valid evidence
maxNumEvidence, _ := types.MaxEvidencePerBlock(maxBytes)
maxNumEvidence := int64(state.ConsensusParams.Evidence.MaxNumEvidence)
evidence := blockExec.evpool.PendingEvidence(maxNumEvidence)
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 change PendingEvidence to accept uint32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay but then we take away the functionality of passing -1 to return all evidence

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 could instead make it that PendingEvidence(0) returns all the pending evidence

Copy link
Contributor

Choose a reason for hiding this comment

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

we're only using -1 in tests, so maybe instead we call PendingEvidence with a high number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - we also use -1 for listevidence in regards to going through all the pending evidence on startup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I think it might be handy (I'm not sure in which case) if there is a function that you can easily pull all the pending evidence from

@melekes
Copy link
Contributor

melekes commented May 4, 2020

abci ConsensusParams type as well

Do you mean should we expose this to the apps? I think so, yes. Also, we should update the ABCI spec https://github.com/tendermint/spec/blob/master/spec/abci/abci.md#evidenceparams

minimum number of evidence be 0 or 1 (being able to set 0 effectively bypasses the use of evidence)

evidence is essential piece in PoS networks. but I don't think we should restrict users from setting it to 0. At least, we don't do it for other things.

@cmwaters
Copy link
Contributor Author

cmwaters commented May 6, 2020

Do you mean should we expose this to the apps? I think so, yes. Also, we should update the ABCI spec https://github.com/tendermint/spec/blob/master/spec/abci/abci.md#evidenceparams

I will do this once this PR is merged

@cmwaters cmwaters requested a review from melekes May 6, 2020 09:04
@@ -31,7 +31,8 @@ message EvidenceParams {
option (gogoproto.equal) = true;
// Note: must be greater than 0
int64 max_age_num_blocks = 1;
google.protobuf.Duration max_age_duration = 2
google.protobuf.Duration max_age_duration = 2;
uint32 max_num_evidence = 3
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 rename this to max_num? why keep the evidence suffix if the struct called Evidence?

@melekes
Copy link
Contributor

melekes commented May 8, 2020

Also, spec (tendermint/spec) needs to be updated.

@melekes melekes added the R:major PR contains breaking changes that have to wait till a major release is made to be merged label May 11, 2020
@cmwaters cmwaters requested a review from melekes May 11, 2020 09:11
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@codecov-io
Copy link

Codecov Report

Merging #4780 into master will decrease coverage by 0.04%.
The diff coverage is 60.00%.

@@            Coverage Diff             @@
##           master    #4780      +/-   ##
==========================================
- Coverage   64.05%   64.01%   -0.05%     
==========================================
  Files         220      220              
  Lines       20426    20433       +7     
==========================================
- Hits        13084    13080       -4     
- Misses       6290     6298       +8     
- Partials     1052     1055       +3     
Impacted Files Coverage Δ
state/execution.go 73.04% <0.00%> (+0.31%) ⬆️
consensus/replay_stubs.go 61.36% <40.00%> (ø)
state/services.go 60.00% <60.00%> (ø)
state/tx_filter.go 100.00% <100.00%> (ø)
state/validation.go 68.11% <100.00%> (-0.23%) ⬇️
crypto/sr25519/pubkey.go 32.14% <0.00%> (-7.15%) ⬇️
statesync/snapshots.go 92.59% <0.00%> (-1.49%) ⬇️
blockchain/v2/reactor.go 35.35% <0.00%> (-1.28%) ⬇️
consensus/reactor.go 72.17% <0.00%> (-0.47%) ⬇️
consensus/state.go 73.28% <0.00%> (-0.40%) ⬇️
... and 6 more

@cmwaters cmwaters merged commit a620e5f into master May 11, 2020
@cmwaters cmwaters deleted the callum/2590-cap-evidence branch May 11, 2020 13:28
@tessr tessr mentioned this pull request May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:evidence Component: Evidence R:major PR contains breaking changes that have to wait till a major release is made to be merged T:breaking Type: Breaking Change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cap evidence by absolute number instead of relative size
4 participants