Skip to content
Snippets Groups Projects
Unverified Commit 84417ec3 authored by bgallois's avatar bgallois
Browse files

refactor error handling

parent a421ce35
No related branches found
No related tags found
1 merge request!222Automatic weights documentation
...@@ -100,7 +100,7 @@ Cancel a named scheduled task. ...@@ -100,7 +100,7 @@ Cancel a named scheduled task.
<details><summary><code>schedule_after(after, maybe_periodic, priority, call)</code></summary> <details><summary><code>schedule_after(after, maybe_periodic, priority, call)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
after: T::BlockNumber after: T::BlockNumber
...@@ -117,7 +117,7 @@ Anonymously schedule a task after a delay. ...@@ -117,7 +117,7 @@ Anonymously schedule a task after a delay.
<details><summary><code>schedule_named_after(id, after, maybe_periodic, priority, call)</code></summary> <details><summary><code>schedule_named_after(id, after, maybe_periodic, priority, call)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
id: TaskName id: TaskName
...@@ -137,7 +137,7 @@ Schedule a named task after a delay. ...@@ -137,7 +137,7 @@ Schedule a named task after a delay.
<details><summary><code>report_equivocation(equivocation_proof, key_owner_proof)</code></summary> <details><summary><code>report_equivocation(equivocation_proof, key_owner_proof)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
equivocation_proof: Box<EquivocationProof<T::Header>> equivocation_proof: Box<EquivocationProof<T::Header>>
...@@ -178,7 +178,7 @@ The dispatch origin for this call must be `Signed` by the transactor. ...@@ -178,7 +178,7 @@ The dispatch origin for this call must be `Signed` by the transactor.
<details><summary><code>set_balance_deprecated(who, new_free, old_reserved)</code></summary> <details><summary><code>set_balance_deprecated(who, new_free, old_reserved)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
who: AccountIdLookupOf<T> who: AccountIdLookupOf<T>
...@@ -248,7 +248,7 @@ The dispatch origin of this call must be Signed. ...@@ -248,7 +248,7 @@ The dispatch origin of this call must be Signed.
<details><summary><code>transfer(dest, value)</code></summary> <details><summary><code>transfer(dest, value)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
dest: AccountIdLookupOf<T> dest: AccountIdLookupOf<T>
...@@ -265,7 +265,7 @@ WARNING: DEPRECATED! Will be released in approximately 3 months. ...@@ -265,7 +265,7 @@ WARNING: DEPRECATED! Will be released in approximately 3 months.
<details><summary><code>force_set_balance(who, new_free)</code></summary> <details><summary><code>force_set_balance(who, new_free)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
who: AccountIdLookupOf<T> who: AccountIdLookupOf<T>
...@@ -407,7 +407,7 @@ remove an identity from the blacklist ...@@ -407,7 +407,7 @@ remove an identity from the blacklist
<details><summary><code>report_equivocation(equivocation_proof, key_owner_proof)</code></summary> <details><summary><code>report_equivocation(equivocation_proof, key_owner_proof)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
equivocation_proof: Box<EquivocationProof<T::Hash, T::BlockNumber>> equivocation_proof: Box<EquivocationProof<T::Hash, T::BlockNumber>>
...@@ -427,7 +427,7 @@ will be reported. ...@@ -427,7 +427,7 @@ will be reported.
<details><summary><code>dispatch_as_root_unchecked_weight(call, weight)</code></summary> <details><summary><code>dispatch_as_root_unchecked_weight(call, weight)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
call: Box<<T as Config>::Call> call: Box<<T as Config>::Call>
...@@ -542,7 +542,7 @@ Origin must be a member of the collective. ...@@ -542,7 +542,7 @@ Origin must be a member of the collective.
<details><summary><code>propose(threshold, proposal, length_bound)</code></summary> <details><summary><code>propose(threshold, proposal, length_bound)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
threshold: MemberCount threshold: MemberCount
...@@ -595,7 +595,7 @@ fee. ...@@ -595,7 +595,7 @@ fee.
<details><summary><code>close(proposal_hash, index, proposal_weight_bound, length_bound)</code></summary> <details><summary><code>close(proposal_hash, index, proposal_weight_bound, length_bound)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
proposal_hash: T::Hash proposal_hash: T::Hash
...@@ -991,7 +991,7 @@ The origin must be allow to certify. ...@@ -991,7 +991,7 @@ The origin must be allow to certify.
<details><summary><code>create_swap(target, hashed_proof, action, duration)</code></summary> <details><summary><code>create_swap(target, hashed_proof, action, duration)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
target: T::AccountId target: T::AccountId
...@@ -1019,7 +1019,7 @@ The dispatch origin for this call must be _Signed_. ...@@ -1019,7 +1019,7 @@ The dispatch origin for this call must be _Signed_.
<details><summary><code>claim_swap(proof, action)</code></summary> <details><summary><code>claim_swap(proof, action)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
proof: Vec<u8> proof: Vec<u8>
...@@ -1040,7 +1040,7 @@ The dispatch origin for this call must be _Signed_. ...@@ -1040,7 +1040,7 @@ The dispatch origin for this call must be _Signed_.
<details><summary><code>cancel_swap(target, hashed_proof)</code></summary> <details><summary><code>cancel_swap(target, hashed_proof)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
target: T::AccountId target: T::AccountId
...@@ -1088,7 +1088,7 @@ O(Z + C) where Z is the length of the call and C its execution weight. ...@@ -1088,7 +1088,7 @@ O(Z + C) where Z is the length of the call and C its execution weight.
<details><summary><code>as_multi(threshold, other_signatories, maybe_timepoint, call, max_weight)</code></summary> <details><summary><code>as_multi(threshold, other_signatories, maybe_timepoint, call, max_weight)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
threshold: u16 threshold: u16
...@@ -1144,7 +1144,7 @@ may be found in the deposited `MultisigExecuted` event. ...@@ -1144,7 +1144,7 @@ may be found in the deposited `MultisigExecuted` event.
<details><summary><code>approve_as_multi(threshold, other_signatories, maybe_timepoint, call_hash, max_weight)</code></summary> <details><summary><code>approve_as_multi(threshold, other_signatories, maybe_timepoint, call_hash, max_weight)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
threshold: u16 threshold: u16
...@@ -1617,7 +1617,7 @@ includes bypassing `frame_system::Config::BaseCallFilter`). ...@@ -1617,7 +1617,7 @@ includes bypassing `frame_system::Config::BaseCallFilter`).
<details><summary><code>with_weight(call, weight)</code></summary> <details><summary><code>with_weight(call, weight)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
call: Box<<T as Config>::RuntimeCall> call: Box<<T as Config>::RuntimeCall>
...@@ -1729,7 +1729,7 @@ Set the number of pages in the WebAssembly environment's heap. ...@@ -1729,7 +1729,7 @@ Set the number of pages in the WebAssembly environment's heap.
<details><summary><code>set_code(code)</code></summary> <details><summary><code>set_code(code)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
code: Vec<u8> code: Vec<u8>
...@@ -1746,7 +1746,7 @@ Set the new runtime code. ...@@ -1746,7 +1746,7 @@ Set the new runtime code.
<details><summary><code>set_code_without_checks(code)</code></summary> <details><summary><code>set_code_without_checks(code)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
code: Vec<u8> code: Vec<u8>
...@@ -1811,7 +1811,7 @@ the prefix we are removing to accurately calculate the weight of this function. ...@@ -1811,7 +1811,7 @@ the prefix we are removing to accurately calculate the weight of this function.
<details><summary><code>plan_config_change(config)</code></summary> <details><summary><code>plan_config_change(config)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
config: NextConfigDescriptor config: NextConfigDescriptor
...@@ -1882,7 +1882,7 @@ remove an identity from the set of authorities ...@@ -1882,7 +1882,7 @@ remove an identity from the set of authorities
<details><summary><code>note_stalled(delay, best_finalized_block_number)</code></summary> <details><summary><code>note_stalled(delay, best_finalized_block_number)</code></summary>
Taking -1 % of a block. Taking 0 % of a block.
```rust ```rust
delay: T::BlockNumber delay: T::BlockNumber
......
...@@ -265,9 +265,9 @@ pub(super) fn gen_doc() -> Result<()> { ...@@ -265,9 +265,9 @@ pub(super) fn gen_doc() -> Result<()> {
bail!("unsuported metadata version") bail!("unsuported metadata version")
}; };
let mut weights = get_weights(max_weight); let mut weights = get_weights(max_weight)?;
// AdHoc names convertion
// TODO automatic, possible??? // Ad hoc names conversion between pallet filename and instance name
rename_key(&mut weights, &"FrameSystem".into(), "System".into()); rename_key(&mut weights, &"FrameSystem".into(), "System".into());
rename_key(&mut weights, &"DuniterAccount".into(), "Account".into()); rename_key(&mut weights, &"DuniterAccount".into(), "Account".into());
rename_key( rename_key(
...@@ -291,20 +291,28 @@ pub(super) fn gen_doc() -> Result<()> { ...@@ -291,20 +291,28 @@ pub(super) fn gen_doc() -> Result<()> {
&"CertificationSmithCert".into(), &"CertificationSmithCert".into(),
"SmithCert".into(), "SmithCert".into(),
); );
// Pallet with manual benchmark
// We enforce weight for each pallet.
// For pallets with manual or no weight, we define a default value.
weights.insert("Babe".to_string(), Default::default()); // Manual weights.insert("Babe".to_string(), Default::default()); // Manual
weights.insert("Grandpa".to_string(), Default::default()); // Manual weights.insert("Grandpa".to_string(), Default::default()); // Manual
weights.insert("Sudo".to_string(), Default::default()); // Only > v1.0 has WeightInfo TODO at update weights.insert("Sudo".to_string(), Default::default()); // Only > v1.0 has WeightInfo TODO at update
weights.insert("AtomicSwap".to_string(), Default::default()); // No weight weights.insert("AtomicSwap".to_string(), Default::default()); // No weight
// Insert weights // Insert weights for each call of each pallet.
// If no weight is available, the weight is set to 0.
// We use the relative weight in percent computed as the extrinsic base +
// the extrinsic execution divided by the total weight available in
// one block. If the weight depends on a complexity parameter,
// we display the worst possible weight, taking the upper limit as
// defined during the benchmark.
runtime.iter_mut().for_each(|pallet| { runtime.iter_mut().for_each(|pallet| {
pallet.calls.iter_mut().for_each(|call| { pallet.calls.iter_mut().for_each(|call| {
call.weight = weights call.weight = weights
.get(&pallet.name) .get(&pallet.name)
.expect(&("No weight for ".to_owned() + &pallet.name)) .expect(&("No weight for ".to_owned() + &pallet.name))
.get(&call.name) .get(&call.name)
.map_or(-1f64, |weight| { .map_or(0f64, |weight| {
(weight.relative_weight * 10000.).round() / 10000. (weight.relative_weight * 10000.).round() / 10000.
}) })
}) })
...@@ -331,9 +339,8 @@ pub(super) fn gen_doc() -> Result<()> { ...@@ -331,9 +339,8 @@ pub(super) fn gen_doc() -> Result<()> {
fn get_max_weight_from_metadata_v14( fn get_max_weight_from_metadata_v14(
metadata_v14: frame_metadata::v14::RuntimeMetadataV14, metadata_v14: frame_metadata::v14::RuntimeMetadataV14,
) -> Result<u128> { ) -> Result<u128> {
// Compute the weights from the weight files. // Extract the maximal weight available in one block
// Require the `pallet_xxx.rs` weights, // from the metadata.
// the `paritydb_weights.rs` and the `extrinsic_weights.rs`
let block_weights = metadata_v14 let block_weights = metadata_v14
.pallets .pallets
.iter() .iter()
...@@ -427,12 +434,12 @@ fn get_from_metadata_v14( ...@@ -427,12 +434,12 @@ fn get_from_metadata_v14(
Ok(pallets) Ok(pallets)
} }
fn get_weights(max_weight: u128) -> HashMap<String, HashMap<String, WeightInfo>> { fn get_weights(max_weight: u128) -> Result<HashMap<String, HashMap<String, WeightInfo>>> {
analyze_weight( analyze_weight(
Path::new(WEIGHT_FILEPATH), Path::new(WEIGHT_FILEPATH),
&MaxBlockWeight::new(max_weight as f64), &MaxBlockWeight::new(max_weight as f64),
) )
.expect("Weights unavailable") .map_err(|e| anyhow::anyhow!(e))
} }
/// use template to render markdown file with runtime calls documentation /// use template to render markdown file with runtime calls documentation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment