Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Modularised dispatch #95

Merged
merged 17 commits into from
Mar 19, 2018
Merged

Modularised dispatch #95

merged 17 commits into from
Mar 19, 2018

Conversation

gavofyork
Copy link
Member

@gavofyork gavofyork commented Mar 13, 2018

#91 and #92 and more.

@gavofyork gavofyork added the A3-in_progress Pull request is in progress. No review needed at this stage. label Mar 13, 2018
@gavofyork gavofyork changed the title Gav dispatch Modularised dispatch Mar 13, 2018
@gavofyork gavofyork added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Mar 14, 2018
= $id:expr ;
)*
) => {
pub mod $mod_name {
Copy link
Contributor

Choose a reason for hiding this comment

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

could put all the warnings to silence on here

Copy link
Member Author

Choose a reason for hiding this comment

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

what's the best way of doing that? is there a #[allow(*)]?

Copy link
Contributor

Choose a reason for hiding this comment

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

i mean the warnings can be blocked at a module level so they don't need to be silenced per struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

isn't it better to keep them focussed? suppressing at module level might let accidental errors get through.

fn from_u8(value: u8) -> Option<Id> {
use self::*;
let functions = [
$( Id::$fn_name ),*
Copy link
Contributor

Choose a reason for hiding this comment

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

why not generate a match statement?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed (not intentional - just was adapting existing code)

@@ -42,12 +44,17 @@ pub fn block_hash(number: BlockNumber) -> Hash {
storage::get_or_default(&number.to_keyed_vec(BLOCK_HASH_AT))
}

pub mod privileged {
use super::*;
pub struct PrivPass;
Copy link
Contributor

Choose a reason for hiding this comment

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

docs

Copy link
Contributor

Choose a reason for hiding this comment

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

also this could be a little harder to create PrivPass.x() doesn't guard anything that x() itself doesn't.

@@ -22,6 +22,8 @@ use codec::KeyedVec;
use runtime_support::{storage, StorageVec};
use demo_primitives::{AccountId, SessionKey, BlockNumber};
use runtime::{system, staking, consensus};
use runtime::system::PrivPass;
use runtime::staking::PublicPass;
Copy link
Contributor

@rphmeier rphmeier Mar 18, 2018

Choose a reason for hiding this comment

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

these should really reside in the same module where all passes are defined

Copy link
Member Author

Choose a reason for hiding this comment

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

they now both reside in the only module that is able to actually create them.

};

println!("TX: {}", HexDisplay::from(&tx.transaction.encode()));
Copy link
Contributor

Choose a reason for hiding this comment

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

stray println

@@ -151,72 +184,92 @@ pub fn next_free_ref_index() -> ReferendumIndex {
storage::get_or_default(REFERENDUM_COUNT)
}

pub mod public {
use super::*;
pub type BoxedProposal = Box<Proposal>;
Copy link
Contributor

Choose a reason for hiding this comment

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

unused

use super::*;
impl_dispatch! {
pub mod privileged;
fn start_referendum(proposal: Box<Proposal>, vote_threshold: VoteThreshold) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this accept a Box?

Copy link
Member Author

Choose a reason for hiding this comment

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

because it's inside impl_dispatch so it needs to be pass-by-value (since the same types will be used in the enum item prototypes).

Copy link
Contributor

@rphmeier rphmeier Mar 19, 2018

Choose a reason for hiding this comment

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

just to clarify: there can be a referendum to dispatch any kind of private-only call from any module? (which we've renamed to Proposal within this module -- I found that confusing)

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, though it's not "private-only", it's "privileged-only".


impl_dispatch! {
pub mod public;
fn propose(proposal: Box<Proposal>, value: Balance) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

and this?

Copy link
Member Author

Choose a reason for hiding this comment

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

same.

pub enum Call {
$(
#[allow(non_camel_case_types)]
$camelcase ( $crate::runtime::$sub_name::$path::Call )
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a little non-general. If we want this to be reusable for other runtimes we shouldn't make any assumptions about module structure.

}

impl $crate::dispatch::Slicable for Call {
fn decode<I: $crate::dispatch::Input>(input: &mut I) -> Option<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

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

likewise here

}

fn encode(&self) -> Vec<u8> {
let mut v = $crate::dispatch::Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

council_vote::privileged::set_voting_period(a),
use runtime::{staking, system};
pub use rstd::prelude::Vec;
pub use codec::{Slicable, Input, NonTrivialSlicable};
Copy link
Contributor

Choose a reason for hiding this comment

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

re-exports in a random module worry me.

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's for the macro.

Copy link
Contributor

@rphmeier rphmeier Mar 19, 2018

Choose a reason for hiding this comment

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

i understand that, but it's still bad style -- re-exports should at the very least be #[doc(hidden)] and preferably in the crate root (ideally, the macro is in its own crate and we can reuse it)

@@ -33,48 +36,12 @@ extern crate demo_primitives;

extern crate integer_sqrt;

#[macro_use] pub mod dispatch;
Copy link
Contributor

Choose a reason for hiding this comment

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

the macros from dispatch aren't used outside of it as far as I can see

Copy link
Member Author

Choose a reason for hiding this comment

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

impl_dispatch is.

use runtime::staking::{PublicPass, Balance};

/// A token for privileged dispatch. Can only be created in this module.
pub struct PrivPass;
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct can be created anywhere. It would need a private field to prevent creation in other modules.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed...

@@ -188,15 +194,15 @@ mod tests {
Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap();

runtime_io::with_externalities(&mut t, || {
assert_eq!(balance(&Alice), 42);
assert_eq!(balance(&Alice), 41);
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering why have these changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

there's a transaction fee now.

pub use codec::{Slicable, Input, NonTrivialSlicable};

#[macro_export]
macro_rules! impl_dispatch {
Copy link
Contributor

Choose a reason for hiding this comment

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

docs

@rphmeier rphmeier added A8-looksgood and removed A0-please_review Pull request needs code review. labels Mar 19, 2018
@gavofyork gavofyork merged commit 7443c0a into master Mar 19, 2018
@gavofyork gavofyork deleted the gav-dispatch branch March 19, 2018 02:51
JoshOrndorff added a commit to moonbeam-foundation/substrate that referenced this pull request Apr 21, 2021
liuchengxu pushed a commit to chainx-org/substrate that referenced this pull request Aug 23, 2021
wasm successful
pending has not remove {:?} debug trait
liuchengxu pushed a commit to autonomys/substrate that referenced this pull request Jun 3, 2022
…depth-requirement

Increase confirmation depth requirement to 100 blocks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants