-
Notifications
You must be signed in to change notification settings - Fork 108
Mf/remove jailed stake from global active stake #533
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
Mf/remove jailed stake from global active stake #533
Conversation
lib/block_view_stake.go
Outdated
| // Restore the PrevGlobalStakeAmountNanos. | ||
| bav._setGlobalStakeAmountNanos(operationData.PrevGlobalStakeAmountNanos) | ||
| // Restore the PrevGlobalActiveStakeAmountNanos if the PrevValidatorEntry was active. | ||
| if prevValidatorEntry.Status() == ValidatorStatusActive { |
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.
we could just check if PrevGlobalActiveStakeAmountNanos is non-nil. I generally prefer that as opposed to relying on a different field. The prevs generally means "revert to this state when disconnecting".
lib/block_view_stake.go
Outdated
| // Restore the PrevGlobalStakeAmountNanos. | ||
| bav._setGlobalStakeAmountNanos(operationData.PrevGlobalStakeAmountNanos) | ||
| // Restore the PrevGlobalActiveStakeAmountNanos if the PrevValidatorEntry was active. | ||
| if prevValidatorEntry.Status() == ValidatorStatusActive { |
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.
lib/block_view_types.go
Outdated
| if prevGlobalActiveStakeAmountNanos, err := VariableDecodeUint256(rr); err == nil { | ||
| op.PrevGlobalActiveStakeAmountNanos = prevGlobalActiveStakeAmountNanos |
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.
we could just write if op.PrevGlobalActiveStakeAmountNanos, err := VariableDecodeUint256(rr); err != nil here instead.
| // Set the CurrentValidatorEntry. | ||
| bav._setValidatorEntryMappings(currentValidatorEntry) | ||
|
|
||
| // Increase the GlobalActiveStakeAmountNanos. |
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.
IsValidUnjailValidatorMetadata ensures that the validator is indeed jailed, correct?
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.
That's correct. See link here. It also validates that sufficient epochs have elapsed for the validator to be unjailed.
| return 0, 0, nil, errors.Wrapf(err, "_connectStake: error adding StakeAmountNanos to GlobalStakeAmountNanos: ") | ||
| // Increase the GlobalActiveStakeAmountNanos if the validator is active. | ||
| var prevGlobalActiveStakeAmountNanos *uint256.Int | ||
| if currentValidatorEntry.Status() == ValidatorStatusActive { |
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'm sure you've thougth about this, but do we want to make it so that you can't stake to a jailed validator? You would just add an else if block here to error if the status is jailed.
If you did this, I'd also add an else for "Unknown validator status" error.
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 thought about it more, and I think what you're doing here is more elegant. If we were to disallow staking to jailed validators, we'd break symmetry with Unstake, which I think adds complexity.
| } else { | ||
| return errors.Wrapf(err, "UtxoOperation.Decode: Problem reading PrevGlobalStakeAmountNanos: ") | ||
| // PrevGlobalActiveStakeAmountNanos | ||
| if op.PrevGlobalActiveStakeAmountNanos, err = VariableDecodeUint256(rr); err != nil { |
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.
Nit: No need to fix this here, but I tend to prefer breaking assignments out of if statements like the following. I know it's not "Go-like" but I find it easier to read and less error-prone:
// PrevGlobalActiveStakeAmountNanos
op.PrevGlobalActiveStakeAmountNanos, err = VariableDecodeUint256(rr)
if err != nil {
return errors.Wrapf(err, "UtxoOperation.Decode: Problem reading PrevGlobalActiveStakeAmountNanos: ")
}
lib/block_view_validator.go
Outdated
| // Restore the PrevGlobalActiveStakeAmountNanos. | ||
| prevGlobalActiveStakeAmountNanos := operationData.PrevGlobalActiveStakeAmountNanos | ||
| if prevGlobalActiveStakeAmountNanos == nil { | ||
| return errors.New("_disconnectUnjailValidator: PrevGlobalActiveStakeAmountNanos is nil") |
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.
Nit: Whenever something should never happen, like I think is the case here, I like to add "This should never happen" or "sanity-check failed" to indicate that in the logs for whoever ends up having to debug it.
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.
Let's add this^
lib/block_view.go
Outdated
|
|
||
| // Global stake across all validators | ||
| GlobalStakeAmountNanos *uint256.Int | ||
| // Global active stake across all validators |
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.
can we expound upon this comment? Something like The global active stake is the sum of all DESO staked to validators who are not jailed.
lib/block_view_validator.go
Outdated
| // Restore the PrevGlobalActiveStakeAmountNanos. | ||
| prevGlobalActiveStakeAmountNanos := operationData.PrevGlobalActiveStakeAmountNanos | ||
| if prevGlobalActiveStakeAmountNanos == nil { | ||
| return errors.New("_disconnectUnjailValidator: PrevGlobalActiveStakeAmountNanos is nil") |
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.
Let's add this^
* Diamondhands/pos txn types review (#530) * POS fixes and comments from diamondhands * Mf/pos txn types review (#531) * Add comments. * Addres review comments. * Add first batch of sanity check utils. * Add second batch of txn sanity checks. * Rename encode uint256 funcs in comments. * Nuke RegisteredAtBlockHeight. * Address review feedback. * Fix a few more typos. * Update some comments --------- Co-authored-by: diamondhands <diamondhands@bitcloutdev.com> --------- Co-authored-by: Matt Foley <100429827+mattfoley8@users.noreply.github.com> * Exclude zero-stake validators from TopValidatorsByStake. (#535) * Mf/remove jailed stake from global active stake (#533) * Remove jailed stake from global active stake. * Write to the UtxoView if no errors in jailing. * Add additional sanity checks. * PR review feedback. * Remove FIXME comment. --------- Co-authored-by: diamondhands0 <81935176+diamondhands0@users.noreply.github.com>
This PR removes any jailed stake from our GlobalActiveStakeAmountNanos value. If a validator is jailed, we do not want to consider their stake in the total active stake across validators used in determining if we have a 2/3rd consensus on votes. This PR makes the following changes:
GlobalStakeAmountNanostoGlobalActiveStakeAmountNanos. Note the addition of the keywordActive. This value describes the total active stake across validators, excluding any jailed validators' stake.GlobalActiveStakeAmountNanosif the validator isn't jailed.GlobalActiveStakeAmountNanosif the validator isn't jailed.TotalStakeAmountNanosfrom theGlobalActiveStakeAmountNanos.TotalStakeAmountNanosto theGlobalActiveStakeAmountNanos.TotalStakeAmountNanosfrom theGlobalActiveStakeAmountNanosit they weren't jailed.