') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Make Polkadot use the Substrate traity libraries by gavofyork · Pull Request #105 · paritytech/substrate · GitHub
Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Make Polkadot use the Substrate traity libraries - #105

Merged
rphmeier merged 21 commits into
masterfrom
gav-merge-runtime
Apr 5, 2018
Merged

Make Polkadot use the Substrate traity libraries#105
rphmeier merged 21 commits into
masterfrom
gav-merge-runtime

Conversation

@gavofyork

Copy link
Copy Markdown
Member

No description provided.

@gavofyorkgavofyork 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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
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.

Comment threadpolkadot/runtime/src/lib.rs Outdated
}
}

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

@rphmeierrphmeierApr 4, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
MemberAuthor

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
Copy Markdown
Contributor

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

@gavofyork

Copy link
Copy Markdown
MemberAuthor

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

@gavofyork

Copy link
Copy Markdown
MemberAuthor

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

#[derive(Eq, PartialEq, Clone)]
#[derive(Eq, PartialEq, Clone, Default)]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
pub struct Ed25519Signature(H512);

Copy link
Copy Markdown
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

@gavofyorkgavofyorkApr 5, 2018

Copy link
Copy Markdown
MemberAuthor

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.)

@rphmeierrphmeierApr 5, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

@gavofyorkgavofyorkApr 5, 2018

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment threadpolkadot/transaction-pool/src/lib.rs Outdated
if unchecked.extrinsics[0].is_signed() {
return Err(unchecked);
}
if let Call::Timestamp(TimestampCall::set(_)) = unchecked.extrinsics[0].extrinsic.function {} else {

Copy link
Copy Markdown
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

ifletCall::Timestamp(...) = ...{Ok(...)}else{Err(...)}

Copy link
Copy Markdown
MemberAuthor

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.

@rphmeierrphmeierApr 5, 2018

Copy link
Copy Markdown
Contributor

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.

Comment threadpolkadot/transaction-pool/src/lib.rs Outdated

/// 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 {

@rphmeierrphmeierApr 5, 2018

Copy link
Copy Markdown
Contributor

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)

Comment threadpolkadot/transaction-pool/src/lib.rs Outdated
if let Call::Timestamp(TimestampCall::set(t)) = self.0.extrinsics[0].extrinsic.function {
t
} else {
unreachable!();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

definitely not unreachable

Comment threadpolkadot/runtime/src/parachains.rs Outdated
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
Copy Markdown
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

@rphmeierrphmeier added A8-looksgood and removed A0-please_review Pull request needs code review. labels Apr 5, 2018
@rphmeier
rphmeier merged commit ef9a426 into masterApr 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 freeto 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

@gavofyork@rphmeier