review fixes
Some checks failed
Audit / audit (push) Has been cancelled
Deny / audit (push) Has been cancelled

This commit is contained in:
Boog900 2024-10-23 00:29:38 +01:00
parent cd6749e8f7
commit 5cae64f214
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
10 changed files with 50 additions and 22 deletions

34
Cargo.lock generated
View file

@ -56,6 +56,18 @@ version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
[[package]]
name = "arrayref"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
[[package]]
name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]] [[package]]
name = "async-stream" name = "async-stream"
version = "0.3.5" version = "0.3.5"
@ -238,6 +250,19 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "blake3"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82033247fd8e890df8f740e407ad4d038debb9eb1f40533fffb32e7d17dc6f7"
dependencies = [
"arrayref",
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq",
]
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@ -403,6 +428,12 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "constant_time_eq"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.4" version = "0.9.4"
@ -899,6 +930,7 @@ name = "cuprate-txpool"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"blake3",
"bytemuck", "bytemuck",
"cuprate-database", "cuprate-database",
"cuprate-database-service", "cuprate-database-service",
@ -910,7 +942,6 @@ dependencies = [
"monero-serai", "monero-serai",
"rayon", "rayon",
"serde", "serde",
"sha3",
"tempfile", "tempfile",
"thiserror", "thiserror",
"tokio", "tokio",
@ -1010,7 +1041,6 @@ dependencies = [
"serde", "serde",
"serde_bytes", "serde_bytes",
"serde_json", "serde_json",
"sha3",
"thiserror", "thiserror",
"thread_local", "thread_local",
"tokio", "tokio",

View file

@ -52,6 +52,7 @@ opt-level = 3
anyhow = { version = "1.0.89", default-features = false } anyhow = { version = "1.0.89", default-features = false }
async-trait = { version = "0.1.82", default-features = false } async-trait = { version = "0.1.82", default-features = false }
bitflags = { version = "2.6.0", default-features = false } bitflags = { version = "2.6.0", default-features = false }
blake3 = { version = "1", default-features = false }
borsh = { version = "1.5.1", default-features = false } borsh = { version = "1.5.1", default-features = false }
bytemuck = { version = "1.18.0", default-features = false } bytemuck = { version = "1.18.0", default-features = false }
bytes = { version = "1.7.2", default-features = false } bytes = { version = "1.7.2", default-features = false }
@ -78,7 +79,6 @@ rayon = { version = "1.10.0", default-features = false }
serde_bytes = { version = "0.11.15", default-features = false } serde_bytes = { version = "0.11.15", default-features = false }
serde_json = { version = "1.0.128", default-features = false } serde_json = { version = "1.0.128", default-features = false }
serde = { version = "1.0.210", default-features = false } serde = { version = "1.0.210", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
strum = { version = "0.26.3", default-features = false } strum = { version = "0.26.3", default-features = false }
thiserror = { version = "1.0.63", default-features = false } thiserror = { version = "1.0.63", default-features = false }
thread_local = { version = "1.1.8", default-features = false } thread_local = { version = "1.1.8", default-features = false }

View file

@ -64,7 +64,6 @@ rayon = { workspace = true }
serde_bytes = { workspace = true } serde_bytes = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
sha3 = { workspace = true, features = ["std"] }
thiserror = { workspace = true } thiserror = { workspace = true }
thread_local = { workspace = true } thread_local = { workspace = true }
tokio-util = { workspace = true } tokio-util = { workspace = true }

View file

@ -277,7 +277,7 @@ async fn handle_valid_tx(
.expect(PANIC_CRITICAL_SERVICE_ERROR) .expect(PANIC_CRITICAL_SERVICE_ERROR)
.call(TxpoolWriteRequest::AddTransaction { .call(TxpoolWriteRequest::AddTransaction {
tx, tx,
state_stem: state.state_stage(), state_stem: state.is_stem_stage(),
}) })
.await .await
.expect("TODO") .expect("TODO")

View file

@ -74,10 +74,10 @@ pub enum TxState<Id> {
} }
impl<Id> TxState<Id> { impl<Id> TxState<Id> {
/// Returns if the tx is in the stem stage. /// Returns `true` if the tx is in the stem stage.
/// ///
/// [`TxState::Local`] & [`TxState::Stem`] are the 2 stem stage states. /// [`TxState::Local`] & [`TxState::Stem`] are the 2 stem stage states.
pub const fn state_stage(&self) -> bool { pub const fn is_stem_stage(&self) -> bool {
matches!(self, Self::Local | Self::Stem { .. }) matches!(self, Self::Local | Self::Stem { .. })
} }
} }

View file

@ -29,7 +29,7 @@ bytemuck = { workspace = true, features = ["must_cast", "derive"
bitflags = { workspace = true, features = ["std", "serde", "bytemuck"] } bitflags = { workspace = true, features = ["std", "serde", "bytemuck"] }
thiserror = { workspace = true } thiserror = { workspace = true }
hex = { workspace = true } hex = { workspace = true }
sha3 = { workspace = true, features = ["std"] } blake3 = { workspace = true, features = ["std"] }
tower = { workspace = true, optional = true } tower = { workspace = true, optional = true }
rayon = { workspace = true, optional = true } rayon = { workspace = true, optional = true }

View file

@ -1,8 +1,6 @@
//! General free functions (related to the tx-pool database). //! General free functions (related to the tx-pool database).
//---------------------------------------------------------------------------------------------------- Import //---------------------------------------------------------------------------------------------------- Import
use sha3::{Digest, Sha3_256};
use cuprate_database::{ConcreteEnv, Env, EnvInner, InitError, RuntimeError, TxRw}; use cuprate_database::{ConcreteEnv, Env, EnvInner, InitError, RuntimeError, TxRw};
use crate::{config::Config, tables::OpenTables, types::TransactionBlobHash}; use crate::{config::Config, tables::OpenTables, types::TransactionBlobHash};
@ -70,7 +68,5 @@ pub fn open(config: Config) -> Result<ConcreteEnv, InitError> {
/// The exact way the hash is calculated is not stable and is subject to change, as such it should not be exposed /// The exact way the hash is calculated is not stable and is subject to change, as such it should not be exposed
/// as a way to interact with Cuprate externally. /// as a way to interact with Cuprate externally.
pub fn transaction_blob_hash(tx_blob: &[u8]) -> TransactionBlobHash { pub fn transaction_blob_hash(tx_blob: &[u8]) -> TransactionBlobHash {
let mut hasher = Sha3_256::new(); blake3::hash(tx_blob).into()
hasher.update(tx_blob);
hasher.finalize().into()
} }

View file

@ -38,9 +38,10 @@ pub fn get_transaction_verification_data(
}) })
} }
/// Returns if the transaction with the given hash is in the stem pool. /// Returns `true` if the transaction with the given hash is in the stem pool.
/// ///
/// This will return an err if the transaction is not in the pool. /// # Errors
/// This will return an [`Err`] if the transaction is not in the pool.
pub fn in_stem_pool( pub fn in_stem_pool(
tx_hash: &TransactionHash, tx_hash: &TransactionHash,
tx_infos: &impl DatabaseRo<TransactionInfos>, tx_infos: &impl DatabaseRo<TransactionInfos>,

View file

@ -17,18 +17,18 @@ use crate::{
/// The transaction pool [`tower::Service`] read request type. /// The transaction pool [`tower::Service`] read request type.
#[derive(Clone)] #[derive(Clone)]
pub enum TxpoolReadRequest { pub enum TxpoolReadRequest {
/// A request for the blob (raw bytes) of a transaction with the given hash. /// Get the blob (raw bytes) of a transaction with the given hash.
TxBlob(TransactionHash), TxBlob(TransactionHash),
/// A request for the [`TransactionVerificationData`] of a transaction in the tx pool. /// Get the [`TransactionVerificationData`] of a transaction in the tx pool.
TxVerificationData(TransactionHash), TxVerificationData(TransactionHash),
/// A request to filter (remove) all **known** transactions from the set. /// Filter (remove) all **known** transactions from the set.
/// ///
/// The hash is **not** the transaction hash, it is the hash of the serialized tx-blob. /// The hash is **not** the transaction hash, it is the hash of the serialized tx-blob.
FilterKnownTxBlobHashes(HashSet<TransactionBlobHash>), FilterKnownTxBlobHashes(HashSet<TransactionBlobHash>),
/// A request to pull some transactions for an incoming block. /// Get some transactions for an incoming block.
TxsForBlock(Vec<TransactionHash>), TxsForBlock(Vec<TransactionHash>),
/// Get information on all transactions in the pool. /// Get information on all transactions in the pool.
@ -42,10 +42,10 @@ pub enum TxpoolReadRequest {
/// The transaction pool [`tower::Service`] read response type. /// The transaction pool [`tower::Service`] read response type.
#[expect(clippy::large_enum_variant)] #[expect(clippy::large_enum_variant)]
pub enum TxpoolReadResponse { pub enum TxpoolReadResponse {
/// A response containing the raw bytes of a transaction. /// The response for [`TxpoolReadRequest::TxBlob`].
TxBlob { tx_blob: Vec<u8>, state_stem: bool }, TxBlob { tx_blob: Vec<u8>, state_stem: bool },
/// A response of [`TransactionVerificationData`]. /// The response for [`TxpoolReadRequest::TxVerificationData`].
TxVerificationData(TransactionVerificationData), TxVerificationData(TransactionVerificationData),
/// The response for [`TxpoolReadRequest::FilterKnownTxBlobHashes`]. /// The response for [`TxpoolReadRequest::FilterKnownTxBlobHashes`].
@ -117,6 +117,8 @@ pub enum TxpoolWriteRequest {
pub enum TxpoolWriteResponse { pub enum TxpoolWriteResponse {
/// Response to: /// Response to:
/// - [`TxpoolWriteRequest::RemoveTransaction`] /// - [`TxpoolWriteRequest::RemoveTransaction`]
/// - [`TxpoolWriteRequest::Promote`]
/// - [`TxpoolWriteRequest::NewBlock`]
Ok, Ok,
/// Response to [`TxpoolWriteRequest::AddTransaction`]. /// Response to [`TxpoolWriteRequest::AddTransaction`].

View file

@ -133,7 +133,7 @@ fn filter_known_tx_blob_hashes(
let mut stem_pool_hashes = Vec::new(); let mut stem_pool_hashes = Vec::new();
// A closure that returns if a tx with a certain blob hash is unknown. // A closure that returns `true` if a tx with a certain blob hash is unknown.
// This also fills in `stem_tx_hashes`. // This also fills in `stem_tx_hashes`.
let mut tx_unknown = |blob_hash| -> Result<bool, RuntimeError> { let mut tx_unknown = |blob_hash| -> Result<bool, RuntimeError> {
match tx_blob_hashes.get(&blob_hash) { match tx_blob_hashes.get(&blob_hash) {