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

multi: Implement stake difficulty change and vote. #666

Merged
merged 1 commit into from
Apr 26, 2017

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Apr 26, 2017

This implements a new stake difficulty algorithm along with a voting agenda for all networks to change and a comprehensive set of tests. It also implements estimation using the new algorithm for the estimatestakediff RPC.

The following is an overview of the changes:

  • Add new agenda to vote on changing the stake difficulty algorithm to all networks
    • The version on mainnet is version 4
    • The version on testnet and simnet is version 5
  • Modifies the stake difficulty calculation function to calculate the difficulty based on the result of the vote
  • Modifies the stake difficulty estimation function to calculate the difficulty based on the result of the vote
  • Makes the stake difficulty estimation function concurrent safe
    • Calls it directly from the RPC server instead of going through block manager
    • Removes no longer needed code from the block manager
  • Generate new version blocks and reject old version blocks after a super majority has been reached
    • New block version on mainnet is version 4
    • New block version on testnet and simnet is version 5
  • Add tests for the supply estimation used in the new algorithm
  • Add tests for the new algorithm calculations
  • Add tests for the estimation based on the new algorithm

Closes #584, closes #592, closes #593, and closes #594.

@dajohi dajohi added this to the v1.0.0 milestone Apr 26, 2017
Copy link
Member

@marcopeereboom marcopeereboom left a comment

Choose a reason for hiding this comment

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

Code looks great but I do have some questions.

var err error
node, err = b.getPrevNodeFromNode(node)
if err != nil {
return 0, err
Copy link
Member

Choose a reason for hiding this comment

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

Is this right? Or should this be a continue?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's correct. The only way this can fail is due to failing to load the node from the database and if that happens something is very wrong and there is no way to continue, so it must error. That is especially critical since this is consensus code, it can't just ignore failure to retrieve the data.

//
// This function is safe for concurrent access.
func sdiffAlgoDeploymentVersion(network wire.CurrencyNet) uint32 {
if network != wire.MainNet {
Copy link
Member

Choose a reason for hiding this comment

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

I find this a bit scary. How do we ensure this gets updated in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

It shouldn't ever need to be updated except to remove it altogether once the agendas are removed.

Copy link
Member

Choose a reason for hiding this comment

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

Ah derp.

state, err := b.deploymentState(curNode, deploymentVersion,
chaincfg.VoteIDSDiffAlgorithm)
if err != nil {
return 0, err
Copy link
Member

Choose a reason for hiding this comment

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

Is this right? What happens on the other end of this function? Should this be either a panic or a fallthrough to have some defaults?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above.

state, err := b.deploymentState(curNode, deploymentVersion,
chaincfg.VoteIDSDiffAlgorithm)
if err != nil {
return 0, err
Copy link
Member

Choose a reason for hiding this comment

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

see above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same.

@@ -873,8 +883,7 @@ func (b *BlockChain) CheckBlockStakeSanity(stakeValidationHeight int64, node *bl
calcSBits, err := b.calcNextRequiredStakeDifficulty(node.parent)
if err != nil {
errStr := fmt.Sprintf("couldn't calculate stake difficulty "+
"for block node %v: %v",
node.hash, calcSBits)
"for block node %v: %v", node.hash, err)
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch.

@davecgh davecgh force-pushed the new_sdiff_algo branch 5 times, most recently from 9f183a2 to 8819c0e Compare April 26, 2017 17:54
This implements a new stake difficulty algorithm along with a voting
agenda for all networks to change and a comprehensive set of tests.  It
also implements estimation using the new algorithm for the
estimatestakediff RPC.

The following is an overview of the changes:

- Add new agenda to vote on changing the stake difficulty algorithm to
  all networks
  - The version on mainnet is version 4
  - The version on testnet and simnet is version 5
- Modifies the stake difficulty calculation function to calculate the
  difficulty based on the result of the vote
- Modifies the stake difficulty estimation function to calculate the
  difficulty based on the result of the vote
- Makes the stake difficulty estimation function concurrent safe
  - Calls it directly from the RPC server instead of going through block
    manager
  - Removes no longer needed code from the block manager
- Generate new version blocks and reject old version blocks after a
  super majority has been reached
  - New block version on mainnet is version 4
  - New block version on testnet and simnet is version 5
- Add tests for the supply estimation used in the new algorithm
- Add tests for the new algorithm calculations
- Add tests for the estimation based on the new algorithm
Copy link
Member

@alexlyp alexlyp left a comment

Choose a reason for hiding this comment

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

tested thoroughly on simnet and sdiff correctly goes active and is easily seen to be more accurate at maintaining poolsize and ticketprice.
tACK, great work.

@davecgh davecgh merged commit 734684d into decred:master Apr 26, 2017
@davecgh davecgh deleted the new_sdiff_algo branch April 26, 2017 18:19
@davecgh davecgh added the consensus changes Changes that involve modifying the consensus rules and thus are required to be gated behind a vote. label Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus changes Changes that involve modifying the consensus rules and thus are required to be gated behind a vote.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rig up new SDiff algorithm Add SDiff agenda Bump mainnet to V4 Next generation SDiff
4 participants