mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-21 02:04:31 +00:00
fix key image types
This commit is contained in:
parent
95ab9765e8
commit
416efcb788
6 changed files with 68 additions and 16 deletions
|
@ -306,7 +306,7 @@ async fn is_key_image_spent(
|
|||
let mut spent_status = Vec::with_capacity(key_images.len());
|
||||
|
||||
// Check the blockchain for key image spend status.
|
||||
blockchain::key_images_spent(&mut state.blockchain_read, key_images.clone())
|
||||
blockchain::key_images_spent_vec(&mut state.blockchain_read, key_images.clone())
|
||||
.await?
|
||||
.into_iter()
|
||||
.for_each(|ki| {
|
||||
|
@ -332,7 +332,7 @@ async fn is_key_image_spent(
|
|||
|
||||
// Check if the remaining unspent key images exist in the transaction pool.
|
||||
if !key_images.is_empty() {
|
||||
txpool::key_images_spent(&mut state.txpool_read, key_images, !restricted)
|
||||
txpool::key_images_spent_vec(&mut state.txpool_read, key_images, !restricted)
|
||||
.await?
|
||||
.into_iter()
|
||||
.for_each(|ki| {
|
||||
|
|
|
@ -124,7 +124,7 @@ pub async fn next_chain_entry(
|
|||
blockchain_read: &mut BlockchainReadHandle,
|
||||
block_hashes: Vec<[u8; 32]>,
|
||||
len: usize,
|
||||
) -> Result<(Vec<[u8; 32]>, Option<std::num::NonZero<usize>>), Error> {
|
||||
) -> Result<(Vec<[u8; 32]>, usize), Error> {
|
||||
let BlockchainResponse::NextChainEntry {
|
||||
block_ids,
|
||||
chain_height,
|
||||
|
@ -274,8 +274,8 @@ pub async fn number_outputs_with_amount(
|
|||
/// [`BlockchainReadRequest::KeyImagesSpent`]
|
||||
pub async fn key_images_spent(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
key_images: Vec<[u8; 32]>,
|
||||
) -> Result<Vec<bool>, Error> {
|
||||
key_images: HashSet<[u8; 32]>,
|
||||
) -> Result<bool, Error> {
|
||||
let BlockchainResponse::KeyImagesSpent(status) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
|
@ -288,6 +288,23 @@ pub async fn key_images_spent(
|
|||
Ok(status)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::KeyImagesSpentVec`]
|
||||
pub async fn key_images_spent_vec(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
key_images: Vec<[u8; 32]>,
|
||||
) -> Result<Vec<bool>, Error> {
|
||||
let BlockchainResponse::KeyImagesSpentVec(status) = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::KeyImagesSpentVec(key_images))
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::CompactChainHistory`]
|
||||
pub async fn compact_chain_history(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Functions to send [`TxpoolReadRequest`]s.
|
||||
|
||||
use std::{convert::Infallible, num::NonZero};
|
||||
use std::{collections::HashSet, convert::Infallible, num::NonZero};
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use monero_serai::transaction::Transaction;
|
||||
|
@ -109,6 +109,29 @@ pub async fn txs_by_hash(
|
|||
|
||||
/// [`TxpoolReadRequest::KeyImagesSpent`]
|
||||
pub async fn key_images_spent(
|
||||
txpool_read: &mut TxpoolReadHandle,
|
||||
key_images: HashSet<[u8; 32]>,
|
||||
include_sensitive_txs: bool,
|
||||
) -> Result<bool, Error> {
|
||||
let TxpoolReadResponse::KeyImagesSpent(status) = txpool_read
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
.call(TxpoolReadRequest::KeyImagesSpent {
|
||||
key_images,
|
||||
include_sensitive_txs,
|
||||
})
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
/// [`TxpoolReadRequest::KeyImagesSpentVec`]
|
||||
pub async fn key_images_spent_vec(
|
||||
txpool_read: &mut TxpoolReadHandle,
|
||||
key_images: Vec<[u8; 32]>,
|
||||
include_sensitive_txs: bool,
|
||||
|
|
|
@ -232,18 +232,16 @@ where
|
|||
})
|
||||
})?;
|
||||
|
||||
let BlockchainResponse::KeyImagesSpent(kis_status) = database
|
||||
let BlockchainResponse::KeyImagesSpent(kis_spent) = database
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::KeyImagesSpent(
|
||||
spent_kis.into_iter().collect(),
|
||||
))
|
||||
.call(BlockchainReadRequest::KeyImagesSpent(spent_kis))
|
||||
.await?
|
||||
else {
|
||||
panic!("Database sent incorrect response!");
|
||||
};
|
||||
|
||||
if kis_status.contains(&true) {
|
||||
if kis_spent {
|
||||
tracing::debug!("One or more key images in batch already spent.");
|
||||
return Err(ConsensusError::Transaction(TransactionError::KeyImageSpent).into());
|
||||
}
|
||||
|
|
|
@ -45,9 +45,7 @@ fn dummy_database(outputs: BTreeMap<u64, OutputOnChain>) -> impl Database + Clon
|
|||
|
||||
BlockchainResponse::Outputs(ret)
|
||||
}
|
||||
BlockchainReadRequest::KeyImagesSpent(_) => {
|
||||
BlockchainResponse::KeyImagesSpent(vec![false])
|
||||
}
|
||||
BlockchainReadRequest::KeyImagesSpent(_) => BlockchainResponse::KeyImagesSpent(false),
|
||||
_ => panic!("Database request not needed for this test"),
|
||||
}))
|
||||
})
|
||||
|
|
|
@ -62,8 +62,16 @@ pub enum TxpoolReadRequest {
|
|||
include_sensitive_txs: bool,
|
||||
},
|
||||
|
||||
/// Check if certain key images exist in the txpool.
|
||||
/// Check if any individual key images of a set exist in the txpool.
|
||||
KeyImagesSpent {
|
||||
key_images: HashSet<[u8; 32]>,
|
||||
include_sensitive_txs: bool,
|
||||
},
|
||||
|
||||
/// Same as [`TxpoolReadRequest::KeyImagesSpent`] but with a [`Vec`].
|
||||
///
|
||||
/// The response will be in the same order as the request.
|
||||
KeyImagesSpentVec {
|
||||
key_images: Vec<[u8; 32]>,
|
||||
include_sensitive_txs: bool,
|
||||
},
|
||||
|
@ -123,7 +131,15 @@ pub enum TxpoolReadResponse {
|
|||
TxsByHash(Vec<TxInPool>),
|
||||
|
||||
/// Response to [`TxpoolReadRequest::KeyImagesSpent`].
|
||||
KeyImagesSpent(Vec<bool>),
|
||||
KeyImagesSpent(bool),
|
||||
|
||||
/// Response to [`TxpoolReadRequest::KeyImagesSpentVec`].
|
||||
///
|
||||
/// Inner value is a `Vec` the same length as the input.
|
||||
///
|
||||
/// The index of each entry corresponds with the request.
|
||||
/// `true` means that the key image was spent.
|
||||
KeyImagesSpentVec(Vec<bool>),
|
||||
|
||||
/// Response to [`TxpoolReadRequest::Pool`].
|
||||
Pool {
|
||||
|
|
Loading…
Reference in a new issue