mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Add the missing internal functions.
This commit is contained in:
@@ -37,14 +37,15 @@ pub fn set_key(validator: &AccountID, key: &SessionKey) {
|
||||
// set new value for next session
|
||||
key.store(&validator.to_keyed_vec(b"ses:nxt:"));
|
||||
}
|
||||
// PRIVILEGED API (available to proposals)
|
||||
|
||||
// PUBLIC API (available to other runtime modules)
|
||||
|
||||
/// Get the current set of authorities. These are the session keys.
|
||||
pub fn validators() -> Vec<AccountID> {
|
||||
ValidatorStorageVec::items()
|
||||
/// Set a new era length. Won't kick in until the next era change (at current length).
|
||||
pub fn set_length(new: BlockNumber) {
|
||||
new.store(b"ses:nln");
|
||||
}
|
||||
|
||||
// INTERNAL API (available to other runtime modules)
|
||||
|
||||
/// Set the current set of validators.
|
||||
///
|
||||
/// Called by staking::next_era() only. `next_session` should be called after this in order to
|
||||
@@ -54,6 +55,23 @@ pub fn set_validators(new: &[AccountID]) {
|
||||
consensus::set_authorities(new);
|
||||
}
|
||||
|
||||
/// Hook to be called after transaction processing.
|
||||
pub fn check_rotate_session() {
|
||||
// do this last, after the staking system has had chance to switch out the authorities for the
|
||||
// new set.
|
||||
// check block number and call next_session if necessary.
|
||||
if (system::block_number() - last_length_change()) % length() == 0 {
|
||||
rotate_session();
|
||||
}
|
||||
}
|
||||
|
||||
// Inspection API
|
||||
|
||||
/// Get the current set of authorities. These are the session keys.
|
||||
pub fn validators() -> Vec<AccountID> {
|
||||
ValidatorStorageVec::items()
|
||||
}
|
||||
|
||||
/// The number of blocks in each session.
|
||||
pub fn length() -> BlockNumber {
|
||||
Storable::lookup_default(b"ses:len")
|
||||
@@ -69,37 +87,17 @@ pub fn current_index() -> BlockNumber {
|
||||
Storable::lookup_default(b"ses:ind")
|
||||
}
|
||||
|
||||
/// Set the current era index.
|
||||
pub fn set_current_index(new: BlockNumber) {
|
||||
new.store(b"ses:ind");
|
||||
}
|
||||
|
||||
/// The block number at which the era length last changed.
|
||||
pub fn last_length_change() -> BlockNumber {
|
||||
Storable::lookup_default(b"ses:llc")
|
||||
}
|
||||
|
||||
/// Set a new era length. Won't kick in until the next era change (at current length).
|
||||
pub fn set_length(new: BlockNumber) {
|
||||
new.store(b"ses:nln");
|
||||
}
|
||||
|
||||
/// Hook to be called after transaction processing.
|
||||
pub fn check_rotate_session() {
|
||||
// do this last, after the staking system has had chance to switch out the authorities for the
|
||||
// new set.
|
||||
// check block number and call next_session if necessary.
|
||||
if (system::block_number() - last_length_change()) % length() == 0 {
|
||||
rotate_session();
|
||||
}
|
||||
}
|
||||
|
||||
// PRIVATE (not available for use externally)
|
||||
|
||||
/// Move onto next session: register the new authority set.
|
||||
fn rotate_session() {
|
||||
// Increment current session index.
|
||||
set_current_index(current_index() + 1);
|
||||
(current_index() + 1).store(b"ses:ind");
|
||||
|
||||
// Enact era length change.
|
||||
if let Some(next_len) = u64::lookup(b"ses:nln") {
|
||||
|
||||
@@ -81,12 +81,33 @@ pub fn unstake(transactor: &AccountID) {
|
||||
(current_era() + bonding_duration()).store(&transactor.to_keyed_vec(b"sta:bon:"));
|
||||
}
|
||||
|
||||
// PUBLIC API
|
||||
// PRIVILEDGED API
|
||||
|
||||
/// Set the number of sessions in an era.
|
||||
pub fn set_sessions_per_era(new: BlockNumber) {
|
||||
new.store(b"sta:nse");
|
||||
}
|
||||
|
||||
/// The length of the bonding duration in eras.
|
||||
pub fn set_bonding_duration(new: BlockNumber) {
|
||||
new.store(b"sta:loc");
|
||||
}
|
||||
|
||||
/// The length of a staking era in sessions.
|
||||
pub fn set_validator_count(new: usize) {
|
||||
(new as u32).store(b"sta:vac");
|
||||
}
|
||||
|
||||
// INTERNAL API
|
||||
|
||||
/// Hook to be called after to transaction processing.
|
||||
pub fn check_new_era() {
|
||||
// check block number and call new_era if necessary.
|
||||
if (system::block_number() - last_era_length_change()) % era_length() == 0 {
|
||||
new_era();
|
||||
}
|
||||
}
|
||||
|
||||
// INSPECTION API
|
||||
|
||||
/// The length of the bonding duration in eras.
|
||||
@@ -129,14 +150,6 @@ pub fn bondage(who: &AccountID) -> Bondage {
|
||||
Storable::lookup_default(&who.to_keyed_vec(b"sta:bon:"))
|
||||
}
|
||||
|
||||
/// Hook to be called after to transaction processing.
|
||||
pub fn check_new_era() {
|
||||
// check block number and call new_era if necessary.
|
||||
if (system::block_number() - last_era_length_change()) % era_length() == 0 {
|
||||
new_era();
|
||||
}
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
/// The era has changed - enact new staking set.
|
||||
|
||||
@@ -42,6 +42,7 @@ pub fn deposit_log(log: &[u8]) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Actually execute all transitioning for `block`.
|
||||
pub fn execute_block(mut block: Block) {
|
||||
// populate environment from header.
|
||||
with_env(|e| {
|
||||
|
||||
@@ -21,7 +21,7 @@ use runtime_support::{size_of, Vec};
|
||||
use slicable::Slicable;
|
||||
use joiner::Joiner;
|
||||
use streamreader::StreamReader;
|
||||
use runtime::{system, governance, staking};
|
||||
use runtime::{system, governance, staking, session};
|
||||
|
||||
/// Internal functions that can be dispatched to.
|
||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||
@@ -29,7 +29,10 @@ use runtime::{system, governance, staking};
|
||||
pub enum InternalFunction {
|
||||
SystemSetCode,
|
||||
StakingSetSessionsPerEra,
|
||||
StakingSetBondingDuration,
|
||||
StakingSetValidatorCount,
|
||||
GovernanceSetApprovalPpmRequired,
|
||||
SessionSetLength,
|
||||
}
|
||||
|
||||
impl InternalFunction {
|
||||
@@ -38,7 +41,10 @@ impl InternalFunction {
|
||||
match value {
|
||||
x if x == InternalFunction::SystemSetCode as u8 => Some(InternalFunction::SystemSetCode),
|
||||
x if x == InternalFunction::StakingSetSessionsPerEra as u8 => Some(InternalFunction::StakingSetSessionsPerEra),
|
||||
x if x == InternalFunction::StakingSetBondingDuration as u8 => Some(InternalFunction::StakingSetBondingDuration),
|
||||
x if x == InternalFunction::StakingSetValidatorCount as u8 => Some(InternalFunction::StakingSetValidatorCount),
|
||||
x if x == InternalFunction::GovernanceSetApprovalPpmRequired as u8 => Some(InternalFunction::GovernanceSetApprovalPpmRequired),
|
||||
x if x == InternalFunction::SessionSetLength as u8 => Some(InternalFunction::SessionSetLength),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -86,10 +92,22 @@ impl Proposal {
|
||||
let value = params.read().unwrap();
|
||||
staking::set_sessions_per_era(value);
|
||||
}
|
||||
InternalFunction::StakingSetBondingDuration => {
|
||||
let value = params.read().unwrap();
|
||||
staking::set_bonding_duration(value);
|
||||
}
|
||||
InternalFunction::StakingSetValidatorCount => {
|
||||
let value = params.read().unwrap();
|
||||
staking::set_validator_count(value);
|
||||
}
|
||||
InternalFunction::GovernanceSetApprovalPpmRequired => {
|
||||
let value = params.read().unwrap();
|
||||
governance::set_approval_ppm_required(value);
|
||||
}
|
||||
InternalFunction::SessionSetLength => {
|
||||
let value = params.read().unwrap();
|
||||
session::set_length(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user