Skip to content

Commit

Permalink
fix cu consumed computations (blockworks-foundation#25)
Browse files Browse the repository at this point in the history
* fix cu consumed computations

* fix compilation errors
  • Loading branch information
kirill lykov authored Feb 28, 2024
1 parent 44ef92f commit d1d61c4
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/confirmation_strategies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use solana_sdk::{
slot_history::Slot,
};
use solana_transaction_status::{
RewardType, TransactionDetails, UiConfirmedBlock, UiTransactionEncoding,
option_serializer::OptionSerializer, RewardType, TransactionDetails, UiConfirmedBlock,
UiTransactionEncoding,
};

use crate::states::{BlockData, TransactionConfirmRecord, TransactionSendRecord};
Expand Down Expand Up @@ -46,33 +47,30 @@ pub async fn process_blocks(

if let Some(transactions) = &block.transactions {
let nb_transactions = transactions.len();
let mut cu_consumed: u64 = 0;
let mut mm_cu_consumed: u64 = 0;
let mut total_cu_consumed: u64 = 0;
for solana_transaction_status::EncodedTransactionWithStatusMeta {
transaction, meta, ..
} in transactions
{
let tx_cu_consumed =
meta.as_ref()
.map_or(0, |meta| match meta.compute_units_consumed {
OptionSerializer::Some(cu_consumed) => cu_consumed,
_ => 0,
});
let transaction = match transaction.decode() {
Some(tx) => tx,
None => {
continue;
}
};
for signature in &transaction.signatures {
let transaction_record_op = {
let rec = transaction_map.get(signature);
rec.map(|x| x.clone())
};
// add CU in counter
if let Some(meta) = &meta {
if let solana_transaction_status::option_serializer::OptionSerializer::Some(x) =
meta.compute_units_consumed
{
cu_consumed = cu_consumed.saturating_add(x);
}
}
if let Some(transaction_record) = transaction_record_op {
let transaction_record = transaction_record.0;
total_cu_consumed = total_cu_consumed.saturating_add(tx_cu_consumed);
if let Some((_, (transaction_record, _))) = transaction_map.remove(signature) {
mm_transaction_count += 1;
mm_cu_consumed = mm_cu_consumed.saturating_add(tx_cu_consumed);

match tx_confirm_records.send(TransactionConfirmRecord {
signature: transaction_record.signature.to_string(),
Expand Down Expand Up @@ -105,8 +103,6 @@ pub async fn process_blocks(
}
}
}

transaction_map.remove(signature);
}
}
// push block data
Expand All @@ -122,8 +118,8 @@ pub async fn process_blocks(
},
number_of_mango_simulation_txs: mm_transaction_count,
total_transactions: nb_transactions as u64,
cu_consumed: 0,
cu_consumed_by_mango_simulations: cu_consumed,
cu_consumed: total_cu_consumed,
cu_consumed_by_mango_simulations: mm_cu_consumed,
commitment,
});
}
Expand Down

0 comments on commit d1d61c4

Please sign in to comment.