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

Misc PoS tasks #2178

Merged
merged 9 commits into from
Nov 21, 2023
Merged

Misc PoS tasks #2178

merged 9 commits into from
Nov 21, 2023

Conversation

brentstone
Copy link
Collaborator

@brentstone brentstone commented Nov 14, 2023

Describe your changes

Closes #17, closes #1270. Some other things addressed in this PR:

  • rename store_total_consensus_stake to compute_and_store_total_consensus_stake
  • Improves docstrings, comments, and logging
  • Removes outdated TODOs in PoS
  • is_delegator issue

Indicate on which release or other PRs this topic is based on

v0.26.0

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

@brentstone brentstone force-pushed the brent/misc-pos-tasks branch 2 times, most recently from 1b8d247 to d5d730f Compare November 14, 2023 18:59
@brentstone brentstone marked this pull request as ready for review November 14, 2023 19:08
brentstone added a commit that referenced this pull request Nov 14, 2023
@brentstone brentstone mentioned this pull request Nov 14, 2023
brentstone added a commit that referenced this pull request Nov 15, 2023
* brent/misc-pos-tasks:
  changelog: add #2178
  fix and test `is_delegator`
  checked arithmetic
  remove unnecessary computation of total consensus stake
  clean up TODOs, docstrings, logging
  remove unused queries fn
  fix FutureEpoch offsets of some data
  panic on slashing error
  rename to `compute_and_store_total_consensus_stake`
brentstone added a commit that referenced this pull request Nov 15, 2023
* brent/misc-pos-tasks:
  changelog: add #2178
  fix and test `is_delegator`
  checked arithmetic
  remove unnecessary computation of total consensus stake
  clean up TODOs, docstrings, logging
  remove unused queries fn
  fix FutureEpoch offsets of some data
  panic on slashing error
  rename to `compute_and_store_total_consensus_stake`
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Minor nits.

@@ -327,7 +322,7 @@ where
current_epoch,
epoch,
)?;
store_total_consensus_stake(storage, epoch)?;
// compute_and_store_total_consensus_stake(storage, epoch)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this now commented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was a redundant operation. We already call this function in init_chain and in finalize_block upon a new epoch, both times before calling copy_validator_sets. It is only necessary to call the function at the beginning of a new epoch and compute the total consensus stake for that current epoch only.

@@ -308,7 +302,8 @@ where
Ok(())
}

/// new init genesis
/// Copies the validator sets into all epochs up through the pipeline epoch at
/// genesis. Also computes the total
Copy link
Contributor

Choose a reason for hiding this comment

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

Sentence fragment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thx, will fix up.

@@ -716,6 +721,8 @@ pub fn is_validator<S>(
where
S: StorageRead,
{
// TODO: should this check be made different? I suppose it does work but
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically this works because all validators need to have a max_commission_rate_change set in storage, but it just seems odd from a readability perspective. May change this in a small PR before the next release

.total_stake
.checked_mul(2.into())
.expect("Amount overflow while computing minimum required votes")
+ (3u64 - 1u64))
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't it technically overflow here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, you are right, this should have an extra checked_add

Fraccaman pushed a commit that referenced this pull request Nov 20, 2023
* origin/brent/misc-pos-tasks:
  changelog: add #2178
  fix and test `is_delegator`
  checked arithmetic
  remove unnecessary computation of total consensus stake
  clean up TODOs, docstrings, logging
  remove unused queries fn
  fix FutureEpoch offsets of some data
  panic on slashing error
  rename to `compute_and_store_total_consensus_stake`
Fraccaman pushed a commit that referenced this pull request Nov 20, 2023
* origin/brent/misc-pos-tasks:
  changelog: add #2178
  fix and test `is_delegator`
  checked arithmetic
  remove unnecessary computation of total consensus stake
  clean up TODOs, docstrings, logging
  remove unused queries fn
  fix FutureEpoch offsets of some data
  panic on slashing error
  rename to `compute_and_store_total_consensus_stake`
Fraccaman pushed a commit that referenced this pull request Nov 20, 2023
* origin/brent/misc-pos-tasks:
  changelog: add #2178
  fix and test `is_delegator`
  checked arithmetic
  remove unnecessary computation of total consensus stake
  clean up TODOs, docstrings, logging
  remove unused queries fn
  fix FutureEpoch offsets of some data
  panic on slashing error
  rename to `compute_and_store_total_consensus_stake`
Fraccaman pushed a commit that referenced this pull request Nov 20, 2023
* origin/brent/misc-pos-tasks:
  changelog: add #2178
  fix and test `is_delegator`
  checked arithmetic
  remove unnecessary computation of total consensus stake
  clean up TODOs, docstrings, logging
  remove unused queries fn
  fix FutureEpoch offsets of some data
  panic on slashing error
  rename to `compute_and_store_total_consensus_stake`
@tzemanovic tzemanovic merged commit 589e2b8 into main Nov 21, 2023
12 of 14 checks passed
@tzemanovic tzemanovic deleted the brent/misc-pos-tasks branch November 21, 2023 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PoS: panic on slashing failure PoS - use checked arithmetics
3 participants