* add stub for new benchmark macro
* benchmark syntax
* add #[extrinsic call] separator
* parse #[benchmark] item as a function
* proper emission of error when #[extrinsic_call] annotation is missing
* clean up
* enclosing module via benchmarks! { } working
* use an attribute macro on the module instead of benchmarks! { }
* cargo fmt
* working component implementation
* WIP
* working
* add syntax for Linear<A, B>
* parsing of param ranges (still need to build tuple though)
* params parsing WIP
* clean up (don't need extrinsic call name)
* use proper Result syntax for BenchmarkDef parsing
* proper parsing of Linear<0, 1> style args
* successfully parse and make use of linear component ranges 💥
* rename support variable => home because eventually will be moved
* compile-time check that param range types implement ParamRange
* switch to using balances as example, failing on instance pallet
* successfully set up __origin and __call with balances 💥
* clean up
* use a module
* don't need a variable for transfer
* rename benchmark_transfer -> transfer because no longer conflicts
* clean up
* working with transfer_increasing_users as well 💥
* re-add BareBlock
* add comments for undocumented structs+functions+traits
* refactor in preparation for removing module requirements
* switch to a block instead of a module
* use the outer macro pattern to to enable #[benchmarks] aggregation
* successfully generate SelectedBenchmark 💥
* implement components for SelectedBenchmark
* implement instance for SelectedBenchmark
* properly track #[extra]
* working impl for fn benchmarks()
* run_benchmarks WIP
* finish run_benchmark! impl 💥
* import balances transfer_best_case benchmark
* import transfer_keep_alive balances pallet benchmark
* import set_balance_creating balances pallet benchmark
* import set_balance_killing balances pallet benchmark
* import force_transfer balances pallet benchmark
* add #[extra] annotation and docs to transfer_increasing_users
* import transfer_all balances pallet benchmark
* import force_unreserve balances pallet benchmark
* prepare to implement impl_benchmark_test_suite!
* ensure tests cover #[extra] before and after #[benchmark] tag
* refactor
* clean up
* fix
* move to outer
* switch to benchmarks/instance_benchmarks
* test impl almost done, strange compiler error
* benchmark test suites working 💥
* clean up
* add stub and basic parsing for where_clause
* working except where clause and extrinsic calls containing method chains
* assume option (2) for now wrt https://github.com/paritytech/substrate/pull/12924#issuecomment-1372938718
* clean up
* switch to attribute-style
* properly handle where clauses
* fix subtle missing where clause, now just MessageQueue issues
* fix block formatting in message-queue pallet
* switch to block vs non-block parsing of extrinsic call
* working now but some benchmark tests failing
* message-queue tests working (run order issue fixed) 🎉
* add comments and internal docs for fame_support_procedural::benchmark
* fix license years
* docs for lib.rs
* add docs to new support procedural macros
* don't allow #[benchmark] outside of benchmarking module
* add docs
* use benchmark(extra, skip_meta) style args
* update docs accordingly
* appease clippy
* bump ci
* add notes about `extra` and `skip_meta`
* fix doc tests
* re-run CI
* use `ignore` instead of `no_run` on doc examples
* bump CI
* replace some if-lets with if-elses
* more refactoring of if-let statements
* fix remaining if-lets in BenchmarkDef::from()
* fix if-lets in benchmarks()
* fix remaining if-lets, use nested find_map for extrinsic call
* switch to use #[extrinsic_call] or #[block] situationally
* refactor ExtrinsicCallDef => BenchmarkCallDef
* update docs with info about #[block]
* add macro stub for #[extrinsic_call]
* fix docs and add stub for #[block] as well
* remove unused extern crate line
* fix clippy nits
* Use V2 bench syntax in pallet-example-basic
Just testing the dev-ex...
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* carry over comment
* use curly-brace style for impl_benchmark_test_suite!
* remove unneeded parenthesis
* proper handling of _() extrinsic call style
* add docs for _() syntax
* fix crate access
* simplify keyword access
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* simplify module content destructuring
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* fix crate access "frame_benchmarking" => "frame-benchmarking", compiles
* use _() extrinsic call syntax where possible in balances
* simplify attr.path.segments.last()
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* fix compile error being suppressed
* simplify extrinsic call keyword parsing
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* use ? operator instead of return None
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* rename generics => type_use_generics
rename full_generics => type_impl_generics
* simplify extrinsic call extraction with transpose
* bump CI
* nit
* proper handling of too many + too few block/extrinsic call annotations
* change to B >= A
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* remove unneeded ignore
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* remove another ignore
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* add ui tests
* use _() style extrinsic call on accumulate_dummy
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* add range check to ParamRange
* ui test for bad param ranges
* fix failing example
* add ignore back to other failing example
* tweak expr_call span
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* fix typo
* eliminate a match
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* change pub fn benchmarks to return Result<TokenStream>
* fix origin error span
* more informative error for invalid benchmark parameter name
* fix spans on a few benchmark errors
* remove unneeded clone
* refactor inner loop of benchmark function parsing
* preserve mod attributes
* refactor outer loop of benchmark def parsing code, greatly simplified
* simplify to use a ? operator when parsing benchmark attr path
* fix another ? operator
* further simplify benchmark function attr parsing with more ? ops
* refactor extrinsic call handling to use if let rather than match
* replace is_ok => is_err
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
* re-use name during expansion of benchmark def
* remove unneeded clone
* fix span for origin missing error
* fix missing semi
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: parity-processbot <>
Basic Example Pallet
The Example: A simple example of a FRAME pallet demonstrating concepts, APIs and structures common to most FRAME runtimes.
Run cargo doc --package pallet-example-basic --open to view this pallet's documentation.
This pallet serves as an example and is not meant to be used in production.
Documentation Guidelines:
- Documentation comments (i.e.
/// comment) - should accompany pallet functions and be restricted to the pallet interface, not the internals of the pallet implementation. Only state inputs, outputs, and a brief description that mentions whether calling it requires root, but without repeating the source code details. Capitalize the first word of each documentation comment and end it with a full stop. See Generic example of annotating source code with documentation comments - Self-documenting code - Try to refactor code to be self-documenting.
- Code comments - Supplement complex code with a brief explanation, not every line of code.
- Identifiers - surround by backticks (i.e.
INHERENT_IDENTIFIER,InherentType,u64) - Usage scenarios - should be simple doctests. The compiler should ensure they stay valid.
- Extended tutorials - should be moved to external files and refer to.
- Mandatory - include all of the sections/subsections where MUST is specified.
- Optional - optionally include sections/subsections where CAN is specified.
Documentation Template:
Copy and paste this template from frame/examples/basic/src/lib.rs into file
frame/<INSERT_CUSTOM_PALLET_NAME>/src/lib.rs of your own custom pallet and complete it.
// Add heading with custom pallet name# <INSERT_CUSTOM_PALLET_NAME> Pallet
// Add simple description
// Include the following links that shows what trait needs to be implemented to use the pallet // and the supported dispatchables that are documented in the Call enum.
- [
<INSERT_CUSTOM_PALLET_NAME>::Config](https://docs.rs/pallet-example-basic/latest/pallet_example_basic/trait.Config.html) - [
Call](https://docs.rs/pallet-example-basic/latest/pallet_example_basic/enum.Call.html) - [
Module](https://docs.rs/pallet-example-basic/latest/pallet_example_basic/struct.Module.html)
## Overview
// Short description of pallet's purpose. // Links to Traits that should be implemented. // What this pallet is for. // What functionality the pallet provides. // When to use the pallet (use case examples). // How it is used. // Inputs it uses and the source of each input. // Outputs it produces.
## Terminology
// Add terminology used in the custom pallet. Include concepts, storage items, or actions that you think // deserve to be noted to give context to the rest of the documentation or pallet usage. The author needs to // use some judgment about what is included. We don't want a list of every storage item nor types - the user // can go to the code for that. For example, "transfer fee" is obvious and should not be included, but // "free balance" and "reserved balance" should be noted to give context to the pallet. // Please do not link to outside resources. The reference docs should be the ultimate source of truth.
## Goals
// Add goals that the custom pallet is designed to achieve.
### Scenarios
#### <INSERT_SCENARIO_NAME>
// Describe requirements prior to interacting with the custom pallet. // Describe the process of interacting with the custom pallet for this scenario and public API functions used.
## Interface
### Supported Origins
// What origins are used and supported in this pallet (root, signed, none)
// i.e. root when `ensure_root` used
// i.e. none when `ensure_none` used
// i.e. signed when `ensure_signed` used
`inherent` <INSERT_DESCRIPTION>
### Types
// Type aliases. Include any associated types and where the user would typically define them.
`ExampleType` <INSERT_DESCRIPTION>
// Reference documentation of aspects such as storageItems and dispatchable functions should only be
// included in the https://docs.rs Rustdocs for Substrate and not repeated in the README file.
### Dispatchable Functions
// A brief description of dispatchable functions and a link to the rustdoc with their actual documentation.
// MUST have link to Call enum // MUST have origin information included in function doc // CAN have more info up to the user
### Public Functions
// A link to the rustdoc and any notes about usage in the pallet, not for specific functions. // For example, in the Balances Pallet: "Note that when using the publicly exposed functions, // you (the runtime developer) are responsible for implementing any necessary checks // (e.g. that the sender is the signer) before calling a function that will affect storage."
// It is up to the writer of the respective pallet (with respect to how much information to provide).
#### Public Inspection functions - Immutable (getters)
// Insert a subheading for each getter function signature
##### `example_getter_name()`
// What it returns // Why, when, and how often to call it // When it could panic or error // When safety issues to consider
#### Public Mutable functions (changing state)
// Insert a subheading for each setter function signature
##### `example_setter_name(origin, parameter_name: T::ExampleType)`
// What state it changes // Why, when, and how often to call it // When it could panic or error // When safety issues to consider // What parameter values are valid and why
### Storage Items
// Explain any storage items included in this pallet
### Digest Items
// Explain any digest items included in this pallet
### Inherent Data
// Explain what inherent data (if any) is defined in the pallet and any other related types
### Events:
// Insert events for this pallet if any
### Errors:
// Explain what generates errors
## Usage
// Insert 2-3 examples of usage and code snippets that show how to // use <INSERT_CUSTOM_PALLET_NAME> Pallet in a custom pallet.
### Prerequisites
// Show how to include necessary imports for <INSERT_CUSTOM_PALLET_NAME> and derive
// your pallet configuration trait with the INSERT_CUSTOM_PALLET_NAME trait.
```rust use <INSERT_CUSTOM_PALLET_NAME>;
pub trait Config: <INSERT_CUSTOM_PALLET_NAME>::Config { } ```
### Simple Code Snippet
// Show a simple example (e.g. how to query a public getter function of <INSERT_CUSTOM_PALLET_NAME>)
### Example from FRAME
// Show a usage example in an actual runtime
// See: // - Substrate TCR https://github.com/parity-samples/substrate-tcr // - Substrate Kitties https://shawntabrizi.github.io/substrate-collectables-workshop/#/
## Genesis Config
## Dependencies
// Dependencies on other FRAME pallets and the genesis config should be mentioned, // but not the Rust Standard Library. // Genesis configuration modifications that may be made to incorporate this pallet // Interaction with other pallets
## Related Pallets
// Interaction with other pallets in the form of a bullet point list
## References
// Links to reference material, if applicable. For example, Phragmen, W3F research, etc. // that the implementation is based on.
License: Unlicense