Skip to content

Commit

Permalink
feat(load-test): update for JSON-RPC 0.8
Browse files Browse the repository at this point in the history
All tasks use JSON-RPC 0.8 now instead of the 0.5 API we've removed.
  • Loading branch information
kkovaacs committed Nov 25, 2024
1 parent c45b23d commit 0d82222
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
71 changes: 38 additions & 33 deletions crates/load-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//! Load test for pathfinder JSON-RPC endpoints.
//!
//! This program expects a mainnet pathfinder node synced until block 1800,
//! This program expects a mainnet pathfinder node synced until block 600000,
//! since it contains references to transactions and contract addresses on
//! mainnet.
//!
Expand All @@ -16,99 +16,104 @@ mod requests;
mod tasks;
mod types;

fn register_v05(attack: GooseAttack) -> GooseAttack {
fn register_scripted(attack: GooseAttack) -> GooseAttack {
use tasks::scripted::{mainnet_scripted, mainnet_scripted_without_huge_calls};
use tasks::v05::*;

attack
.register_scenario(
scenario!("v08_scripted_mainnet").register_transaction(transaction!(mainnet_scripted)),
)
.register_scenario(
scenario!("v08_scripted_mainnet_without_huge_calls")
.register_transaction(transaction!(mainnet_scripted_without_huge_calls)),
)
}

fn register_v08(attack: GooseAttack) -> GooseAttack {
use tasks::v08::*;

attack
// primitive operations using the database
.register_scenario(
scenario!("v05_block_by_number")
scenario!("v08_block_by_number")
.register_transaction(transaction!(task_block_by_number)),
)
.register_scenario(
scenario!("v05_block_by_hash").register_transaction(transaction!(task_block_by_hash)),
scenario!("v08_block_by_hash").register_transaction(transaction!(task_block_by_hash)),
)
.register_scenario(
scenario!("v05_state_update_by_hash")
scenario!("v08_state_update_by_hash")
.register_transaction(transaction!(task_state_update_by_hash)),
)
.register_scenario(
scenario!("v05_get_class").register_transaction(transaction!(task_class_by_hash)),
scenario!("v08_get_class").register_transaction(transaction!(task_class_by_hash)),
)
.register_scenario(
scenario!("v05_get_class_hash_at")
scenario!("v08_get_class_hash_at")
.register_transaction(transaction!(task_class_hash_at)),
)
.register_scenario(
scenario!("v05_get_class_at").register_transaction(transaction!(task_class_at)),
scenario!("v08_get_class_at").register_transaction(transaction!(task_class_at)),
)
.register_scenario(
scenario!("v05_block_transaction_count_by_hash")
scenario!("v08_block_transaction_count_by_hash")
.register_transaction(transaction!(task_block_transaction_count_by_hash)),
)
.register_scenario(
scenario!("v05_block_transaction_count_by_number")
scenario!("v08_block_transaction_count_by_number")
.register_transaction(transaction!(task_block_transaction_count_by_number)),
)
.register_scenario(
scenario!("v05_transaction_by_hash")
scenario!("v08_transaction_by_hash")
.register_transaction(transaction!(task_transaction_by_hash)),
)
.register_scenario(
scenario!("v05_transaction_by_block_number_and_index")
scenario!("v08_transaction_by_block_number_and_index")
.register_transaction(transaction!(task_transaction_by_block_number_and_index)),
)
.register_scenario(
scenario!("v05_transaction_by_block_hash_and_index")
scenario!("v08_transaction_by_block_hash_and_index")
.register_transaction(transaction!(task_transaction_by_block_hash_and_index)),
)
.register_scenario(
scenario!("v05_transaction_receipt_by_hash")
scenario!("v08_transaction_receipt_by_hash")
.register_transaction(transaction!(task_transaction_receipt_by_hash)),
)
.register_scenario(
scenario!("v05_block_number").register_transaction(transaction!(task_block_number)),
scenario!("v08_block_number").register_transaction(transaction!(task_block_number)),
)
.register_scenario(
scenario!("v05_get_events").register_transaction(transaction!(task_get_events)),
scenario!("v08_get_events").register_transaction(transaction!(task_get_events)),
)
.register_scenario(
scenario!("v05_get_storage_at").register_transaction(transaction!(task_get_storage_at)),
scenario!("v08_get_storage_at").register_transaction(transaction!(task_get_storage_at)),
)
.register_scenario(
scenario!("v05_get_nonce").register_transaction(transaction!(task_get_nonce)),
scenario!("v08_get_nonce").register_transaction(transaction!(task_get_nonce)),
)
// primitive operations that don't use the database
.register_scenario(
scenario!("v05_syncing").register_transaction(transaction!(task_syncing)),
scenario!("v08_syncing").register_transaction(transaction!(task_syncing)),
)
.register_scenario(
scenario!("v05_chain_id").register_transaction(transaction!(task_chain_id)),
scenario!("v08_chain_id").register_transaction(transaction!(task_chain_id)),
)
// primitive operation doing execution
.register_scenario(scenario!("v05_call").register_transaction(transaction!(task_call)))
.register_scenario(scenario!("v08_call").register_transaction(transaction!(task_call)))
.register_scenario(
scenario!("v05_estimate_fee").register_transaction(transaction!(task_estimate_fee)),
scenario!("v08_estimate_fee").register_transaction(transaction!(task_estimate_fee)),
)
// composite scenario
.register_scenario(
scenario!("v05_block_explorer").register_transaction(transaction!(block_explorer)),
)
// scripted scenarios
.register_scenario(
scenario!("v06_scripted_mainnet").register_transaction(transaction!(mainnet_scripted)),
)
.register_scenario(
scenario!("v06_scripted_mainnet_without_huge_calls")
.register_transaction(transaction!(mainnet_scripted_without_huge_calls)),
scenario!("v08_block_explorer").register_transaction(transaction!(block_explorer)),
)
}

#[tokio::main]
async fn main() -> Result<(), GooseError> {
let attack = GooseAttack::initialize()?;
let attack = register_v05(attack);
let attack = register_v08(attack);
let attack = register_scripted(attack);

attack.execute().await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/load-test/src/requests.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod v05;
pub mod v08;
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub async fn estimate_fee_for_invoke(
json!({
"request": [{
"type": "INVOKE",
"version": "0x0",
"version": "0x1",
"max_fee": max_fee,
"signature": [],
"contract_address": contract_address,
Expand Down Expand Up @@ -289,7 +289,7 @@ async fn post_jsonrpc_request<T: DeserializeOwned>(
) -> MethodResult<T> {
let request = jsonrpc_request(method, params);
let response = user
.post_json("/rpc/v0.5", &request)
.post_json("/rpc/v0_8", &request)
.await?
.response
.map_err(|e| Box::new(e.into()))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/load-test/src/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod scripted;
pub mod v05;
pub mod v08;
4 changes: 2 additions & 2 deletions crates/load-test/src/tasks/scripted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use goose::prelude::*;
use serde::de::DeserializeOwned;
use serde::Deserialize;

use crate::requests::v05::*;
use crate::requests::v08::*;

/// Script from Starkware that contain some heavy-weight calls mixed with
/// wallet-like calls.
Expand Down Expand Up @@ -102,7 +102,7 @@ async fn post_request<T: DeserializeOwned>(
request: &'static str,
) -> MethodResult<RpcResult<T>> {
let request_builder = user
.get_request_builder(&GooseMethod::Post, "/rpc/v0_6")?
.get_request_builder(&GooseMethod::Post, "/rpc/v0_8")?
.header("Content-Type", "application/json")
.body(request);
let goose_request = GooseRequest::builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use goose::prelude::*;
use pathfinder_crypto::Felt;
use rand::{Rng, SeedableRng};

use crate::requests::v05::*;
use crate::requests::v08::*;

/// Fetch a random block, then fetch all individual transactions and receipts in
/// the block.
pub async fn block_explorer(user: &mut GooseUser) -> TransactionResult {
let mut rng = rand::rngs::StdRng::from_entropy();
let block_number: u64 = rng.gen_range(1..290000);
let block_number: u64 = rng.gen_range(1..600000);

let block = get_block_by_number(user, block_number).await?;
let block_by_hash = get_block_by_hash(user, block.block_hash).await?;
Expand Down

0 comments on commit 0d82222

Please sign in to comment.