Skip to content

Commit

Permalink
Allow for simple distribution of failure types across workers
Browse files Browse the repository at this point in the history
  • Loading branch information
williampsmith committed Nov 4, 2024
1 parent f8cd99d commit 05b6417
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/drivers/bench_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ async fn run_bench_worker(
num_submitted += 1;
metrics_cloned.num_in_flight.with_label_values(&[&payload.to_string()]).inc();
metrics_cloned.num_submitted.with_label_values(&[&payload.to_string()]).inc();
let tx = payload.make_transaction();
let tx = payload.make_transaction(worker.id);
let start = Arc::new(Instant::now());
// TODO: clone committee for each request is not ideal.
let committee = worker.proxy.clone_committee();
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/adversarial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Payload for AdversarialTestPayload {
self.state.update(effects);
}

fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
let payload_type = self.adversarial_payload_cfg.payload_type;

self.create_transaction(
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/batch_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Payload for BatchPaymentTestPayload {
self.num_payments += self.state.num_addresses();
}

fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
let addrs = self.state.addresses().cloned().collect::<Vec<SuiAddress>>();
let num_recipients = addrs.len();
let sender = if self.num_payments == 0 {
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Payload for DelegationTestPayload {
/// delegation flow is split into two phases
/// first `make_transaction` call creates separate coin object for future delegation
/// followup call creates delegation transaction itself
fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
match self.coin {
Some(coin) => TestTransactionBuilder::new(
self.sender,
Expand Down
65 changes: 46 additions & 19 deletions crates/sui-benchmark/src/workloads/expected_failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sui_types::base_types::SuiAddress;
use sui_types::crypto::{AccountKeyPair, Ed25519SuiSignature};
use sui_types::signature::GenericSignature;
use sui_types::{base_types::ObjectRef, crypto::get_key_pair, transaction::Transaction};
use tracing::debug;
use tracing::{debug, error};

#[derive(Debug, Clone)]
pub struct ExpectedFailurePayload {
Expand All @@ -41,33 +41,60 @@ pub struct ExpectedFailurePayloadCfg {
impl Copy for ExpectedFailurePayloadCfg {}

impl ExpectedFailurePayload {
fn create_failing_transaction(&self, mut tx: Transaction) -> Transaction {
fn create_failing_transaction(&self, tx: Transaction, worker_id: u64) -> Transaction {
let create_invalid_signature = |mut tx: Transaction| {
let signatures = tx.tx_signatures_mut_for_testing();
signatures.pop();
signatures.push(GenericSignature::Signature(
sui_types::crypto::Signature::Ed25519SuiSignature(Ed25519SuiSignature::default()),
));
tx
};
match self.failure_type {
ExpectedFailureType::InvalidSignature => {
let signatures = tx.tx_signatures_mut_for_testing();
signatures.pop();
signatures.push(GenericSignature::Signature(
sui_types::crypto::Signature::Ed25519SuiSignature(
Ed25519SuiSignature::default(),
),
));
tx
ExpectedFailureType::InvalidSignature => create_invalid_signature(tx),
ExpectedFailureType::InvalidSignatureFromHalfOfClients => {
if worker_id % 2 == 0 {
create_invalid_signature(tx)
} else {
tx
}
}
ExpectedFailureType::Random => unreachable!(),
}
}
}

impl Payload for ExpectedFailurePayload {
fn make_new_payload(&mut self, _effects: &ExecutionEffects) {
// This should never be called, as an expected failure payload
// should fail (thereby having no effects) and be retried. Note
// that since these are failures rather than Move level errors,
// no gas should be consumed, nor any objects mutated.
unreachable!()
fn make_new_payload(&mut self, effects: &ExecutionEffects) {
if !effects.is_ok() {
effects.print_gas_summary();
error!("Transfer tx failed... Status: {:?}", effects.status());
}

let recipient = self.gas.iter().find(|x| x.1 != self.transfer_to).unwrap().1;
let updated_gas: Vec<Gas> = self
.gas
.iter()
.map(|x| {
if x.1 == self.transfer_from {
(effects.gas_object().0, self.transfer_from, x.2.clone())
} else {
x.clone()
}
})
.collect();
self.transfer_object = effects
.mutated()
.iter()
.find(|(object_ref, _)| object_ref.0 == self.transfer_object.0)
.map(|x| x.0)
.unwrap();
self.transfer_from = self.transfer_to;
self.transfer_to = recipient;
self.gas = updated_gas;
}

fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, worker_id: u64) -> Transaction {
let (gas_obj, _, keypair) = self.gas.iter().find(|x| x.1 == self.transfer_from).unwrap();
let tx = make_transfer_object_transaction(
self.transfer_object,
Expand All @@ -80,7 +107,7 @@ impl Payload for ExpectedFailurePayload {
.borrow()
.reference_gas_price,
);
self.create_failing_transaction(tx)
self.create_failing_transaction(tx, worker_id)
}

fn get_failure_type(&self) -> Option<ExpectedFailureType> {
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sui_types::transaction::Transaction;
/// effect by invoking `make_new_payload(effects)`
pub trait Payload: Send + Sync + std::fmt::Debug + Display {
fn make_new_payload(&mut self, effects: &ExecutionEffects);
fn make_transaction(&mut self) -> Transaction;
fn make_transaction(&mut self, worker_id: u64) -> Transaction;
fn get_failure_type(&self) -> Option<ExpectedFailureType> {
None // Default implementation returns None
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Payload for RandomnessTestPayload {
}
self.gas.0 = effects.gas_object().0;
}
fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
let rgp = self
.system_state_observer
.state
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/shared_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Payload for SharedCounterTestPayload {
}
self.gas.0 = effects.gas_object().0;
}
fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
let rgp = self
.system_state_observer
.state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Payload for SharedCounterDeletionTestPayload {
}
}

fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
let rgp = self
.system_state_observer
.state
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/workloads/transfer_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Payload for TransferObjectTestPayload {
self.transfer_to = recipient;
self.gas = updated_gas;
}
fn make_transaction(&mut self) -> Transaction {
fn make_transaction(&mut self, _worker_id: u64) -> Transaction {
let (gas_obj, _, keypair) = self.gas.iter().find(|x| x.1 == self.transfer_from).unwrap();
make_transfer_object_transaction(
self.transfer_object,
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-benchmark/src/workloads/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub const ESTIMATED_COMPUTATION_COST: u64 = 1_000_000;
pub enum ExpectedFailureType {
Random = 0,
InvalidSignature,
/// For even ID'ed workers, we will create an invalid signature.
InvalidSignatureFromHalfOfClients,
// TODO: Add other failure types
}

Expand Down

0 comments on commit 05b6417

Please sign in to comment.