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

Make Polkadot use the Substrate traity libraries #105

Merged
merged 21 commits into from
Apr 5, 2018
Merged

Conversation

gavofyork
Copy link
Member

No description provided.

@gavofyork gavofyork added A3-in_progress Pull request is in progress. No review needed at this stage. 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 Apr 2, 2018
pub fn signature(&self) -> &Signature {
&self.0.signature
}
mod tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe reinstate these

Copy link
Member Author

Choose a reason for hiding this comment

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

meh - they're just serialisation tests; not sure they really belong here (i.e. rather than in generic) but didn't want to throw away the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

some of the tests are for things like transactions coming after timestamp, etc. I would prefer to remove anything rather than comment it out because it's in the git history anyway.

}
}

pub type Header = generic::Header<BlockNumber, Hash, Vec<u8>>;
Copy link
Contributor

@rphmeier rphmeier Apr 4, 2018

Choose a reason for hiding this comment

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

seems like changes from the end of the last PR were lost (docs and presumably all the other small cleanups)

Copy link
Member Author

Choose a reason for hiding this comment

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

may have got clobbered. my god i hate that git can't support merging squashed commits.

@rphmeier
Copy link
Contributor

rphmeier commented Apr 4, 2018

All the other changes in the recent cleanup commits were lost as well -- maybe they can be replayed on top.

@gavofyork
Copy link
Member Author

those were not lost - they were never there. i had previously split out the runtime.

@gavofyork
Copy link
Member Author

(i already replayed them - they're already in there)

@@ -35,7 +35,7 @@ pub trait Verify {
}

/// Ed25519 signature verify.
#[derive(Eq, PartialEq, Clone)]
#[derive(Eq, PartialEq, Clone, Default)]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
pub struct Ed25519Signature(H512);
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't a trait, and makes the type alias Signature which references this confusing

Copy link
Member Author

@gavofyork gavofyork Apr 5, 2018

Choose a reason for hiding this comment

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

it's not meant to be a trait. not sure which usage of Signature you mean, but if it's in a more general context than ed25519 or Polkadot than it should be removed in favour of this. (i would note that it's perfectly reasonable for polkadot::Signature to mean Ed25519Signature.)

Copy link
Contributor

@rphmeier rphmeier Apr 5, 2018

Choose a reason for hiding this comment

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

I mean that it's in the traits module and type polkadot::Signature = traits::Ed25519Signature is misleading.

fn is_empty(&self) -> bool;
}

impl<T: Default + PartialEq> MaybeEmpty for T {
Copy link
Contributor

Choose a reason for hiding this comment

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

this blanket impl is overbroad. The Default trait doesn't imply emptiness at all. Are there some types in particular we want this for?

Copy link
Member Author

@gavofyork gavofyork Apr 5, 2018

Choose a reason for hiding this comment

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

yes - specifically for PublicAux, for which AccountId is used in production environments (but tests use u64 hence this generalisation). it should eventually be refactored (as i note somewhere near) so that it's actually only implemented for Option<AccountId> and u64, but for now, it gets the job done without requiring substantial changes in how PublicAux is dispatched

Copy link
Contributor

Choose a reason for hiding this comment

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

if unchecked.extrinsics[0].is_signed() {
return Err(unchecked);
}
if let Call::Timestamp(TimestampCall::set(_)) = unchecked.extrinsics[0].extrinsic.function {} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

could rewrite this as

if let Call::Timestamp(...) = ... { 
    Ok(...) 
} else { 
    Err(...)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

would work right now, but not in general since we'd expect more validity tests to be added here.

Copy link
Contributor

@rphmeier rphmeier Apr 5, 2018

Choose a reason for hiding this comment

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

that's fine. the if let X {} else { ... } is unidiomatic so I'd prefer a match statement.


/// Create a new block, skipping any high-level well-formedness checks. WARNING: This could
/// result in internal functions panicking if the block is, in fact, not well-formed.
pub fn force_from(known_good: Block) -> Self {
Copy link
Contributor

@rphmeier rphmeier Apr 5, 2018

Choose a reason for hiding this comment

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

the main problem with this is that the errors occur in such a way that it's difficult to track down the point at which the programmer error was actually made.

We're changing types like HeaderView which are supposed to take only trusted data in Parity-Ethereum to solve a similar problem by having the function take the file name and line number and having the view carry those around to incorporate in panic messages, so we get the cause instead of just the symptom. We also provide a macro which invokes this constructor using the file!() and line!() macros internally.

I would be in support of a similar change being done here (it only adds a pointer and u32 to the size of the structure)

if let Call::Timestamp(TimestampCall::set(t)) = self.0.extrinsics[0].extrinsic.function {
t
} else {
unreachable!();
Copy link
Contributor

Choose a reason for hiding this comment

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

definitely not unreachable

let mut roles_gua = roles_val.clone();

let h = <system::Module<T>>::random_seed();
let mut seed = Vec::<u8>::new().and(&h).and(b"validator_role_pairs").blake2_256();
Copy link
Contributor

Choose a reason for hiding this comment

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

h.to_vec().and(...) seems cleaner

@rphmeier rphmeier added A8-looksgood and removed A0-please_review Pull request needs code review. labels Apr 5, 2018
@rphmeier rphmeier merged commit ef9a426 into master Apr 5, 2018
@rphmeier rphmeier deleted the gav-merge-runtime branch April 5, 2018 15:13
lamafab pushed a commit to lamafab/substrate that referenced this pull request Jun 16, 2020
JoshOrndorff pushed 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
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
* Update to substrate alpha.7

* Remove gas limit from contracts put code

* Rename SystemEvent::ReapedAccount to KilledAccount

* Log debug event received before attempting to decode

* Temporary registration of Balance type before paritytech#102 merged

* Show contract test errors, increase instantiate gas_limit
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.

2 participants