-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage-provider): Benchmarks, part 1 (#740)
Signed-off-by: Lucas Åström <[email protected]>
- Loading branch information
Showing
16 changed files
with
611 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[package] | ||
authors.workspace = true | ||
description = "Benchmarks for the Storage Provider Pallet" | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license-file.workspace = true | ||
name = "pallet-storage-provider-benchmarks" | ||
repository.workspace = true | ||
version = "0.0.0" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { workspace = true, default-features = false, features = ["derive"] } | ||
pallet-balances = { workspace = true, default-features = false } | ||
pallet-market = { workspace = true, default-features = false } | ||
pallet-storage-provider = { workspace = true, default-features = false } | ||
primitives = { workspace = true, default-features = false } | ||
scale-info = { workspace = true, default-features = false, features = ["derive"] } | ||
sp-arithmetic = { workspace = true, default-features = false } | ||
sp-core = { workspace = true, default-features = false } | ||
sp-io = { workspace = true } | ||
sp-keystore = { workspace = true, default-features = false } | ||
sp-runtime = { workspace = true, default-features = false } | ||
|
||
|
||
# Frame deps | ||
frame-benchmarking = { workspace = true, default-features = false, optional = true } | ||
frame-support = { workspace = true, default-features = false } | ||
frame-system = { workspace = true, default-features = false } | ||
|
||
[dev-dependencies] | ||
env_logger = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"pallet-balances/runtime-benchmarks", | ||
"pallet-market/runtime-benchmarks", | ||
"pallet-storage-provider/runtime-benchmarks", | ||
"primitives/testing", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
std = [ | ||
"codec/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"pallet-balances/std", | ||
"pallet-market/std", | ||
"pallet-storage-provider/std", | ||
"primitives/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
] | ||
try-runtime = ["frame-support/try-runtime", "frame-system/try-runtime", "sp-runtime/try-runtime"] |
14 changes: 14 additions & 0 deletions
14
pallets/storage-provider/benchmarks/src/benchmarking/accounts.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use sp_io::crypto::ed25519_generate; | ||
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSigner}; | ||
|
||
pub const ALICE: &'static str = "//Alice"; | ||
pub const STORAGE_PROVIDER: &'static str = "//StorageProvider"; | ||
|
||
pub fn generate_benchmark_account(name: &'static str) -> (AccountId32, MultiSigner) { | ||
let signer: sp_core::ed25519::Public = | ||
ed25519_generate(0.into(), Some(name.as_bytes().to_vec())).into(); | ||
let signer: MultiSigner = signer.into(); | ||
let account_id = signer.clone().into_account(); | ||
|
||
(account_id, signer) | ||
} |
32 changes: 32 additions & 0 deletions
32
pallets/storage-provider/benchmarks/src/benchmarking/deal_proposals.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use codec::Encode; | ||
use frame_system::pallet_prelude::BlockNumberFor; | ||
use pallet_market::{BalanceOf, ClientDealProposal, DealProposal}; | ||
use sp_core::ed25519; | ||
use sp_io::crypto::ed25519_sign; | ||
use sp_runtime::{MultiSignature, MultiSigner}; | ||
|
||
pub type ClientDealProposalOf<T> = ClientDealProposal< | ||
<T as frame_system::Config>::AccountId, | ||
BalanceOf<T>, | ||
BlockNumberFor<T>, | ||
MultiSignature, | ||
>; | ||
pub type DealProposalOf<Test> = | ||
DealProposal<<Test as frame_system::Config>::AccountId, BalanceOf<Test>, BlockNumberFor<Test>>; | ||
|
||
pub fn sign_proposal<T: pallet_market::Config>( | ||
pubkey: MultiSigner, | ||
proposal: DealProposalOf<T>, | ||
) -> ClientDealProposalOf<T> { | ||
let client_signature = create_ed25519_signature(&Encode::encode(&proposal), pubkey); | ||
ClientDealProposal { | ||
proposal, | ||
client_signature, | ||
} | ||
} | ||
|
||
pub fn create_ed25519_signature(payload: &[u8], pubkey: MultiSigner) -> MultiSignature { | ||
let edpubkey = ed25519::Public::try_from(pubkey).unwrap(); | ||
let edsig = ed25519_sign(0.into(), &edpubkey, payload).unwrap(); | ||
edsig.into() | ||
} |
Oops, something went wrong.