mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-21 10:14:30 +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());
|
let mut spent_status = Vec::with_capacity(key_images.len());
|
||||||
|
|
||||||
// Check the blockchain for key image spend status.
|
// 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?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|ki| {
|
.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.
|
// Check if the remaining unspent key images exist in the transaction pool.
|
||||||
if !key_images.is_empty() {
|
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?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|ki| {
|
.for_each(|ki| {
|
||||||
|
|
|
@ -124,7 +124,7 @@ pub async fn next_chain_entry(
|
||||||
blockchain_read: &mut BlockchainReadHandle,
|
blockchain_read: &mut BlockchainReadHandle,
|
||||||
block_hashes: Vec<[u8; 32]>,
|
block_hashes: Vec<[u8; 32]>,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<(Vec<[u8; 32]>, Option<std::num::NonZero<usize>>), Error> {
|
) -> Result<(Vec<[u8; 32]>, usize), Error> {
|
||||||
let BlockchainResponse::NextChainEntry {
|
let BlockchainResponse::NextChainEntry {
|
||||||
block_ids,
|
block_ids,
|
||||||
chain_height,
|
chain_height,
|
||||||
|
@ -274,8 +274,8 @@ pub async fn number_outputs_with_amount(
|
||||||
/// [`BlockchainReadRequest::KeyImagesSpent`]
|
/// [`BlockchainReadRequest::KeyImagesSpent`]
|
||||||
pub async fn key_images_spent(
|
pub async fn key_images_spent(
|
||||||
blockchain_read: &mut BlockchainReadHandle,
|
blockchain_read: &mut BlockchainReadHandle,
|
||||||
key_images: Vec<[u8; 32]>,
|
key_images: HashSet<[u8; 32]>,
|
||||||
) -> Result<Vec<bool>, Error> {
|
) -> Result<bool, Error> {
|
||||||
let BlockchainResponse::KeyImagesSpent(status) = blockchain_read
|
let BlockchainResponse::KeyImagesSpent(status) = blockchain_read
|
||||||
.ready()
|
.ready()
|
||||||
.await?
|
.await?
|
||||||
|
@ -288,6 +288,23 @@ pub async fn key_images_spent(
|
||||||
Ok(status)
|
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`]
|
/// [`BlockchainReadRequest::CompactChainHistory`]
|
||||||
pub async fn compact_chain_history(
|
pub async fn compact_chain_history(
|
||||||
blockchain_read: &mut BlockchainReadHandle,
|
blockchain_read: &mut BlockchainReadHandle,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Functions to send [`TxpoolReadRequest`]s.
|
//! Functions to send [`TxpoolReadRequest`]s.
|
||||||
|
|
||||||
use std::{convert::Infallible, num::NonZero};
|
use std::{collections::HashSet, convert::Infallible, num::NonZero};
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use monero_serai::transaction::Transaction;
|
use monero_serai::transaction::Transaction;
|
||||||
|
@ -109,6 +109,29 @@ pub async fn txs_by_hash(
|
||||||
|
|
||||||
/// [`TxpoolReadRequest::KeyImagesSpent`]
|
/// [`TxpoolReadRequest::KeyImagesSpent`]
|
||||||
pub async fn key_images_spent(
|
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,
|
txpool_read: &mut TxpoolReadHandle,
|
||||||
key_images: Vec<[u8; 32]>,
|
key_images: Vec<[u8; 32]>,
|
||||||
include_sensitive_txs: bool,
|
include_sensitive_txs: bool,
|
||||||
|
|
|
@ -232,18 +232,16 @@ where
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let BlockchainResponse::KeyImagesSpent(kis_status) = database
|
let BlockchainResponse::KeyImagesSpent(kis_spent) = database
|
||||||
.ready()
|
.ready()
|
||||||
.await?
|
.await?
|
||||||
.call(BlockchainReadRequest::KeyImagesSpent(
|
.call(BlockchainReadRequest::KeyImagesSpent(spent_kis))
|
||||||
spent_kis.into_iter().collect(),
|
|
||||||
))
|
|
||||||
.await?
|
.await?
|
||||||
else {
|
else {
|
||||||
panic!("Database sent incorrect response!");
|
panic!("Database sent incorrect response!");
|
||||||
};
|
};
|
||||||
|
|
||||||
if kis_status.contains(&true) {
|
if kis_spent {
|
||||||
tracing::debug!("One or more key images in batch already spent.");
|
tracing::debug!("One or more key images in batch already spent.");
|
||||||
return Err(ConsensusError::Transaction(TransactionError::KeyImageSpent).into());
|
return Err(ConsensusError::Transaction(TransactionError::KeyImageSpent).into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,7 @@ fn dummy_database(outputs: BTreeMap<u64, OutputOnChain>) -> impl Database + Clon
|
||||||
|
|
||||||
BlockchainResponse::Outputs(ret)
|
BlockchainResponse::Outputs(ret)
|
||||||
}
|
}
|
||||||
BlockchainReadRequest::KeyImagesSpent(_) => {
|
BlockchainReadRequest::KeyImagesSpent(_) => BlockchainResponse::KeyImagesSpent(false),
|
||||||
BlockchainResponse::KeyImagesSpent(vec![false])
|
|
||||||
}
|
|
||||||
_ => panic!("Database request not needed for this test"),
|
_ => panic!("Database request not needed for this test"),
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
|
@ -62,8 +62,16 @@ pub enum TxpoolReadRequest {
|
||||||
include_sensitive_txs: bool,
|
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 {
|
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]>,
|
key_images: Vec<[u8; 32]>,
|
||||||
include_sensitive_txs: bool,
|
include_sensitive_txs: bool,
|
||||||
},
|
},
|
||||||
|
@ -123,7 +131,15 @@ pub enum TxpoolReadResponse {
|
||||||
TxsByHash(Vec<TxInPool>),
|
TxsByHash(Vec<TxInPool>),
|
||||||
|
|
||||||
/// Response to [`TxpoolReadRequest::KeyImagesSpent`].
|
/// 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`].
|
/// Response to [`TxpoolReadRequest::Pool`].
|
||||||
Pool {
|
Pool {
|
||||||
|
|
Loading…
Reference in a new issue