Skip to content

Commit

Permalink
enable indivisual checks in native and symbiotic
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Nov 15, 2024
1 parent 4d70121 commit 44014b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 56 deletions.
49 changes: 0 additions & 49 deletions matching_engine/src/generator_lib/generator_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,54 +812,6 @@ impl GeneratorStore {
GeneratorQueryResult::new(generator_result)
}

#[deprecated(
note = "filter_by_available_native_stake and filter_by_available_symbiotic_stake will be used. filter_by_available_stake will be removed"
)]
pub fn filter_by_available_stake(
&self,
generator_query: GeneratorQueryResult,
min_stake: Vec<AddressTokenPair>, // Now accepting a vector of AddressTokenPairs
) -> GeneratorQueryResult {
let generator_array = generator_query.result();

// Use rayon's parallel iterator to process in parallel
let generator_result: Vec<&GeneratorInfoPerMarket> = generator_array
.into_par_iter() // Convert the array to a parallel iterator
.filter_map(|elem| {
// Try to get the generator from the store
if let Some(generator) = self.generators.get(&elem.address) {
let remaining_stake = generator
.total_native_stake
.clone()
.add(generator.total_symbiotic_stake.clone())
.sub(
generator
.native_stake_locked
.clone()
.add(generator.symbiotic_stake_locked.clone()),
);

// Check if at least one of the AddressTokenPairs in min_stake meets the condition
let is_valid = min_stake
.iter()
.any(|min_stake_pair| remaining_stake.has_more_than_or_eq(min_stake_pair));

// If valid, retrieve the generator market and return it
if is_valid {
self.generator_markets.get(&(elem.address, elem.market_id))
} else {
None // Otherwise, filter it out
}
} else {
None // If generator doesn't exist, filter it out
}
})
.collect(); // Collect the results into a Vec

GeneratorQueryResult::new(generator_result)
}

#[allow(unused)]
pub fn filter_by_available_native_stake(
&self,
generator_query: GeneratorQueryResult,
Expand Down Expand Up @@ -898,7 +850,6 @@ impl GeneratorStore {
GeneratorQueryResult::new(generator_result)
}

#[allow(unused)]
pub fn filter_by_available_symbiotic_stake(
&self,
generator_query: GeneratorQueryResult,
Expand Down
40 changes: 33 additions & 7 deletions matching_engine/src/jobs/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ impl LogParser {
&self.shared_market_store,
&self.shared_key_store,
random_pending_ask.reward,
&self.shared_native_stake_store,
&self.shared_symbiotic_stake_store,
)
.await;

Expand Down Expand Up @@ -668,16 +670,22 @@ impl LogParser {
&self,
random_pending_ask: LocalAsk,
generator_store: &Arc<RwLock<GeneratorStore>>,
market_store: &Arc<RwLock<MarketMetadataStore>>,
_: &Arc<RwLock<MarketMetadataStore>>,
key_store: &Arc<RwLock<KeyStore>>,
task_reward: U256,
native_staking_store: &Arc<RwLock<NativeStakingStore>>,
symbiotic_staking_store: &Arc<RwLock<SymbioticStakeStore>>,
) -> Vec<generator_store::GeneratorInfoPerMarket> {
// Ensure Generator implements Clone
let generator_store = generator_store.read().await;
let market_metadata_store = market_store.read().await;
let key_store = key_store.read().await;
let slashing_penalty =
market_metadata_store.get_slashing_penalty_by_market_id(&random_pending_ask.market_id);
let native_staking_store = native_staking_store.read().await;
let symbiotic_staking_store = symbiotic_staking_store.read().await;

let native_stake_requirements = native_staking_store.tokens_to_lock.to_address_token_pair();
let symbiotic_stake_requirements = symbiotic_staking_store
.tokens_to_lock
.to_address_token_pair();

let idle_generators = {
let generator_query = {
Expand All @@ -691,8 +699,18 @@ impl LogParser {
let generator_with_idle_compute =
generator_store.filter_by_has_idle_compute(generator_query);

let generator_with_available_native_stake = generator_store
.filter_by_available_native_stake(
generator_with_idle_compute,
native_stake_requirements,
);

let generator_with_available_stake = generator_store
.filter_by_available_stake(generator_with_idle_compute, slashing_penalty);
.filter_by_available_symbiotic_stake(
generator_with_available_native_stake,
symbiotic_stake_requirements,
);

generator_store.filter_by_has_private_inputs_support(
generator_with_available_stake,
key_store,
Expand All @@ -707,8 +725,16 @@ impl LogParser {
let generator_with_idle_compute =
generator_store.filter_by_has_idle_compute(generator_query);

generator_store
.filter_by_available_stake(generator_with_idle_compute, slashing_penalty)
let generator_with_available_native_stake = generator_store
.filter_by_available_native_stake(
generator_with_idle_compute,
native_stake_requirements,
);

generator_store.filter_by_available_symbiotic_stake(
generator_with_available_native_stake,
symbiotic_stake_requirements,
)
}
};

Expand Down

0 comments on commit 44014b2

Please sign in to comment.