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

Runtime safety and style tweaks#44

Merged
gavofyork merged 5 commits intomasterfrom
runtime-tweaks
Jan 23, 2018
Merged

Runtime safety and style tweaks#44
gavofyork merged 5 commits intomasterfrom
runtime-tweaks

Conversation

@rphmeier
Copy link
Contributor

No description provided.

@rphmeier rphmeier added the A0-please_review Pull request needs code review. label Jan 23, 2018
@rphmeier rphmeier requested a review from gavofyork January 23, 2018 16:22
impl<T: Copy + EndianSensitive + 'static> Slicable for T {
fn set_as_slice<F: FnOnce(&mut [u8]) -> bool>(fill_slice: F) -> Option<Self> {
let size = mem::size_of::<T>();
let mut result: T = unsafe { mem::zeroed() };
Copy link
Member

Choose a reason for hiding this comment

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

why is this better? it's obvious that it'll be written to; looks like it's just an invitation for the compiler's optimiser to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reading from zeroed memory is allowed. reading from uninitialized memory is undefined behavior. "reading" in this case includes writing without using ptr::write, which the fill_slice closure is probably expected to do.

Copy link
Member

Choose a reason for hiding this comment

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

well, at least it'll likely be in L0 cache when the zeroes are being overwritten with the real data.

//! Conensus module for runtime; manages the authority set ready for the native code.

use runtime_support::Vec;
use runtime_support::vec::Vec;
Copy link
Member

Choose a reason for hiding this comment

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

why not use runtime_support::prelude::*;?

//! consensus module.

use runtime_support::Vec;
use runtime_support::vec::Vec;
Copy link
Member

Choose a reason for hiding this comment

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

same

//! Staking manager: Handles balances and periodically determines the best set of validators.

use runtime_support::Vec;
use runtime_support::vec::Vec;
Copy link
Member

Choose a reason for hiding this comment

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

same

use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder, Hashable};
use runtime_support::{Vec, swap};
use runtime_support::mem;
use runtime_support::vec::Vec;
Copy link
Member

Choose a reason for hiding this comment

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

same

//! Primitive types.

use runtime_support::Vec;
use runtime_support::vec::Vec;
Copy link
Member

Choose a reason for hiding this comment

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

same

pub fn kill(key: &[u8]) { runtime_support::set_storage(&twox_128(key)[..], b""); }

impl<T: Default + Sized + EndianSensitive> Storable for T {
impl<T: Default + Copy + EndianSensitive + 'static> Storable for T {
Copy link
Member

Choose a reason for hiding this comment

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

why not add to EndianSensitive directly?

@gavofyork
Copy link
Member

some comments.

@gavofyork gavofyork closed this Jan 23, 2018
@gavofyork gavofyork reopened this Jan 23, 2018
@gavofyork gavofyork merged commit 01fcf2e into master Jan 23, 2018
@gavofyork gavofyork deleted the runtime-tweaks branch January 23, 2018 19:46
JoshOrndorff referenced this pull request in moonbeam-foundation/substrate Apr 21, 2021
Add command line arguments for logs limit
iStrike7 referenced this pull request in gasp-xyz/substrate Aug 3, 2021
Co-authored-by: Dan Forbes <dan@danforbes.dev>
iStrike7 referenced this pull request in gasp-xyz/substrate Aug 3, 2021
…ests_trello_91

Feature/enable outdated tests trello 91
liuchengxu pushed a commit to chainx-org/substrate that referenced this pull request Aug 23, 2021
imstar15 pushed a commit to imstar15/substrate that referenced this pull request Jan 3, 2023
…evert-consider-hooks-and-runtime-upgrade-when-constructing-block

Revert "dummy commit for revert-consider-hooks-and-runtime-upgrade-when-const…"
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
- Use thiserror instead of derive_more
- Format code
- Fix clippy warnings
- Add LICENSE_TEMPLATE

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants