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

Commit a2ced89

Browse files
authoredAug 29, 2018
Avoid need for ident strings in storage (#624)
* Remove need for ident strings for storage items * Fixes * Fix tests * Minor change to macro grammer
1 parent 770e565 commit a2ced89

File tree

17 files changed

+606
-597
lines changed

17 files changed

+606
-597
lines changed
 

‎demo/executor/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ mod tests {
257257
// Blake
258258
// hex!("3437bf4b182ab17bb322af5c67e55f6be487a77084ad2b4e27ddac7242e4ad21").into(),
259259
// Keccak
260-
hex!("56c9a542e48ccf4e0821de301ea4384e87425604278b12a9db31c6d4e89ca51e").into(),
260+
hex!("0b401681b95d04e91dbe53835867bdcb5d9e0590b54ae06bd7b347d49f9a737f").into(),
261261
vec![BareExtrinsic {
262262
signed: alice(),
263263
index: 0,
@@ -273,7 +273,7 @@ mod tests {
273273
// Blake
274274
// hex!("741fcb660e6fa9f625fbcd993b49f6c1cc4040f5e0cc8727afdedf11fd3c464b").into(),
275275
// Keccak
276-
hex!("166a2593d35f2d1bc87eca8cf2e320ed06759000a02aa88e51fa85b12c6f1267").into(),
276+
hex!("03f051dc4f588fdc713145772486a129d33c7f178c133b5801fa79c3ecca2dc9").into(),
277277
vec![
278278
BareExtrinsic {
279279
signed: bob(),
@@ -296,7 +296,7 @@ mod tests {
296296
// Blake
297297
// hex!("2c7231a9c210a7aa4bea169d944bc4aaacd517862b244b8021236ffa7f697991").into(),
298298
// Keccak
299-
hex!("be186810570e437f0d803493fced9879207b064a0701fd8d68662b9563b4d33e").into(),
299+
hex!("6e3b6aaf0be927394b520e3ebc0c34a7c26519711bc836e116e371273c3aca44").into(),
300300
vec![BareExtrinsic {
301301
signed: alice(),
302302
index: 0,
Binary file not shown.
Binary file not shown.

‎substrate/runtime-support/src/storage/generator.rs

+351-348
Large diffs are not rendered by default.

‎substrate/runtime/contract/src/lib.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,25 @@ decl_module! {
150150
}
151151

152152
decl_storage! {
153-
trait Store for Module<T: Trait>;
154-
155-
// The fee required to create a contract. At least as big as staking's ReclaimRebate.
156-
ContractFee get(contract_fee): b"con:contract_fee" => required T::Balance;
157-
// The fee charged for a call into a contract.
158-
CallBaseFee get(call_base_fee): b"con:base_call_fee" => required T::Gas;
159-
// The fee charged for a create of a contract.
160-
CreateBaseFee get(create_base_fee): b"con:base_create_fee" => required T::Gas;
161-
// The price of one unit of gas.
162-
GasPrice get(gas_price): b"con:gas_price" => required T::Balance;
163-
// The maximum nesting level of a call/create stack.
164-
MaxDepth get(max_depth): b"con:max_depth" => required u32;
165-
// The maximum amount of gas that could be expended per block.
166-
BlockGasLimit get(block_gas_limit): b"con:block_gas_limit" => required T::Gas;
167-
// Gas spent so far in this block.
168-
GasSpent get(gas_spent): b"con:gas_spent" => default T::Gas;
169-
170-
// The code associated with an account.
171-
CodeOf: b"con:cod:" => default map [ T::AccountId => Vec<u8> ]; // TODO Vec<u8> values should be optimised to not do a length prefix.
153+
trait Store for Module<T: Trait> as Contract {
154+
// The fee required to create a contract. At least as big as staking's ReclaimRebate.
155+
ContractFee get(contract_fee): required T::Balance;
156+
// The fee charged for a call into a contract.
157+
CallBaseFee get(call_base_fee): required T::Gas;
158+
// The fee charged for a create of a contract.
159+
CreateBaseFee get(create_base_fee): required T::Gas;
160+
// The price of one unit of gas.
161+
GasPrice get(gas_price): required T::Balance;
162+
// The maximum nesting level of a call/create stack.
163+
MaxDepth get(max_depth): required u32;
164+
// The maximum amount of gas that could be expended per block.
165+
BlockGasLimit get(block_gas_limit): required T::Gas;
166+
// Gas spent so far in this block.
167+
GasSpent get(gas_spent): default T::Gas;
168+
169+
// The code associated with an account.
170+
pub CodeOf: default map [ T::AccountId => Vec<u8> ]; // TODO Vec<u8> values should be optimised to not do a length prefix.
171+
}
172172
}
173173

174174
// TODO: consider storing upper-bound for contract's gas limit in fixed-length runtime

‎substrate/runtime/council/src/lib.rs

+52-51
Original file line numberDiff line numberDiff line change
@@ -131,57 +131,58 @@ decl_module! {
131131
}
132132

133133
decl_storage! {
134-
trait Store for Module<T: Trait>;
135-
136-
// parameters
137-
// How much should be locked up in order to submit one's candidacy.
138-
pub CandidacyBond get(candidacy_bond): b"cou:cbo" => required T::Balance;
139-
// How much should be locked up in order to be able to submit votes.
140-
pub VotingBond get(voting_bond): b"cou:vbo" => required T::Balance;
141-
// The punishment, per voter, if you provide an invalid presentation.
142-
pub PresentSlashPerVoter get(present_slash_per_voter): b"cou:pss" => required T::Balance;
143-
// How many runners-up should have their approvals persist until the next vote.
144-
pub CarryCount get(carry_count): b"cou:cco" => required u32;
145-
// How long to give each top candidate to present themselves after the vote ends.
146-
pub PresentationDuration get(presentation_duration): b"cou:pdu" => required T::BlockNumber;
147-
// How many votes need to go by after a voter's last vote before they can be reaped if their
148-
// approvals are moot.
149-
pub InactiveGracePeriod get(inactivity_grace_period): b"cou:vgp" => required VoteIndex;
150-
// How often (in blocks) to check for new votes.
151-
pub VotingPeriod get(voting_period): b"cou:per" => required T::BlockNumber;
152-
// How long each position is active for.
153-
pub TermDuration get(term_duration): b"cou:trm" => required T::BlockNumber;
154-
// Number of accounts that should be sitting on the council.
155-
pub DesiredSeats get(desired_seats): b"cou:sts" => required u32;
156-
157-
// permanent state (always relevant, changes only at the finalisation of voting)
158-
// The current council. When there's a vote going on, this should still be used for executive
159-
// matters.
160-
pub ActiveCouncil get(active_council): b"cou:act" => default Vec<(T::AccountId, T::BlockNumber)>;
161-
// The total number of votes that have happened or are in progress.
162-
pub VoteCount get(vote_index): b"cou:vco" => default VoteIndex;
163-
164-
// persistent state (always relevant, changes constantly)
165-
// The last cleared vote index that this voter was last active at.
166-
pub ApprovalsOf get(approvals_of): b"cou:apr" => default map [ T::AccountId => Vec<bool> ];
167-
// The vote index and list slot that the candidate `who` was registered or `None` if they are not
168-
// currently registered.
169-
pub RegisterInfoOf get(candidate_reg_info): b"cou:reg" => map [ T::AccountId => (VoteIndex, u32) ];
170-
// The last cleared vote index that this voter was last active at.
171-
pub LastActiveOf get(voter_last_active): b"cou:lac" => map [ T::AccountId => VoteIndex ];
172-
// The present voter list.
173-
pub Voters get(voters): b"cou:vrs" => default Vec<T::AccountId>;
174-
// The present candidate list.
175-
pub Candidates get(candidates): b"cou:can" => default Vec<T::AccountId>; // has holes
176-
pub CandidateCount get(candidate_count): b"cou:cnc" => default u32;
177-
178-
// temporary state (only relevant during finalisation/presentation)
179-
// The accounts holding the seats that will become free on the next tally.
180-
pub NextFinalise get(next_finalise): b"cou:nxt" => (T::BlockNumber, u32, Vec<T::AccountId>);
181-
// The stakes as they were at the point that the vote ended.
182-
pub SnapshotedStakes get(snapshoted_stakes): b"cou:sss" => required Vec<T::Balance>;
183-
// Get the leaderboard if we;re in the presentation phase.
184-
pub Leaderboard get(leaderboard): b"cou:win" => Vec<(T::Balance, T::AccountId)>; // ORDERED low -> high
134+
trait Store for Module<T: Trait> as Council {
135+
136+
// parameters
137+
// How much should be locked up in order to submit one's candidacy.
138+
pub CandidacyBond get(candidacy_bond): required T::Balance;
139+
// How much should be locked up in order to be able to submit votes.
140+
pub VotingBond get(voting_bond): required T::Balance;
141+
// The punishment, per voter, if you provide an invalid presentation.
142+
pub PresentSlashPerVoter get(present_slash_per_voter): required T::Balance;
143+
// How many runners-up should have their approvals persist until the next vote.
144+
pub CarryCount get(carry_count): required u32;
145+
// How long to give each top candidate to present themselves after the vote ends.
146+
pub PresentationDuration get(presentation_duration): required T::BlockNumber;
147+
// How many votes need to go by after a voter's last vote before they can be reaped if their
148+
// approvals are moot.
149+
pub InactiveGracePeriod get(inactivity_grace_period): required VoteIndex;
150+
// How often (in blocks) to check for new votes.
151+
pub VotingPeriod get(voting_period): required T::BlockNumber;
152+
// How long each position is active for.
153+
pub TermDuration get(term_duration): required T::BlockNumber;
154+
// Number of accounts that should be sitting on the council.
155+
pub DesiredSeats get(desired_seats): required u32;
156+
157+
// permanent state (always relevant, changes only at the finalisation of voting)
158+
// The current council. When there's a vote going on, this should still be used for executive
159+
// matters.
160+
pub ActiveCouncil get(active_council): default Vec<(T::AccountId, T::BlockNumber)>;
161+
// The total number of votes that have happened or are in progress.
162+
pub VoteCount get(vote_index): default VoteIndex;
163+
164+
// persistent state (always relevant, changes constantly)
165+
// The last cleared vote index that this voter was last active at.
166+
pub ApprovalsOf get(approvals_of): default map [ T::AccountId => Vec<bool> ];
167+
// The vote index and list slot that the candidate `who` was registered or `None` if they are not
168+
// currently registered.
169+
pub RegisterInfoOf get(candidate_reg_info): map [ T::AccountId => (VoteIndex, u32) ];
170+
// The last cleared vote index that this voter was last active at.
171+
pub LastActiveOf get(voter_last_active): map [ T::AccountId => VoteIndex ];
172+
// The present voter list.
173+
pub Voters get(voters): default Vec<T::AccountId>;
174+
// The present candidate list.
175+
pub Candidates get(candidates): default Vec<T::AccountId>; // has holes
176+
pub CandidateCount get(candidate_count): default u32;
177+
178+
// temporary state (only relevant during finalisation/presentation)
179+
// The accounts holding the seats that will become free on the next tally.
180+
pub NextFinalise get(next_finalise): (T::BlockNumber, u32, Vec<T::AccountId>);
181+
// The stakes as they were at the point that the vote ended.
182+
pub SnapshotedStakes get(snapshoted_stakes): required Vec<T::Balance>;
183+
// Get the leaderboard if we;re in the presentation phase.
184+
pub Leaderboard get(leaderboard): Vec<(T::Balance, T::AccountId)>; // ORDERED low -> high
185+
}
185186
}
186187

187188
impl<T: Trait> Module<T> {

‎substrate/runtime/council/src/voting.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ decl_module! {
4343
}
4444

4545
decl_storage! {
46-
trait Store for Module<T: Trait>;
47-
48-
pub CooloffPeriod get(cooloff_period): b"cov:cooloff" => required T::BlockNumber;
49-
pub VotingPeriod get(voting_period): b"cov:period" => required T::BlockNumber;
50-
pub Proposals get(proposals): b"cov:prs" => required Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry.
51-
pub ProposalOf get(proposal_of): b"cov:pro" => map [ T::Hash => T::Proposal ];
52-
pub ProposalVoters get(proposal_voters): b"cov:voters:" => default map [ T::Hash => Vec<T::AccountId> ];
53-
pub CouncilVoteOf get(vote_of): b"cov:vote:" => map [ (T::Hash, T::AccountId) => bool ];
54-
pub VetoedProposal get(veto_of): b"cov:veto:" => map [ T::Hash => (T::BlockNumber, Vec<T::AccountId>) ];
46+
trait Store for Module<T: Trait> as CouncilVoting {
47+
pub CooloffPeriod get(cooloff_period): required T::BlockNumber;
48+
pub VotingPeriod get(voting_period): required T::BlockNumber;
49+
pub Proposals get(proposals): required Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry.
50+
pub ProposalOf get(proposal_of): map [ T::Hash => T::Proposal ];
51+
pub ProposalVoters get(proposal_voters): default map [ T::Hash => Vec<T::AccountId> ];
52+
pub CouncilVoteOf get(vote_of): map [ (T::Hash, T::AccountId) => bool ];
53+
pub VetoedProposal get(veto_of): map [ T::Hash => (T::BlockNumber, Vec<T::AccountId>) ];
54+
}
5555
}
5656

5757
impl<T: Trait> Module<T> {

‎substrate/runtime/democracy/src/lib.rs

+29-28
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,35 @@ decl_module! {
8484
}
8585

8686
decl_storage! {
87-
trait Store for Module<T: Trait>;
88-
89-
// The number of (public) proposals that have been made so far.
90-
pub PublicPropCount get(public_prop_count): b"dem:ppc" => default PropIndex;
91-
// The public proposals. Unsorted.
92-
pub PublicProps get(public_props): b"dem:pub" => default Vec<(PropIndex, T::Proposal, T::AccountId)>;
93-
// Those who have locked a deposit.
94-
pub DepositOf get(deposit_of): b"dem:dep:" => map [ PropIndex => (T::Balance, Vec<T::AccountId>) ];
95-
// How often (in blocks) new public referenda are launched.
96-
pub LaunchPeriod get(launch_period): b"dem:lau" => required T::BlockNumber;
97-
// The minimum amount to be used as a deposit for a public referendum proposal.
98-
pub MinimumDeposit get(minimum_deposit): b"dem:min" => required T::Balance;
99-
100-
// How often (in blocks) to check for new votes.
101-
pub VotingPeriod get(voting_period): b"dem:per" => required T::BlockNumber;
102-
103-
// The next free referendum index, aka the number of referendums started so far.
104-
pub ReferendumCount get(referendum_count): b"dem:rco" => required ReferendumIndex;
105-
// The next referendum index that should be tallied.
106-
pub NextTally get(next_tally): b"dem:nxt" => required ReferendumIndex;
107-
// Information concerning any given referendum.
108-
pub ReferendumInfoOf get(referendum_info): b"dem:pro:" => map [ ReferendumIndex => (T::BlockNumber, T::Proposal, VoteThreshold) ];
109-
110-
// Get the voters for the current proposal.
111-
pub VotersFor get(voters_for): b"dem:vtr:" => default map [ ReferendumIndex => Vec<T::AccountId> ];
112-
113-
// Get the vote, if Some, of `who`.
114-
pub VoteOf get(vote_of): b"dem:vot:" => map [ (ReferendumIndex, T::AccountId) => bool ];
87+
trait Store for Module<T: Trait> as Democracy {
88+
89+
// The number of (public) proposals that have been made so far.
90+
pub PublicPropCount get(public_prop_count): default PropIndex;
91+
// The public proposals. Unsorted.
92+
pub PublicProps get(public_props): default Vec<(PropIndex, T::Proposal, T::AccountId)>;
93+
// Those who have locked a deposit.
94+
pub DepositOf get(deposit_of): map [ PropIndex => (T::Balance, Vec<T::AccountId>) ];
95+
// How often (in blocks) new public referenda are launched.
96+
pub LaunchPeriod get(launch_period): required T::BlockNumber;
97+
// The minimum amount to be used as a deposit for a public referendum proposal.
98+
pub MinimumDeposit get(minimum_deposit): required T::Balance;
99+
100+
// How often (in blocks) to check for new votes.
101+
pub VotingPeriod get(voting_period): required T::BlockNumber;
102+
103+
// The next free referendum index, aka the number of referendums started so far.
104+
pub ReferendumCount get(referendum_count): required ReferendumIndex;
105+
// The next referendum index that should be tallied.
106+
pub NextTally get(next_tally): required ReferendumIndex;
107+
// Information concerning any given referendum.
108+
pub ReferendumInfoOf get(referendum_info): map [ ReferendumIndex => (T::BlockNumber, T::Proposal, VoteThreshold) ];
109+
110+
// Get the voters for the current proposal.
111+
pub VotersFor get(voters_for): default map [ ReferendumIndex => Vec<T::AccountId> ];
112+
113+
// Get the vote, if Some, of `who`.
114+
pub VoteOf get(vote_of): map [ (ReferendumIndex, T::AccountId) => bool ];
115+
}
115116
}
116117

117118
impl<T: Trait> Module<T> {

‎substrate/runtime/executive/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ mod tests {
336336
// Blake
337337
// state_root: hex!("02532989c613369596025dfcfc821339fc9861987003924913a5a1382f87034a").into(),
338338
// Keccak
339-
state_root: hex!("246ea6d86eefe3fc32f746fdcb1749a5f245570c70a04b43d08b5defac44505a").into(),
339+
state_root: hex!("e576ed2adacdc09b61844b5106bfaa18d2a4bfd7feb56d7af97c3421cdefca48").into(),
340340
extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
341341
digest: Digest { logs: vec![], },
342342
},
@@ -370,7 +370,7 @@ mod tests {
370370
header: Header {
371371
parent_hash: [69u8; 32].into(),
372372
number: 1,
373-
state_root: hex!("246ea6d86eefe3fc32f746fdcb1749a5f245570c70a04b43d08b5defac44505a").into(),
373+
state_root: hex!("e576ed2adacdc09b61844b5106bfaa18d2a4bfd7feb56d7af97c3421cdefca48").into(),
374374
extrinsics_root: [0u8; 32].into(),
375375
digest: Digest { logs: vec![], },
376376
},

‎substrate/runtime/session/src/lib.rs

+25-24
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,31 @@ impl<N> From<RawEvent<N>> for () {
103103
}
104104

105105
decl_storage! {
106-
trait Store for Module<T: Trait>;
107-
108-
// The current set of validators.
109-
pub Validators get(validators): b"ses:val" => required Vec<T::AccountId>;
110-
// Current length of the session.
111-
pub SessionLength get(length): b"ses:len" => required T::BlockNumber;
112-
// Current index of the session.
113-
pub CurrentIndex get(current_index): b"ses:ind" => required T::BlockNumber;
114-
// Timestamp when current session started.
115-
pub CurrentStart get(current_start): b"ses:current_start" => required T::Moment;
116-
117-
// Opinions of the current validator set about the activeness of their peers.
118-
// Gets cleared when the validator set changes.
119-
pub BadValidators get(bad_validators): b"ses:bad_validators" => Vec<T::AccountId>;
120-
121-
// New session is being forced is this entry exists; in which case, the boolean value is whether
122-
// the new session should be considered a normal rotation (rewardable) or exceptional (slashable).
123-
pub ForcingNewSession get(forcing_new_session): b"ses:forcing_new_session" => bool;
124-
// Block at which the session length last changed.
125-
LastLengthChange: b"ses:llc" => T::BlockNumber;
126-
// The next key for a given validator.
127-
NextKeyFor: b"ses:nxt:" => map [ T::AccountId => T::SessionKey ];
128-
// The next session length.
129-
NextSessionLength: b"ses:nln" => T::BlockNumber;
106+
trait Store for Module<T: Trait> as Session {
107+
108+
// The current set of validators.
109+
pub Validators get(validators): required Vec<T::AccountId>;
110+
// Current length of the session.
111+
pub SessionLength get(length): required T::BlockNumber;
112+
// Current index of the session.
113+
pub CurrentIndex get(current_index): required T::BlockNumber;
114+
// Timestamp when current session started.
115+
pub CurrentStart get(current_start): required T::Moment;
116+
117+
// Opinions of the current validator set about the activeness of their peers.
118+
// Gets cleared when the validator set changes.
119+
pub BadValidators get(bad_validators): Vec<T::AccountId>;
120+
121+
// New session is being forced is this entry exists; in which case, the boolean value is whether
122+
// the new session should be considered a normal rotation (rewardable) or exceptional (slashable).
123+
pub ForcingNewSession get(forcing_new_session): bool;
124+
// Block at which the session length last changed.
125+
LastLengthChange: T::BlockNumber;
126+
// The next key for a given validator.
127+
NextKeyFor: map [ T::AccountId => T::SessionKey ];
128+
// The next session length.
129+
NextSessionLength: T::BlockNumber;
130+
}
130131
}
131132

132133
impl<T: Trait> Module<T> {

0 commit comments

Comments
 (0)