mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-11-16 15:58:17 +00:00
review fixes
This commit is contained in:
parent
cd6749e8f7
commit
5cae64f214
10 changed files with 50 additions and 22 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
@ -56,6 +56,18 @@ version = "1.0.89"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "async-stream"
|
||||
version = "0.3.5"
|
||||
|
@ -238,6 +250,19 @@ dependencies = [
|
|||
"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]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
|
@ -403,6 +428,12 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
|
@ -899,6 +930,7 @@ name = "cuprate-txpool"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"blake3",
|
||||
"bytemuck",
|
||||
"cuprate-database",
|
||||
"cuprate-database-service",
|
||||
|
@ -910,7 +942,6 @@ dependencies = [
|
|||
"monero-serai",
|
||||
"rayon",
|
||||
"serde",
|
||||
"sha3",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
|
@ -1010,7 +1041,6 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_json",
|
||||
"sha3",
|
||||
"thiserror",
|
||||
"thread_local",
|
||||
"tokio",
|
||||
|
|
|
@ -52,6 +52,7 @@ opt-level = 3
|
|||
anyhow = { version = "1.0.89", default-features = false }
|
||||
async-trait = { version = "0.1.82", 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 }
|
||||
bytemuck = { version = "1.18.0", 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_json = { version = "1.0.128", 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 }
|
||||
thiserror = { version = "1.0.63", default-features = false }
|
||||
thread_local = { version = "1.1.8", default-features = false }
|
||||
|
|
|
@ -64,7 +64,6 @@ rayon = { workspace = true }
|
|||
serde_bytes = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
sha3 = { workspace = true, features = ["std"] }
|
||||
thiserror = { workspace = true }
|
||||
thread_local = { workspace = true }
|
||||
tokio-util = { workspace = true }
|
||||
|
|
|
@ -277,7 +277,7 @@ async fn handle_valid_tx(
|
|||
.expect(PANIC_CRITICAL_SERVICE_ERROR)
|
||||
.call(TxpoolWriteRequest::AddTransaction {
|
||||
tx,
|
||||
state_stem: state.state_stage(),
|
||||
state_stem: state.is_stem_stage(),
|
||||
})
|
||||
.await
|
||||
.expect("TODO")
|
||||
|
|
|
@ -74,10 +74,10 @@ pub enum 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.
|
||||
pub const fn state_stage(&self) -> bool {
|
||||
pub const fn is_stem_stage(&self) -> bool {
|
||||
matches!(self, Self::Local | Self::Stem { .. })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ bytemuck = { workspace = true, features = ["must_cast", "derive"
|
|||
bitflags = { workspace = true, features = ["std", "serde", "bytemuck"] }
|
||||
thiserror = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
sha3 = { workspace = true, features = ["std"] }
|
||||
blake3 = { workspace = true, features = ["std"] }
|
||||
|
||||
tower = { workspace = true, optional = true }
|
||||
rayon = { workspace = true, optional = true }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
//! General free functions (related to the tx-pool database).
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Import
|
||||
use sha3::{Digest, Sha3_256};
|
||||
|
||||
use cuprate_database::{ConcreteEnv, Env, EnvInner, InitError, RuntimeError, TxRw};
|
||||
|
||||
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
|
||||
/// as a way to interact with Cuprate externally.
|
||||
pub fn transaction_blob_hash(tx_blob: &[u8]) -> TransactionBlobHash {
|
||||
let mut hasher = Sha3_256::new();
|
||||
hasher.update(tx_blob);
|
||||
hasher.finalize().into()
|
||||
blake3::hash(tx_blob).into()
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
tx_hash: &TransactionHash,
|
||||
tx_infos: &impl DatabaseRo<TransactionInfos>,
|
||||
|
|
|
@ -17,18 +17,18 @@ use crate::{
|
|||
/// The transaction pool [`tower::Service`] read request type.
|
||||
#[derive(Clone)]
|
||||
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),
|
||||
|
||||
/// A request for the [`TransactionVerificationData`] of a transaction in the tx pool.
|
||||
/// Get the [`TransactionVerificationData`] of a transaction in the tx pool.
|
||||
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.
|
||||
FilterKnownTxBlobHashes(HashSet<TransactionBlobHash>),
|
||||
|
||||
/// A request to pull some transactions for an incoming block.
|
||||
/// Get some transactions for an incoming block.
|
||||
TxsForBlock(Vec<TransactionHash>),
|
||||
|
||||
/// Get information on all transactions in the pool.
|
||||
|
@ -42,10 +42,10 @@ pub enum TxpoolReadRequest {
|
|||
/// The transaction pool [`tower::Service`] read response type.
|
||||
#[expect(clippy::large_enum_variant)]
|
||||
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 },
|
||||
|
||||
/// A response of [`TransactionVerificationData`].
|
||||
/// The response for [`TxpoolReadRequest::TxVerificationData`].
|
||||
TxVerificationData(TransactionVerificationData),
|
||||
|
||||
/// The response for [`TxpoolReadRequest::FilterKnownTxBlobHashes`].
|
||||
|
@ -117,6 +117,8 @@ pub enum TxpoolWriteRequest {
|
|||
pub enum TxpoolWriteResponse {
|
||||
/// Response to:
|
||||
/// - [`TxpoolWriteRequest::RemoveTransaction`]
|
||||
/// - [`TxpoolWriteRequest::Promote`]
|
||||
/// - [`TxpoolWriteRequest::NewBlock`]
|
||||
Ok,
|
||||
|
||||
/// Response to [`TxpoolWriteRequest::AddTransaction`].
|
||||
|
|
|
@ -133,7 +133,7 @@ fn filter_known_tx_blob_hashes(
|
|||
|
||||
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`.
|
||||
let mut tx_unknown = |blob_hash| -> Result<bool, RuntimeError> {
|
||||
match tx_blob_hashes.get(&blob_hash) {
|
||||
|
|
Loading…
Reference in a new issue