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

R4R: Offset validator set power calculations by one block #2255

Merged
merged 52 commits into from
Oct 9, 2018

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Sep 7, 2018

Use correct offsets in slashing to account for what voting power signed which block. This has changed with NextValSet in Tendermint 0.24, and I think it was previously wrong for slashing-for-downtime using LastCommit.Votes.

  • Clarify that distributionHeight means at-end-of-block and test this
  • Ensure we never slash with a negative height
  • Simulate NextValSet
  • Add some testcases (negative distribution height, offset correctness, double-signing "extra block")

Closes #1789
Dependent on #2219

  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added entries in PENDING.md with issue #

  • rereviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@cwgoes cwgoes changed the title Update PENDING.md WIP: Offset validator set power calculations by one block Sep 7, 2018
@cwgoes cwgoes mentioned this pull request Sep 7, 2018
23 tasks
@cwgoes
Copy link
Contributor Author

cwgoes commented Sep 12, 2018

Also note case of double-signing the "extra block" at the end due to NextValSet offset - what happens? Validator no longer stored in SDK state as bonded. Panic? Freebie?

@cwgoes cwgoes removed the wip label Oct 5, 2018
@@ -68,7 +68,7 @@ func (k Keeper) unmarshalSlashingPeriodKeyValue(key []byte, value []byte) Valida
var slashingPeriodValue ValidatorSlashingPeriodValue
k.cdc.MustUnmarshalBinary(value, &slashingPeriodValue)
address := sdk.ConsAddress(key[1 : 1+sdk.AddrLen])
startHeight := int64(binary.LittleEndian.Uint64(key[1+sdk.AddrLen : 1+sdk.AddrLen+8]))
startHeight := int64(binary.LittleEndian.Uint64(key[1+sdk.AddrLen:1+sdk.AddrLen+8]) - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be - 1 -> - ValidatorDelay ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, updated.

// We need to pretend to be "one block before genesis" so that e.g. slashing periods
// are correctly initialized for the validator set one-block offset - the first TM block
// is at height 0, so state updates applied from genesis.json are in block -1.
ctx = ctx.WithBlockHeight(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

-ValidatorDelay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, updated.

x/slashing/keys.go Outdated Show resolved Hide resolved
// For example, if this is 0, the validator set at the end of a block will sign the next block, or
// if this is 1, the validator set at the end of a block will sign the block after the next.
// Constant as this should not change without a hard fork.
ValidatorUpdateDelay int64 = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

+++ - more a dis!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above comment.

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

Generally - looks good, wrote a few comments throughout RE: code-comprehension

@cwgoes
Copy link
Contributor Author

cwgoes commented Oct 5, 2018

Thanks @rigelrozanski - I agree on making ValidatorUpdateDelay clearer, if it is ever anything other than one some other code will need to change (not so easy to abstract the simulation & testcases) but I've used it where possible.

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

Thanks, much clearer now :)

@rigelrozanski
Copy link
Contributor

(won't merge until a Tendermint-team review as per your mention)

// Note that this *can* result in a negative "distributionHeight", up to -ValidatorUpdateDelay,
// i.e. at the end of the pre-genesis block (none) = at the beginning of the genesis block.
// That's fine since this is just used to filter unbonding delegations & redelegations.
distributionHeight := infractionHeight - stake.ValidatorUpdateDelay
Copy link
Member

Choose a reason for hiding this comment

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

I probably need to dig deeper into the slashing mechanics to confirm this, but the infractionHeight is the actual height at which the validator double signed, and is the height at which we want to know the validator set. Are we tracking validator sets differently here? If the double signing was at height H, here we're looking at the validator set at height H-1

// Note that this *can* result in a negative "distributionHeight" up to -ValidatorUpdateDelay-1,
// i.e. at the end of the pre-genesis block (none) = at the beginning of the genesis block.
// That's fine since this is just used to filter unbonding delegations & redelegations.
distributionHeight := height - stake.ValidatorUpdateDelay - 1
Copy link
Member

Choose a reason for hiding this comment

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

height - 1 is correct, but same comment as before around also subtracting the update delay.

@cwgoes cwgoes merged commit e13bbe2 into develop Oct 9, 2018
@cwgoes cwgoes deleted the cwgoes/nextvalset branch October 9, 2018 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants