mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-26 12:26:02 +00:00
Boog900
b44c6b045b
* add `pop_blocks` to the difficulty cache * add a rolling median struct * use RollingMedian in weight cache * add pop_blocks to weight cache * add alt context cache * add getting alt RX vms * rework alt cache * add alt block verify function * keep alt caches around * add alt checked alt blocks to the cache * check the alt blocks timestamp * add docs + cleanup code * add popping blocks from the context cache * finish popping blocks + fix tests * fix doc * add a test popping blocks from HF cache * add a request to clear alt caches * add back lint * Apply suggestions from code review Co-authored-by: hinto-janai <hinto.janai@protonmail.com> * review fixes * small changes * change panic doc --------- Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
32 lines
1 KiB
Rust
32 lines
1 KiB
Rust
//! Free functions for block verification
|
|
use std::collections::HashMap;
|
|
|
|
use monero_serai::block::Block;
|
|
|
|
use crate::{transactions::TransactionVerificationData, ExtendedConsensusError};
|
|
|
|
/// Returns a list of transactions, pulled from `txs` in the order they are in the [`Block`].
|
|
///
|
|
/// Will error if a tx need is not in `txs` or if `txs` contain more txs than needed.
|
|
pub(crate) fn pull_ordered_transactions(
|
|
block: &Block,
|
|
mut txs: HashMap<[u8; 32], TransactionVerificationData>,
|
|
) -> Result<Vec<TransactionVerificationData>, ExtendedConsensusError> {
|
|
if block.txs.len() != txs.len() {
|
|
return Err(ExtendedConsensusError::TxsIncludedWithBlockIncorrect);
|
|
}
|
|
|
|
let mut ordered_txs = Vec::with_capacity(txs.len());
|
|
|
|
if !block.txs.is_empty() {
|
|
for tx_hash in &block.txs {
|
|
let tx = txs
|
|
.remove(tx_hash)
|
|
.ok_or(ExtendedConsensusError::TxsIncludedWithBlockIncorrect)?;
|
|
ordered_txs.push(tx);
|
|
}
|
|
drop(txs);
|
|
}
|
|
|
|
Ok(ordered_txs)
|
|
}
|