Revert "cross block bp(+) batch verification"

This reverts commit 764c4663a0.
This commit is contained in:
Boog900 2025-01-05 01:39:41 +00:00
parent a133490b31
commit 4c3ee18d0b
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
5 changed files with 6 additions and 50 deletions

View file

@ -20,8 +20,6 @@ use crate::{
BlockChainContextRequest, BlockChainContextResponse, ExtendedConsensusError,
VerifyBlockResponse,
};
use crate::batch_verifier::MultiThreadedBatchVerifier;
use crate::transactions::verify_tx_semantic;
/// Batch prepares a list of blocks for verification.
#[instrument(level = "debug", name = "batch_prep_blocks", skip_all, fields(amt = blocks.len()))]
@ -170,9 +168,7 @@ where
tracing::debug!("Calculating PoW and prepping transaction");
let blocks = rayon_spawn_async(move || {
let batch_verifier = MultiThreadedBatchVerifier::new(rayon::current_num_threads());
let res = blocks
blocks
.into_par_iter()
.zip(difficulties)
.zip(txs)
@ -187,16 +183,11 @@ where
// Check the PoW
check_block_pow(&block.pow_hash, difficultly).map_err(ConsensusError::Block)?;
let hf = block.hf_version;
// Now setup the txs.
let txs = txs
.into_par_iter()
.map(|tx| {
let mut tx = new_tx_verification_data(tx)?;
verify_tx_semantic(&mut tx, hf, &batch_verifier)?;
let tx = new_tx_verification_data(tx)?;
Ok::<_, ConsensusError>((tx.tx_hash, tx))
})
.collect::<Result<HashMap<_, _>, _>>()?;
@ -210,13 +201,7 @@ where
Ok((block, ordered_txs))
})
.collect::<Result<Vec<_>, ExtendedConsensusError>>()?;
if !batch_verifier.verify() {
return Err(ExtendedConsensusError::OneOrMoreBatchVerificationStatementsInvalid);
}
Ok(res)
.collect::<Result<Vec<_>, ExtendedConsensusError>>()
})
.await?;

View file

@ -38,7 +38,7 @@ use crate::{
pub mod contextual_data;
mod free;
pub use free::{new_tx_verification_data, verify_tx_semantic};
pub use free::new_tx_verification_data;
/// A struct representing the type of validation that needs to be completed for this transaction.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
@ -333,19 +333,6 @@ fn transactions_needing_verification(
.push((Arc::clone(tx), VerificationNeeded::SemanticAndContextual));
continue;
}
CachedVerificationState::SemanticallyValidAtHF(hf) => {
if current_hf != *hf {
drop(guard);
full_validation_transactions
.push((Arc::clone(tx), VerificationNeeded::SemanticAndContextual));
continue;
}
drop(guard);
full_validation_transactions
.push((Arc::clone(tx), VerificationNeeded::Contextual));
continue;
}
CachedVerificationState::ValidAtHashAndHF { block_hash, hf } => {
if current_hf != *hf {
drop(guard);

View file

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex as StdMutex};
use std::sync::Mutex as StdMutex;
use monero_serai::{
ringct::{bulletproofs::Bulletproof, RctType},
@ -6,8 +6,7 @@ use monero_serai::{
};
use cuprate_consensus_rules::{transactions::TransactionError, ConsensusError};
use cuprate_types::{CachedVerificationState, HardFork, TransactionVerificationData, TxVersion};
use crate::batch_verifier::MultiThreadedBatchVerifier;
use cuprate_types::{CachedVerificationState, TransactionVerificationData, TxVersion};
/// Creates a new [`TransactionVerificationData`] from a [`Transaction`].
///
@ -37,18 +36,6 @@ pub fn new_tx_verification_data(
})
}
pub fn verify_tx_semantic(
tx: &mut TransactionVerificationData,
hf: HardFork,
multi_threaded_batch_verifier: &MultiThreadedBatchVerifier,
) -> Result<(), ConsensusError> {
cuprate_consensus_rules::transactions::check_transaction_semantic(&tx.tx, tx.tx_blob.len(), tx.tx_weight, &tx.tx_hash, hf, multi_threaded_batch_verifier)?;
*tx.cached_verification_state.get_mut().unwrap() = CachedVerificationState::SemanticallyValidAtHF(hf);
Ok(())
}
/// Calculates the weight of a [`Transaction`].
///
/// This is more efficient that [`Transaction::weight`] if you already have the transaction blob.

View file

@ -103,7 +103,6 @@ impl From<CachedVerificationState> for RawCachedVerificationState {
raw_hf: 0,
raw_valid_past_timestamp: [0; 8],
},
CachedVerificationState::SemanticallyValidAtHF(hf) => todo!(),
CachedVerificationState::ValidAtHashAndHF { block_hash, hf } => Self {
raw_valid_at_hash: block_hash,
raw_hf: hf.as_u8(),

View file

@ -37,7 +37,6 @@ impl TxVersion {
pub enum CachedVerificationState {
/// The transaction has not been validated.
NotVerified,
SemanticallyValidAtHF(HardFork),
/// The transaction is valid* if the block represented by this hash is in the blockchain and the [`HardFork`]
/// is the same.
///
@ -69,7 +68,6 @@ impl CachedVerificationState {
pub const fn verified_at_block_hash(&self) -> Option<[u8; 32]> {
match self {
Self::NotVerified => None,
Self::SemanticallyValidAtHF(_) => None,
Self::ValidAtHashAndHF { block_hash, .. }
| Self::ValidAtHashAndHFWithTimeBasedLock { block_hash, .. } => Some(*block_hash),
}