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

Add StakingPrecompileV2 #1356

Open
wants to merge 3 commits into
base: devnet-ready
Choose a base branch
from
Open

Conversation

ales-otf
Copy link
Contributor

@ales-otf ales-otf commented Mar 4, 2025

Description

Recently we changed some methods in StakingPrecompile to conform the amount precisions to our Substrate API. They were in ETH-precision before. But that affected some users.

This PR takes back ETH-precisions to those methods and introduces a new version of StakingPrecompile, that has API consistent with our Substrate API.

Tests are here: opentensor/subtensor-js-tests#12

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

  • StakingPrecompile exists only for backward compatibility from now on and considered deprecated (replaced by StakingPrecompileV2 at a new address)
  • StakingPrecompile::get_stake now again returns the amount, converted to ETH-precision
  • StakingPrecompile::remove_stake accepts amount in ETH-precision as it was before

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

@ales-otf ales-otf marked this pull request as ready for review March 4, 2025 15:34
<<R as frame_system::Config>::Lookup as StaticLookup>::Source: From<R::AccountId>,
{
const INDEX: u64 = 2053;
const ADDRESS_SS58: [u8; 32] = [0; 32];
Copy link
Contributor

Choose a reason for hiding this comment

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

need set the valid value.

Copy link
Contributor Author

@ales-otf ales-otf Mar 4, 2025

Choose a reason for hiding this comment

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

This is not used in the new version, so I set it to 0s (as in Metagraph and Ed25519Verify contracts). But I now think, it's better to change this value to Option<[u8; 32]> in the trait, to prevent potential mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@ales-otf ales-otf Mar 4, 2025

Choose a reason for hiding this comment

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

Even better would be ridding of this constant and using a conversion from the contract's address. Just look at this value is hard to understand whether it came from the contract address or not. Would be good to have a method in PrecompileExt trait and use Self::INDEX to generate this value on-demand. Will introduce a little runtime overhead, but that would be a lot more sound.

open-junius
open-junius previously approved these changes Mar 4, 2025
Copy link
Contributor

@open-junius open-junius left a comment

Choose a reason for hiding this comment

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

looks great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants