forked from jito-foundation/jito-solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jito-foundation#10 from solana-forge/forge/message…
…_hash_filter cache simulation result during leader slots
- Loading branch information
Showing
3 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use { | ||
crate::pbs::grpc::SanitizedTransactionWithSimulationResult, | ||
solana_bundle::bundle_execution::LoadAndExecuteBundleError, | ||
solana_sdk::{hash::Hash, transaction::SanitizedTransaction}, | ||
std::collections::HashSet, | ||
}; | ||
|
||
pub struct SimulationResultCache { | ||
cache: HashSet<Hash>, | ||
} | ||
|
||
impl SimulationResultCache { | ||
pub fn new() -> Self { | ||
Self { | ||
cache: HashSet::new(), | ||
} | ||
} | ||
|
||
pub fn clear(&mut self) { | ||
self.cache.clear(); | ||
} | ||
|
||
pub fn contains(&self, sanitized_transaction: &SanitizedTransaction) -> bool { | ||
let mut message = sanitized_transaction.to_versioned_transaction().message; | ||
message.set_recent_blockhash(Default::default()); | ||
self.cache.contains(&message.hash()) | ||
} | ||
|
||
pub fn populate_with_failed_simulations( | ||
&mut self, | ||
simulation_results: &[SanitizedTransactionWithSimulationResult], | ||
) { | ||
self.cache.extend(simulation_results.iter().filter_map(|v| { | ||
if let Some(Err(LoadAndExecuteBundleError::TransactionError { .. })) = | ||
v.simulation_result | ||
{ | ||
let mut message = v.transaction.to_versioned_transaction().message; | ||
message.set_recent_blockhash(Default::default()); | ||
Some(message.hash()) | ||
} else { | ||
None | ||
} | ||
})) | ||
} | ||
} |