Skip to content

Commit

Permalink
fix shibuya benchmarks
Browse files Browse the repository at this point in the history
fix gmp execution errors
add chronicle refund test
  • Loading branch information
haider-rs committed Jun 15, 2024
1 parent 692ce9f commit 5841c9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

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

20 changes: 6 additions & 14 deletions tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type TssKeyR = <TssKey as alloy_sol_types::SolType>::RustType;

// A fixed gas cost of executing the gateway contract
pub const GATEWAY_EXECUTE_GAS_COST: u128 = 100_000;
pub const GATEWAY_BASE_GAS_COST: u128 = 100_000;

pub async fn sleep_or_abort(duration: Duration) -> Result<()> {
tokio::select! {
Expand Down Expand Up @@ -112,17 +113,6 @@ impl Tester {
})
}

pub async fn wallet_faucet(
runtime: SubxtClient,
network: &ChainNetwork,
keyfile: &Path,
) -> Result<()> {
let tester =
Tester::new(runtime, network, keyfile, &PathBuf::new(), &PathBuf::new()).await?;
tester.faucet().await;
Ok(())
}

pub fn wallet(&self) -> &Wallet {
&self.wallet
}
Expand Down Expand Up @@ -1413,12 +1403,14 @@ pub async fn deposit_gmp_funds(

// Calculate the deposit amount based on the gas_cost x gas_price + 20%
//how much the user provides the gmp
let gmp_gas_limit = gmp_gas_limit.saturating_add(GATEWAY_EXECUTE_GAS_COST);
let gmp_gas_limit = gmp_gas_limit
.saturating_add(GATEWAY_EXECUTE_GAS_COST)
.saturating_add(GATEWAY_BASE_GAS_COST);
let deposit_amount = gas_price
.saturating_mul(gmp_gas_limit)
.saturating_mul(12)
.saturating_mul(15)
.saturating_mul(total_calls)
/ 10; // 20% more, in case of the gas price increase
/ 10; // 50% more, in case of the gas price increase

let remaining_submitable_gas = deposit_amount.saturating_sub(funds_in_contract);
println!("funds required for call: {:?}", deposit_amount);
Expand Down
25 changes: 22 additions & 3 deletions tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum Test {
Basic,
Batch { tasks: u64 },
Gmp,
ChroniclePayment,
Migration,
Restart,
}
Expand All @@ -110,6 +111,7 @@ async fn main() -> Result<()> {
let args = Args::parse();
let runtime = tester::subxt_client(&args.timechain_keyfile, &args.timechain_url).await?;
let mut tester = Vec::with_capacity(args.network.len());
let mut chronicles = vec![];
for network in &args.network {
tester.push(
Tester::new(
Expand All @@ -124,7 +126,16 @@ async fn main() -> Result<()> {

// fund chronicle faucets for testing
for item in CHRONICLE_KEYFILES {
Tester::wallet_faucet(runtime.clone(), network, Path::new(item)).await?;
let chronicle_tester = Tester::new(
runtime.clone(),
network,
&PathBuf::from(item),
&PathBuf::new(),
&PathBuf::new(),
)
.await?;
chronicle_tester.faucet().await;
chronicles.push(chronicle_tester);
}
}
let contract = args.contract;
Expand Down Expand Up @@ -174,6 +185,15 @@ async fn main() -> Result<()> {
Command::Test(Test::Batch { tasks }) => {
batch_test(&tester[0], &contract, tasks).await?;
},
// chronicles are refunded the gas for gmp call
Command::Test(Test::ChroniclePayment) => {
println!("This test is only available local with single node shard");
let starting_balance = chronicles[0].wallet().balance().await?;
gmp_test(&tester[0], &tester[1], &contract).await?;
let ending_balance = chronicles[0].wallet().balance().await?;
println!("Verifying balance");
assert!(starting_balance <= ending_balance);
},
Command::Test(Test::Gmp) => {
gmp_test(&tester[0], &tester[1], &contract).await?;
},
Expand Down Expand Up @@ -226,7 +246,7 @@ async fn gmp_benchmark(
// get contract stats of src contract
let start_stats = stats(src_tester, src_contract, None).await?;
// get contract stats of destination contract
let dest_stats = stats(src_tester, src_contract, None).await?;
let dest_stats = stats(dest_tester, dest_contract, None).await?;
println!("stats in start: {:?}", start_stats);

//get nonce of the caller to manage explicitly
Expand Down Expand Up @@ -437,7 +457,6 @@ async fn batch_test(tester: &Tester, contract: &Path, total_tasks: u64) -> Resul
}

async fn gmp_test(src: &Tester, dest: &Tester, contract: &Path) -> Result<()> {
src.set_shard_config(1, 1).await?;
let (src_contract, dest_contract, _) = setup_gmp_with_contracts(src, dest, contract, 1).await?;

println!("submitting vote");
Expand Down

0 comments on commit 5841c9a

Please sign in to comment.