diff --git a/helper/src/lib.rs b/helper/src/lib.rs index e82ec827..ed78af1e 100644 --- a/helper/src/lib.rs +++ b/helper/src/lib.rs @@ -32,7 +32,7 @@ pub mod thread; pub mod time; #[cfg(feature = "tx-utils")] -pub mod tx_utils; +pub mod tx; //---------------------------------------------------------------------------------------------------- Private Usage //---------------------------------------------------------------------------------------------------- diff --git a/helper/src/tx_utils.rs b/helper/src/tx.rs similarity index 100% rename from helper/src/tx_utils.rs rename to helper/src/tx.rs diff --git a/storage/blockchain/src/ops/block.rs b/storage/blockchain/src/ops/block.rs index 55123931..a9a0df4f 100644 --- a/storage/blockchain/src/ops/block.rs +++ b/storage/blockchain/src/ops/block.rs @@ -9,7 +9,7 @@ use cuprate_database::{ }; use cuprate_helper::{ map::{combine_low_high_bits_to_u128, split_u128_into_low_high_bits}, - tx_utils::tx_fee, + tx::tx_fee, }; use cuprate_types::{ AltBlockInformation, ChainId, ExtendedBlockHeader, HardFork, VerifiedBlockInformation, @@ -156,7 +156,11 @@ pub fn pop_block( let block = Block::read(&mut block_blob.as_slice())?; //------------------------------------------------------ Transaction / Outputs / Key Images - let mut txs = Vec::with_capacity(block.transactions.len()); + let mut txs = if move_to_alt_chain.is_some() { + Vec::with_capacity(block.transactions.len()) + } else { + Vec::new() + }; remove_tx(&block.miner_transaction.hash(), tables)?; for tx_hash in &block.transactions { diff --git a/test-utils/src/data/statics.rs b/test-utils/src/data/statics.rs index a45cc13f..2ae97115 100644 --- a/test-utils/src/data/statics.rs +++ b/test-utils/src/data/statics.rs @@ -11,7 +11,7 @@ use std::sync::LazyLock; use hex_literal::hex; use monero_serai::{block::Block, transaction::Transaction}; -use cuprate_helper::{map::combine_low_high_bits_to_u128, tx_utils::tx_fee}; +use cuprate_helper::{map::combine_low_high_bits_to_u128, tx::tx_fee}; use cuprate_types::{VerifiedBlockInformation, VerifiedTransactionInformation}; use crate::data::constants::{ diff --git a/test-utils/src/rpc/client.rs b/test-utils/src/rpc/client.rs index 3711334b..cd54066a 100644 --- a/test-utils/src/rpc/client.rs +++ b/test-utils/src/rpc/client.rs @@ -8,7 +8,7 @@ use serde::Deserialize; use serde_json::json; use tokio::task::spawn_blocking; -use cuprate_helper::tx_utils::tx_fee; +use cuprate_helper::tx::tx_fee; use cuprate_types::{VerifiedBlockInformation, VerifiedTransactionInformation}; //---------------------------------------------------------------------------------------------------- Constants diff --git a/types/src/blockchain.rs b/types/src/blockchain.rs index 099668c0..f2b96db0 100644 --- a/types/src/blockchain.rs +++ b/types/src/blockchain.rs @@ -2,7 +2,6 @@ //! //! Tests that assert particular requests lead to particular //! responses are also tested in Cuprate's blockchain database crate. -//! //---------------------------------------------------------------------------------------------------- Import use std::{ collections::{HashMap, HashSet}, @@ -114,10 +113,12 @@ pub enum BlockchainWriteRequest { /// /// Input is an already verified block. WriteBlock(VerifiedBlockInformation), + /// Write an alternative block to the database, /// /// Input is the alternative block. WriteAltBlock(AltBlockInformation), + /// A request to pop some blocks from the top of the main chain /// /// Input is the amount of blocks to pop. @@ -125,6 +126,7 @@ pub enum BlockchainWriteRequest { /// This request flushes all alt-chains from the cache before adding the popped blocks to the /// alt cache. PopBlocks(usize), + /// A request to reverse the re-org process. /// /// The inner value is the [`ChainId`] of the old main chain. @@ -132,6 +134,7 @@ pub enum BlockchainWriteRequest { /// # Invariant /// It is invalid to call this with a [`ChainId`] that was not returned from [`BlockchainWriteRequest::PopBlocks`]. ReverseReorg(ChainId), + /// A request to flush all alternative blocks. FlushAltBlocks, }