Skip to content

Commit

Permalink
optimize reset tx
Browse files Browse the repository at this point in the history
  • Loading branch information
miralandlabs committed Jun 22, 2024
1 parent abd5aa0 commit 50148cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/import_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn ImportKeyImport() -> Element {
let mut private_key_input = use_signal(|| "".to_string());
let gateway = use_gateway();
let nav = navigator();
log::info!("OK: to import... {}", *private_key_input.read()); // MI
// log::info!("OK: to import... {}", *private_key_input.read()); // MI

// MI, use_future ==> use_resource
let _ = use_resource(move || {
Expand Down
18 changes: 14 additions & 4 deletions src/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_std::utils::channel::UseChannel;
use lazy_static::lazy_static;
use mars::{state::Proof, state::Treasury, BUS_COUNT, EPOCH_DURATION};
use mars::{state::Proof, state::Treasury, BUS_COUNT, EPOCH_DURATION, ONE_MARS};
use rand::Rng;
use serde_wasm_bindgen::to_value;
use solana_client_wasm::solana_sdk::{
Expand Down Expand Up @@ -42,6 +42,10 @@ fn fetch_logical_processors() -> usize {
1 as usize
}

const WARNING_REWARD_RATE: u64 = ONE_MARS.saturating_div(10); // MI
// Odds of being selected to submit a reset tx
const RESET_ODDS: u64 = 20;

/// Miner encapsulates the logic needed to efficiently mine for valid hashes according to the application runtime and hardware.
pub struct Miner {
_power_level: Signal<PowerLevel>,
Expand Down Expand Up @@ -159,15 +163,21 @@ pub async fn submit_solution(
// Submit restart epoch tx, if needed
if clock.unix_timestamp.ge(&epoch_end_at) {
// There are a lot of miners right now, randomize who tries the reset
let selected_to_reset = rng.gen_range(0..10).eq(&0);
if selected_to_reset {
// If there are a lot of miners, randomly select into submitting tx
let (odds, skip_confirm) = if treasury.reward_rate.ge(&WARNING_REWARD_RATE) {
(1, false)
} else {
(RESET_ODDS, true)
};
if rng.gen_range(0..odds).eq(&0) {
println!("Sending epoch reset transaction...");
let cu_limit_ix =
ComputeBudgetInstruction::set_compute_unit_limit(CU_LIMIT_RESET);
let cu_price_ix =
ComputeBudgetInstruction::set_compute_unit_price(priority_fee);
let ix = mars::instruction::reset(signer.pubkey());
gateway
.send_and_confirm(&[cu_limit_ix, cu_price_ix, ix], false, true)
.send_and_confirm(&[cu_limit_ix, cu_price_ix, ix], false, skip_confirm)
.await
.ok();
}
Expand Down

0 comments on commit 50148cb

Please sign in to comment.