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

Use parameter_types instead of thread_local for test-setup #12036

Merged
merged 38 commits into from
Sep 8, 2022

Conversation

tifecool
Copy link
Contributor

@tifecool tifecool commented Aug 15, 2022

PR for: #12020

WIP

Fixes: #12020
might close: #10479

polkadot address: 1s51dYXziQwTnSnModErKfra3TeEsVipqzY846CLCTEXtHJ

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1746777

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1746778

@tifecool tifecool changed the title Edit to Assets. parameter_types Use parameter_types instead of thread_local for test-setup Aug 15, 2022
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1746999

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1746998

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Good direction, but:

  1. naming needs fixing
  2. Please add https://github.com/paritytech/substrate/pull/12002/files#diff-31d6476b566f793c17f32f9fdefeb487988af58c61ba752d0275b91f6c8aaccaR433 to your PR and use it instead of :get and :set when appropriate

Co-authored-by: Kian Paimani <[email protected]>
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1748220

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1748335

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - cargo-check-benches
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1748405

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1750233

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1750594

frame/aura/src/mock.rs Outdated Show resolved Hide resolved
@tifecool tifecool requested a review from athei as a code owner August 17, 2022 21:59
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1754151

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1754150

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
The job name - test-linux-stable
The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1754152

@@ -96,7 +97,8 @@ fn should_report_offline_validators() {
advance_session();

// then
let offences = OFFENCES.with(|l| l.replace(vec![]));
let offences = OFFENCES::get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not applied yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it.

Comment on lines 79 to 80
let offences = OFFENCES::get();
OFFENCES::mutate(|l| l.clear());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let offences = OFFENCES::get();
OFFENCES::mutate(|l| l.clear());
let offences = Offences::take();

pub static ON_OFFENCE_PERBILL: RefCell<Vec<Perbill>> = RefCell::new(Default::default());
pub static OFFENCE_WEIGHT: RefCell<Weight> = RefCell::new(Default::default());
parameter_types! {
pub static OnOffencePerBill: Vec<Perbill> = Default::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub static OnOffencePerBill: Vec<Perbill> = Default::default();
pub static OnOffencePerbill: Vec<Perbill> = Default::default();

@@ -58,16 +57,16 @@ impl<Reporter, Offender> offence::OnOffenceHandler<Reporter, Offender, Weight>
_offence_session: SessionIndex,
_disable_strategy: DisableStrategy,
) -> Weight {
ON_OFFENCE_PERBILL.with(|f| {
*f.borrow_mut() = slash_fraction.to_vec();
OnOffencePerBill::mutate(|f| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OnOffencePerBill::mutate(|f| {
OnOffencePerbill::mutate(|f| {

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

LGTM modulo some last nits, please make sure all open comments are addressed.

@kianenigma
Copy link
Contributor

/tip large

@substrate-tip-bot
Copy link

@kianenigma A large tip was successfully submitted for tifecool (1s51dYXziQwTnSnModErKfra3TeEsVipqzY846CLCTEXtHJ on polkadot).

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/treasury/tips

@tifecool
Copy link
Contributor Author

Wow. Really appreciate the tip! Will round up immediately ❤️

frame/support/src/lib.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Sep 2, 2022

@tifecool please merge master

@tifecool
Copy link
Contributor Author

tifecool commented Sep 5, 2022

@athei please review

@kianenigma
Copy link
Contributor

kianenigma commented Sep 6, 2022

The ::take seem to have caused some issues in Polkadot.

Let's do @bkchr's suggestion in #12036 (comment) and use $value, not Default.

Please document this in the ::take() function! it is a bit of strange behavior.

@tifecool
Copy link
Contributor Author

tifecool commented Sep 7, 2022

Let's do @bkchr's suggestion in #12036 (comment) and use $value, not Default.

Ok, let me try.

#[derive(Default)]
struct MockLoader {
#[derive(Default, Clone)]
pub struct MockLoader {
Copy link
Member

Choose a reason for hiding this comment

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

Why does it need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parameter_types requires it

#[derive(Default, Debug, PartialEq, Eq)]
struct TestExt {
#[derive(Default, Debug, PartialEq, Eq, Clone)]
pub struct TestExt {
Copy link
Member

Choose a reason for hiding this comment

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

Why does it need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parameter_types requires it

@kianenigma
Copy link
Contributor

Are we sure this closes #10479 too?

frame/support/src/lib.rs Outdated Show resolved Hide resolved
@kianenigma
Copy link
Contributor

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@athei
Copy link
Member

athei commented Sep 8, 2022

Are we sure this closes #10479 too?

It still uses thread local under the hood. So I don't think so.

@paritytech-processbot paritytech-processbot bot merged commit 0478535 into paritytech:master Sep 8, 2022
@tifecool tifecool deleted the fix12020 branch September 8, 2022 15:56
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…h#12036)

* Edit to Assets. parameter_types

* fixes

* Test Fixes. WIP

* Edits to pallet-aura

* Camel Case

Co-authored-by: Kian Paimani <[email protected]>

* Implementation of mutate fn

* update to pallet-aura

* Update to frame-system. Fixes

* Update to frame-support-test. CamelCases

* Updates to frame- contracts, offences, staking, bounties, child bounties

* Edit to mutate fn. Changes to frame-contracts. CamelCase pallet-aura

* Edits to frame-contracts & executive

* cargo +nightly fmt

* unused import removed

* unused import removed

* cargo +nightly fmt

* minor adjustment

* updates

* updates

* cargo +nightly fmt

* cargo +nightly fmt

* take fn implemented

* update

* update

* Fixes to CallFilter

* cargo +nightly fmt

* final fixes

* Default changed to $value

* Update frame/support/src/lib.rs

Co-authored-by: Kian Paimani <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Use parameter_types instead of thread_local for test-setup Tests fail with --test-threads 1
6 participants