diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml.disabled similarity index 100% rename from .github/workflows/master.yml rename to .github/workflows/master.yml.disabled diff --git a/Cargo.dev.toml b/Cargo.dev.toml index e10d3796f..db59efb92 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -17,76 +17,82 @@ members = [ "vesting", "rewards", "nft", - "xtokens", - "xcm-support", - "unknown-tokens", + # "xtokens", + # "xcm-support", + # "unknown-tokens", "build-script-utils", "weight-gen", - "weight-meter", + "weight-meter", ] resolver = "2" +[profile.dev] +split-debuginfo = "unpacked" + [patch.'https://github.com/paritytech/substrate'] -frame-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -frame-support = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -frame-system = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-balances = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-elections-phragmen = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-treasury = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-authorship = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-vesting = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-timestamp = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-session = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-offences = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -pallet-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-api = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-core = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-inherents = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-io = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-runtime = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-runtime-interface = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-std = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-trie = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-version = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-externalities = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-state-machine = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-keystore = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-staking = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-storage = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-panic-handler = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-npos-elections = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-npos-elections-compact = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-debug-derive = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-allocator = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sc-executor-common = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sc-executor = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sc-client-api = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-tasks = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-timestamp = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-session = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } -sp-transaction-pool = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" } +frame-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +frame-support = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +frame-system = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-balances = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-elections-phragmen = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-treasury = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-authorship = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-vesting = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-timestamp = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-session = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-offences = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +pallet-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-api = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-core = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-inherents = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-io = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-runtime = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-runtime-interface = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-std = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-trie = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-version = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-externalities = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-state-machine = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-keystore = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-staking = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-storage = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-panic-handler = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-npos-elections = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-npos-elections-compact = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-debug-derive = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-allocator = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sc-executor-common = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sc-executor = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sc-client-api = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-tasks = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-timestamp = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-session = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } +sp-transaction-pool = { git = "https://github.com/paritytech//substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } + +# [patch.'https://github.com/paritytech/cumulus'] +# cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "da4c3bac6e9584e65740ef5db4dbd2c31c1a91db" } +# cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "da4c3bac6e9584e65740ef5db4dbd2c31c1a91db" } +# parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "da4c3bac6e9584e65740ef5db4dbd2c31c1a91db" } +# cumulus-pallet-xcm-handler = { git = "https://github.com/paritytech//cumulus", rev = "da4c3bac6e9584e65740ef5db4dbd2c31c1a91db" } -[patch.'https://github.com/paritytech/cumulus'] -cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" } -parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" } -cumulus-pallet-xcm-handler = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" } +# [patch.'https://github.com/paritytech/polkadot'] +# xcm = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } +# xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } +# xcm-builder = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } +# polkadot-core-primitives = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } +# polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } +# polkadot-parachain = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } +# polkadot-primitives = { git = "https://github.com/paritytech//polkadot", rev = "127eb17a25bbe2a9f2731ff11a65d7f8170f2373" } -[patch.'https://github.com/paritytech/polkadot'] -xcm = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } -xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } -xcm-builder = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } -polkadot-core-primitives = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } -polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } -polkadot-parachain = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } -polkadot-primitives = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" } +# [patch.'https://github.com/shaunxw/xcm-simulator'] +# xcm-simulator = { git = "https://github.com/shaunxw//xcm-simulator", rev = "c52bd64a41a51d08bd5a1e27f32c47419b41f3e5" } diff --git a/Makefile b/Makefile index 0583cd27d..51dfe8fe8 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,17 @@ dev-check-tests: Cargo.toml dev-test: Cargo.toml cargo test --all --features runtime-benchmarks + +# run benchmarks via Acala node +benchmark-all: + cargo run --release --bin=acala --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_auction --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./auction/src/weights.rs --template ../templates/orml-weight-template.hbs + + cargo run --release --bin=acala --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_authority --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./authority/src/weights.rs --template ../templates/orml-weight-template.hbs + + cargo run --release --bin=acala --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=module_currencies --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./currencies/src/weights.rs --template ../templates/orml-weight-template.hbs + + cargo run --release --bin=acala --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_oracle --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./oracle/src/weights.rs --template ../templates/orml-weight-template.hbs + + cargo run --release --bin=acala --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_tokens --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./tokens/src/weights.rs --template ../templates/orml-weight-template.hbs + + cargo run --release --bin=acala --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_vesting --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./vesting/src/weights.rs --template ../templates/orml-weight-template.hbs diff --git a/README.md b/README.md index 852832c49..126fddb04 100644 --- a/README.md +++ b/README.md @@ -7,27 +7,29 @@ The Open Runtime Module Library (ORML) is a community maintained collection of S ## Runtime Modules Overview -- [orml-traits](./traits) - - Shared traits including `BasicCurrency`, `MultiCurrency`, `Auction` and more. -- [orml-utilities](./utilities) - - Various utilities including `OrderSet`. -- [orml-tokens](./tokens) - - Fungible tokens module that implements `MultiCurrency` trait. +- [orml-auction](./auction) + - Auction module that implements `Auction` trait. - [orml-currencies](./currencies) - Provide `MultiCurrency` implementation using `pallet-balances` and `orml-tokens` module. +- [orml-gradually-update](./gradually-update) + - Provides way to adjust numeric parameter gradually over a period of time. +- [orml-nft](./nft) + - Non-fungible-token module provides basic functions to create and manager NFT(non fungible token) such as `create_class`, `transfer`, `mint`, `burn`, `destroy_class`. - [orml-oracle](./oracle) - - Oracle module that makes off-chain data available on-chain. -- [orml-auction](./auction) - - Auction module that implements `Auction` trait. + - Oracle module that makes off-chain data available on-chain. +- [orml-tokens](./tokens) + - Fungible tokens module that implements `MultiCurrency` trait. +- [orml-traits](./traits) + - Shared traits including `BasicCurrency`, `MultiCurrency`, `Auction` and more. +- [orml-utilities](./utilities) + - Various utilities including `OrderSet`. - [orml-vesting](./vesting) - - Provides scheduled balance locking mechanism, in a *graded vesting* way. -- [orml-gradually-update](./gradually-update) - - Provides way to adjust numeric parameter gradually over a period of time. -- [orml-xtokens](./xtokens) - - Provides way to do cross-chain assets transfer. - - [Step-by-Step guide](https://github.com/open-web3-stack/open-runtime-module-library/wiki/xtokens) to make XCM cross-chain fungible asset transfer available on your parachain + - Provides scheduled balance locking mechanism, in a *graded vesting* way. - [orml-xcm-support](./xcm-support) - - Provides traits, types, and implementations to support XCM integration. + - Provides traits, types, and implementations to support XCM integration. +- [orml-xtokens](./xtokens) + - Provides way to do cross-chain assets transfer. + - [Step-by-Step guide](https://github.com/open-web3-stack/open-runtime-module-library/wiki/xtokens) to make XCM cross-chain fungible asset transfer available on your parachain ## Example @@ -67,6 +69,7 @@ _In alphabetical order_ - [HydraDX](https://github.com/galacticcouncil/hack.HydraDX-node) - [Laminar Chain](https://github.com/laminar-protocol/laminar-chain) - [Listen](https://github.com/listenofficial) +- [Manta Network](https://github.com/Manta-Network) - [Minterest](https://github.com/minterest-finance/minterest-chain-node) - [Plasm Network](https://github.com/PlasmNetwork) - [Setheum Network](https://github.com/Setheum-Labs/Setheum) diff --git a/auction/Cargo.toml b/auction/Cargo.toml index 64d024a3d..ab367b80f 100644 --- a/auction/Cargo.toml +++ b/auction/Cargo.toml @@ -17,8 +17,6 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "roc frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } diff --git a/auction/src/default_weight.rs b/auction/src/default_weight.rs index 26e552fef..e69de29bb 100644 --- a/auction/src/default_weight.rs +++ b/auction/src/default_weight.rs @@ -1,23 +0,0 @@ -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 - -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; - -impl crate::WeightInfo for () { - fn bid_collateral_auction() -> Weight { - (493_957_000 as Weight) - .saturating_add(DbWeight::get().reads(12 as Weight)) - .saturating_add(DbWeight::get().writes(12 as Weight)) - } - fn on_finalize(c: u32) -> Weight { - (50_992_000 as Weight) - .saturating_add((171_653_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().reads((4 as Weight).saturating_mul(c as Weight))) - .saturating_add(DbWeight::get().writes(2 as Weight)) - .saturating_add(DbWeight::get().writes((3 as Weight).saturating_mul(c as Weight))) - } -} diff --git a/auction/src/lib.rs b/auction/src/lib.rs index 53b40f31c..69aefa886 100644 --- a/auction/src/lib.rs +++ b/auction/src/lib.rs @@ -21,21 +21,17 @@ use sp_runtime::{ DispatchError, DispatchResult, }; -mod default_weight; mod mock; mod tests; +mod weights; pub use module::*; +pub use weights::WeightInfo; #[frame_support::pallet] pub mod module { use super::*; - pub trait WeightInfo { - fn bid_collateral_auction() -> Weight; - fn on_finalize(c: u32) -> Weight; - } - #[pallet::config] pub trait Config: frame_system::Config { type Event: From> + IsType<::Event>; @@ -95,7 +91,7 @@ pub mod module { StorageDoubleMap<_, Twox64Concat, T::BlockNumber, Blake2_128Concat, T::AuctionId, (), OptionQuery>; #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet { diff --git a/auction/src/weights.rs b/auction/src/weights.rs new file mode 100644 index 000000000..9dcb4f32d --- /dev/null +++ b/auction/src/weights.rs @@ -0,0 +1,53 @@ +//! Autogenerated weights for orml_auction +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-05-04, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// /Users/xiliangchen/projects/acala/target/release/acala +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=orml_auction +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./auction/src/weights.rs +// --template +// ../templates/orml-weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for orml_auction. +pub trait WeightInfo { + fn bid_collateral_auction() -> Weight; + fn on_finalize(c: u32, ) -> Weight; +} + +/// Default weights. +impl WeightInfo for () { + fn bid_collateral_auction() -> Weight { + (108_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes(9 as Weight)) + } + fn on_finalize(c: u32, ) -> Weight { + (9_779_000 as Weight) + // Standard Error: 13_000 + .saturating_add((57_962_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(c as Weight))) + } +} diff --git a/authority/Cargo.toml b/authority/Cargo.toml index ecd262d0d..3a3a432df 100644 --- a/authority/Cargo.toml +++ b/authority/Cargo.toml @@ -17,10 +17,6 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" frame-support = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } - -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } @@ -35,7 +31,6 @@ std = [ "sp-std/std", "frame-support/std", "frame-system/std", - "orml-traits/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", diff --git a/authority/src/default_weight.rs b/authority/src/default_weight.rs deleted file mode 100644 index 802a567bb..000000000 --- a/authority/src/default_weight.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Weights for orml_authority -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 -//! DATE: 2020-11-18, STEPS: [1, ], REPEAT: 1, LOW RANGE: [], HIGH RANGE: [] -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB -//! CACHE: 128 - -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; -use sp_std::marker::PhantomData; - -/// Weight functions for orml_authority. -impl crate::WeightInfo for () { - fn dispatch_as() -> Weight { - (48_680_000 as Weight) - } - fn schedule_dispatch_without_delay() -> Weight { - (121_510_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) - } - fn schedule_dispatch_with_delay() -> Weight { - (130_696_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) - } - fn fast_track_scheduled_dispatch() -> Weight { - (145_530_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) - } - fn delay_scheduled_dispatch() -> Weight { - (145_169_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) - } - fn cancel_scheduled_dispatch() -> Weight { - (104_990_000 as Weight) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) - } -} diff --git a/authority/src/lib.rs b/authority/src/lib.rs index 6481a2c01..ef4aec224 100644 --- a/authority/src/lib.rs +++ b/authority/src/lib.rs @@ -35,9 +35,11 @@ use sp_runtime::{ }; use sp_std::prelude::*; -mod default_weight; mod mock; mod tests; +mod weights; + +pub use weights::WeightInfo; /// A delayed origin. Can only be dispatched via `dispatch_as` with a delay. #[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode)] @@ -120,15 +122,6 @@ pub use module::*; pub mod module { use super::*; - pub trait WeightInfo { - fn dispatch_as() -> Weight; - fn schedule_dispatch_without_delay() -> Weight; - fn schedule_dispatch_with_delay() -> Weight; - fn fast_track_scheduled_dispatch() -> Weight; - fn delay_scheduled_dispatch() -> Weight; - fn cancel_scheduled_dispatch() -> Weight; - } - /// Origin for the authority module. pub type Origin = DelayedOrigin<::BlockNumber, ::PalletsOrigin>; pub(crate) type CallOf = ::Call; @@ -202,7 +195,7 @@ pub mod module { pub type NextTaskIndex = StorageValue<_, ScheduleTaskIndex, ValueQuery>; #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet {} diff --git a/authority/src/weights.rs b/authority/src/weights.rs new file mode 100644 index 000000000..59c1354f1 --- /dev/null +++ b/authority/src/weights.rs @@ -0,0 +1,71 @@ +//! Autogenerated weights for orml_authority +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-05-04, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// /Users/xiliangchen/projects/acala/target/release/acala +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=orml_authority +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./authority/src/weights.rs +// --template +// ../templates/orml-weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for orml_authority. +pub trait WeightInfo { + fn dispatch_as() -> Weight; + fn schedule_dispatch_without_delay() -> Weight; + fn schedule_dispatch_with_delay() -> Weight; + fn fast_track_scheduled_dispatch() -> Weight; + fn delay_scheduled_dispatch() -> Weight; + fn cancel_scheduled_dispatch() -> Weight; +} + +/// Default weights. +impl WeightInfo for () { + fn dispatch_as() -> Weight { + (10_000_000 as Weight) + } + fn schedule_dispatch_without_delay() -> Weight { + (28_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn schedule_dispatch_with_delay() -> Weight { + (29_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn fast_track_scheduled_dispatch() -> Weight { + (36_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn delay_scheduled_dispatch() -> Weight { + (36_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn cancel_scheduled_dispatch() -> Weight { + (24_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } +} diff --git a/benchmarking/Cargo.toml b/benchmarking/Cargo.toml index 5727669c6..7fc86eb67 100644 --- a/benchmarking/Cargo.toml +++ b/benchmarking/Cargo.toml @@ -9,20 +9,19 @@ edition = "2018" [dependencies] serde = { version = "1.0.124", optional = true } -paste = "0.1.16" +paste = "1.0" codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } +sp-storage = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] +frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } hex-literal = "0.2.1" [features] @@ -35,7 +34,6 @@ std = [ "sp-api/std", "sp-std/std", "frame-support/std", - "frame-system/std", "frame-benchmarking/std", ] diff --git a/benchmarking/src/lib.rs b/benchmarking/src/lib.rs index 0755894cd..332f452e6 100644 --- a/benchmarking/src/lib.rs +++ b/benchmarking/src/lib.rs @@ -7,16 +7,22 @@ mod tests; pub use frame_benchmarking::{ benchmarking, whitelisted_caller, BenchmarkBatch, BenchmarkConfig, BenchmarkParameter, BenchmarkResults, - Benchmarking, BenchmarkingSetup, TrackedStorageKey, + Benchmarking, BenchmarkingSetup, }; #[cfg(feature = "std")] pub use frame_benchmarking::{Analysis, BenchmarkSelector}; +#[doc(hidden)] pub use frame_support; +#[doc(hidden)] pub use paste; #[doc(hidden)] pub use sp_io::storage::root as storage_root; +#[doc(hidden)] pub use sp_runtime::traits::Zero; - +#[doc(hidden)] +pub use sp_std::{self, boxed::Box, prelude::Vec, vec}; +#[doc(hidden)] +pub use sp_storage::TrackedStorageKey; /// Construct pallet benchmarks for weighing dispatchables. /// /// Works around the idea of complexity parameters, named by a single letter @@ -54,11 +60,6 @@ pub use sp_runtime::traits::Zero; /// for arbitrary expresions to be evaluated in a benchmark (including for /// example, `on_initialize`). /// -/// The macro allows for common parameters whose ranges and instancing -/// expressions may be drawn upon (or not) by each arm. Syntax is available to -/// allow for only the range to be drawn upon if desired, allowing an -/// alternative instancing expression to be given. -/// /// Note that the ranges are *inclusive* on both sides. This is in contrast to /// ranges in Rust which are left-inclusive right-exclusive. /// @@ -68,9 +69,6 @@ pub use sp_runtime::traits::Zero; /// between the two pre- and post- code blocks, but do not leak from the /// interior of any instancing expressions. /// -/// Any common parameters that are unused in an arm do not have their instancing -/// expressions evaluated. -/// /// Example: /// ```ignore /// use path_to_node_runtime::MyRuntime; @@ -87,21 +85,20 @@ pub use sp_runtime::traits::Zero; /// // size `l`, which we allow to be initialized as usual. /// foo { /// let caller = account::(b"caller", 0, benchmarks_seed); -/// let l = ...; +/// let l in 1 .. MAX_LENGTH => initialize_l(l); /// }: _(Origin::Signed(caller), vec![0u8; l]) /// /// // second dispatchable: bar; this is a root dispatchable and accepts a `u8` vector of size -/// // `l`. We don't want it pre-initialized like before so we override using the `=> ()` notation. +/// // `l`. /// // In this case, we explicitly name the call using `bar` instead of `_`. /// bar { -/// let l = _ .. _ => (); +/// let l in 1 .. MAX_LENGTH => initialize_l(l); /// }: bar(Origin::Root, vec![0u8; l]) /// /// // third dispatchable: baz; this is a user dispatchable. It isn't dependent on length like the /// // other two but has its own complexity `c` that needs setting up. It uses `caller` (in the /// // pre-instancing block) within the code block. This is only allowed in the param instancers -/// // of arms. Instancers of common params cannot optimistically draw upon hypothetical variables -/// // that the arm's pre-instancing code block might have declared. +/// // of arms. /// baz1 { /// let caller = account::(b"caller", 0, benchmarks_seed); /// let c = 0 .. 10 => setup_c(&caller, c); @@ -168,18 +165,12 @@ pub use sp_runtime::traits::Zero; macro_rules! runtime_benchmarks { ( { $runtime:ident, $pallet:ident } - _ { - $( - let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; - )* - } $( $rest:tt )* ) => { $crate::benchmarks_iter!( { } $runtime $pallet - { $( { $common , $common_from , $common_to , $common_instancer } )* } ( ) ( ) $( $rest )* @@ -192,18 +183,12 @@ macro_rules! runtime_benchmarks { macro_rules! runtime_benchmarks_instance { ( { $runtime:ident, $pallet:ident, $instance:ident } - _ { - $( - let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; - )* - } $( $rest:tt )* ) => { $crate::benchmarks_iter!( { $instance } $runtime $pallet - { $( { $common , $common_from , $common_to , $common_instancer } )* } ( ) ( ) $( $rest )* @@ -219,7 +204,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) #[extra] @@ -230,7 +214,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* ) ( $( $names_extra )* $name ) $name @@ -242,7 +225,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) // This contains $( $( { $instance } )? $name:ident )* ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* ) @@ -253,7 +235,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $name ( $origin $( , $arg )* ) @@ -266,7 +247,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* ) @@ -277,7 +257,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: { @@ -297,7 +276,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $eval:block @@ -309,7 +287,6 @@ macro_rules! benchmarks_iter { $name $runtime $pallet - { $( $common )* } { } { $eval } { $( $code )* } @@ -328,7 +305,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* { $( $instance )? } $name ) ( $( $names_extra )* ) $( $rest )* @@ -339,7 +315,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) ) => { @@ -362,7 +337,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* ) @@ -372,7 +346,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: _ ( $origin $( , $arg )* ) @@ -385,7 +358,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* ) @@ -395,7 +367,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $dispatch ( $origin $( , $arg )* ) @@ -408,7 +379,6 @@ macro_rules! benchmarks_iter { { $( $instance:ident )? } $runtime:ident $pallet:ident - { $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $eval:block @@ -418,7 +388,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $runtime $pallet - { $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $eval @@ -437,7 +406,6 @@ macro_rules! benchmark_backend { $name:ident $runtime:ident $pallet:ident - { $( $common:tt )* } { $( PRE { $( $pre_parsed:tt )* } )* } { $eval:block } { @@ -451,7 +419,6 @@ macro_rules! benchmark_backend { $name $runtime $pallet - { $( $common )* } { $( PRE { $( $pre_parsed )* } )* PRE { $pre_id , $pre_ty , $pre_ex } @@ -466,7 +433,6 @@ macro_rules! benchmark_backend { $name:ident $runtime:ident $pallet:ident - { $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -480,7 +446,6 @@ macro_rules! benchmark_backend { $name $runtime $pallet - { $( $common )* } { $( $parsed )* PARAM { $param , $param_from , $param_to , $param_instancer } @@ -490,79 +455,12 @@ macro_rules! benchmark_backend { $postcode } }; - // mutation arm to look after defaulting to a common param - ( - { $( $instance:ident )? } - $name:ident - $runtime:ident - $pallet:ident - { $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } - { $( $parsed:tt )* } - { $eval:block } - { - let $param:ident in ...; - $( $rest:tt )* - } - $postcode:block - ) => { - $crate::benchmark_backend! { - { $( $instance)? } - $name - $runtime - $pallet - { $( { $common , $common_from , $common_to , $common_instancer } )* } - { $( $parsed )* } - { $eval } - { - let $param - in ({ $( let $common = $common_from; )* $param }) - .. ({ $( let $common = $common_to; )* $param }) - => ({ $( let $common = || -> Result<(), &'static str> { $common_instancer ; Ok(()) }; )* $param()? }); - $( $rest )* - } - $postcode - } - }; - // mutation arm to look after defaulting only the range to common param - ( - { $( $instance:ident )? } - $name:ident - $runtime:ident - $pallet:ident - { $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } - { $( $parsed:tt )* } - { $eval:block } - { - let $param:ident in _ .. _ => $param_instancer:expr ; - $( $rest:tt )* - } - $postcode:block - ) => { - $crate::benchmark_backend! { - { $( $instance)? } - $name - $runtime - $pallet - { $( { $common , $common_from , $common_to , $common_instancer } )* } - { $( $parsed )* } - { $eval } - { - let $param - in ({ $( let $common = $common_from; )* $param }) - .. ({ $( let $common = $common_to; )* $param }) - => $param_instancer ; - $( $rest )* - } - $postcode - } - }; // mutation arm to look after a single tt for param_from. ( { $( $instance:ident )? } $name:ident $runtime:ident $pallet:ident - { $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -576,7 +474,6 @@ macro_rules! benchmark_backend { $name $runtime $pallet - { $( $common )* } { $( $parsed )* } { $eval } { @@ -592,7 +489,6 @@ macro_rules! benchmark_backend { $name:ident $runtime:ident $pallet:ident - { $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -606,7 +502,6 @@ macro_rules! benchmark_backend { $name $runtime $pallet - { $( $common )* } { $( $parsed )* } { $eval } { @@ -622,7 +517,6 @@ macro_rules! benchmark_backend { $name:ident $runtime:ident $pallet:ident - { $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -636,7 +530,6 @@ macro_rules! benchmark_backend { $name $runtime $pallet - { $( $common )* } { $( $parsed )* } { $eval } { @@ -652,7 +545,6 @@ macro_rules! benchmark_backend { $name:ident $runtime:ident $pallet:ident - { $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( PRE { $pre_id:tt , $pre_ty:ty , $pre_ex:expr } )* $( PARAM { $param:ident , $param_from:expr , $param_to:expr , $param_instancer:expr } )* @@ -665,8 +557,8 @@ macro_rules! benchmark_backend { struct $name; #[allow(unused_variables)] impl $crate::BenchmarkingSetup<$runtime $(, $instance)?> for $name { - fn components(&self) -> Vec<($crate::BenchmarkParameter, u32, u32)> { - vec! [ + fn components(&self) -> $crate::Vec<($crate::BenchmarkParameter, u32, u32)> { + $crate::vec! [ $( ($crate::BenchmarkParameter::$param, $param_from, $param_to) ),* @@ -677,10 +569,7 @@ macro_rules! benchmark_backend { &self, components: &[($crate::BenchmarkParameter, u32)], verify: bool - ) -> Result Result<(), &'static str>>, &'static str> { - $( - let $common = $common_from; - )* + ) -> Result<$crate::Box Result<(), &'static str>>, &'static str> { $( // Prepare instance let $param = components.iter() @@ -694,7 +583,7 @@ macro_rules! benchmark_backend { $( $param_instancer ; )* $( $post )* - Ok(Box::new(move || -> Result<(), &'static str> { + Ok($crate::Box::new(move || -> Result<(), &'static str> { $eval; if verify { $postcode; @@ -737,7 +626,7 @@ macro_rules! selected_benchmark { // Allow us to select a benchmark from the list of available benchmarks. impl $crate::BenchmarkingSetup<$runtime $(, $instance)?> for SelectedBenchmark { - fn components(&self) -> Vec<($crate::BenchmarkParameter, u32, u32)> { + fn components(&self) -> $crate::Vec<($crate::BenchmarkParameter, u32, u32)> { match self { $( Self::$bench => < @@ -751,9 +640,7 @@ macro_rules! selected_benchmark { &self, components: &[($crate::BenchmarkParameter, u32)], verify: bool - ) - -> Result Result<(), &'static str>>, &'static str> - { + ) -> Result<$crate::Box Result<(), &'static str>>, &'static str> { match self { $( Self::$bench => < @@ -779,8 +666,8 @@ macro_rules! impl_benchmark { pub struct Benchmark; impl $crate::Benchmarking<$crate::BenchmarkResults> for Benchmark { - fn benchmarks(extra: bool) -> Vec<&'static [u8]> { - let mut all = vec![ $( stringify!($name).as_ref() ),* ]; + fn benchmarks(extra: bool) -> $crate::Vec<&'static [u8]> { + let mut all = $crate::vec![ $( stringify!($name).as_ref() ),* ]; if !extra { let extra = [ $( stringify!($name_extra).as_ref() ),* ]; all.retain(|x| !extra.contains(x)); @@ -796,15 +683,15 @@ macro_rules! impl_benchmark { repeat: u32, whitelist: &[$crate::TrackedStorageKey], verify: bool, - ) -> Result, &'static str> { + ) -> Result<$crate::Vec<$crate::BenchmarkResults>, &'static str> { // Map the input to the selected benchmark. - let extrinsic = sp_std::str::from_utf8(extrinsic) + let extrinsic = $crate::sp_std::str::from_utf8(extrinsic) .map_err(|_| "`extrinsic` is not a valid utf8 string!")?; let selected_benchmark = match extrinsic { $( stringify!($name) => SelectedBenchmark::$name, )* _ => return Err("Could not find extrinsic."), }; - let mut results: Vec<$crate::BenchmarkResults> = Vec::new(); + let mut results: $crate::Vec<$crate::BenchmarkResults> = $crate::Vec::new(); if repeat == 0 { return Ok(results); } @@ -812,7 +699,7 @@ macro_rules! impl_benchmark { // Add whitelist to DB including whitelisted caller let mut whitelist = whitelist.to_vec(); let whitelisted_caller_key = - as frame_support::storage::StorageMap<_,_>>::hashed_key_for( + as $crate::frame_support::storage::StorageMap<_,_>>::hashed_key_for( $crate::whitelisted_caller::<<$runtime as frame_system::Config>::AccountId>() ); whitelist.push(whitelisted_caller_key.into()); @@ -832,7 +719,7 @@ macro_rules! impl_benchmark { let repeat_benchmark = | repeat: u32, c: &[($crate::BenchmarkParameter, u32)], - results: &mut Vec<$crate::BenchmarkResults>, + results: &mut $crate::Vec<$crate::BenchmarkResults>, verify: bool, | -> Result<(), &'static str> { // Run the benchmark `repeat` times. @@ -859,7 +746,7 @@ macro_rules! impl_benchmark { closure_to_benchmark()?; } else { // Time the extrinsic logic. - frame_support::log::trace!( + $crate::frame_support::log::trace!( target: "benchmark", "Start Benchmark: {:?}", c ); @@ -881,12 +768,12 @@ macro_rules! impl_benchmark { // Commit the changes to get proper write count $crate::benchmarking::commit_db(); - frame_support::log::trace!( + $crate::frame_support::log::trace!( target: "benchmark", "End Benchmark: {} ns", elapsed_extrinsic ); let read_write_count = $crate::benchmarking::read_write_count(); - frame_support::log::trace!( + $crate::frame_support::log::trace!( target: "benchmark", "Read/Write Count {:?}", read_write_count ); @@ -919,7 +806,7 @@ macro_rules! impl_benchmark { if components.is_empty() { if verify { // If `--verify` is used, run the benchmark once to verify it would complete. - repeat_benchmark(1, Default::default(), &mut Vec::new(), true)?; + repeat_benchmark(1, Default::default(), &mut $crate::Vec::new(), true)?; } repeat_benchmark(repeat, Default::default(), &mut results, false)?; } else { @@ -946,7 +833,7 @@ macro_rules! impl_benchmark { let component_value = lowest + step_size * s; // Select the max value for all the other components. - let c: Vec<($crate::BenchmarkParameter, u32)> = components.iter() + let c: $crate::Vec<($crate::BenchmarkParameter, u32)> = components.iter() .enumerate() .map(|(idx, (n, _, h))| if n == name { @@ -959,7 +846,7 @@ macro_rules! impl_benchmark { if verify { // If `--verify` is used, run the benchmark once to verify it would complete. - repeat_benchmark(1, &c, &mut Vec::new(), true)?; + repeat_benchmark(1, &c, &mut $crate::Vec::new(), true)?; } repeat_benchmark(repeat, &c, &mut results, false)?; } @@ -968,6 +855,28 @@ macro_rules! impl_benchmark { return Ok(results); } } + + /// Test a particular benchmark by name. + /// + /// This isn't called `test_benchmark_by_name` just in case some end-user eventually + /// writes a benchmark, itself called `by_name`; the function would be shadowed in + /// that case. + /// + /// This is generally intended to be used by child test modules such as those created + /// by the `impl_benchmark_test_suite` macro. However, it is not an error if a pallet + /// author chooses not to implement benchmarks. + #[cfg(test)] + #[allow(unused)] + fn test_bench_by_name(name: &[u8]) -> Result<(), &'static str> { + let name = $crate::sp_std::str::from_utf8(name) + .map_err(|_| "`name` is not a valid utf8 string!")?; + match name { + $( stringify!($name) => { + $crate::paste::paste! { [< test_benchmark_ $name >]() } + } )* + _ => Err("Could not find test for requested benchmark."), + } + } }; } @@ -992,7 +901,7 @@ macro_rules! impl_benchmark_test { >::components(&selected_benchmark); let execute_benchmark = | - c: Vec<($crate::BenchmarkParameter, u32)> + c: $crate::Vec<($crate::BenchmarkParameter, u32)> | -> Result<(), &'static str> { // Set up the benchmark, return execution + verification function. let closure_to_verify = < @@ -1018,9 +927,9 @@ macro_rules! impl_benchmark_test { } else { for (_, (name, low, high)) in components.iter().enumerate() { // Test only the low and high value, assuming values in the middle won't break - for component_value in vec![low, high] { + for component_value in $crate::vec![low, high] { // Select the max value for all the other components. - let c: Vec<($crate::BenchmarkParameter, u32)> = components.iter() + let c: $crate::Vec<($crate::BenchmarkParameter, u32)> = components.iter() .enumerate() .map(|(_, (n, _, h))| if n == name { @@ -1041,6 +950,239 @@ macro_rules! impl_benchmark_test { }; } +/// This creates a test suite which runs the module's benchmarks. +/// +/// When called in `pallet_example` as +/// +/// ```rust,ignore +/// impl_benchmark_test_suite!(crate::tests::new_test_ext()); +/// ``` +/// +/// It expands to the equivalent of: +/// +/// ```rust,ignore +/// #[cfg(test)] +/// mod tests { +/// use super::*; +/// use crate::tests::new_test_ext; +/// use frame_support::assert_ok; +/// +/// #[test] +/// fn test_benchmarks() { +/// new_test_ext().execute_with(|| { +/// assert_ok!(test_benchmark_accumulate_dummy()); +/// assert_ok!(test_benchmark_set_dummy()); +/// assert_ok!(test_benchmark_another_set_dummy()); +/// assert_ok!(test_benchmark_sort_vector()); +/// }); +/// } +/// } +/// ``` +/// +/// ## Arguments +/// +/// The first argument, `new_test_ext`, must be a function call which returns +/// either a `sp_io::TestExternalities`, or some other type with a similar +/// interface. +/// +/// Note that this function call is _not_ evaluated at compile time, but is +/// instead copied textually into each appropriate invocation site. +/// +/// There is an optional second argument, with keyword syntax: `benchmarks_path +/// = path_to_benchmarks_invocation`. In the typical case in which this macro is +/// in the same module as the `benchmarks!` invocation, you don't need to supply +/// this. However, if the `impl_benchmark_test_suite!` invocation is in a +/// different module than the `runtime_benchmarks!` invocation, then you should +/// provide the path to the module containing the `benchmarks!` invocation: +/// +/// ```rust,ignore +/// mod benches { +/// runtime_benchmarks!{ +/// ... +/// } +/// } +/// +/// mod tests { +/// // because of macro syntax limitations, benches can't be paths, but has +/// // to be idents in the scope of `impl_benchmark_test_suite`. +/// use crate::benches; +/// +/// impl_benchmark_test_suite!(new_test_ext(), benchmarks_path = benches); +/// +/// // new_test_ext are defined later in this module +/// } +/// ``` +/// +/// There is an optional 3rd argument, with keyword syntax: `extra = true` or +/// `extra = false`. By default, this generates a test suite which iterates over +/// all benchmarks, including those marked with the `#[extra]` annotation. +/// Setting `extra = false` excludes those. +/// +/// There is an optional 4th argument, with keyword syntax: `exec_name = +/// custom_exec_name`. By default, this macro uses `execute_with` for this +/// parameter. This argument, if set, is subject to these restrictions: +/// +/// - It must be the name of a method applied to the output of the +/// `new_test_ext` argument. +/// - That method must have a signature capable of receiving a single argument +/// of the form `impl FnOnce()`. +#[macro_export] +macro_rules! impl_benchmark_test_suite { + // user might or might not have set some keyword arguments; set the defaults + // + // The weird syntax indicates that `rest` comes only after a comma, which is otherwise optional + ( + $new_test_ext:expr, + $(, $( $rest:tt )* )? + ) => { + impl_benchmark_test_suite!( + @selected: + $new_test_ext, + benchmarks_path = super, + extra = true, + exec_name = execute_with, + @user: + $( $( $rest )* )? + ); + }; + // pick off the benchmarks_path keyword argument + ( + @selected: + $new_test_ext:expr, + benchmarks_path = $old:ident, + extra = $extra:expr, + exec_name = $exec_name:ident, + @user: + benchmarks_path = $benchmarks_path:ident + $(, $( $rest:tt )* )? + ) => { + impl_benchmark_test_suite!( + @selected: + $new_test_ext, + benchmarks_path = $benchmarks_path, + extra = $extra, + exec_name = $exec_name, + @user: + $( $( $rest )* )? + ); + }; + // pick off the extra keyword argument + ( + @selected: + $new_test_ext:expr, + benchmarks_path = $benchmarks_path:ident, + extra = $old:expr, + exec_name = $exec_name:ident, + @user: + extra = $extra:expr + $(, $( $rest:tt )* )? + ) => { + impl_benchmark_test_suite!( + @selected: + $new_test_ext, + benchmarks_path = $benchmarks_path, + extra = $extra, + exec_name = $exec_name, + @user: + $( $( $rest )* )? + ); + }; + // pick off the exec_name keyword argument + ( + @selected: + $new_test_ext:expr, + benchmarks_path = $benchmarks_path:ident, + extra = $extra:expr, + exec_name = $old:ident, + @user: + exec_name = $exec_name:ident + $(, $( $rest:tt )* )? + ) => { + impl_benchmark_test_suite!( + @selected: + $new_test_ext, + benchmarks_path = $benchmarks_path, + extra = $extra, + exec_name = $exec_name, + @user: + $( $( $rest )* )? + ); + }; + // all options set; nothing else in user-provided keyword arguments + ( + @selected: + $new_test_ext:expr, + benchmarks_path = $path_to_benchmarks_invocation:ident, + extra = $extra:expr, + exec_name = $exec_name:ident, + @user: + $(,)? + ) => { + #[cfg(test)] + mod benchmark_tests { + use $path_to_benchmarks_invocation::test_bench_by_name; + use super::*; + + #[test] + fn test_benchmarks() { + $new_test_ext.$exec_name(|| { + use $crate::Benchmarking; + + let mut anything_failed = false; + println!("failing benchmark tests:"); + for benchmark_name in $path_to_benchmarks_invocation::Benchmark::benchmarks($extra) { + match std::panic::catch_unwind(|| test_bench_by_name(benchmark_name)) { + Err(err) => { + println!("{}: {:?}", String::from_utf8_lossy(benchmark_name), err); + anything_failed = true; + }, + Ok(Err(err)) => { + println!("{}: {}", String::from_utf8_lossy(benchmark_name), err); + anything_failed = true; + }, + Ok(Ok(_)) => (), + } + } + assert!(!anything_failed); + }); + } + } + }; +} + +/// show error message and debugging info for the case of an error happening +/// during a benchmark +#[allow(clippy::too_many_arguments)] +pub fn show_benchmark_debug_info( + instance_string: &[u8], + benchmark: &[u8], + lowest_range_values: &[u32], + highest_range_values: &[u32], + steps: &[u32], + repeat: &u32, + verify: &bool, + error_message: &str, +) -> sp_runtime::RuntimeString { + sp_runtime::format_runtime_string!( + "\n* Pallet: {}\n\ + * Benchmark: {}\n\ + * Lowest_range_values: {:?}\n\ + * Highest_range_values: {:?}\n\ + * Steps: {:?}\n\ + * Repeat: {:?}\n\ + * Verify: {:?}\n\ + * Error message: {}", + sp_std::str::from_utf8(instance_string).expect("it's all just strings ran through the wasm interface. qed"), + sp_std::str::from_utf8(benchmark).expect("it's all just strings ran through the wasm interface. qed"), + lowest_range_values, + highest_range_values, + steps, + repeat, + verify, + error_message, + ) +} + /// This macro adds pallet benchmarks to a `Vec` object. /// /// First create an object that holds in the input parameters for the benchmark: @@ -1050,15 +1192,15 @@ macro_rules! impl_benchmark_test { /// ``` /// /// The `whitelist` is a parameter you pass to control the DB read/write -/// tracking. We use a vector of [TrackedStorageKey], which is a simple struct -/// used to set if a key has been read or written to. +/// tracking. We use a vector of +/// [TrackedStorageKey](./struct.TrackedStorageKey.html), which is a simple +/// struct used to set if a key has been read or written to. /// /// For values that should be skipped entirely, we can just pass `key.into()`. /// For example: /// /// ``` /// use frame_benchmarking::TrackedStorageKey; -/// use hex_literal; /// let whitelist: Vec = vec![ /// // Block Number /// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), @@ -1106,7 +1248,9 @@ macro_rules! add_benchmark { if &pallet[..] == &b"*"[..] || &benchmark[..] == &b"*"[..] { for benchmark in $( $location )*::Benchmark::benchmarks(*extra).into_iter() { $batches.push($crate::BenchmarkBatch { + pallet: name_string.to_vec(), instance: instance_string.to_vec(), + benchmark: benchmark.to_vec(), results: $( $location )*::Benchmark::run_benchmark( benchmark, &lowest_range_values[..], @@ -1115,14 +1259,25 @@ macro_rules! add_benchmark { *repeat, whitelist, *verify, - )?, - pallet: name_string.to_vec(), - benchmark: benchmark.to_vec(), - }); + ).map_err(|e| { + $crate::show_benchmark_debug_info( + instance_string, + benchmark, + lowest_range_values, + highest_range_values, + steps, + repeat, + verify, + e, + ) + })?, + }); } } else { $batches.push($crate::BenchmarkBatch { + pallet: name_string.to_vec(), instance: instance_string.to_vec(), + benchmark: benchmark.clone(), results: $( $location )*::Benchmark::run_benchmark( &benchmark[..], &lowest_range_values[..], @@ -1131,11 +1286,29 @@ macro_rules! add_benchmark { *repeat, whitelist, *verify, - )?, - pallet: name_string.to_vec(), - benchmark: benchmark.clone(), + ).map_err(|e| { + $crate::show_benchmark_debug_info( + instance_string, + benchmark, + lowest_range_values, + highest_range_values, + steps, + repeat, + verify, + e, + ) + })?, }); } } ) } + +#[macro_export] +macro_rules! whitelist_account { + ($acc:ident) => { + frame_benchmarking::benchmarking::add_to_whitelist( + frame_system::Account::::hashed_key_for(&$acc).into(), + ); + }; +} diff --git a/benchmarking/src/tests.rs b/benchmarking/src/tests.rs index 333a776cb..56717b50c 100644 --- a/benchmarking/src/tests.rs +++ b/benchmarking/src/tests.rs @@ -100,7 +100,6 @@ construct_runtime!( { System: frame_system::{Pallet, Call, Storage, Config, Event}, Pallet: test::{Pallet, Call, Storage, Config}, - } ); @@ -116,13 +115,8 @@ fn new_test_ext() -> sp_io::TestExternalities { runtime_benchmarks! { { Test, test } - _ { - // Define a common range for `b`. - let b in 1 .. 1000 => (); - } - set_value { - let b in ...; + let b in 1 .. 1000; let caller = account::("caller", 0, 0); }: _ (RawOrigin::Signed(caller), b.into()) verify { @@ -130,7 +124,7 @@ runtime_benchmarks! { } other_name { - let b in ...; + let b in 1 .. 1000; }: dummy (RawOrigin::None, b.into()) sort_vector { @@ -146,7 +140,7 @@ runtime_benchmarks! { } bad_origin { - let b in ...; + let b in 1 .. 1000; let caller = account::("caller", 0, 0); }: dummy (RawOrigin::Signed(caller), b.into()) diff --git a/currencies/Cargo.toml b/currencies/Cargo.toml index a58fd4cf8..da5f2e0b4 100644 --- a/currencies/Cargo.toml +++ b/currencies/Cargo.toml @@ -20,8 +20,6 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "roco orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } diff --git a/currencies/src/lib.rs b/currencies/src/lib.rs index adf09dfd2..cec25c405 100644 --- a/currencies/src/lib.rs +++ b/currencies/src/lib.rs @@ -49,8 +49,8 @@ use frame_support::{ }; use frame_system::{ensure_root, ensure_signed, pallet_prelude::*}; use orml_traits::{ - account::MergeAccount, arithmetic::{Signed, SimpleArithmetic}, + currency::TransferAll, BalanceStatus, BasicCurrency, BasicCurrencyExtended, BasicLockableCurrency, BasicReservableCurrency, LockIdentifier, MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency, MultiReservableCurrency, }; @@ -65,24 +65,17 @@ use sp_std::{ marker, result, }; -mod default_weight; mod mock; mod tests; +mod weights; pub use module::*; +pub use weights::WeightInfo; #[frame_support::pallet] pub mod module { use super::*; - pub trait WeightInfo { - fn transfer_non_native_currency() -> Weight; - fn transfer_native_currency() -> Weight; - fn update_balance_non_native_currency() -> Weight; - fn update_balance_native_currency_creating() -> Weight; - fn update_balance_native_currency_killing() -> Weight; - } - pub(crate) type BalanceOf = <::MultiCurrency as MultiCurrency<::AccountId>>::Balance; pub(crate) type CurrencyIdOf = @@ -94,7 +87,7 @@ pub mod module { pub trait Config: frame_system::Config { type Event: From> + IsType<::Event>; - type MultiCurrency: MergeAccount + type MultiCurrency: TransferAll + MultiCurrencyExtended + MultiLockableCurrency + MultiReservableCurrency; @@ -132,7 +125,7 @@ pub mod module { } #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet {} @@ -685,14 +678,11 @@ where } } -impl MergeAccount for Pallet { - fn merge_account(source: &T::AccountId, dest: &T::AccountId) -> DispatchResult { +impl TransferAll for Pallet { + fn transfer_all(source: &T::AccountId, dest: &T::AccountId) -> DispatchResult { with_transaction_result(|| { // transfer non-native free to dest - T::MultiCurrency::merge_account(source, dest)?; - - // unreserve all reserved currency - T::NativeCurrency::unreserve(source, T::NativeCurrency::reserved_balance(source)); + T::MultiCurrency::transfer_all(source, dest)?; // transfer all free to dest T::NativeCurrency::transfer(source, dest, T::NativeCurrency::free_balance(source)) diff --git a/currencies/src/weights.rs b/currencies/src/weights.rs new file mode 100644 index 000000000..a75ebb239 --- /dev/null +++ b/currencies/src/weights.rs @@ -0,0 +1,67 @@ +//! Autogenerated weights for module_currencies +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-05-04, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// /Users/xiliangchen/projects/acala/target/release/acala +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=module_currencies +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./currencies/src/weights.rs +// --template +// ../templates/orml-weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for module_currencies. +pub trait WeightInfo { + fn transfer_non_native_currency() -> Weight; + fn transfer_native_currency() -> Weight; + fn update_balance_non_native_currency() -> Weight; + fn update_balance_native_currency_creating() -> Weight; + fn update_balance_native_currency_killing() -> Weight; +} + +/// Default weights. +impl WeightInfo for () { + fn transfer_non_native_currency() -> Weight { + (60_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn transfer_native_currency() -> Weight { + (60_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn update_balance_non_native_currency() -> Weight { + (29_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn update_balance_native_currency_creating() -> Weight { + (31_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn update_balance_native_currency_killing() -> Weight { + (37_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } +} diff --git a/gradually-update/Cargo.toml b/gradually-update/Cargo.toml index 1bde0d610..b9d11b63b 100644 --- a/gradually-update/Cargo.toml +++ b/gradually-update/Cargo.toml @@ -17,8 +17,6 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [features] default = ["std"] std = [ diff --git a/gradually-update/src/lib.rs b/gradually-update/src/lib.rs index 2167fe187..9479e766e 100644 --- a/gradually-update/src/lib.rs +++ b/gradually-update/src/lib.rs @@ -112,7 +112,7 @@ pub mod module { pub(crate) type LastUpdatedAt = StorageValue<_, T::BlockNumber, ValueQuery>; #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet { diff --git a/nft/Cargo.toml b/nft/Cargo.toml index 35f1b3cee..6866cac4b 100644 --- a/nft/Cargo.toml +++ b/nft/Cargo.toml @@ -20,8 +20,6 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "roco sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [features] default = ["std"] std = [ diff --git a/nft/src/lib.rs b/nft/src/lib.rs index 19110231b..ba6b831ef 100644 --- a/nft/src/lib.rs +++ b/nft/src/lib.rs @@ -168,7 +168,7 @@ pub mod module { } #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet {} diff --git a/oracle/Cargo.toml b/oracle/Cargo.toml index 54e7bde93..5ba51042e 100644 --- a/oracle/Cargo.toml +++ b/oracle/Cargo.toml @@ -21,8 +21,6 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "roco orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } diff --git a/oracle/rpc/Cargo.toml b/oracle/rpc/Cargo.toml index d64349197..c27a5d01c 100644 --- a/oracle/rpc/Cargo.toml +++ b/oracle/rpc/Cargo.toml @@ -16,5 +16,3 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } orml-oracle-rpc-runtime-api = { path = "runtime-api", version = "0.4.1-dev" } - -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 diff --git a/oracle/rpc/runtime-api/Cargo.toml b/oracle/rpc/runtime-api/Cargo.toml index 19edb53a2..5976c9233 100644 --- a/oracle/rpc/runtime-api/Cargo.toml +++ b/oracle/rpc/runtime-api/Cargo.toml @@ -11,8 +11,6 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [features] default = ["std"] std = [ diff --git a/oracle/src/default_combine_data.rs b/oracle/src/default_combine_data.rs index 4f096cfff..d8c3f080c 100644 --- a/oracle/src/default_combine_data.rs +++ b/oracle/src/default_combine_data.rs @@ -27,13 +27,13 @@ where let count = values.len() as u32; let minimum_count = MinimumCount::get(); - if count < minimum_count { + if count < minimum_count || count == 0 { return prev_value; } - values.sort_by(|a, b| a.value.cmp(&b.value)); - - let median_index = count / 2; - Some(values[median_index as usize].clone()) + let mid_index = count / 2; + // Won't panic as `values` ensured not empty. + let (_, value, _) = values.select_nth_unstable_by(mid_index as usize, |a, b| a.value.cmp(&b.value)); + Some(value.clone()) } } diff --git a/oracle/src/default_weight.rs b/oracle/src/default_weight.rs deleted file mode 100644 index d910445d9..000000000 --- a/oracle/src/default_weight.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 - -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; - -impl crate::WeightInfo for () { - fn feed_values(c: u32) -> Weight { - (74_792_000 as Weight) - .saturating_add((11_208_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(1 as Weight)) - .saturating_add(DbWeight::get().writes((2 as Weight).saturating_mul(c as Weight))) - } - fn on_finalize() -> Weight { - (15_881_000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight)) - } -} diff --git a/oracle/src/lib.rs b/oracle/src/lib.rs index 0716ff3b9..e17708f2c 100644 --- a/oracle/src/lib.rs +++ b/oracle/src/lib.rs @@ -42,21 +42,17 @@ use sp_std::{prelude::*, vec}; pub use crate::default_combine_data::DefaultCombineData; mod default_combine_data; -mod default_weight; mod mock; mod tests; +mod weights; pub use module::*; +pub use weights::WeightInfo; #[frame_support::pallet] pub mod module { use super::*; - pub trait WeightInfo { - fn feed_values(c: u32) -> Weight; - fn on_finalize() -> Weight; - } - pub(crate) type MomentOf = <>::Time as Time>::Moment; pub(crate) type TimestampedValueOf = TimestampedValue<>::OracleValue, MomentOf>; diff --git a/oracle/src/weights.rs b/oracle/src/weights.rs new file mode 100644 index 000000000..36447bdd5 --- /dev/null +++ b/oracle/src/weights.rs @@ -0,0 +1,51 @@ +//! Autogenerated weights for orml_oracle +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-05-04, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// /Users/xiliangchen/projects/acala/target/release/acala +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=orml_oracle +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./oracle/src/weights.rs +// --template +// ../templates/orml-weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for orml_oracle. +pub trait WeightInfo { + fn feed_values(c: u32, ) -> Weight; + fn on_finalize() -> Weight; +} + +/// Default weights. +impl WeightInfo for () { + fn feed_values(c: u32, ) -> Weight { + (16_800_000 as Weight) + // Standard Error: 84_000 + .saturating_add((3_600_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(c as Weight))) + } + fn on_finalize() -> Weight { + (3_000_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } +} diff --git a/rewards/Cargo.toml b/rewards/Cargo.toml index 674018a63..e329d4fee 100644 --- a/rewards/Cargo.toml +++ b/rewards/Cargo.toml @@ -17,8 +17,6 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "roc frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } diff --git a/rewards/src/lib.rs b/rewards/src/lib.rs index 55be0d164..cd2acfb11 100644 --- a/rewards/src/lib.rs +++ b/rewards/src/lib.rs @@ -78,7 +78,7 @@ pub mod module { StorageDoubleMap<_, Twox64Concat, T::PoolId, Twox64Concat, T::AccountId, (T::Share, T::Balance), ValueQuery>; #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet {} diff --git a/scripts/run.sh b/scripts/run.sh index 1e5a5b3e7..fd8cc73ec 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -8,6 +8,10 @@ shift set -x for file in **/Cargo.toml; do + if [ "$file" == "xtokens/Cargo.toml" ] || [ "$file" == "xcm-support/Cargo.toml" ] || [ "$file" == "unknown-tokens/Cargo.toml" ] + then + continue + fi cargo $COMMAND --manifest-path "$file" $@; done diff --git a/tokens/Cargo.toml b/tokens/Cargo.toml index 735420dd3..ba4b68433 100644 --- a/tokens/Cargo.toml +++ b/tokens/Cargo.toml @@ -16,13 +16,13 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "ro frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } -pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } +# Patch doesn't work as `pallet-elections-phragmen` is now 4.0.0 version. Revert `rev` to `rococo-v1` branch after +# other `rococo-v1` dependencies upgraded. +pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", rev = "2be8fcc4236d32786c62f6f27a98e7fe7e550807" } [features] default = ["std"] diff --git a/tokens/src/default_weight.rs b/tokens/src/default_weight.rs deleted file mode 100644 index e46bf5656..000000000 --- a/tokens/src/default_weight.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 - -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; - -impl crate::WeightInfo for () { - fn transfer() -> Weight { - (158_835_000 as Weight) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) - } - fn transfer_all() -> Weight { - (162_545_000 as Weight) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) - } -} diff --git a/tokens/src/lib.rs b/tokens/src/lib.rs index 6c1202fca..955b56856 100644 --- a/tokens/src/lib.rs +++ b/tokens/src/lib.rs @@ -51,8 +51,8 @@ use frame_support::{ }; use frame_system::{ensure_signed, pallet_prelude::*}; use orml_traits::{ - account::MergeAccount, arithmetic::{self, Signed}, + currency::TransferAll, BalanceStatus, GetByKey, LockIdentifier, MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency, MultiReservableCurrency, OnDust, }; @@ -70,10 +70,12 @@ use sp_std::{ vec::Vec, }; -mod default_weight; mod imbalances; mod mock; mod tests; +mod weights; + +pub use weights::WeightInfo; pub struct TransferDust(marker::PhantomData<(T, GetAccountId)>); impl OnDust for TransferDust @@ -150,11 +152,6 @@ pub use module::*; pub mod module { use super::*; - pub trait WeightInfo { - fn transfer() -> Weight; - fn transfer_all() -> Weight; - } - #[pallet::config] pub trait Config: frame_system::Config { type Event: From> + IsType<::Event>; @@ -198,8 +195,6 @@ pub mod module { AmountIntoBalanceFailed, /// Failed because liquidity restrictions due to locking LiquidityRestrictions, - /// Account still has active reserved - StillHasActiveReserved, } #[pallet::event] @@ -298,7 +293,7 @@ pub mod module { } #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet {} @@ -1042,16 +1037,11 @@ where } } -impl MergeAccount for Pallet { +impl TransferAll for Pallet { #[transactional] - fn merge_account(source: &T::AccountId, dest: &T::AccountId) -> DispatchResult { + fn transfer_all(source: &T::AccountId, dest: &T::AccountId) -> DispatchResult { Accounts::::iter_prefix(source).try_for_each(|(currency_id, account_data)| -> DispatchResult { - // ensure the account has no active reserved of non-native token - ensure!(account_data.reserved.is_zero(), Error::::StillHasActiveReserved); - - // transfer all free to recipient - >::transfer(currency_id, source, dest, account_data.free)?; - Ok(()) + >::transfer(currency_id, source, dest, account_data.free) }) } } diff --git a/tokens/src/mock.rs b/tokens/src/mock.rs index c83901dae..85229a717 100644 --- a/tokens/src/mock.rs +++ b/tokens/src/mock.rs @@ -5,7 +5,7 @@ use super::*; use frame_support::{ construct_runtime, parameter_types, - traits::{ChangeMembers, Contains, ContainsLengthBound, SaturatingCurrencyToVote}, + traits::{ChangeMembers, ContainsLengthBound, SaturatingCurrencyToVote, SortedMembers}, }; use orml_traits::parameter_type_with_key; use sp_core::H256; @@ -68,7 +68,7 @@ thread_local! { } pub struct TenToFourteen; -impl Contains for TenToFourteen { +impl SortedMembers for TenToFourteen { fn sorted_members() -> Vec { TEN_TO_FOURTEEN.with(|v| v.borrow().clone()) } diff --git a/tokens/src/tests.rs b/tokens/src/tests.rs index 1b2f04021..ff2c5cf02 100644 --- a/tokens/src/tests.rs +++ b/tokens/src/tests.rs @@ -431,7 +431,7 @@ fn no_op_if_amount_is_zero() { } #[test] -fn merge_account_should_work() { +fn transfer_all_trait_should_work() { ExtBuilder::default() .balances(vec![(ALICE, DOT, 100), (ALICE, BTC, 200)]) .build() @@ -440,18 +440,18 @@ fn merge_account_should_work() { assert_eq!(Tokens::free_balance(BTC, &ALICE), 200); assert_eq!(Tokens::free_balance(DOT, &BOB), 0); - assert_ok!(Tokens::reserve(DOT, &ALICE, 1)); - assert_noop!( - Tokens::merge_account(&ALICE, &BOB), - Error::::StillHasActiveReserved - ); - Tokens::unreserve(DOT, &ALICE, 1); - - assert_ok!(Tokens::merge_account(&ALICE, &BOB)); + assert_ok!(>::transfer_all(&ALICE, &BOB)); assert_eq!(Tokens::free_balance(DOT, &ALICE), 0); assert_eq!(Tokens::free_balance(BTC, &ALICE), 0); assert_eq!(Tokens::free_balance(DOT, &BOB), 100); assert_eq!(Tokens::free_balance(BTC, &BOB), 200); + + assert_ok!(Tokens::reserve(DOT, &BOB, 1)); + assert_ok!(>::transfer_all(&BOB, &ALICE)); + assert_eq!(Tokens::free_balance(DOT, &ALICE), 99); + assert_eq!(Tokens::free_balance(BTC, &ALICE), 200); + assert_eq!(Tokens::free_balance(DOT, &BOB), 0); + assert_eq!(Tokens::free_balance(BTC, &BOB), 0); }); } diff --git a/tokens/src/weights.rs b/tokens/src/weights.rs new file mode 100644 index 000000000..5b6ed9474 --- /dev/null +++ b/tokens/src/weights.rs @@ -0,0 +1,49 @@ +//! Autogenerated weights for orml_tokens +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-05-04, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// /Users/xiliangchen/projects/acala/target/release/acala +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=orml_tokens +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./tokens/src/weights.rs +// --template +// ../templates/orml-weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for orml_tokens. +pub trait WeightInfo { + fn transfer() -> Weight; + fn transfer_all() -> Weight; +} + +/// Default weights. +impl WeightInfo for () { + fn transfer() -> Weight { + (60_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn transfer_all() -> Weight { + (62_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } +} diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 2c92c0f16..bf3b3ddf4 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -19,8 +19,6 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "roc orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false } xcm = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [features] default = ["std"] std = [ diff --git a/traits/src/account.rs b/traits/src/account.rs deleted file mode 100644 index f3c74c66d..000000000 --- a/traits/src/account.rs +++ /dev/null @@ -1,19 +0,0 @@ -use impl_trait_for_tuples::impl_for_tuples; -use orml_utilities::with_transaction_result; -use sp_runtime::DispatchResult; - -pub trait MergeAccount { - fn merge_account(source: &AccountId, dest: &AccountId) -> DispatchResult; -} - -#[impl_for_tuples(5)] -impl MergeAccount for Tuple { - fn merge_account(source: &AccountId, dest: &AccountId) -> DispatchResult { - with_transaction_result(|| { - for_tuples!( #( { - Tuple::merge_account(source, dest)?; - } )* ); - Ok(()) - }) - } -} diff --git a/traits/src/currency.rs b/traits/src/currency.rs index a7034d586..c104368ff 100644 --- a/traits/src/currency.rs +++ b/traits/src/currency.rs @@ -1,6 +1,9 @@ use crate::arithmetic; use codec::{Codec, FullCodec}; -pub use frame_support::traits::{BalanceStatus, LockIdentifier}; +pub use frame_support::{ + traits::{BalanceStatus, LockIdentifier}, + transactional, +}; use sp_runtime::{ traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize}, DispatchError, DispatchResult, @@ -341,3 +344,18 @@ pub trait OnDust { impl OnDust for () { fn on_dust(_: &AccountId, _: CurrencyId, _: Balance) {} } + +pub trait TransferAll { + fn transfer_all(source: &AccountId, dest: &AccountId) -> DispatchResult; +} + +#[impl_trait_for_tuples::impl_for_tuples(5)] +impl TransferAll for Tuple { + #[transactional] + fn transfer_all(source: &AccountId, dest: &AccountId) -> DispatchResult { + for_tuples!( #( { + Tuple::transfer_all(source, dest)?; + } )* ); + Ok(()) + } +} diff --git a/traits/src/data_provider.rs b/traits/src/data_provider.rs index 4b3483df3..650d3982c 100644 --- a/traits/src/data_provider.rs +++ b/traits/src/data_provider.rs @@ -30,10 +30,9 @@ pub fn median(mut items: Vec) -> Option { let mid_index = items.len() / 2; - items.sort(); - - // Won't panic as guarded items not empty case. - Some(items[mid_index as usize].clone()) + // Won't panic as `items` ensured not empty. + let (_, item, _) = items.select_nth_unstable(mid_index); + Some(item.clone()) } #[macro_export] diff --git a/traits/src/lib.rs b/traits/src/lib.rs index a8962dbcf..7ec0efb4a 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -22,7 +22,6 @@ pub use nft::NFT; pub use price::{DefaultPriceProvider, PriceProvider}; pub use rewards::RewardHandler; -pub mod account; pub mod arithmetic; pub mod auction; pub mod currency; diff --git a/utilities/Cargo.toml b/utilities/Cargo.toml index 4b505a7a6..1d8806bab 100644 --- a/utilities/Cargo.toml +++ b/utilities/Cargo.toml @@ -15,8 +15,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] serde_json = "1.0.64" frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } diff --git a/vesting/Cargo.toml b/vesting/Cargo.toml index 064519e91..bd241011a 100644 --- a/vesting/Cargo.toml +++ b/vesting/Cargo.toml @@ -17,8 +17,6 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" frame-support = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false } -funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105 - [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" } diff --git a/vesting/src/lib.rs b/vesting/src/lib.rs index b913d0516..2d3db167d 100644 --- a/vesting/src/lib.rs +++ b/vesting/src/lib.rs @@ -44,11 +44,12 @@ use sp_std::{ vec::Vec, }; -mod default_weight; mod mock; mod tests; +mod weights; pub use module::*; +pub use weights::WeightInfo; /// The maximum number of vesting schedules an account can have. pub const MAX_VESTINGS: usize = 20; @@ -109,12 +110,6 @@ impl VestingSche pub mod module { use super::*; - pub trait WeightInfo { - fn vested_transfer() -> Weight; - fn claim(i: u32) -> Weight; - fn update_vesting_schedules(i: u32) -> Weight; - } - pub(crate) type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; pub(crate) type VestingScheduleOf = VestingSchedule<::BlockNumber, BalanceOf>; @@ -216,7 +211,7 @@ pub mod module { } #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::hooks] impl Hooks for Pallet {} diff --git a/vesting/src/weights.rs b/vesting/src/weights.rs new file mode 100644 index 000000000..0efb3bb8b --- /dev/null +++ b/vesting/src/weights.rs @@ -0,0 +1,59 @@ +//! Autogenerated weights for orml_vesting +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-05-04, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// /Users/xiliangchen/projects/acala/target/release/acala +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=orml_vesting +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./vesting/src/weights.rs +// --template +// ../templates/orml-weight-template.hbs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for orml_vesting. +pub trait WeightInfo { + fn vested_transfer() -> Weight; + fn claim(i: u32, ) -> Weight; + fn update_vesting_schedules(i: u32, ) -> Weight; +} + +/// Default weights. +impl WeightInfo for () { + fn vested_transfer() -> Weight { + (69_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn claim(i: u32, ) -> Weight { + (31_747_000 as Weight) + // Standard Error: 4_000 + .saturating_add((63_000 as Weight).saturating_mul(i as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn update_vesting_schedules(i: u32, ) -> Weight { + (29_457_000 as Weight) + // Standard Error: 4_000 + .saturating_add((117_000 as Weight).saturating_mul(i as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } +} diff --git a/weight-meter/src/meter_std.rs b/weight-meter/src/meter_std.rs index 9622d05cb..0b787762c 100644 --- a/weight-meter/src/meter_std.rs +++ b/weight-meter/src/meter_std.rs @@ -3,10 +3,12 @@ use super::{Meter, Weight}; -static METER: spin::Mutex = spin::Mutex::new(Meter { - used_weight: 0, - depth: 0, -}); +thread_local! { + static METER: spin::Mutex = spin::Mutex::new(Meter { + used_weight: 0, + depth: 0, + }); +} /// Start weight meter with base weight pub fn start_with(base: Weight) { diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 7df979629..c98981145 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -105,7 +105,7 @@ pub mod module { impl Hooks for Pallet {} #[pallet::pallet] - pub struct Pallet(PhantomData); + pub struct Pallet(_); #[pallet::call] impl Pallet {