Skip to content

Commit

Permalink
Slashng improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 3, 2024
1 parent 6ba9992 commit e3f8dea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions matching_engine/src/routes/ui_routes/single_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ async fn recompute_single_market_response<'a>(
.collect::<Vec<RegisteredGenerator>>(),
unmatched_jobs: local_ask_store
.get_by_ask_state_except_complete(AskState::Create)
.filter_by_market_id(market_id)
.result()
.map(|mut asks| {
asks.sort_by(|a, b| a.ask_id.cmp(&b.ask_id));
Expand Down
58 changes: 49 additions & 9 deletions slasher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct SlashingInstance {
proof_marketplace: ProofMarketplaceInstance,
#[allow(unused)]
reward_address: Address,

delay_in_ms: Duration,
confirmations: usize,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand All @@ -50,6 +53,8 @@ pub struct SlashingInstanceConfig {
#[serde(alias = "relayer_private_key")]
pub slasher_key: String,
pub chain_id: String,
pub delay_in_time_ms: Option<u64>,
pub confirmations: Option<usize>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -113,9 +118,11 @@ impl SlashingInstance {
Self {
indexer_url: indexer_url.into(),
client: Client::new(),
config,
config: config.clone(),
proof_marketplace,
reward_address: slasher_key.address(),
delay_in_ms: Duration::from_millis(config.delay_in_time_ms.unwrap_or(100)),
confirmations: config.confirmations.unwrap_or(10),
}
}

Expand All @@ -129,15 +136,32 @@ impl SlashingInstance {
}
};

log::debug!("Found {} operators", operators.len());

for operator in operators.iter() {
sleep(Duration::from_secs(1)).await;
log::debug!(
"Searching active requests of operator: {:?}",
operator.address
);
sleep(self.delay_in_ms).await;
let active_requests = self.active_requests(operator.address.clone()).await?;

log::debug!(
"Found {} active requests for operator: {}",
active_requests.len(),
operator.address
);
for active_request in active_requests.iter() {
sleep(Duration::from_secs(1)).await;
log::debug!(
"Trying to slash request: {} for operator {:?}",
active_request.ask_id,
operator.address
);
sleep(self.delay_in_ms).await;
self._handle_request(active_request).await;
}
}
sleep(Duration::from_secs(1)).await;
sleep(self.delay_in_ms).await;

let markets = match self.get_markets().await {
Ok(data) => data,
Expand All @@ -147,16 +171,32 @@ impl SlashingInstance {
}
};

log::debug!("Found {} markets", markets.len());

for market in markets.iter() {
sleep(Duration::from_secs(1)).await;
log::debug!(
"Searching expired requests for market: {}",
market.market_id
);
sleep(self.delay_in_ms).await;
let expired_requests = self.expired_requests(market.market_id.clone()).await?;
log::debug!(
"Found {} expired requests in market: {}",
expired_requests.len(),
market.market_id
);
for expired_request in expired_requests.iter() {
sleep(Duration::from_secs(1)).await;
log::debug!(
"Trying to cancel expired request: {} in the market: {}",
expired_request.ask_id,
market.market_id
);
sleep(self.delay_in_ms).await;
self._handle_request(expired_request).await;
}
}

sleep(Duration::from_secs(1)).await;
sleep(self.delay_in_ms).await;
}
}

Expand Down Expand Up @@ -195,7 +235,7 @@ impl SlashingInstance {
}

let slashing_transaction = match slashing_transaction.send().await {
Ok(data) => data.confirmations(10),
Ok(data) => data.confirmations(self.confirmations),
Err(err) => {
log::error!("{}", err);
log::error!("failed sending the transaction");
Expand Down Expand Up @@ -241,7 +281,7 @@ impl SlashingInstance {
}

let cancellation_transaction = match cancellation_transaction.send().await {
Ok(data) => data.confirmations(10),
Ok(data) => data.confirmations(self.confirmations),
Err(err) => {
log::error!("{}", err);
log::error!("failed sending the transaction");
Expand Down

0 comments on commit e3f8dea

Please sign in to comment.