Skip to content

Commit

Permalink
add ExpectedFailurePayload
Browse files Browse the repository at this point in the history
  • Loading branch information
williampsmith committed Oct 22, 2024
1 parent 4cd5965 commit f8d05bc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/sui-benchmark/src/drivers/bench_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use prometheus::{register_int_counter_vec_with_registry, CounterVec};
use prometheus::{register_int_gauge_with_registry, GaugeVec};
use prometheus::{HistogramVec, IntGauge};
use rand::seq::SliceRandom;
use sui_types::crypto::Signature;
use tokio::sync::mpsc::{channel, Sender};
use tokio::sync::OnceCell;
use tokio_util::sync::CancellationToken;
Expand Down
78 changes: 78 additions & 0 deletions crates/sui-benchmark/src/workloads/expected_failure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use crate::workloads::{FailureType, Payload};
use crate::ExecutionEffects;
use std::fmt;
use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::transaction::{Transaction, TransactionData};

#[derive(Debug, Clone)]
pub struct ExpectedFailurePayload {
failure_type: FailureType,
sender: SuiAddress,
}

impl ExpectedFailurePayload {
pub fn new(failure_type: FailureType, sender: SuiAddress) -> Self {
Self {
failure_type,
sender,
}
}

fn create_failing_transaction(&self) -> Transaction {
let mut rng = rand::thread_rng();
let random_object_id = ObjectID::random();

match self.failure_type {
FailureType::LowGasBudget => {
// Create a transaction with insufficient gas
let data = TransactionData::new_move_call(
self.sender,
random_object_id,
"dummy_package",
"dummy_module",
"dummy_function",
vec![],
vec![],
1, // Set gas budget to 1, which is insufficient
1000,
)
.unwrap();
Transaction::new(data)
}
FailureType::InvalidSignature => {
// Create a transaction with an invalid signature
let data = TransactionData::new_transfer(
random_object_id,
self.sender,
self.sender,
random_object_id,
1000,
1000,
);
let mut tx = Transaction::new(data);
tx.signatures_mut().push(vec![0; 32]); // Invalid signature
tx
}
}
}
}

impl Payload for ExpectedFailurePayload {
fn make_new_payload(&mut self, _effects: &ExecutionEffects) {
// For this payload, we don't need to update anything based on effects
}

fn make_transaction(&mut self) -> Transaction {
self.create_failing_transaction()
}

fn get_failure_type(&self) -> Option<FailureType> {
Some(self.failure_type)
}
}

impl fmt::Display for ExpectedFailurePayload {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ExpectedFailurePayload({:?})", self.failure_type)
}
}
1 change: 1 addition & 0 deletions crates/sui-benchmark/src/workloads/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub mod adversarial;
pub mod batch_payment;
pub mod delegation;
pub mod expected_failure;
pub mod payload;
pub mod randomness;
pub mod shared_counter;
Expand Down

0 comments on commit f8d05bc

Please sign in to comment.