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

Feat/dapp staking v3 precompiles #1096

Merged
merged 39 commits into from
Dec 19, 2023

Conversation

Dinonard
Copy link
Member

@Dinonard Dinonard commented Dec 5, 2023

dApp Staking v3 - Precompile Support

This PR introduces precompile support for dApp staking v3.
It includes two major updates:

  • the legacy interface is adapter to work as best as possible with the new dApp Staking v3 functionality
  • new interface is introduced specifically for dApp Staking v3

A slightly different approach is taken, compared to the old interface.
Number of getters is being kept to a minimum - only bare essentials are covered.
If a need arises for additional getters from project, we can consider adding them.

Check list

  • update mock & unit tests, add new unit tests
  • implement new interface support
  • sort out .sol file TODOs
  • migrate to precompile-utils-v2
  • improve documentation

@Dinonard Dinonard changed the base branch from master to feat/dapp-staking-v3 December 5, 2023 13:31
@Dinonard Dinonard added the runtime This PR/Issue is related to the topic “runtime”. label Dec 5, 2023
@Dinonard Dinonard mentioned this pull request Dec 5, 2023
10 tasks
@Dinonard Dinonard marked this pull request as ready for review December 16, 2023 13:20
@Dinonard Dinonard force-pushed the feat/dapp-staking-v3-precompiles branch from cbadf34 to c880ed2 Compare December 16, 2023 13:47
Copy link
Member

@ashutoshvarma ashutoshvarma left a comment

Choose a reason for hiding this comment

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

Looks good overall! Just minor comment

precompiles/dapps-staking-v3/src/lib.rs Outdated Show resolved Hide resolved
precompiles/dapps-staking-v3/src/lib.rs Outdated Show resolved Hide resolved
precompiles/dapps-staking-v3/src/lib.rs Outdated Show resolved Hide resolved
/// Register contract with the dapp-staking pallet
/// Register is root origin only. This should always fail when called via evm precompile.
#[precompile::public("register(address)")]
fn register(_: &mut impl PrecompileHandle, _address: Address) -> EvmResult<bool> {
Copy link
Member

Choose a reason for hiding this comment

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

Why is some exposed functions that will always fail ?

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 was part of the 'old' functionality, similar as setting the reward destination.
Not it's no longer valid, it's impossible for me to port it to v3.

So failing with a custom error seems better to me than just throwing unsupported address (not sure what the exact error would be).

impl RegisteredChainExtension<Runtime> for DappsStakingExtension<Runtime> {
const ID: u16 = 00;
}
// This can be restored when integrated with dApp staking v3.
Copy link
Member

Choose a reason for hiding this comment

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

I think you can remove everything related to dapp staking chain extension (in local in shibuya). We can still update it if there is a need for it

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will do that.

Copy link

Code Coverage

Package Line Rate Branch Rate Health
chain-extensions/types/dapps-staking/src 0% 0%
precompiles/xcm/src 72% 0%
chain-extensions/xvm/src 0% 0%
pallets/unified-accounts/src 84% 0%
precompiles/sr25519/src 64% 0%
pallets/xc-asset-config/src 53% 0%
chain-extensions/unified-accounts/src 0% 0%
pallets/inflation/src 78% 0%
primitives/src 66% 0%
chain-extensions/types/xvm/src 0% 0%
pallets/dapps-staking/src 81% 0%
precompiles/dapps-staking/src 94% 0%
pallets/xvm/src 40% 0%
pallets/dapp-staking-v3/src/test 0% 0%
chain-extensions/dapps-staking/src 0% 0%
pallets/ethereum-checked/src 48% 0%
precompiles/assets-erc20/src 81% 0%
primitives/src/xcm 66% 0%
pallets/block-rewards-hybrid/src 87% 0%
precompiles/xvm/src 74% 0%
precompiles/unified-accounts/src 100% 0%
pallets/dapps-staking/src/pallet 85% 0%
pallets/dynamic-evm-base-fee/src 81% 0%
pallets/dapp-staking-v3/src 83% 0%
chain-extensions/types/unified-accounts/src 0% 0%
chain-extensions/pallet-assets/src 0% 0%
pallets/dapp-staking-v3/rpc/runtime-api/src 0% 0%
pallets/dapp-staking-v3/src/benchmarking 0% 0%
chain-extensions/types/assets/src 0% 0%
precompiles/dapp-staking-v3/src/test 0% 0%
precompiles/dapp-staking-v3/src 90% 0%
pallets/collator-selection/src 69% 0%
pallets/dapp-staking-migration/src 40% 0%
precompiles/substrate-ecdsa/src 74% 0%
Summary 66% (3135 / 4750) 0% (0 / 0)

Minimum allowed line rate is 50%

Copy link
Member

@PierreOssun PierreOssun left a comment

Choose a reason for hiding this comment

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

LGTM

@Dinonard Dinonard merged commit 808686f into feat/dapp-staking-v3 Dec 19, 2023
8 checks passed
@Dinonard Dinonard deleted the feat/dapp-staking-v3-precompiles branch December 19, 2023 13:22
Dinonard added a commit that referenced this pull request Dec 20, 2023
* dApp Staking v3 Part1

* Feat/dapp staking v3 phase2 (#991)

* Phase2 progress

* Adapt for 0.9.43

* Abstract sparse vector type

* Further modifications

* claim unlocked functionality WIP

* claim unlocked tested

* Relock unlocking

* Check era when adding chunk

* Custom error for some types

* Additional type tests - WIP

* More type tests

* Review comments

* Additional changes

* dApp staking v3 - part 3 (#1036)

* dApp staking v3 - PR3

* SingularStakingInfo

* SingularStakingInfo tests

* Stake work

* Stake & lots of tests

* TODOs, renaming, improvements

* Refactoring & cleanup

* More fixes

* Rework series

* Series tests

* Minor adjustment

* stake test utils & first test

* Stake test

* stake extrinsic tests

* Era & Period change logic

* Update era/period transition in mock & tests

* on_init tests & refactoring

* Unstake & some minor improvements

* Lots of type tests for unstake

* More tests

* More types test

* Testing utils for unstake, some TODOs

* Unstake tests

* Minor adjustments

* Fixes

* Additional scenario

* Address review comments

* Correct unstake amount

* Tests

* dapp staking v3 - part 4 (#1053)

* EraRewardSpan

* Initial version of claim_staker_reward

* Tests

* Test utils for claim-staker

* Bug fixes, improvements

* Claim improvements & some tests

* Refactoring in progress

* Refactoring continued

* Refactoring progress

* Refactoring finished

* Bonus rewards

* Docs & some minor changes

* Comments, tests, improved coverage

* Tier params & config init solution

* Tier reward calculation WIP

* Tier assignemnt

* Minor cleanup

* Claim dapp rewards

* Claim dapp reward tests

* unstake from unregistered call

* Extra traits

* fixes

* Extra calls

* Refactoring

* More refactoring, improvements, TODO solving

* Local integration

* Genesis config

* Add forcing call

* try runtime build fix

* Minor changes

* Minor

* Formatting

* Benchmarks INIT

* Compiling benchmarks

* Fix

* dapp tier calculation benchmark

* Measured tier assignment

* Decending rewards in benchmarks

* Series refactoring & partial tests

* Comments, minor changes

* Tests, improvements

* More tests, some minor refactoring

* Formatting

* More benchmarks & experiments, refactoring

* Readme, docs

* Minor renaming, docs

* More docs

* More docs

* Minor addition

* Review comment fixes & changes

* Minor change

* Review comments

* Update frontier to make CI pass

* Fix for cleanup

* dapp staking v3 - part 5 (#1087)

* EraRewardSpan

* Initial version of claim_staker_reward

* Tests

* Test utils for claim-staker

* Bug fixes, improvements

* Claim improvements & some tests

* Refactoring in progress

* Refactoring continued

* Refactoring progress

* Refactoring finished

* Bonus rewards

* Docs & some minor changes

* Comments, tests, improved coverage

* Tier params & config init solution

* Tier reward calculation WIP

* Tier assignemnt

* Minor cleanup

* Claim dapp rewards

* Claim dapp reward tests

* unstake from unregistered call

* Extra traits

* fixes

* Extra calls

* Refactoring

* More refactoring, improvements, TODO solving

* Local integration

* Genesis config

* Add forcing call

* try runtime build fix

* Minor changes

* Minor

* Formatting

* Benchmarks INIT

* Compiling benchmarks

* Fix

* dapp tier calculation benchmark

* Measured tier assignment

* Decending rewards in benchmarks

* Series refactoring & partial tests

* Comments, minor changes

* Tests, improvements

* More tests, some minor refactoring

* Formatting

* More benchmarks & experiments, refactoring

* Readme, docs

* Minor renaming, docs

* More docs

* More docs

* Minor addition

* Review comment fixes & changes

* Minor change

* Review comments

* Update frontier to make CI pass

* dApp staking v3 - part 5

* Make check work

* Limit map size to improve benchmarks

* Fix for cleanup

* Minor fixes, more tests

* More fixes & test

* Minor changes

* More tests

* More tests, some clippy fixes

* Finished with type tests for now

* Log, remove some TODOs

* Changes

* Bug fix for unstake era, more tests

* Formatting, extra test

* Unregistered unstake, expired cleanup, test utils & tests

* Cleanup tests, minor fixes

* force tests

* Remove TODOs

* Tier assignment test WIP

* Finish dapp tier assignment test, fix reward calculation bug

* Some renaming, test utils for era change WIP

* Fix minor issues, propagaste renaming

* More checks

* Finish on_init tests

* Comments, docs, some benchmarks

* Benchmark progress

* More benchmarks

* Even more benchmarks

* All extrinsics benchmarked

* Expand tests

* Comment

* Missed error test

* Review comments

* Pallet inflation (#1091)

* Pallet inflation

* Hooks

* Functionality, mock & benchmarks

* Empty commit since it seems last push didn't work properly

* Tests, fixes

* More tests, minor fixes&changes

* Zero divison protection, frontier update

* More tests, minor changes

* Integration & renaming

* Genesis integration, more tests

* Final integration

* Cleanup deps

* Division with zero test

* Comments

* More minor changes

* Improve test coverage

* Integrate into pallet-timestamp

* Remove timestamp

* Fix

* review comments

* toml format

* dApp Staking v3 - part 6 (#1093)

* dApp staking v3 part 6

* Minor refactor of benchmarks

* Weights integration

* Fix

* remove orig file

* Minor refactoring, more benchmark code

* Extract on_init logic

* Some renaming

* More benchmarks

* Full benchmarks integration

* Testing primitives

* staking primitives

* dev fix

* Integration part1

* Integration part2

* Reward payout integration

* Replace lock functionality with freeze

* Cleanup TODOs

* More negative tests

* Frozen balance test

* Zero div

* Docs for inflation

* Rename is_active & add some more docs

* More docs

* pallet docs

* text

* scripts

* More tests

* Test, docs

* Review comment

* dApp staking v3 - part 7 (#1099)

* dApp staking v3 part 6

* Minor refactor of benchmarks

* Weights integration

* Fix

* remove orig file

* Minor refactoring, more benchmark code

* Extract on_init logic

* Some renaming

* More benchmarks

* Full benchmarks integration

* Testing primitives

* staking primitives

* dev fix

* Integration part1

* Integration part2

* Reward payout integration

* Replace lock functionality with freeze

* Cleanup TODOs

* More negative tests

* Frozen balance test

* Zero div

* Docs for inflation

* Rename is_active & add some more docs

* More docs

* pallet docs

* text

* scripts

* More tests

* Test, docs

* Review comment

* Runtime API

* Changes

* Change dep

* Comment

* Formatting

* Expired entry cleanup

* Cleanup logic test

* Remove tier labels

* fix

* Improve README

* Improved cleanup

* Review comments

* Docs

* Formatting

* Typo

* Fix - bonus reward update ledger (#1102)

* Bonus claim reduced contract_stake_count

* Extra test

* dApp Staking Migration (#1101)

* dApp Staking Migration

* Events, benchmark prep

* benchmarks

* Benchmarks & mock

* weights

* limit

* Use extrinsic call

* Solved todos, docs, improvements

* Maintenance mode, on_runtime_upgrade logic

* Tests, refactoring

* Finish

* More tests

* Type cleanup

* try-runtime checks

* deps

* Improve docs

* Fixes & try-runtime testing modifications

* Fix test

* repeated

* Minor improvements

* Improvements

* taplo

* Minor rename

* Feat/dapp staking v3 precompiles (#1096)

* Init commit

* All legacy calls covered

* v2 interface first definition

* Rename

* Resolve merge errors

* TODO

* v2 init implementation

* Prepared mock

* todo

* Migration to v2 utils

* More adjustments

* Finish adapting implementation to v2

* Mock & fixes

* Primitive smart contract

* Fix dsv3 test

* Prepare impl & mock

* Remove redundant code, adjust mock & prepare tests

* Tests & utils

* Test for legacy getters/view functions

* More legacy tests

* v1 interface covered with tests

* Minor refactor, organization, improvements

* v2 tests

* Cleanup TODOs

* More tests

* Updates

* docs

* Fixes

* Address review comments

* Adjustments

* Audit comments

* Fix mock

* FMT

* Review comments

* Fix for incorrect freeze amount (#1111)

* dApp Staking v3 - Shibuya integration (#1109)

* dApp staking v3 - Shibuya integration

* Init

* Fix build

* Fix find/replace doc mess

* Migration & disable

* More integration

* Progress

* Adjusted integration

* Finished integration

* Additional modifications & cleanup

* Move comment

* Fixes

* Shibuya integration tests fix & proxy

* Renaming

* Integration test fixes & legacy support

* Adjust for benchmarks

* Remove chain-extension, small updates

* fixes

* Partial weights

* Minor changes

* Benchmark fixes

* dApp staking weights

* Weights, deps

* Remove redundant storage item

* Inflation params, resolve TODOs

* Optimize lengthy benchmark

* Integration test

* Sort out more TODOs

* Benchmark optimization

* Fix seed

* Remove spec version bump

* Fix integration test

* Weights update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants