Convert all UK spelling to US (#2138)

* all the ise

* forgot a misspelling

* a few more replacements

* bump impl

* rollback and fixes

* bump impl again

* Add aliases for RPC

* Update on_demand.rs
This commit is contained in:
joe petrowski
2019-03-29 14:11:45 +01:00
committed by Gav Wood
parent a10e86ba5a
commit 0ddcbf747f
74 changed files with 453 additions and 451 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ edition = "2018"
hex-literal = "0.1.0"
serde = { version = "1.0", optional = true }
parity-codec = { version = "3.2", default-features = false }
# Needed for various traits. In our case, `OnFinalise`.
# Needed for various traits. In our case, `OnFinalize`.
primitives = { package = "sr-primitives", path = "../../core/sr-primitives", default-features = false }
# Needed for type-safe access to storage DB.
srml-support = { path = "../support", default-features = false }
+4 -4
View File
@@ -73,18 +73,18 @@ fn aura_reports_offline() {
}
with_externalities(&mut new_test_ext(vec![0, 1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
let slot_duration = Aura::slot_duration();
Aura::on_timestamp_set::<HandleTestReport>(5 * slot_duration, slot_duration);
let header = System::finalise();
let header = System::finalize();
// no slashing when last step was 0.
assert_eq!(SLASH_COUNTS.lock().as_slice(), &[0, 0, 0, 0]);
System::initialise(&2, &header.hash(), &Default::default());
System::initialize(&2, &header.hash(), &Default::default());
Aura::on_timestamp_set::<HandleTestReport>(8 * slot_duration, slot_duration);
let _header = System::finalise();
let _header = System::finalize();
// Steps 6 and 7 were skipped.
assert_eq!(SLASH_COUNTS.lock().as_slice(), &[0, 0, 1, 1]);
+2 -2
View File
@@ -183,7 +183,7 @@ decl_storage! {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Report some misbehaviour.
/// Report some misbehavior.
fn report_misbehavior(origin, _report: Vec<u8>) {
ensure_signed(origin)?;
}
@@ -224,7 +224,7 @@ decl_module! {
}
}
fn on_finalise() {
fn on_finalize() {
if let Some(original_authorities) = <OriginalAuthorities<T>>::take() {
let current_authorities = AuthorityStorageVec::<T::SessionKey>::items();
if current_authorities != original_authorities {
+12 -12
View File
@@ -18,7 +18,7 @@
#![cfg(test)]
use primitives::{generic, testing::{self, UintAuthorityId}, traits::OnFinalise};
use primitives::{generic, testing::{self, UintAuthorityId}, traits::OnFinalize};
use runtime_io::with_externalities;
use crate::mock::{Consensus, System, new_test_ext};
use inherents::{InherentData, ProvideInherent};
@@ -26,10 +26,10 @@ use inherents::{InherentData, ProvideInherent};
#[test]
fn authorities_change_logged() {
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]);
Consensus::on_finalise(1);
let header = System::finalise();
Consensus::on_finalize(1);
let header = System::finalize();
assert_eq!(header.digest, testing::Digest {
logs: vec![
generic::DigestItem::AuthoritiesChange(
@@ -47,9 +47,9 @@ fn authorities_change_logged() {
#[test]
fn authorities_change_is_not_logged_when_not_changed() {
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
Consensus::on_finalise(1);
let header = System::finalise();
System::initialize(&1, &Default::default(), &Default::default());
Consensus::on_finalize(1);
let header = System::finalize();
assert_eq!(header.digest, testing::Digest {
logs: vec![],
});
@@ -59,11 +59,11 @@ fn authorities_change_is_not_logged_when_not_changed() {
#[test]
fn authorities_change_is_not_logged_when_changed_back_to_original() {
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]);
Consensus::set_authorities(&[UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
Consensus::on_finalise(1);
let header = System::finalise();
Consensus::on_finalize(1);
let header = System::finalize();
assert_eq!(header.digest, testing::Digest {
logs: vec![],
});
@@ -73,7 +73,7 @@ fn authorities_change_is_not_logged_when_changed_back_to_original() {
#[test]
fn offline_report_can_be_excluded() {
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
assert!(Consensus::create_inherent(&InherentData::new()).is_none());
let offline_report: Vec<u32> = vec![0];
@@ -89,7 +89,7 @@ fn set_and_kill_storage_work() {
use srml_support::storage;
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
let item = (vec![42u8], vec![42u8]);
+1 -1
View File
@@ -44,7 +44,7 @@ pub struct CallReceipt {
/// An interface that provides access to the external environment in which the
/// smart-contract is executed.
///
/// This interface is specialised to an account of the executing code, so all
/// This interface is specialized to an account of the executing code, so all
/// operations are implicitly performed on that account.
pub trait Ext {
type T: Trait;
+35 -35
View File
@@ -15,70 +15,70 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! # Contract Module
//!
//!
//! The contract module provides functionality for the runtime to deploy and execute WebAssembly smart-contracts.
//! The supported dispatchable functions are documented as part of the [`Call`](./enum.Call.html) enum.
//!
//!
//! ## Overview
//!
//!
//! This module extends accounts (see `Balances` module) to have smart-contract functionality.
//! These "smart-contract accounts" have the ability to create smart-contracts and make calls to other contract
//! These "smart-contract accounts" have the ability to create smart-contracts and make calls to other contract
//! and non-contract accounts.
//!
//!
//! The smart-contract code is stored once in a `code_cache`, and later retrievable via its `code_hash`.
//! This means that multiple smart-contracts can be instantiated from the same `code_cache`, without replicating
//! This means that multiple smart-contracts can be instantiated from the same `code_cache`, without replicating
//! the code each time.
//!
//!
//! When a smart-contract is called, its associated code is retrieved via the code hash and gets executed.
//! This call can alter the storage entries of the smart-contract account, create new smart-contracts,
//! or call other smart-contracts.
//!
//!
//! Finally, when the `Balances` module determines an account is dead (i.e. account balance fell below the
//! existential deposit), it reaps the account. This will delete the associated code and storage of the
//! existential deposit), it reaps the account. This will delete the associated code and storage of the
//! smart-contract account.
//!
//!
//! ### Gas
//!
//!
//! Senders must specify a gas limit with every call, as all instructions invoked by the smart-contract require gas.
//! Unused gas is refunded after the call, regardless of the execution outcome.
//!
//!
//! If the gas limit is reached, then all calls and state changes (including balance transfers) are only
//! reverted at the current call's contract level. For example, if contract A calls B and B runs out of gas mid-call,
//! then all of B's calls are reverted. Assuming correct error handling by contract A, A's other calls and state
//! changes still persist.
//!
//! then all of B's calls are reverted. Assuming correct error handling by contract A, A's other calls and state
//! changes still persist.
//!
//! ### Notable Scenarios
//!
//!
//! Contract call failures are not always cascading. When failures occur in a sub-call, they do not "bubble up",
//! and the call will only revert at the specific contract level. For example, if contract A calls contract B, and B
//! fails, A can decide how to handle that failure, either proceeding or reverting A's changes.
//!
//!
//! ## Interface
//!
//!
//! ### Dispatchable functions
//!
//!
//! * `put_code` - Stores the given binary Wasm code into the chains storage and returns its `code_hash`.
//!
//! * `create` - Deploys a new contract from the given `code_hash`, optionally transferring some balance.
//!
//! * `create` - Deploys a new contract from the given `code_hash`, optionally transferring some balance.
//! This creates a new smart contract account and calls its contract deploy handler to initialize the contract.
//!
//!
//! * `call` - Makes a call to an account, optionally transferring some balance.
//!
//! ### Public functions
//!
//!
//! See the [module](./struct.Module.html) for details on publicly available functions.
//!
//!
//! ## Usage
//!
//! The contract module is a work in progress. The following examples show how this contract module can be
//!
//! The contract module is a work in progress. The following examples show how this contract module can be
//! used to create and call contracts.
//!
//! * [`pDSL`](https://github.com/Robbepop/pdsl) is a domain specific language which enables writing
//!
//! * [`pDSL`](https://github.com/Robbepop/pdsl) is a domain specific language which enables writing
//! WebAssembly based smart contracts in the Rust programming language. This is a work in progress.
//!
//!
//! ## Related Modules
//! * [`Balances`](https://crates.parity.io/srml_balances/index.html)
//!
//!
#![cfg_attr(not(feature = "std"), no_std)]
@@ -136,7 +136,7 @@ pub struct AccountInfo {
/// property (being a proper uniqueid).
pub trait TrieIdGenerator<AccountId> {
/// get a trie id for an account, using reference to parent account trie id to ensure
/// uniqueness of trie id
/// uniqueness of trie id
/// The implementation must ensure every new trie id is unique: two consecutive call with the
/// same parameter needs to return different trie id values.
fn trie_id(account_id: &AccountId) -> TrieId;
@@ -248,7 +248,7 @@ decl_module! {
Ok(())
}
/// Stores the given binary Wasm code into the chains storage and returns its `codehash`.
/// Stores the given binary Wasm code into the chains storage and returns its `codehash`.
/// You can instantiate contracts only with stored code.
fn put_code(
origin,
@@ -272,10 +272,10 @@ decl_module! {
/// Makes a call to an account, optionally transferring some balance.
///
/// * If the account is a smart-contract account, the associated code will be
/// * If the account is a smart-contract account, the associated code will be
/// executed and any value will be transferred.
/// * If the account is a regular account, any value will be transferred.
/// * If no account exists and the call value is not less than `existential_deposit`,
/// * If no account exists and the call value is not less than `existential_deposit`,
/// a regular account will be created and any value will be transferred.
fn call(
origin,
@@ -377,7 +377,7 @@ decl_module! {
result.map(|_| ())
}
fn on_finalise() {
fn on_finalize() {
<GasSpent<T>>::kill();
}
}
+19 -19
View File
@@ -242,7 +242,7 @@ decl_module! {
let candidate = T::Lookup::lookup(candidate)?;
ensure!(index == Self::vote_index(), "index not current");
let (_, _, expiring) = Self::next_finalise().ok_or("cannot present outside of presentation period")?;
let (_, _, expiring) = Self::next_finalize().ok_or("cannot present outside of presentation period")?;
let stakes = Self::snapshoted_stakes();
let voters = Self::voters();
let bad_presentation_punishment = Self::present_slash_per_voter() * BalanceOf::<T>::sa(voters.len() as u64);
@@ -303,18 +303,18 @@ decl_module! {
}
/// Set the presentation duration. If there is currently a vote being presented for, will
/// invoke `finalise_vote`.
/// invoke `finalize_vote`.
fn set_presentation_duration(#[compact] count: T::BlockNumber) {
<PresentationDuration<T>>::put(count);
}
/// Set the presentation duration. If there is current a vote being presented for, will
/// invoke `finalise_vote`.
/// invoke `finalize_vote`.
fn set_term_duration(#[compact] count: T::BlockNumber) {
<TermDuration<T>>::put(count);
}
fn on_finalise(n: T::BlockNumber) {
fn on_finalize(n: T::BlockNumber) {
if let Err(e) = Self::end_block(n) {
print("Guru meditation");
print(e);
@@ -347,7 +347,7 @@ decl_storage! {
/// Number of accounts that should be sitting on the council.
pub DesiredSeats get(desired_seats) config(): u32;
// permanent state (always relevant, changes only at the finalisation of voting)
// permanent state (always relevant, changes only at the finalization of voting)
/// The current council. When there's a vote going on, this should still be used for executive
/// matters. The block number (second element in the tuple) is the block that their position is
/// active until (calculated by the sum of the block number when the council member was elected
@@ -371,9 +371,9 @@ decl_storage! {
pub Candidates get(candidates): Vec<T::AccountId>; // has holes
pub CandidateCount get(candidate_count): u32;
// temporary state (only relevant during finalisation/presentation)
// temporary state (only relevant during finalization/presentation)
/// The accounts holding the seats that will become free on the next tally.
pub NextFinalise get(next_finalise): Option<(T::BlockNumber, u32, Vec<T::AccountId>)>;
pub NextFinalize get(next_finalize): Option<(T::BlockNumber, u32, Vec<T::AccountId>)>;
/// The stakes as they were at the point that the vote ended.
pub SnapshotedStakes get(snapshoted_stakes): Vec<BalanceOf<T>>;
/// Get the leaderboard if we;re in the presentation phase.
@@ -390,7 +390,7 @@ decl_event!(
/// A tally (for approval votes of council seat(s)) has started.
TallyStarted(u32),
/// A tally (for approval votes of council seat(s)) has ended (with one or more new members).
TallyFinalised(Vec<AccountId>, Vec<AccountId>),
TallyFinalized(Vec<AccountId>, Vec<AccountId>),
}
);
@@ -399,7 +399,7 @@ impl<T: Trait> Module<T> {
/// True if we're currently in a presentation period.
pub fn presentation_active() -> bool {
<NextFinalise<T>>::exists()
<NextFinalize<T>>::exists()
}
/// If `who` a candidate at the moment?
@@ -422,7 +422,7 @@ impl<T: Trait> Module<T> {
} else {
let c = Self::active_council();
let (next_possible, count, coming) =
if let Some((tally_end, comers, leavers)) = Self::next_finalise() {
if let Some((tally_end, comers, leavers)) = Self::next_finalize() {
// if there's a tally in progress, then next tally can begin immediately afterwards
(tally_end, c.len() - leavers.len() + comers as usize, comers)
} else {
@@ -453,9 +453,9 @@ impl<T: Trait> Module<T> {
}
}
}
if let Some((number, _, _)) = Self::next_finalise() {
if let Some((number, _, _)) = Self::next_finalize() {
if block_number == number {
Self::finalise_tally()?
Self::finalize_tally()?
}
}
Ok(())
@@ -477,13 +477,13 @@ impl<T: Trait> Module<T> {
let retaining_seats = active_council.len() - expiring.len();
if retaining_seats < desired_seats {
let empty_seats = desired_seats - retaining_seats;
<NextFinalise<T>>::put((number + Self::presentation_duration(), empty_seats as u32, expiring));
<NextFinalize<T>>::put((number + Self::presentation_duration(), empty_seats as u32, expiring));
let voters = Self::voters();
let votes = voters.iter().map(T::Currency::total_balance).collect::<Vec<_>>();
<SnapshotedStakes<T>>::put(votes);
// initialise leaderboard.
// initialize leaderboard.
let leaderboard_size = empty_seats + Self::carry_count() as usize;
<Leaderboard<T>>::put(vec![(BalanceOf::<T>::zero(), T::AccountId::default()); leaderboard_size]);
@@ -491,14 +491,14 @@ impl<T: Trait> Module<T> {
}
}
/// Finalise the vote, removing each of the `removals` and inserting `seats` of the most approved
/// Finalize the vote, removing each of the `removals` and inserting `seats` of the most approved
/// candidates in their place. If the total council members is less than the desired membership
/// a new vote is started.
/// Clears all presented candidates, returning the bond of the elected ones.
fn finalise_tally() -> Result {
fn finalize_tally() -> Result {
<SnapshotedStakes<T>>::kill();
let (_, coming, expiring): (T::BlockNumber, u32, Vec<T::AccountId>) =
<NextFinalise<T>>::take().ok_or("finalise can only be called after a tally is started.")?;
<NextFinalize<T>>::take().ok_or("finalize can only be called after a tally is started.")?;
let leaderboard: Vec<(BalanceOf<T>, T::AccountId)> = <Leaderboard<T>>::take().unwrap_or_default();
let new_expiry = <system::Module<T>>::block_number() + Self::term_duration();
@@ -548,7 +548,7 @@ impl<T: Trait> Module<T> {
new_candidates.truncate(last_index + 1);
}
Self::deposit_event(RawEvent::TallyFinalised(incoming, outgoing));
Self::deposit_event(RawEvent::TallyFinalized(incoming, outgoing));
<Candidates<T>>::put(new_candidates);
<CandidateCount<T>>::put(count);
@@ -584,7 +584,7 @@ mod tests {
assert_eq!(Council::active_council(), vec![]);
assert_eq!(Council::next_tally(), Some(4));
assert_eq!(Council::presentation_active(), false);
assert_eq!(Council::next_finalise(), None);
assert_eq!(Council::next_finalize(), None);
assert_eq!(Council::candidates(), Vec::<u64>::new());
assert_eq!(Council::is_a_candidate(&1), false);
+1 -1
View File
@@ -102,7 +102,7 @@ decl_module! {
<VotingPeriod<T>>::put(blocks);
}
fn on_finalise(n: T::BlockNumber) {
fn on_finalize(n: T::BlockNumber) {
if let Err(e) = Self::end_block(n) {
print("Guru meditation");
print(e);
+5 -5
View File
@@ -153,7 +153,7 @@ decl_module! {
Ok(())
}
fn on_finalise(n: T::BlockNumber) {
fn on_finalize(n: T::BlockNumber) {
if let Err(e) = Self::end_block(n) {
runtime_io::print(e);
}
@@ -306,7 +306,7 @@ impl<T: Trait> Module<T> {
}
/// Get the delegated voters for the current proposal.
/// I think this goes into a worker once https://github.com/paritytech/substrate/issues/1458 is done.
/// I think this goes into a worker once https://github.com/paritytech/substrate/issues/1458 is done.
fn tally_delegation(ref_index: ReferendumIndex) -> (BalanceOf<T>, BalanceOf<T>, BalanceOf<T>) {
Self::voters_for(ref_index).iter()
.fold((Zero::zero(), Zero::zero(), Zero::zero()), |(approve_acc, against_acc, capital_acc), voter| {
@@ -625,7 +625,7 @@ mod tests {
assert_eq!(Democracy::voters_for(r), vec![1]);
assert_eq!(Democracy::vote_of((r, 1)), AYE);
assert_eq!(Democracy::tally(r), (10, 0, 10));
assert_eq!(Democracy::end_block(System::block_number()), Ok(()));
assert_eq!(Balances::free_balance(&42), 2);
});
@@ -671,11 +671,11 @@ mod tests {
System::set_block_number(2);
let r = 0;
// Check behaviour with cycle.
// Check behavior with cycle.
assert_ok!(Democracy::delegate(Origin::signed(2), 1, 100));
assert_ok!(Democracy::delegate(Origin::signed(3), 2, 100));
assert_ok!(Democracy::delegate(Origin::signed(1), 3, 100));
assert_ok!(Democracy::vote(Origin::signed(1), r, AYE));
assert_eq!(Democracy::referendum_count(), 1);
@@ -37,7 +37,7 @@ pub enum VoteThreshold {
pub trait Approved<Balance> {
/// Given `approve` votes for and `against` votes against from a total electorate size of
/// `electorate` (`electorate - (approve + against)` are abstainers), then returns true if the
/// overall outcome is in favour of approval.
/// overall outcome is in favor of approval.
fn approved(&self, approve: Balance, against: Balance, voters: Balance, electorate: Balance) -> bool;
}
@@ -72,7 +72,7 @@ fn compare_rationals<T: Zero + Mul<T, Output = T> + Div<T, Output = T> + Rem<T,
impl<Balance: IntegerSquareRoot + Zero + Ord + Add<Balance, Output = Balance> + Mul<Balance, Output = Balance> + Div<Balance, Output = Balance> + Rem<Balance, Output = Balance> + Copy> Approved<Balance> for VoteThreshold {
/// Given `approve` votes for and `against` votes against from a total electorate size of
/// `electorate` of whom `voters` voted (`electorate - voters` are abstainers) then returns true if the
/// overall outcome is in favour of approval.
/// overall outcome is in favor of approval.
///
/// We assume each *voter* may cast more than one *vote*, hence `voters` is not necessarily equal to
/// `approve + against`.
+8 -8
View File
@@ -201,14 +201,14 @@ decl_module! {
<Dummy<T>>::put(new_value);
}
// The signature could also look like: `fn on_initialise()`
fn on_initialise(_n: T::BlockNumber) {
// The signature could also look like: `fn on_initialize()`
fn on_initialize(_n: T::BlockNumber) {
// Anything that needs to be done at the start of the block.
// We don't do anything here.
}
// The signature could also look like: `fn on_finalise()`
fn on_finalise(_n: T::BlockNumber) {
// The signature could also look like: `fn on_finalize()`
fn on_finalize(_n: T::BlockNumber) {
// Anything that needs to be done at the end of the block.
// We just kill our dummy storage item.
<Dummy<T>>::kill();
@@ -258,7 +258,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sr_primitives::{
BuildStorage, traits::{BlakeTwo256, OnInitialise, OnFinalise, IdentityLookup},
BuildStorage, traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup},
testing::{Digest, DigestItem, Header}
};
@@ -323,12 +323,12 @@ mod tests {
assert_ok!(Example::accumulate_dummy(Origin::signed(1), 27));
assert_eq!(Example::dummy(), Some(69));
// Check that finalising the block removes Dummy from storage.
<Example as OnFinalise<u64>>::on_finalise(1);
// Check that finalizing the block removes Dummy from storage.
<Example as OnFinalize<u64>>::on_finalize(1);
assert_eq!(Example::dummy(), None);
// Check that accumulate works when we Dummy has None in it.
<Example as OnInitialise<u64>>::on_initialise(2);
<Example as OnInitialize<u64>>::on_initialize(2);
assert_ok!(Example::accumulate_dummy(Origin::signed(1), 42));
assert_eq!(Example::dummy(), Some(42));
});
+20 -20
View File
@@ -22,8 +22,8 @@ use rstd::prelude::*;
use rstd::marker::PhantomData;
use rstd::result;
use primitives::traits::{
self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalise,
OnInitialise, Hash, As, Digest, NumberFor, Block as BlockT, OffchainWorker
self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize,
OnInitialize, Hash, As, Digest, NumberFor, Block as BlockT, OffchainWorker
};
use srml_support::{Dispatchable, traits::MakePayment};
use parity_codec::{Codec, Encode};
@@ -65,7 +65,7 @@ impl<
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
Context: Default,
Payment: MakePayment<System::AccountId>,
AllModules: OnInitialise<System::BlockNumber> + OnFinalise<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
AllModules: OnInitialize<System::BlockNumber> + OnFinalize<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
> ExecuteBlock<Block> for Executive<System, Block, Context, Payment, AllModules> where
Block::Extrinsic: Checkable<Context> + Codec,
<Block::Extrinsic as Checkable<Context>>::Checked: Applyable<Index=System::Index, AccountId=System::AccountId>,
@@ -86,7 +86,7 @@ impl<
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
Context: Default,
Payment: MakePayment<System::AccountId>,
AllModules: OnInitialise<System::BlockNumber> + OnFinalise<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
AllModules: OnInitialize<System::BlockNumber> + OnFinalize<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
> Executive<System, Block, Context, Payment, AllModules> where
Block::Extrinsic: Checkable<Context> + Codec,
<Block::Extrinsic as Checkable<Context>>::Checked: Applyable<Index=System::Index, AccountId=System::AccountId>,
@@ -94,13 +94,13 @@ impl<
<<<Block::Extrinsic as Checkable<Context>>::Checked as Applyable>::Call as Dispatchable>::Origin: From<Option<System::AccountId>>
{
/// Start the execution of a particular block.
pub fn initialise_block(header: &System::Header) {
Self::initialise_block_impl(header.number(), header.parent_hash(), header.extrinsics_root());
pub fn initialize_block(header: &System::Header) {
Self::initialize_block_impl(header.number(), header.parent_hash(), header.extrinsics_root());
}
fn initialise_block_impl(block_number: &System::BlockNumber, parent_hash: &System::Hash, extrinsics_root: &System::Hash) {
<system::Module<System>>::initialise(block_number, parent_hash, extrinsics_root);
<AllModules as OnInitialise<System::BlockNumber>>::on_initialise(*block_number);
fn initialize_block_impl(block_number: &System::BlockNumber, parent_hash: &System::Hash, extrinsics_root: &System::Hash) {
<system::Module<System>>::initialize(block_number, parent_hash, extrinsics_root);
<AllModules as OnInitialize<System::BlockNumber>>::on_initialize(*block_number);
}
fn initial_checks(block: &Block) {
@@ -121,7 +121,7 @@ impl<
/// Actually execute all transitioning for `block`.
pub fn execute_block(block: Block) {
Self::initialise_block(block.header());
Self::initialize_block(block.header());
// any initial checks
Self::initial_checks(&block);
@@ -140,7 +140,7 @@ impl<
let parent_hash = <Block::Header as Header>::Hashing::hash(b"parent_hash");
let extrinsics_root = <Block::Header as Header>::Hashing::hash(b"extrinsics_root");
Self::initialise_block_impl(&block_number, &parent_hash, &extrinsics_root);
Self::initialize_block_impl(&block_number, &parent_hash, &extrinsics_root);
// execute extrinsics
Self::execute_extrinsics_with_book_keeping(extrinsics, block_number);
@@ -152,18 +152,18 @@ impl<
// post-extrinsics book-keeping.
<system::Module<System>>::note_finished_extrinsics();
<AllModules as OnFinalise<System::BlockNumber>>::on_finalise(block_number);
<AllModules as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
}
/// Finalise the block - it is up the caller to ensure that all header fields are valid
/// Finalize the block - it is up the caller to ensure that all header fields are valid
/// except state-root.
pub fn finalise_block() -> System::Header {
pub fn finalize_block() -> System::Header {
<system::Module<System>>::note_finished_extrinsics();
<AllModules as OnFinalise<System::BlockNumber>>::on_finalise(<system::Module<System>>::block_number());
<AllModules as OnFinalize<System::BlockNumber>>::on_finalize(<system::Module<System>>::block_number());
// setup extrinsics
<system::Module<System>>::derive_extrinsics();
<system::Module<System>>::finalise()
<system::Module<System>>::finalize()
}
/// Apply extrinsic outside of the block execution function.
@@ -241,7 +241,7 @@ impl<
fn final_checks(header: &System::Header) {
// remove temporaries.
let new_header = <system::Module<System>>::finalise();
let new_header = <system::Module<System>>::finalize();
// check digest.
assert_eq!(
@@ -394,7 +394,7 @@ mod tests {
let xt = primitives::testing::TestXt(Some(1), 0, Call::transfer(2, 69));
let mut t = runtime_io::TestExternalities::<Blake2Hasher>::new(t);
with_externalities(&mut t, || {
Executive::initialise_block(&Header::new(1, H256::default(), H256::default(),
Executive::initialize_block(&Header::new(1, H256::default(), H256::default(),
[69u8; 32].into(), Digest::default()));
Executive::apply_extrinsic(xt).unwrap();
assert_eq!(<balances::Module<Runtime>>::total_balance(&1), 32);
@@ -463,7 +463,7 @@ mod tests {
let mut t = new_test_ext();
let xt = primitives::testing::TestXt(Some(1), 42, Call::transfer(33, 69));
with_externalities(&mut t, || {
Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default()));
Executive::initialize_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default()));
assert!(Executive::apply_extrinsic(xt).is_err());
assert_eq!(<system::Module<Runtime>>::extrinsic_index(), Some(0));
});
@@ -478,7 +478,7 @@ mod tests {
let encoded = xt2.encode();
let len = if should_fail { (internal::MAX_TRANSACTIONS_SIZE - 1) as usize } else { encoded.len() };
with_externalities(&mut t, || {
Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default()));
Executive::initialize_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default()));
assert_eq!(<system::Module<Runtime>>::all_extrinsics_len(), 0);
Executive::apply_extrinsic(xt).unwrap();
+8 -8
View File
@@ -126,7 +126,7 @@ decl_module! {
<Self as Store>::Update::put(hint);
}
fn on_finalise() {
fn on_finalize() {
Self::update_hint(<Self as Store>::Update::take())
}
}
@@ -262,7 +262,7 @@ mod tests {
use sr_io::{with_externalities, TestExternalities};
use substrate_primitives::H256;
use primitives::BuildStorage;
use primitives::traits::{BlakeTwo256, IdentityLookup, OnFinalise, Header as HeaderT};
use primitives::traits::{BlakeTwo256, IdentityLookup, OnFinalize, Header as HeaderT};
use primitives::testing::{Digest, DigestItem, Header};
use srml_support::impl_outer_origin;
use srml_system as system;
@@ -344,9 +344,9 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
let mut parent_hash = System::parent_hash();
for i in 2..106 {
System::initialise(&i, &parent_hash, &Default::default());
FinalityTracker::on_finalise(i);
let hdr = System::finalise();
System::initialize(&i, &parent_hash, &Default::default());
FinalityTracker::on_finalize(i);
let hdr = System::finalize();
parent_hash = hdr.hash();
}
@@ -369,13 +369,13 @@ mod tests {
with_externalities(&mut TestExternalities::new(t), || {
let mut parent_hash = System::parent_hash();
for i in 2..106 {
System::initialise(&i, &parent_hash, &Default::default());
System::initialize(&i, &parent_hash, &Default::default());
assert_ok!(FinalityTracker::dispatch(
Call::final_hint(i-1),
Origin::INHERENT,
));
FinalityTracker::on_finalise(i);
let hdr = System::finalise();
FinalityTracker::on_finalize(i);
let hdr = System::finalize();
parent_hash = hdr.hash();
}
+5 -5
View File
@@ -73,7 +73,7 @@ pub trait GrandpaChangeSignal<N> {
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
#[derive(Encode, Decode, PartialEq, Eq, Clone)]
pub enum RawLog<N, SessionKey> {
/// Authorities set change has been signalled. Contains the new set of authorities
/// Authorities set change has been signaled. Contains the new set of authorities
/// and the delay in blocks _to finalize_ before applying.
AuthoritiesChangeSignal(N, Vec<(SessionKey, u64)>),
/// A forced authorities set change. Contains in this order: the median last
@@ -185,7 +185,7 @@ decl_event!(
decl_storage! {
trait Store for Module<T: Trait> as GrandpaFinality {
// Pending change: (signalled at, scheduled change).
// Pending change: (signaled at, scheduled change).
PendingChange get(pending_change): Option<StoredPendingChange<T::BlockNumber, T::SessionKey>>;
// next block number where we can force a change.
NextForced get(next_forced): Option<T::BlockNumber>;
@@ -215,13 +215,13 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event<T>() = default;
/// Report some misbehaviour.
/// Report some misbehavior.
fn report_misbehavior(origin, _report: Vec<u8>) {
ensure_signed(origin)?;
// FIXME: https://github.com/paritytech/substrate/issues/1112
}
fn on_finalise(block_number: T::BlockNumber) {
fn on_finalize(block_number: T::BlockNumber) {
if let Some(pending_change) = <PendingChange<T>>::get() {
if block_number == pending_change.scheduled_at {
if let Some(median) = pending_change.forced {
@@ -268,7 +268,7 @@ impl<T: Trait> Module<T> {
/// indicates the median last finalized block number and it should be used
/// as the canon block when starting the new grandpa voter.
///
/// No change should be signalled while any change is pending. Returns
/// No change should be signaled while any change is pending. Returns
/// an error if a change is already pending.
pub fn schedule_change(
next_authorities: Vec<(T::SessionKey, u64)>,
+37 -37
View File
@@ -18,7 +18,7 @@
#![cfg(test)]
use primitives::{testing, traits::OnFinalise};
use primitives::{testing, traits::OnFinalize};
use primitives::traits::Header;
use runtime_io::with_externalities;
use crate::mock::{Grandpa, System, new_test_ext};
@@ -30,13 +30,13 @@ use super::*;
#[test]
fn authorities_change_logged() {
with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
Grandpa::schedule_change(vec![(4, 1), (5, 1), (6, 1)], 0, None).unwrap();
System::note_finished_extrinsics();
Grandpa::on_finalise(1);
Grandpa::on_finalize(1);
let header = System::finalise();
let header = System::finalize();
assert_eq!(header.digest, testing::Digest {
logs: vec![
RawLog::AuthoritiesChangeSignal(0, vec![(4, 1), (5, 1), (6, 1)]).into(),
@@ -55,10 +55,10 @@ fn authorities_change_logged() {
#[test]
fn authorities_change_logged_after_delay() {
with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
Grandpa::schedule_change(vec![(4, 1), (5, 1), (6, 1)], 1, None).unwrap();
Grandpa::on_finalise(1);
let header = System::finalise();
Grandpa::on_finalize(1);
let header = System::finalize();
assert_eq!(header.digest, testing::Digest {
logs: vec![
RawLog::AuthoritiesChangeSignal(1, vec![(4, 1), (5, 1), (6, 1)]).into(),
@@ -68,11 +68,11 @@ fn authorities_change_logged_after_delay() {
// no change at this height.
assert_eq!(System::events(), vec![]);
System::initialise(&2, &header.hash(), &Default::default());
System::initialize(&2, &header.hash(), &Default::default());
System::note_finished_extrinsics();
Grandpa::on_finalise(2);
Grandpa::on_finalize(2);
let _header = System::finalise();
let _header = System::finalize();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Finalization,
@@ -85,27 +85,27 @@ fn authorities_change_logged_after_delay() {
#[test]
fn cannot_schedule_change_when_one_pending() {
with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
Grandpa::schedule_change(vec![(4, 1), (5, 1), (6, 1)], 1, None).unwrap();
assert!(Grandpa::pending_change().is_some());
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err());
Grandpa::on_finalise(1);
let header = System::finalise();
Grandpa::on_finalize(1);
let header = System::finalize();
System::initialise(&2, &header.hash(), &Default::default());
System::initialize(&2, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().is_some());
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err());
Grandpa::on_finalise(2);
let header = System::finalise();
Grandpa::on_finalize(2);
let header = System::finalize();
System::initialise(&3, &header.hash(), &Default::default());
System::initialize(&3, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().is_none());
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_ok());
Grandpa::on_finalise(3);
let _header = System::finalise();
Grandpa::on_finalize(3);
let _header = System::finalize();
});
}
@@ -128,7 +128,7 @@ fn new_decodes_from_old() {
#[test]
fn dispatch_forced_change() {
with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || {
System::initialise(&1, &Default::default(), &Default::default());
System::initialize(&1, &Default::default(), &Default::default());
Grandpa::schedule_change(
vec![(4, 1), (5, 1), (6, 1)],
5,
@@ -138,60 +138,60 @@ fn dispatch_forced_change() {
assert!(Grandpa::pending_change().is_some());
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, Some(0)).is_err());
Grandpa::on_finalise(1);
let mut header = System::finalise();
Grandpa::on_finalize(1);
let mut header = System::finalize();
for i in 2..7 {
System::initialise(&i, &header.hash(), &Default::default());
System::initialize(&i, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().unwrap().forced.is_some());
assert_eq!(Grandpa::next_forced(), Some(11));
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err());
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, Some(0)).is_err());
Grandpa::on_finalise(i);
header = System::finalise();
Grandpa::on_finalize(i);
header = System::finalize();
}
// change has been applied at the end of block 6.
// add a normal change.
{
System::initialise(&7, &header.hash(), &Default::default());
System::initialize(&7, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().is_none());
assert_eq!(Grandpa::grandpa_authorities(), vec![(4, 1), (5, 1), (6, 1)]);
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_ok());
Grandpa::on_finalise(7);
header = System::finalise();
Grandpa::on_finalize(7);
header = System::finalize();
}
// run the normal change.
{
System::initialise(&8, &header.hash(), &Default::default());
System::initialize(&8, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().is_some());
assert_eq!(Grandpa::grandpa_authorities(), vec![(4, 1), (5, 1), (6, 1)]);
assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err());
Grandpa::on_finalise(8);
header = System::finalise();
Grandpa::on_finalize(8);
header = System::finalize();
}
// normal change applied. but we can't apply a new forced change for some
// time.
for i in 9..11 {
System::initialise(&i, &header.hash(), &Default::default());
System::initialize(&i, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().is_none());
assert_eq!(Grandpa::grandpa_authorities(), vec![(5, 1)]);
assert_eq!(Grandpa::next_forced(), Some(11));
assert!(Grandpa::schedule_change(vec![(5, 1), (6, 1)], 5, Some(0)).is_err());
Grandpa::on_finalise(i);
header = System::finalise();
Grandpa::on_finalize(i);
header = System::finalize();
}
{
System::initialise(&11, &header.hash(), &Default::default());
System::initialize(&11, &header.hash(), &Default::default());
assert!(Grandpa::pending_change().is_none());
assert!(Grandpa::schedule_change(vec![(5, 1), (6, 1), (7, 1)], 5, Some(0)).is_ok());
assert_eq!(Grandpa::next_forced(), Some(21));
Grandpa::on_finalise(11);
header = System::finalise();
Grandpa::on_finalize(11);
header = System::finalize();
}
let _ = header;
});
+1 -1
View File
@@ -78,7 +78,7 @@ decl_module! {
Self::apply_force_new_session(apply_rewards)
}
fn on_finalise(n: T::BlockNumber) {
fn on_finalize(n: T::BlockNumber) {
Self::check_rotate_session(n);
}
}
+3 -3
View File
@@ -414,7 +414,7 @@ decl_storage! {
/// The length of the bonding duration in blocks.
pub BondingDuration get(bonding_duration) config(): T::BlockNumber = T::BlockNumber::sa(1000);
/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're easy to initialise
/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're easy to initialize
/// and the performance hit is minimal (we expect no more than four invulnerables) and restricted to testnets.
pub Invulnerables get(invulnerables) config(): Vec<T::AccountId>;
@@ -915,7 +915,7 @@ impl<T: Trait> Module<T> {
Self::slashable_balance_of,
min_validator_count,
ElectionConfig::<BalanceOf<T>> {
equalise: false,
equalize: false,
tolerance: <BalanceOf<T>>::sa(10 as u64),
iterations: 10,
}
@@ -960,7 +960,7 @@ impl<T: Trait> Module<T> {
}
/// Call when a validator is determined to be offline. `count` is the
/// number of offences the validator has committed.
/// number of offenses the validator has committed.
///
/// NOTE: This is called with the controller (not the stash) account id.
pub fn on_offline_validator(controller: T::AccountId, count: usize) {
+13 -13
View File
@@ -26,11 +26,11 @@ use crate::{Exposure, BalanceOf, Trait, ValidatorPrefs, IndividualExposure};
/// Configure the behavior of the Phragmen election.
/// Might be deprecated.
pub struct ElectionConfig<Balance: HasCompact> {
/// Perform equalise?.
pub equalise: bool,
/// Number of equalise iterations.
/// Perform equalize?.
pub equalize: bool,
/// Number of equalize iterations.
pub iterations: usize,
/// Tolerance of max change per equalise iteration.
/// Tolerance of max change per equalize iteration.
pub tolerance: Balance,
}
@@ -48,7 +48,7 @@ pub struct Candidate<AccountId, Balance: HasCompact> {
approval_stake: Balance,
/// Flag for being elected.
elected: bool,
/// This is most often equal to `Exposure.total` but not always. Needed for [`equalise`]
/// This is most often equal to `Exposure.total` but not always. Needed for [`equalize`]
backing_stake: Balance
}
@@ -78,9 +78,9 @@ pub struct Edge<AccountId, Balance: HasCompact> {
backing_stake: Balance,
/// Index of the candidate stored in the 'candidates' vector
candidate_index: usize,
/// Index of the candidate stored in the 'elected_candidates' vector. Used only with equalise.
/// Index of the candidate stored in the 'elected_candidates' vector. Used only with equalize.
elected_idx: usize,
/// Indicates if this edge is a vote for an elected candidate. Used only with equalise.
/// Indicates if this edge is a vote for an elected candidate. Used only with equalize.
elected: bool,
}
@@ -223,10 +223,10 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
}
}
// Optionally perform equalise post-processing.
if config.equalise {
// Optionally perform equalize post-processing.
if config.equalize {
let tolerance = config.tolerance;
let equalise_iterations = config.iterations;
let equalize_iterations = config.iterations;
// Fix indexes
nominators.iter_mut().for_each(|n| {
@@ -237,10 +237,10 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
});
});
for _i in 0..equalise_iterations {
for _i in 0..equalize_iterations {
let mut max_diff = <BalanceOf<T>>::zero();
nominators.iter_mut().for_each(|mut n| {
let diff = equalise::<T>(&mut n, &mut elected_candidates, tolerance);
let diff = equalize::<T>(&mut n, &mut elected_candidates, tolerance);
if diff > max_diff {
max_diff = diff;
}
@@ -274,7 +274,7 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
Some(elected_candidates)
}
pub fn equalise<T: Trait + 'static>(
pub fn equalize<T: Trait + 'static>(
nominator: &mut Nominator<T::AccountId, BalanceOf<T>>,
elected_candidates: &mut Vec<Candidate<T::AccountId, BalanceOf<T>>>,
tolerance: BalanceOf<T>
+2 -2
View File
@@ -1525,7 +1525,7 @@ fn phragmen_election_works_example_2() {
Staking::slashable_balance_of,
min_validator_count,
ElectionConfig::<BalanceOf<Test>> {
equalise: true,
equalize: true,
tolerance: <BalanceOf<Test>>::sa(10 as u64),
iterations: 10,
}
@@ -1806,7 +1806,7 @@ fn bond_with_little_staked_value() {
#[test]
#[ignore] // Enable this once post-processing is on.
fn phragmen_linear_worse_case_equalise() {
fn phragmen_linear_worse_case_equalize() {
with_externalities(&mut ExtBuilder::default()
.nominate(false)
.validator_pool(true)
+72 -72
View File
@@ -89,7 +89,7 @@ impl<T> Parameter for T where T: Codec + Clone + Eq {}
/// corresponding to a function of the module. This enum implements Callable and thus its values
/// can be used as an extrinsic's payload.
///
/// The `on_initialise` and `on_finalise` functions are special, since it can either take no
/// The `on_initialize` and `on_finalize` functions are special, since it can either take no
/// parameters, or one parameter, which has the runtime's block number type.
///
/// ### Module with instances
@@ -147,8 +147,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{}
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -160,8 +160,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* () = default; }
{ $( $on_initialise )* }
{ $( $on_finalise )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
[ $($t)* ]
$($rest)*
@@ -172,8 +172,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{}
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -187,8 +187,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* ($( $param_name: $param ),* ) { $( $impl )* } }
{ $( $on_initialise )* }
{ $( $on_finalise )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
[ $($t)* ]
$($rest)*
@@ -199,12 +199,12 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_initialize:tt )* }
{}
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
fn on_finalise($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
fn on_finalize($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
$($rest:tt)*
) => {
$crate::decl_module!(@normalize
@@ -212,8 +212,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $deposit_event )* }
{ $( $on_initialise )* }
{ fn on_finalise( $( $param_name : $param ),* ) { $( $impl )* } }
{ $( $on_initialize )* }
{ fn on_finalize( $( $param_name : $param ),* ) { $( $impl )* } }
{ $( $offchain )* }
[ $($t)* ]
$($rest)*
@@ -225,11 +225,11 @@ macro_rules! decl_module {
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{}
{ $( $on_finalise:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
fn on_initialise($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
fn on_initialize($($param_name:ident : $param:ty),* ) { $( $impl:tt )* }
$($rest:tt)*
) => {
$crate::decl_module!(@normalize
@@ -237,8 +237,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name$(<I>, I: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $deposit_event )* }
{ fn on_initialise( $( $param_name : $param ),* ) { $( $impl )* } }
{ $( $on_finalise )* }
{ fn on_initialize( $( $param_name : $param ),* ) { $( $impl )* } }
{ $( $on_finalize )* }
{ $( $offchain )* }
[ $($t)* ]
$($rest)*
@@ -249,8 +249,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -262,8 +262,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name>
for enum $call_type where origin: $origin_type, system = $system
{ $( $deposit_event )* }
{ $( $on_initialise )* }
{ $( $on_finalise )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ fn offchain_worker( $( $param_name : $param ),* ) { $( $impl )* } }
[ $($t)* ]
$($rest)*
@@ -274,8 +274,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -289,8 +289,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $deposit_event )* }
{ $( $on_initialise )* }
{ $( $on_finalise )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
[
$($t)*
@@ -308,8 +308,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -329,8 +329,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -350,8 +350,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
$(#[doc = $doc_attr:tt])*
@@ -365,8 +365,8 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name$(<I>, $instance: $instantiable $(= $module_default_instance)?)?>
for enum $call_type where origin: $origin_type, system = $system
{ $( $deposit_event )* }
{ $( $on_initialise )* }
{ $( $on_finalise )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
[
$($t)*
@@ -384,8 +384,8 @@ macro_rules! decl_module {
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
[ $($t:tt)* ]
) => {
@@ -396,8 +396,8 @@ macro_rules! decl_module {
$($t)*
}
{ $( $deposit_event )* }
{ $( $on_initialise )* }
{ $( $on_finalise )* }
{ $( $on_initialize )* }
{ $( $on_finalize )* }
{ $( $offchain )* }
);
};
@@ -453,68 +453,68 @@ macro_rules! decl_module {
}
};
(@impl_on_initialise
(@impl_on_initialize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
fn on_initialise() { $( $impl:tt )* }
fn on_initialize() { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnInitialise<$trait_instance::BlockNumber>
$crate::runtime_primitives::traits::OnInitialize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
{
fn on_initialise(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
fn on_initialize(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
}
};
(@impl_on_initialise
(@impl_on_initialize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
fn on_initialise($param:ident : $param_ty:ty) { $( $impl:tt )* }
fn on_initialize($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnInitialise<$trait_instance::BlockNumber>
$crate::runtime_primitives::traits::OnInitialize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
{
fn on_initialise($param: $param_ty) { $( $impl )* }
fn on_initialize($param: $param_ty) { $( $impl )* }
}
};
(@impl_on_initialise
(@impl_on_initialize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnInitialise<$trait_instance::BlockNumber>
$crate::runtime_primitives::traits::OnInitialize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
{}
};
(@impl_on_finalise
(@impl_on_finalize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
fn on_finalise() { $( $impl:tt )* }
fn on_finalize() { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber>
$crate::runtime_primitives::traits::OnFinalize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
{
fn on_finalise(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
fn on_finalize(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* }
}
};
(@impl_on_finalise
(@impl_on_finalize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
fn on_finalise($param:ident : $param_ty:ty) { $( $impl:tt )* }
fn on_finalize($param:ident : $param_ty:ty) { $( $impl:tt )* }
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber>
$crate::runtime_primitives::traits::OnFinalize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
{
fn on_finalise($param: $param_ty) { $( $impl )* }
fn on_finalize($param: $param_ty) { $( $impl )* }
}
};
(@impl_on_finalise
(@impl_on_finalize
$module:ident<$trait_instance:ident: $trait_name:ident$(<I>, $instance:ident: $instantiable:path)?>;
) => {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?>
$crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber>
$crate::runtime_primitives::traits::OnFinalize<$trait_instance::BlockNumber>
for $module<$trait_instance$(, $instance)?>
{
}
@@ -630,8 +630,8 @@ macro_rules! decl_module {
)*
}
{ $( $deposit_event:tt )* }
{ $( $on_initialise:tt )* }
{ $( $on_finalise:tt )* }
{ $( $on_initialize:tt )* }
{ $( $on_finalize:tt )* }
{ $( $offchain:tt )* }
) => {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
@@ -650,15 +650,15 @@ macro_rules! decl_module {
pub struct $mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable $( = $module_default_instance)?)?>(::core::marker::PhantomData<($trait_instance $(, $instance)?)>);
$crate::decl_module! {
@impl_on_initialise
@impl_on_initialize
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
$( $on_initialise )*
$( $on_initialize )*
}
$crate::decl_module! {
@impl_on_finalise
@impl_on_finalize
$mod_type<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?>;
$( $on_finalise )*
$( $on_finalize )*
}
$crate::decl_module! {
@@ -1143,7 +1143,7 @@ macro_rules! __function_to_metadata {
#[allow(dead_code)]
mod tests {
use super::*;
use crate::runtime_primitives::traits::{OnInitialise, OnFinalise};
use crate::runtime_primitives::traits::{OnInitialize, OnFinalize};
pub trait Trait {
type Origin;
@@ -1167,8 +1167,8 @@ mod tests {
fn aux_3() -> Result { unreachable!() }
fn aux_4(_data: i32) -> Result { unreachable!() }
fn on_initialise(n: T::BlockNumber) { if n.into() == 42 { panic!("on_initialise") } }
fn on_finalise(n: T::BlockNumber) { if n.into() == 42 { panic!("on_finalise") } }
fn on_initialize(n: T::BlockNumber) { if n.into() == 42 { panic!("on_initialize") } }
fn on_finalize(n: T::BlockNumber) { if n.into() == 42 { panic!("on_finalize") } }
fn offchain_worker() {}
}
}
@@ -1243,14 +1243,14 @@ mod tests {
}
#[test]
#[should_panic(expected = "on_initialise")]
fn on_initialise_should_work() {
<Module<TraitImpl> as OnInitialise<u32>>::on_initialise(42);
#[should_panic(expected = "on_initialize")]
fn on_initialize_should_work() {
<Module<TraitImpl> as OnInitialize<u32>>::on_initialize(42);
}
#[test]
#[should_panic(expected = "on_finalise")]
fn on_finalise_should_work() {
<Module<TraitImpl> as OnFinalise<u32>>::on_finalise(42);
#[should_panic(expected = "on_finalize")]
fn on_finalize_should_work() {
<Module<TraitImpl> as OnFinalize<u32>>::on_finalize(42);
}
}
+2 -2
View File
@@ -193,7 +193,7 @@ mod tests {
#[test]
fn linked_map_basic_insert_remove_should_work() {
with_externalities(&mut new_test_ext(), || {
// initialised during genesis
// initialized during genesis
assert_eq!(Map::get(&15u32), 42u64);
// get / insert / take
@@ -272,7 +272,7 @@ mod tests {
fn double_map_basic_insert_remove_remove_prefix_should_work() {
with_externalities(&mut new_test_ext(), || {
type DoubleMap = DataDM<Test>;
// initialised during genesis
// initialized during genesis
assert_eq!(DoubleMap::get(&15u32, &16u32), 42u64);
// get / insert / take
@@ -227,7 +227,7 @@ pub trait EnumerableStorageMap<K: codec::Codec, V: codec::Codec>: StorageMap<K,
fn enumerate<'a, S: Storage>(storage: &'a S) -> Box<dyn Iterator<Item = (K, V)> + 'a> where K: 'a, V: 'a;
}
// FIXME #1466 Remove this in favour of `decl_storage` macro.
// FIXME #1466 Remove this in favor of `decl_storage` macro.
/// Declares strongly-typed wrappers around codec-compatible types in storage.
#[macro_export]
macro_rules! storage_items {
+9 -9
View File
@@ -380,7 +380,7 @@ impl<T: Trait> Module<T> {
}
/// Start the execution of a particular block.
pub fn initialise(number: &T::BlockNumber, parent_hash: &T::Hash, txs_root: &T::Hash) {
pub fn initialize(number: &T::BlockNumber, parent_hash: &T::Hash, txs_root: &T::Hash) {
// populate environment.
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32);
<Number<T>>::put(number);
@@ -392,7 +392,7 @@ impl<T: Trait> Module<T> {
}
/// Remove temporary "environment" entries in storage.
pub fn finalise() -> T::Header {
pub fn finalize() -> T::Header {
<RandomSeed<T>>::kill();
<ExtrinsicCount<T>>::kill();
<AllExtrinsicsLen<T>>::kill();
@@ -448,7 +448,7 @@ impl<T: Trait> Module<T> {
}
/// Set the block number to something in particular. Can be used as an alternative to
/// `initialise` for tests that don't need to bother with the other environment entries.
/// `initialize` for tests that don't need to bother with the other environment entries.
#[cfg(any(feature = "std", test))]
pub fn set_block_number(n: T::BlockNumber) {
<Number<T>>::put(n);
@@ -461,14 +461,14 @@ impl<T: Trait> Module<T> {
}
/// Set the parent hash number to something in particular. Can be used as an alternative to
/// `initialise` for tests that don't need to bother with the other environment entries.
/// `initialize` for tests that don't need to bother with the other environment entries.
#[cfg(any(feature = "std", test))]
pub fn set_parent_hash(n: T::Hash) {
<ParentHash<T>>::put(n);
}
/// Set the random seed to something in particular. Can be used as an alternative to
/// `initialise` for tests that don't need to bother with the other environment entries.
/// `initialize` for tests that don't need to bother with the other environment entries.
#[cfg(any(feature = "std", test))]
pub fn set_random_seed(seed: T::Hash) {
<RandomSeed<T>>::put(seed);
@@ -595,19 +595,19 @@ mod tests {
#[test]
fn deposit_event_should_work() {
with_externalities(&mut new_test_ext(), || {
System::initialise(&1, &[0u8; 32].into(), &[0u8; 32].into());
System::initialize(&1, &[0u8; 32].into(), &[0u8; 32].into());
System::note_finished_extrinsics();
System::deposit_event(1u16);
System::finalise();
System::finalize();
assert_eq!(System::events(), vec![EventRecord { phase: Phase::Finalization, event: 1u16 }]);
System::initialise(&2, &[0u8; 32].into(), &[0u8; 32].into());
System::initialize(&2, &[0u8; 32].into(), &[0u8; 32].into());
System::deposit_event(42u16);
System::note_applied_extrinsic(&Ok(()), 0);
System::note_applied_extrinsic(&Err(""), 0);
System::note_finished_extrinsics();
System::deposit_event(3u16);
System::finalise();
System::finalize();
assert_eq!(System::events(), vec![
EventRecord { phase: Phase::ApplyExtrinsic(0), event: 42u16 },
EventRecord { phase: Phase::ApplyExtrinsic(0), event: 100u16 },
+2 -2
View File
@@ -229,7 +229,7 @@ decl_module! {
// Manage upgrade. Remove after all networks upgraded.
// TODO: #2133
fn on_initialise() {
fn on_initialize() {
if let Some(period) = <BlockPeriod<T>>::take() {
if !<MinimumPeriod<T>>::exists() {
<MinimumPeriod<T>>::put(period)
@@ -237,7 +237,7 @@ decl_module! {
}
}
fn on_finalise() {
fn on_finalize() {
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");
}
}
+8 -8
View File
@@ -117,7 +117,7 @@ decl_module! {
<Approvals<T>>::mutate(|v| v.push(proposal_id));
}
fn on_finalise(n: T::BlockNumber) {
fn on_finalize(n: T::BlockNumber) {
// Check to see if we should spend some funds!
if (n % Self::spend_period()).is_zero() {
Self::spend_funds();
@@ -264,7 +264,7 @@ mod tests {
use srml_support::{impl_outer_origin, assert_ok, assert_noop};
use substrate_primitives::{H256, Blake2Hasher};
use runtime_primitives::BuildStorage;
use runtime_primitives::traits::{BlakeTwo256, OnFinalise, IdentityLookup};
use runtime_primitives::traits::{BlakeTwo256, OnFinalize, IdentityLookup};
use runtime_primitives::testing::{Digest, DigestItem, Header};
impl_outer_origin! {
@@ -380,7 +380,7 @@ mod tests {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(1);
<Treasury as OnFinalize<u64>>::on_finalize(1);
assert_eq!(Balances::free_balance(&3), 0);
assert_eq!(Treasury::pot(), 100);
});
@@ -391,7 +391,7 @@ mod tests {
with_externalities(&mut new_test_ext(), || {
Treasury::on_dilution(100, 100);
<Treasury as OnFinalise<u64>>::on_finalise(2);
<Treasury as OnFinalize<u64>>::on_finalize(2);
assert_eq!(Treasury::pot(), 50);
});
}
@@ -404,7 +404,7 @@ mod tests {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(2);
<Treasury as OnFinalize<u64>>::on_finalize(2);
assert_eq!(Balances::free_balance(&3), 0);
assert_eq!(Treasury::pot(), 50);
});
@@ -454,7 +454,7 @@ mod tests {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(2);
<Treasury as OnFinalize<u64>>::on_finalize(2);
assert_eq!(Balances::free_balance(&3), 100);
assert_eq!(Treasury::pot(), 0);
});
@@ -468,11 +468,11 @@ mod tests {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3));
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
<Treasury as OnFinalise<u64>>::on_finalise(2);
<Treasury as OnFinalize<u64>>::on_finalize(2);
assert_eq!(Treasury::pot(), 100);
Treasury::on_dilution(100, 100);
<Treasury as OnFinalise<u64>>::on_finalise(4);
<Treasury as OnFinalize<u64>>::on_finalize(4);
assert_eq!(Balances::free_balance(&3), 150);
assert_eq!(Treasury::pot(), 25);
});