mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-11-16 15:58:17 +00:00
init tx-pool DBs
This commit is contained in:
parent
d646eac694
commit
68940de18e
10 changed files with 120 additions and 7 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -804,6 +804,13 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cuprate-txpool"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"cuprate-database",
|
||||
"cuprate-database-service",
|
||||
"cuprate-types",
|
||||
"monero-serai",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cuprate-types"
|
||||
|
|
|
@ -27,7 +27,7 @@ cuprate-helper = { path = "../../helper", features = ["fs", "thread", "map"] }
|
|||
cuprate-types = { path = "../../types", features = ["blockchain"] }
|
||||
|
||||
bitflags = { workspace = true, features = ["serde", "bytemuck"] }
|
||||
bytemuck = { version = "1.14.3", features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
|
||||
bytemuck = { workspace = true, features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
|
||||
curve25519-dalek = { workspace = true }
|
||||
cuprate-pruning = { path = "../../pruning" }
|
||||
monero-serai = { workspace = true, features = ["std"] }
|
||||
|
|
|
@ -28,7 +28,6 @@ use crate::types::{
|
|||
// - Tables are defined in plural to avoid name conflicts with types
|
||||
// - If adding/changing a table also edit:
|
||||
// - the tests in `src/backend/tests.rs`
|
||||
// - `call_fn_on_all_tables_or_early_return!()` macro in `src/open_tables.rs`
|
||||
cuprate_database::define_tables! {
|
||||
/// Serialized block blobs (bytes).
|
||||
///
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Database [table](crate::tables) types.
|
||||
//! Blockchain [table](crate::tables) types.
|
||||
//!
|
||||
//! This module contains all types used by the database tables,
|
||||
//! and aliases for common Monero-related types that use the
|
||||
|
|
|
@ -4,12 +4,18 @@ version = "0.0.0"
|
|||
edition = "2021"
|
||||
description = "Cuprate's transaction pool database"
|
||||
license = "MIT"
|
||||
authors = ["hinto-janai"]
|
||||
repository = "https://github.com/Cuprate/cuprate/tree/main/storage/cuprate-txpool"
|
||||
authors = ["Boog900"]
|
||||
repository = "https://github.com/Cuprate/cuprate/tree/main/storage/txpool"
|
||||
keywords = ["cuprate", "txpool", "transaction", "pool", "database"]
|
||||
|
||||
[features]
|
||||
|
||||
[dependencies]
|
||||
cuprate-database = { path = "../database" }
|
||||
cuprate-database-service = { path = "../service" }
|
||||
cuprate-types = { path = "../../types" }
|
||||
|
||||
monero-serai = { workspace = true, features = ["std"] }
|
||||
bytemuck = { workspace = true, features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
|
||||
mod tables;
|
||||
mod types;
|
||||
|
|
0
storage/txpool/src/tables.rs
Normal file
0
storage/txpool/src/tables.rs
Normal file
67
storage/txpool/src/types.rs
Normal file
67
storage/txpool/src/types.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use bytemuck::{Pod, Zeroable};
|
||||
|
||||
use cuprate_types::CachedVerificationState;
|
||||
use monero_serai::transaction::Timelock;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||
#[repr(C)]
|
||||
pub struct RawCachedVerificationState {
|
||||
raw_valid_at_hash: [u8; 32],
|
||||
raw_hf: u8,
|
||||
raw_valid_past_timestamp: [u8; 8],
|
||||
}
|
||||
|
||||
impl From<RawCachedVerificationState> for CachedVerificationState {
|
||||
fn from(value: RawCachedVerificationState) -> Self {
|
||||
if value.raw_valid_at_hash == [0; 32] {
|
||||
return CachedVerificationState::NotVerified;
|
||||
}
|
||||
|
||||
let raw_valid_past_timestamp = u64::from_le_bytes(value.raw_valid_past_timestamp);
|
||||
|
||||
if raw_valid_past_timestamp == 0 {
|
||||
return CachedVerificationState::ValidAtHashAndHF {
|
||||
block_hash: value.raw_valid_at_hash,
|
||||
hf: value.raw_hf,
|
||||
};
|
||||
}
|
||||
|
||||
CachedVerificationState::ValidAtHashAndHFWithTimeBasedLock {
|
||||
block_hash: value.raw_valid_at_hash,
|
||||
hf: value.raw_hf,
|
||||
time_lock: Timelock::Time(raw_valid_past_timestamp),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CachedVerificationState> for RawCachedVerificationState {
|
||||
fn from(value: CachedVerificationState) -> Self {
|
||||
match value {
|
||||
CachedVerificationState::NotVerified => Self {
|
||||
raw_valid_at_hash: [0; 32],
|
||||
raw_hf: 0,
|
||||
raw_valid_past_timestamp: [0; 8],
|
||||
},
|
||||
CachedVerificationState::ValidAtHashAndHF { block_hash, hf } => Self {
|
||||
raw_valid_at_hash: block_hash,
|
||||
raw_hf: hf,
|
||||
raw_valid_past_timestamp: [0; 8],
|
||||
},
|
||||
CachedVerificationState::ValidAtHashAndHFWithTimeBasedLock {
|
||||
block_hash,
|
||||
hf,
|
||||
time_lock,
|
||||
} => {
|
||||
let Timelock::Time(time) = time_lock else {
|
||||
panic!("ValidAtHashAndHFWithTimeBasedLock timelock was not time-based");
|
||||
};
|
||||
|
||||
Self {
|
||||
raw_valid_at_hash: block_hash,
|
||||
raw_hf: hf,
|
||||
raw_valid_past_timestamp: time.to_le_bytes(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -84,7 +84,8 @@ mod types;
|
|||
|
||||
pub use block_complete_entry::{BlockCompleteEntry, PrunedTxBlobEntry, TransactionBlobs};
|
||||
pub use types::{
|
||||
ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation, VerifiedTransactionInformation,
|
||||
CachedVerificationState, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation,
|
||||
VerifiedTransactionInformation,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Feature-gated
|
||||
|
|
|
@ -105,6 +105,38 @@ pub struct OutputOnChain {
|
|||
pub commitment: EdwardsPoint,
|
||||
}
|
||||
|
||||
/// Represents if a transaction has been fully validated and under what conditions
|
||||
/// the transaction is valid in the future.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CachedVerificationState {
|
||||
/// The transaction has not been validated.
|
||||
NotVerified,
|
||||
/// The transaction is valid* if the block represented by this hash is in the blockchain and the [`HardFork`]
|
||||
/// is the same.
|
||||
///
|
||||
/// *V1 transactions require checks on their ring-length even if this hash is in the blockchain.
|
||||
ValidAtHashAndHF {
|
||||
/// The block hash that was in the chain when this transaction was validated.
|
||||
block_hash: [u8; 32],
|
||||
/// The hf this transaction was validated against.
|
||||
hf: u8,
|
||||
},
|
||||
/// The transaction is valid* if the block represented by this hash is in the blockchain _and_ this
|
||||
/// given time lock is unlocked. The time lock here will represent the youngest used time based lock
|
||||
/// (If the transaction uses any time based time locks). This is because time locks are not monotonic
|
||||
/// so unlocked outputs could become re-locked.
|
||||
///
|
||||
/// *V1 transactions require checks on their ring-length even if this hash is in the blockchain.
|
||||
ValidAtHashAndHFWithTimeBasedLock {
|
||||
/// The block hash that was in the chain when this transaction was validated.
|
||||
block_hash: [u8; 32],
|
||||
/// The hf this transaction was validated against.
|
||||
hf: u8,
|
||||
/// The youngest used time based lock.
|
||||
time_lock: Timelock,
|
||||
},
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Tests
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
Loading…
Reference in a new issue