-
Notifications
You must be signed in to change notification settings - Fork 296
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch.
9f183a2
to
8819c0e
Compare
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
There was a problem hiding this 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.
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:
Closes #584, closes #592, closes #593, and closes #594.