Skip to content

Commit

Permalink
feat(storage-provider): Benchmarks, part 1 (#740)
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Åström <[email protected]>
  • Loading branch information
Jinxit authored Feb 18, 2025
1 parent f62cd11 commit 176455a
Show file tree
Hide file tree
Showing 16 changed files with 611 additions and 5 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,18 @@ jobs:
--steps 5 \
--repeat 1 \
--template node/benchmark_template.hbs
- name: pallet-storage-provider — Run test benchmarks
run: cargo test --profile ci --locked -p pallet-storage-provider-benchmarks --features runtime-benchmarks -- benchmark --nocapture

- name: pallet-storage-provider — Run node benchmarks
run: |
cargo run \
-p polka-storage-node -r -F runtime-benchmarks -F testnet -- \
benchmark pallet \
--wasm-execution=compiled \
--pallet "pallet_storage_provider" \
--extrinsic "*" \
--steps 5 \
--repeat 1 \
--template node/benchmark_template.hbs
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"pallets/proofs",
"pallets/randomness",
"pallets/storage-provider",
"pallets/storage-provider/benchmarks",
"primitives",
"runtime",
"storage-provider/client",
Expand Down Expand Up @@ -146,6 +147,7 @@ pallet-market = { path = "pallets/market", default-features = false }
pallet-proofs = { path = "pallets/proofs", default-features = false }
pallet-randomness = { path = "pallets/randomness", default-features = false }
pallet-storage-provider = { path = "pallets/storage-provider", default-features = false }
pallet-storage-provider-benchmarks = { path = "pallets/storage-provider/benchmarks", default-features = false }
polka-storage-proofs = { path = "lib/polka-storage-proofs", default-features = false }
polka-storage-provider-common = { path = "storage-provider/common" }
polka-storage-retrieval = { path = "storage-retrieval/lib" }
Expand Down
14 changes: 14 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,17 @@ full-coverage: pallet-storage-provider-coverage market-coverage mater-coverage
generate-proof-params sector-size:
cargo r -r -p polka-storage-provider-client -- proofs porep-params --seal-proof "{{sector-size}}"
cargo r -r -p polka-storage-provider-client -- proofs post-params --post-type "{{sector-size}}"

bench-test pallet:
cargo test --profile ci --locked -p pallet-{{pallet}} --features runtime-benchmarks -- benchmark --nocapture

bench-node pallet:
cargo run \
-p polka-storage-node -r -F runtime-benchmarks -F testnet -- \
benchmark pallet \
--wasm-execution=compiled \
--pallet "pallet_{{pallet}}" \
--extrinsic "*" \
--steps 5 \
--repeat 1 \
--template node/benchmark_template.hbs
65 changes: 65 additions & 0 deletions pallets/storage-provider/benchmarks/Cargo.toml
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 pallets/storage-provider/benchmarks/src/benchmarking/accounts.rs
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)
}
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()
}
Loading

0 comments on commit 176455a

Please sign in to comment.