-
Notifications
You must be signed in to change notification settings - Fork 1.2k
staking-async: allow session keys handling on AssetHub #10666
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
dc9400a
session/staking/westend AH and RC: allow to set/purge session keys vi…
sigurpol 0955884
ah-client: proper weight for set_keys_from_ah, purge_keys_from_ah
sigurpol 3e86054
staking-async/rc-client: improve documentation
sigurpol 1c09588
staking-async-rc-client: only validators are allowed to set/purge keys
sigurpol 9b76270
fix prdoc
sigurpol 4dd074b
staking-async-rc-client: session keys as raw bytes
sigurpol 45a7526
staking-async-rc-client: improve documentation
sigurpol d36a42c
improve prdoc
sigurpol 5064a6c
staking-async/ah: add unit testss
sigurpol 619ec8a
staking-async/rc: add unit tests
sigurpol 668f7a3
staking-async/ah: add e2e test
sigurpol e5b2ef8
staking-async/ah: more tests
sigurpol fe233b0
session keys and ownership proof fully validated on AH
sigurpol 5fd5a0c
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol d4c3f2f
Updated ownership_proof_is_valid call to use the new 2 arg signature
sigurpol 96a5e00
more tests
sigurpol bcd7664
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol e4af53f
staking-async: fix CI
sigurpol 0a13bb5
asset-hub-westend: add support for staking proxy
sigurpol 294704e
staking-async: tests around staking proxy
sigurpol b28ced4
asset-hub-westend: test keys match between AH and RC
sigurpol a498cbb
staking-async/rc: add benchmarks for set/purge_keys
sigurpol 3519aef
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol fa76173
staking-async/rc: bounded vec for set_keys
sigurpol be0cd04
Update from github-actions[bot] running command 'bench --pallet palle…
github-actions[bot] 23f49e5
Cleanup
sigurpol 95d37aa
Merge branch 'master' into sigurpol-session-keys-asset-hub
Ank4n 93e82f8
staking-async/rc: remove check on validator in purge_keys
sigurpol e0f8374
asset-hub-westend: missing weights + cleanup
sigurpol 627348c
pallet-session: add a trait for managing session keys
sigurpol 9978796
pallet-session: add SessionInterface trait for better decoupling with…
sigurpol e0eb51a
Update from github-actions[bot] running command 'bench --pallet palle…
github-actions[bot] 7b7b349
staking-async/ah-client: add Unexpected(InvalidKeysFromAssetHub event
sigurpol e17be07
westend/staking-async runtime: fix SessionInterface config
sigurpol 6b2d6cb
pallet-session: remove SessionKeyManager and make do_set/purge_keys p…
sigurpol b2f8e36
pallet-session: SessionInterface feature-gated with historical
sigurpol 796f268
staking/rc-client: handle XCM fees
sigurpol e990a3e
staking-async/rc-client: proper benchmark XCM in set/purge_keys
sigurpol c57ca8c
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol e1210a9
staking-async/rc-client: cleanup
sigurpol a19df4c
Update from github-actions[bot] running command 'bench --pallet palle…
github-actions[bot] 70391e3
ahm-test: cleanup
sigurpol d4c47db
staking-async/rc-client: improve documentation
sigurpol 2f42e83
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol 4ce53b9
Fix review comments
sigurpol 6b3ad41
Fix remaining review comments
sigurpol a74d143
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol 3bff2f5
Fix merge conflict in asset-hub-westend tests
sigurpol c4ac31f
Update from github-actions[bot] running command 'bench --pallet palle…
github-actions[bot] f8656fc
Merge remote-tracking branch 'origin/master' into sigurpol-session-ke…
sigurpol 42b10fb
[staking-async] Abstract XCM from SendToRelayChain trait
sigurpol 436e598
SessionInterface: set/purge_keys bypass deposit holds and consumer re…
sigurpol aab20e1
fee rework
sigurpol 19d443a
staking-async: mock cleanup
sigurpol 709fd3c
staking-async/rc-client: fix benchmark
sigurpol ccbe701
Update from github-actions[bot] running command 'bench --pallet palle…
github-actions[bot] 5807eb1
wrap fee charging and delivery in a transaction
sigurpol 7e22c64
Merge remote-tracking branch 'origin/master' into sigurpol-session-ke…
sigurpol c747ad8
fix prdoc vs semver: breaking changes only for ah/rc-client
sigurpol e262839
fix prdoc vs semver
sigurpol d458a78
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol a247b4d
Fix review comments
sigurpol 4963b1f
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol 9b840ca
staking-async/rc-client: improve doc around fees
sigurpol 88616fe
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol 7d62d55
Merge remote-tracking branch 'origin/master' into sigurpol-session-ke…
sigurpol 45342f2
Fix review comments
sigurpol b0f0a46
Fix more review comments
sigurpol f4b92b3
Revert transaction wrapper
sigurpol 90a06a2
staking-async: use realistic keys in testnet runtime
sigurpol d0d034b
staking-async/papi_test: add test to set and purge keys
sigurpol b686e91
Added SessionKeysUpdated event to ah-client pallet
sigurpol 30c8ba9
staking-async: handle fees in the test runtime
sigurpol 91ad234
stakig-async: rc-client cleanup to easily integrate runtimes
sigurpol 962ea91
Merge branch 'master' into sigurpol-session-keys-asset-hub
sigurpol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| title: 'staking-async: allow session keys handling on AssetHub' | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: |- | ||
| - Added session keys handling on AssetHub for staking-async: validators can now call set_keys and purge_keys on AssetHub, which forwards the request to the RelayChain via XCM. | ||
| - Validators are still allowed to call `set_keys` and `purge_keys` via relay-chain pallet-session's related extrinsics. This option will be deprecated in the future. | ||
| - No key deposit is set on AssetHub yet. | ||
| crates: | ||
| - name: asset-hub-westend-runtime | ||
| bump: major | ||
| - name: westend-runtime | ||
| bump: major | ||
| - name: pallet-session | ||
| bump: minor | ||
| - name: pallet-staking-async-ah-client | ||
| bump: major | ||
| - name: pallet-staking-async-rc-client | ||
| bump: major | ||
| - name: pallet-staking-async | ||
| bump: major |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ use frame_support::{ | |
| pallet_prelude::*, | ||
| traits::{Defensive, DefensiveSaturating, RewardsReporter}, | ||
| }; | ||
| use pallet_session::WeightInfo as SessionWeightInfo; | ||
| pub use pallet_staking_async_rc_client::SendToAssetHub; | ||
| use pallet_staking_async_rc_client::{self as rc_client}; | ||
| use sp_runtime::SaturatedConversion; | ||
|
|
@@ -103,6 +104,12 @@ pub trait SessionInterface { | |
| /// The validator id type of the session pallet | ||
| type ValidatorId: Clone; | ||
|
|
||
| /// The account id type | ||
| type AccountId; | ||
|
|
||
| /// The session keys type | ||
| type Keys: sp_runtime::traits::OpaqueKeys + codec::Decode; | ||
|
|
||
| fn validators() -> Vec<Self::ValidatorId>; | ||
|
|
||
| /// prune up to the given session index. | ||
|
|
@@ -112,12 +119,30 @@ pub trait SessionInterface { | |
| /// | ||
| /// This is used to disable validators directly on the RC, until the next validator set. | ||
| fn report_offence(offender: Self::ValidatorId, severity: OffenceSeverity); | ||
|
|
||
| /// Set session keys for an account. | ||
| /// | ||
| /// This is called when AssetHub forwards a session key registration via XCM. | ||
| fn set_keys(account: &Self::AccountId, keys: Self::Keys) -> DispatchResult; | ||
|
|
||
| /// Purge session keys for an account. | ||
| /// | ||
| /// This is called when AssetHub forwards a session key purge request via XCM. | ||
| fn purge_keys(account: &Self::AccountId) -> DispatchResult; | ||
|
|
||
| /// Weight for setting session keys. | ||
| fn set_keys_weight() -> Weight; | ||
|
|
||
| /// Weight for purging session keys. | ||
| fn purge_keys_weight() -> Weight; | ||
| } | ||
|
|
||
| impl<T: Config + pallet_session::Config + pallet_session::historical::Config> SessionInterface | ||
| for T | ||
| { | ||
| type ValidatorId = <T as pallet_session::Config>::ValidatorId; | ||
| type AccountId = <T as frame_system::Config>::AccountId; | ||
| type Keys = <T as pallet_session::Config>::Keys; | ||
|
|
||
| fn validators() -> Vec<Self::ValidatorId> { | ||
| pallet_session::Pallet::<T>::validators() | ||
|
|
@@ -129,6 +154,22 @@ impl<T: Config + pallet_session::Config + pallet_session::historical::Config> Se | |
| fn report_offence(offender: Self::ValidatorId, severity: OffenceSeverity) { | ||
| pallet_session::Pallet::<T>::report_offence(offender, severity) | ||
| } | ||
|
|
||
| fn set_keys(account: &Self::AccountId, keys: Self::Keys) -> DispatchResult { | ||
| pallet_session::Pallet::<T>::do_set_keys(account, keys) | ||
Ank4n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| fn purge_keys(account: &Self::AccountId) -> DispatchResult { | ||
sigurpol marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pallet_session::Pallet::<T>::do_purge_keys(account) | ||
| } | ||
|
|
||
| fn set_keys_weight() -> Weight { | ||
| <T as pallet_session::Config>::WeightInfo::set_keys() | ||
| } | ||
|
|
||
| fn purge_keys_weight() -> Weight { | ||
| <T as pallet_session::Config>::WeightInfo::purge_keys() | ||
| } | ||
| } | ||
|
|
||
| /// Represents the operating mode of the pallet. | ||
|
|
@@ -208,7 +249,7 @@ pub mod pallet { | |
| use frame_system::pallet_prelude::*; | ||
| use pallet_session::{historical, SessionManager}; | ||
| use pallet_staking_async_rc_client::SessionReport; | ||
| use sp_runtime::{Perbill, Saturating}; | ||
| use sp_runtime::{traits::OpaqueKeys, Perbill, Saturating}; | ||
| use sp_staking::{ | ||
| offence::{OffenceSeverity, OnOffenceHandler}, | ||
| SessionIndex, | ||
|
|
@@ -275,7 +316,10 @@ pub mod pallet { | |
| type MaxOffenceBatchSize: Get<u32>; | ||
|
|
||
| /// Interface to talk to the local Session pallet. | ||
| type SessionInterface: SessionInterface<ValidatorId = Self::AccountId>; | ||
| type SessionInterface: SessionInterface< | ||
| ValidatorId = Self::AccountId, | ||
| AccountId = Self::AccountId, | ||
| >; | ||
|
|
||
| /// A fallback implementation to delegate logic to when the pallet is in | ||
| /// [`OperatingMode::Passive`]. | ||
|
|
@@ -463,6 +507,10 @@ pub mod pallet { | |
| pub enum Error<T> { | ||
| /// Could not process incoming message because incoming messages are blocked. | ||
| Blocked, | ||
| /// The session keys could not be decoded. | ||
| InvalidKeys, | ||
sigurpol marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Invalid ownership proof for the session keys. | ||
| InvalidProof, | ||
| } | ||
|
|
||
| #[pallet::event] | ||
|
|
@@ -633,6 +681,55 @@ pub mod pallet { | |
| Self::on_migration_end(); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Set session keys for a validator, forwarded from AssetHub. | ||
| /// | ||
| /// This is called when a validator sets their session keys on AssetHub, which forwards | ||
| /// the request to the RelayChain via XCM. | ||
| /// | ||
| /// The `keys` parameter contains the encoded session keys that will be decoded and | ||
| /// registered with the session pallet. | ||
| /// The `proof` parameter is validated using the `OpaqueKeys::ownership_proof_is_valid` | ||
| /// method to verify key ownership. | ||
| #[pallet::call_index(3)] | ||
| #[pallet::weight(T::SessionInterface::set_keys_weight())] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its better to be able to benchmark calls, even if its proxy call. But not a blocker.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed - I will add as followup PR |
||
| pub fn set_keys_from_ah( | ||
| origin: OriginFor<T>, | ||
| stash: T::AccountId, | ||
| keys: Vec<u8>, | ||
| proof: Vec<u8>, | ||
| ) -> DispatchResult { | ||
| T::AssetHubOrigin::ensure_origin_or_root(origin)?; | ||
| log::info!(target: LOG_TARGET, "Received set_keys request from AssetHub for {stash:?}"); | ||
|
|
||
| // Decode the keys from bytes | ||
| let session_keys = | ||
| <<T as Config>::SessionInterface as SessionInterface>::Keys::decode(&mut &keys[..]) | ||
| .map_err(|_| Error::<T>::InvalidKeys)?; | ||
sigurpol marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ensure!(session_keys.ownership_proof_is_valid(&proof), Error::<T>::InvalidProof); | ||
|
|
||
| // Forward to session pallet via SessionInterface | ||
| T::SessionInterface::set_keys(&stash, session_keys)?; | ||
|
|
||
| Ok(()) | ||
sigurpol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Purge session keys for a validator, forwarded from AssetHub. | ||
| /// | ||
| /// This is called when a validator purges their session keys on AssetHub, which forwards | ||
| /// the request to the RelayChain via XCM. | ||
| #[pallet::call_index(4)] | ||
| #[pallet::weight(T::SessionInterface::purge_keys_weight())] | ||
| pub fn purge_keys_from_ah(origin: OriginFor<T>, stash: T::AccountId) -> DispatchResult { | ||
muharem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| T::AssetHubOrigin::ensure_origin_or_root(origin)?; | ||
| log::info!(target: LOG_TARGET, "Received purge_keys request from AssetHub for {stash:?}"); | ||
|
|
||
| // Forward to session pallet via SessionInterface | ||
| T::SessionInterface::purge_keys(&stash)?; | ||
|
|
||
| Ok(()) | ||
sigurpol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| #[pallet::hooks] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.