clean up dependencies

This commit is contained in:
Boog900 2024-01-21 14:46:03 +00:00
parent 50894bef89
commit b9334b6a90
No known key found for this signature in database
GPG key ID: 5401367FB7302004
11 changed files with 776 additions and 838 deletions

91
Cargo.lock generated
View file

@ -285,9 +285,7 @@ checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
"js-sys",
"num-traits", "num-traits",
"wasm-bindgen",
"windows-targets 0.48.5", "windows-targets 0.48.5",
] ]
@ -408,7 +406,6 @@ version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
dependencies = [ dependencies = [
"rand_core",
"subtle", "subtle",
] ]
@ -448,7 +445,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"borsh", "borsh",
"clap", "clap",
"crypto-bigint",
"cuprate-common", "cuprate-common",
"curve25519-dalek", "curve25519-dalek",
"dalek-ff-group", "dalek-ff-group",
@ -701,7 +697,6 @@ checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-executor",
"futures-io", "futures-io",
"futures-sink", "futures-sink",
"futures-task", "futures-task",
@ -724,34 +719,12 @@ version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
[[package]]
name = "futures-executor"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]] [[package]]
name = "futures-io" name = "futures-io"
version = "0.3.30" version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
[[package]]
name = "futures-macro"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.30" version = "0.3.30"
@ -773,7 +746,6 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-io", "futures-io",
"futures-macro",
"futures-sink", "futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
@ -1063,16 +1035,6 @@ version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.20" version = "0.4.20"
@ -1166,7 +1128,6 @@ dependencies = [
"thiserror", "thiserror",
"tokio", "tokio",
"tracing", "tracing",
"zeroize",
] ]
[[package]] [[package]]
@ -1349,29 +1310,6 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.48.5",
]
[[package]] [[package]]
name = "password-hash" name = "password-hash"
version = "0.5.0" version = "0.5.0"
@ -1483,9 +1421,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.76" version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1594,7 +1532,7 @@ dependencies = [
[[package]] [[package]]
name = "randomx-rs" name = "randomx-rs"
version = "1.3.0" version = "1.3.0"
source = "git+https://github.com/Cuprate/randomx-rs.git#6496a61208852a020575dafc160080cf50bda67f" source = "git+https://github.com/Cuprate/randomx-rs.git?rev=6496a61#6496a61208852a020575dafc160080cf50bda67f"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"libc", "libc",
@ -1764,12 +1702,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "sct" name = "sct"
version = "0.7.1" version = "0.7.1"
@ -1879,15 +1811,6 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "simple-request" name = "simple-request"
version = "0.1.0" version = "0.1.0"
@ -1909,9 +1832,9 @@ dependencies = [
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.12.0" version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]] [[package]]
name = "socket2" name = "socket2"
@ -2055,13 +1978,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes",
"libc", "libc",
"mio", "mio",
"num_cpus", "num_cpus",
"parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.48.0", "windows-sys 0.48.0",
@ -2169,7 +2089,6 @@ version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [ dependencies = [
"log",
"pin-project-lite", "pin-project-lite",
"tracing-attributes", "tracing-attributes",
"tracing-core", "tracing-core",

View file

@ -35,32 +35,36 @@ opt-level = 1
opt-level = 3 opt-level = 3
[workspace.dependencies] [workspace.dependencies]
async-trait = { version = "0.1.74" } async-trait = { version = "0.1.74", default-features = false }
borsh = { version = "1.2.1", features = ["derive"] } borsh = { version = "1.2.1", default-features = false }
bytes = { version = "1.5.0" } bytes = { version = "1.5.0", default-features = false }
clap = { version = "4.4.7" } clap = { version = "4.4.7", default-features = false }
chrono = { version = "0.4.31" } chrono = { version = "0.4.31", default-features = false }
crypto-bigint = { version = "0.5.3" } primitive-types = { version = "0.12.2", default-features = false }
curve25519-dalek = { version = "4.1.1" } curve25519-dalek = { version = "4.1.1", default-features = false }
dalek-ff-group = { git = "https://github.com/Cuprate/serai.git", rev = "a59966b" } dalek-ff-group = { git = "https://github.com/Cuprate/serai.git", rev = "a59966b", default-features = false }
dirs = { version = "5.0.1" } dirs = { version = "5.0.1", default-features = false }
futures = { version = "0.3.29" } futures = { version = "0.3.29", default-features = false }
hex = { version = "0.4.3" } hex = { version = "0.4.3", default-features = false }
monero-epee-bin-serde = { git = "https://github.com/monero-rs/monero-epee-bin-serde.git", rev = "e4a585a" } hex-literal = { version = "0.4", default-features = false }
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "a59966b" } monero-epee-bin-serde = { git = "https://github.com/monero-rs/monero-epee-bin-serde.git", rev = "e4a585a", default-features = false }
multiexp = { git = "https://github.com/Cuprate/serai.git", rev = "a59966b" } monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "a59966b", default-features = false }
randomx-rs = { version = "1.2.1" } multiexp = { git = "https://github.com/Cuprate/serai.git", rev = "a59966b", default-features = false }
rand = { version = "0.8.5" } pin-project = { version = "1.1.3", default-features = false }
rayon = { version = "1.8.0" } randomx-rs = { git = "https://github.com/Cuprate/randomx-rs.git", rev = "6496a61", default-features = false }
serde_bytes = { version = "0.11.12" } rand = { version = "0.8.5", default-features = false }
serde_json = { version = "1.0.108" } rayon = { version = "1.8.0", default-features = false }
serde = { version = "1.0.190", features = ["derive"] } serde_bytes = { version = "0.11.12", default-features = false }
thiserror = { version = "1.0.50" } serde_json = { version = "1.0.108", default-features = false }
tokio-util = { version = "0.7.10", features = ["codec"]} serde = { version = "1.0.190", default-features = false }
tokio = { version = "1.33.0", features = ["full"] } thiserror = { version = "1.0.50", default-features = false }
tower = { version = "0.4.13", features = ["util", "steer"] } thread_local = { version = "1.1.7", default-features = false }
tracing-subscriber = { version = "0.3.17" } tokio-util = { version = "0.7.10", default-features = false }
tracing = { version = "0.1.40" } tokio-stream = { version = "0.1.14", default-features = false }
tokio = { version = "1.33.0", default-features = false }
tower = { version = "0.4.13", default-features = false }
tracing-subscriber = { version = "0.3.17", default-features = false }
tracing = { version = "0.1.40", default-features = false }
## workspace.dev-dependencies ## workspace.dev-dependencies
proptest = { version = "1" } proptest = { version = "1" }

View file

@ -10,10 +10,10 @@ default = []
borsh = ["dep:borsh"] borsh = ["dep:borsh"]
[dependencies] [dependencies]
chrono = "0.4.24" chrono = { workspace = true }
thiserror = "1" thiserror = { workspace = true }
hex = "0.4" hex = { workspace = true, features = ["std"] }
futures = "0.3.29" futures = { workspace = true, features = ["std"] }
borsh = {version = "1.2.1", default-features = false, features = ["derive",], optional = true } borsh = { workspace = true, features = ["derive", "std"], optional = true }

View file

@ -8,15 +8,17 @@ authors = ["Boog900"]
repository = "https://github.com/Cuprate/cuprate/tree/main/consensus" repository = "https://github.com/Cuprate/cuprate/tree/main/consensus"
[features] [features]
default = ["binaries"] default = []
binaries = [ binaries = [
"tokio/rt-multi-thread", "tokio/rt-multi-thread",
"tokio/macros", "tokio/macros",
"dep:tracing-subscriber",
"tower/retry", "tower/retry",
"tower/balance", "tower/balance",
"tower/buffer", "tower/buffer",
"tower/timeout", "tower/timeout",
"monero-serai/http-rpc",
"dep:curve25519-dalek",
"dep:tracing-subscriber",
"dep:serde_json", "dep:serde_json",
"dep:serde", "dep:serde",
"dep:monero-epee-bin-serde", "dep:monero-epee-bin-serde",
@ -27,27 +29,23 @@ binaries = [
] ]
[dependencies] [dependencies]
cuprate-common = {path = "../common"}
monero-consensus = {path = "./rules", features = ["rayon"]} monero-consensus = {path = "./rules", features = ["rayon"]}
thiserror = "1" thiserror = { workspace = true }
tower = {version = "0.4", features = ["util"]} tower = { workspace = true, features = ["util"] }
tracing = "0.1" tracing = { workspace = true, features = ["std", "attributes"] }
futures = "0.3" futures = { workspace = true, features = ["std"] }
crypto-bigint = "0.5" randomx-rs = { workspace = true }
curve25519-dalek = "4" monero-serai = { workspace = true, features = ["std"] }
randomx-rs = {git = "https://github.com/Cuprate/randomx-rs.git"}
monero-serai = { workspace = true }
multiexp = { workspace = true } multiexp = { workspace = true }
dalek-ff-group = { workspace = true } dalek-ff-group = { workspace = true }
cuprate-common = {path = "../common"} rayon = { workspace = true }
thread_local = { workspace = true }
rayon = "1" tokio = { workspace = true }
thread_local = "1.1.7" tokio-util = { workspace = true }
tokio = "1"
tokio-util = "0.7"
hex = "0.4" hex = "0.4"
@ -60,6 +58,7 @@ tracing-subscriber = {version = "0.3", optional = true}
borsh = { workspace = true, optional = true} borsh = { workspace = true, optional = true}
dirs = {version="5.0", optional = true} dirs = {version="5.0", optional = true}
clap = { version = "4.4.8", optional = true, features = ["derive"] } clap = { version = "4.4.8", optional = true, features = ["derive"] }
curve25519-dalek = { workspace = true, optional = true }
# here to help cargo to pick a version - remove me # here to help cargo to pick a version - remove me
syn = "2.0.37" syn = "2.0.37"
@ -67,6 +66,6 @@ syn = "2.0.37"
[dev-dependencies] [dev-dependencies]
monero-consensus = {path = "./rules", features = ["proptest"]} monero-consensus = {path = "./rules", features = ["proptest"]}
tokio = {version = "1", features = ["rt-multi-thread", "macros"]} tokio = { workspace = true, features = ["rt-multi-thread", "macros"]}
proptest = "1" proptest = { workspace = true }
proptest-derive = "0.4.0" proptest-derive = { workspace = true }

View file

@ -12,19 +12,18 @@ rayon = ["dep:rayon"]
cryptonight-cuprate = {path = "../../cryptonight"} cryptonight-cuprate = {path = "../../cryptonight"}
cuprate-common = {path = "../../common"} cuprate-common = {path = "../../common"}
monero-serai = { workspace = true } monero-serai = { workspace = true, features = ["std"] }
multiexp = { workspace = true } multiexp = { workspace = true, features = ["std", "batch"] }
dalek-ff-group = { workspace = true } dalek-ff-group = { workspace = true, features = ["std"] }
zeroize = "1.7" curve25519-dalek = { workspace = true, features = ["alloc", "zeroize", "precomputed-tables"] }
curve25519-dalek = { workspace = true }
rand = { workspace = true } rand = { workspace = true, features = ["std"] }
hex = "0.4" hex = { workspace = true, features = ["std"] }
hex-literal = "0.4" hex-literal = { workspace = true }
primitive-types = { version = "0.12.2", default-features = false } primitive-types = { workspace = true } # enabiling std pulls in 9 extra crates!
tracing = { workspace = true } tracing = { workspace = true, features = ["std"] }
thiserror = { workspace = true } thiserror = { workspace = true }
rayon = { workspace = true, optional = true } rayon = { workspace = true, optional = true }

View file

@ -1,25 +1,27 @@
#![cfg(feature = "binaries")] mod tx_pool;
use std::{ #[cfg(feature = "binaries")]
mod bin {
use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
ops::Range, ops::Range,
path::PathBuf, path::PathBuf,
sync::Arc, sync::Arc,
}; };
use clap::Parser; use clap::Parser;
use futures::{ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
SinkExt, StreamExt, SinkExt, StreamExt,
}; };
use monero_serai::{block::Block, transaction::Transaction}; use monero_serai::{block::Block, transaction::Transaction};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
use tracing::level_filters::LevelFilter; use tracing::level_filters::LevelFilter;
use cuprate_common::Network; use cuprate_common::Network;
use cuprate_consensus::{ use cuprate_consensus::{
block::PrePreparedBlockExPOW, block::PrePreparedBlockExPOW,
context::{ context::{
BlockChainContextRequest, BlockChainContextResponse, ContextConfig, BlockChainContextRequest, BlockChainContextResponse, ContextConfig,
@ -30,38 +32,38 @@ use cuprate_consensus::{
rpc::{cache::ScanningCache, init_rpc_load_balancer, RpcConfig}, rpc::{cache::ScanningCache, init_rpc_load_balancer, RpcConfig},
Database, DatabaseRequest, DatabaseResponse, PrePreparedBlock, VerifiedBlockInformation, Database, DatabaseRequest, DatabaseResponse, PrePreparedBlock, VerifiedBlockInformation,
VerifyBlockRequest, VerifyBlockResponse, VerifyBlockRequest, VerifyBlockResponse,
}; };
use monero_consensus::{blocks::randomx_seed_height, HardFork}; use monero_consensus::{blocks::randomx_seed_height, HardFork};
mod tx_pool; use super::tx_pool;
const MAX_BLOCKS_IN_RANGE: u64 = 500; const MAX_BLOCKS_IN_RANGE: u64 = 500;
const BATCHES_IN_REQUEST: u64 = 3; const BATCHES_IN_REQUEST: u64 = 3;
const MAX_BLOCKS_HEADERS_IN_RANGE: u64 = 1000; const MAX_BLOCKS_HEADERS_IN_RANGE: u64 = 1000;
/// Calls for a batch of blocks, returning the response and the time it took. /// Calls for a batch of blocks, returning the response and the time it took.
async fn call_batch<D: Database>( async fn call_batch<D: Database>(
range: Range<u64>, range: Range<u64>,
database: D, database: D,
) -> Result<DatabaseResponse, tower::BoxError> { ) -> Result<DatabaseResponse, tower::BoxError> {
database database
.oneshot(DatabaseRequest::BlockBatchInRange(range)) .oneshot(DatabaseRequest::BlockBatchInRange(range))
.await .await
} }
async fn update_cache_and_context<Ctx>( async fn update_cache_and_context<Ctx>(
cache: &RwLock<ScanningCache>, cache: &RwLock<ScanningCache>,
context_updater: &mut Ctx, context_updater: &mut Ctx,
verified_block_info: VerifiedBlockInformation, verified_block_info: VerifiedBlockInformation,
) -> Result<(), tower::BoxError> ) -> Result<(), tower::BoxError>
where where
Ctx: tower::Service< Ctx: tower::Service<
BlockChainContextRequest, BlockChainContextRequest,
Response = BlockChainContextResponse, Response = BlockChainContextResponse,
Error = tower::BoxError, Error = tower::BoxError,
>, >,
{ {
// add the new block to the cache // add the new block to the cache
cache.write().await.add_new_block_data( cache.write().await.add_new_block_data(
verified_block_info.generated_coins, verified_block_info.generated_coins,
@ -87,21 +89,22 @@ where
.await?; .await?;
Ok(()) Ok(())
} }
async fn call_blocks<D>( async fn call_blocks<D>(
mut new_tx_chan: tx_pool::NewTxChanSen, mut new_tx_chan: tx_pool::NewTxChanSen,
mut block_chan: mpsc::Sender<Vec<Block>>, mut block_chan: mpsc::Sender<Vec<Block>>,
start_height: u64, start_height: u64,
chain_height: u64, chain_height: u64,
database: D, database: D,
) -> Result<(), tower::BoxError> ) -> Result<(), tower::BoxError>
where where
D: Database + Clone + Send + Sync + 'static, D: Database + Clone + Send + Sync + 'static,
D::Future: Send + 'static, D::Future: Send + 'static,
{ {
let mut next_fut = tokio::spawn(call_batch( let mut next_fut = tokio::spawn(call_batch(
start_height..(start_height + (MAX_BLOCKS_IN_RANGE * BATCHES_IN_REQUEST)).min(chain_height), start_height
..(start_height + (MAX_BLOCKS_IN_RANGE * BATCHES_IN_REQUEST)).min(chain_height),
database.clone(), database.clone(),
)); ));
@ -165,19 +168,19 @@ where
} }
Ok(()) Ok(())
} }
async fn scan_chain<D>( async fn scan_chain<D>(
cache: Arc<RwLock<ScanningCache>>, cache: Arc<RwLock<ScanningCache>>,
save_file: PathBuf, save_file: PathBuf,
_rpc_config: Arc<std::sync::RwLock<RpcConfig>>, _rpc_config: Arc<std::sync::RwLock<RpcConfig>>,
database: D, database: D,
net: Network, net: Network,
) -> Result<(), tower::BoxError> ) -> Result<(), tower::BoxError>
where where
D: Database + Clone + Send + Sync + 'static, D: Database + Clone + Send + Sync + 'static,
D::Future: Send + 'static, D::Future: Send + 'static,
{ {
tracing::info!("Beginning chain scan"); tracing::info!("Beginning chain scan");
// TODO: when we implement all rules use the RPCs chain height, for now we don't check v2 txs. // TODO: when we implement all rules use the RPCs chain height, for now we don't check v2 txs.
@ -331,10 +334,22 @@ where
} }
Ok(()) Ok(())
} }
#[derive(Parser)] async fn rayon_spawn_async<F, R>(f: F) -> R
struct Args { where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
let (tx, rx) = tokio::sync::oneshot::channel();
rayon::spawn(|| {
let _ = tx.send(f());
});
rx.await.expect("The sender must not be dropped")
}
#[derive(Parser)]
struct Args {
/// The log level, valid values: /// The log level, valid values:
/// "off", "error", "warn", "info", "debug", "trace", or a number 0-5. /// "off", "error", "warn", "info", "debug", "trace", or a number 0-5.
#[arg(short, long, default_value = "info")] #[arg(short, long, default_value = "info")]
@ -355,10 +370,9 @@ struct Args {
/// This will default to your user cache directory. /// This will default to your user cache directory.
#[arg(long)] #[arg(long)]
cache_dir: Option<PathBuf>, cache_dir: Option<PathBuf>,
} }
#[tokio::main] pub async fn run() {
async fn main() {
let args = Args::parse(); let args = Args::parse();
if args.dont_use_default_nodes & args.rpc_nodes.is_empty() { if args.dont_use_default_nodes & args.rpc_nodes.is_empty() {
@ -491,16 +505,14 @@ async fn main() {
scan_chain(cache, file_for_cache, rpc_config, rpc, network) scan_chain(cache, file_for_cache, rpc_config, rpc, network)
.await .await
.unwrap(); .unwrap();
}
} }
async fn rayon_spawn_async<F, R>(f: F) -> R #[cfg(feature = "binaries")]
where #[tokio::main]
F: FnOnce() -> R + Send + 'static, async fn main() {
R: Send + 'static, bin::run().await
{
let (tx, rx) = tokio::sync::oneshot::channel();
rayon::spawn(|| {
let _ = tx.send(f());
});
rx.await.expect("The sender must not be dropped")
} }
#[cfg(not(feature = "binaries"))]
fn main() {}

View file

@ -1,40 +1,40 @@
#![cfg(feature = "binaries")] #[cfg(feature = "binaries")]
mod bin {
use std::{ use std::{
collections::HashMap, collections::HashMap,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
task::{Context, Poll}, task::{Context, Poll},
}; };
use futures::{ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
StreamExt, StreamExt,
}; };
use monero_serai::transaction::Transaction; use monero_serai::transaction::Transaction;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
use cuprate_common::tower_utils::InfallibleOneshotReceiver; use cuprate_common::tower_utils::InfallibleOneshotReceiver;
use cuprate_consensus::{ use cuprate_consensus::{
context::{ context::{
BlockChainContext, BlockChainContextRequest, BlockChainContextResponse, BlockChainContext, BlockChainContextRequest, BlockChainContextResponse,
RawBlockChainContext, RawBlockChainContext,
}, },
transactions::{TransactionVerificationData, VerifyTxRequest, VerifyTxResponse}, transactions::{TransactionVerificationData, VerifyTxRequest, VerifyTxResponse},
ExtendedConsensusError, TxNotInPool, TxPoolRequest, TxPoolResponse, ExtendedConsensusError, TxNotInPool, TxPoolRequest, TxPoolResponse,
}; };
use monero_consensus::HardFork; use monero_consensus::HardFork;
#[derive(Clone)] #[derive(Clone)]
pub struct TxPoolHandle { pub struct TxPoolHandle {
tx_pool_task: std::sync::Arc<tokio::task::JoinHandle<()>>, tx_pool_task: std::sync::Arc<tokio::task::JoinHandle<()>>,
tx_pool_chan: mpsc::Sender<( tx_pool_chan: mpsc::Sender<(
TxPoolRequest, TxPoolRequest,
oneshot::Sender<Result<TxPoolResponse, TxNotInPool>>, oneshot::Sender<Result<TxPoolResponse, TxNotInPool>>,
)>, )>,
} }
impl tower::Service<TxPoolRequest> for TxPoolHandle { impl tower::Service<TxPoolRequest> for TxPoolHandle {
type Response = TxPoolResponse; type Response = TxPoolResponse;
type Error = TxNotInPool; type Error = TxNotInPool;
type Future = InfallibleOneshotReceiver<Result<Self::Response, Self::Error>>; type Future = InfallibleOneshotReceiver<Result<Self::Response, Self::Error>>;
@ -57,28 +57,28 @@ impl tower::Service<TxPoolRequest> for TxPoolHandle {
rx.into() rx.into()
} }
} }
pub type NewTxChanRec = mpsc::Receiver<( pub type NewTxChanRec = mpsc::Receiver<(
Vec<(Vec<Transaction>, HardFork)>, Vec<(Vec<Transaction>, HardFork)>,
oneshot::Sender<Result<(), tower::BoxError>>, oneshot::Sender<Result<(), tower::BoxError>>,
)>; )>;
pub type NewTxChanSen = mpsc::Sender<( pub type NewTxChanSen = mpsc::Sender<(
Vec<(Vec<Transaction>, HardFork)>, Vec<(Vec<Transaction>, HardFork)>,
oneshot::Sender<Result<(), tower::BoxError>>, oneshot::Sender<Result<(), tower::BoxError>>,
)>; )>;
pub struct TxPool<TxV, Ctx> { pub struct TxPool<TxV, Ctx> {
txs: Arc<Mutex<HashMap<[u8; 32], Arc<TransactionVerificationData>>>>, txs: Arc<Mutex<HashMap<[u8; 32], Arc<TransactionVerificationData>>>>,
current_ctx: BlockChainContext, current_ctx: BlockChainContext,
tx_verifier: Option<TxV>, tx_verifier: Option<TxV>,
tx_verifier_chan: Option<oneshot::Receiver<TxV>>, tx_verifier_chan: Option<oneshot::Receiver<TxV>>,
ctx_svc: Ctx, ctx_svc: Ctx,
} }
impl<TxV, Ctx> TxPool<TxV, Ctx> impl<TxV, Ctx> TxPool<TxV, Ctx>
where where
TxV: Service<VerifyTxRequest, Response = VerifyTxResponse, Error = ExtendedConsensusError> TxV: Service<VerifyTxRequest, Response = VerifyTxResponse, Error = ExtendedConsensusError>
+ Clone + Clone
+ Send + Send
@ -91,7 +91,7 @@ where
> + Send > + Send
+ 'static, + 'static,
Ctx::Future: Send + 'static, Ctx::Future: Send + 'static,
{ {
pub async fn spawn( pub async fn spawn(
tx_verifier_chan: oneshot::Receiver<TxV>, tx_verifier_chan: oneshot::Receiver<TxV>,
mut ctx_svc: Ctx, mut ctx_svc: Ctx,
@ -241,7 +241,11 @@ where
} }
} }
} }
}
} }
#[cfg(feature = "binaries")]
pub use bin::*;
#[allow(dead_code)] #[allow(dead_code)]
fn main() {} fn main() {}

View file

@ -14,8 +14,8 @@ time = ["dep:chrono", "std"]
thread = ["std", "dep:target_os_lib"] thread = ["std", "dep:target_os_lib"]
[dependencies] [dependencies]
chrono = { workspace = true, optional = true } chrono = { workspace = true, optional = true, features = ["std", "clock"] }
futures = { workspace = true, optional = true } futures = { workspace = true, optional = true, features = ["std"] }
rayon = { workspace = true, optional = true } rayon = { workspace = true, optional = true }
# This is kinda a stupid work around. # This is kinda a stupid work around.

View file

@ -11,20 +11,21 @@ cuprate-common = {path = "../../common"}
monero-wire = {path= "../../net/monero-wire"} monero-wire = {path= "../../net/monero-wire"}
monero-p2p = {path = "../monero-p2p" } monero-p2p = {path = "../monero-p2p" }
tower = { version= "0.4.13", features = ["util", "buffer"] } tower = { workspace = true, features = ["util", "buffer"] }
tokio = {version = "1.34.0", default-features = false, features = ["time", "fs", "rt"]} tokio = { workspace = true, features = ["time", "fs", "rt"]}
futures = "0.3.29" futures = { workspace = true, features = ["std"] }
pin-project = "1.1.3" pin-project = { workspace = true }
async-trait = "0.1.74" async-trait = { workspace = true }
thiserror = "1.0.50" thiserror = { workspace = true }
tracing = "0.1.40" tracing = { workspace = true, features = ["std", "attributes"] }
rand = "0.8.5" rand = { workspace = true, features = ["std", "std_rng"] }
borsh = {version = "1.2.1", features = ["derive"]} borsh = { workspace = true, features = ["derive", "std"]}
[dev-dependencies] [dev-dependencies]
tokio = {version = "1.34.0", features = ["rt-multi-thread", "macros"]}
cuprate-test-utils = {path = "../../test-utils"} cuprate-test-utils = {path = "../../test-utils"}
tokio = { workspace = true, features = ["rt-multi-thread", "macros"]}

View file

@ -13,21 +13,21 @@ borsh = ["dep:borsh"]
monero-wire = {path= "../../net/monero-wire"} monero-wire = {path= "../../net/monero-wire"}
cuprate-common = {path = "../../common", features = ["borsh"]} cuprate-common = {path = "../../common", features = ["borsh"]}
tokio = {version= "1.34.0", default-features = false, features = ["net", "sync"]} tokio = { workspace = true, features = ["net", "sync", "macros"]}
tokio-util = { version = "0.7.10", default-features = false, features = ["codec"] } tokio-util = { workspace = true, features = ["codec"] }
tokio-stream = {version = "0.1.14", default-features = false, features = ["sync"]} tokio-stream = { workspace = true, features = ["sync"]}
futures = "0.3.29" futures = { workspace = true, features = ["std"] }
async-trait = "0.1.74" async-trait = { workspace = true }
tower = { version= "0.4.13", features = ["util"] } tower = { workspace = true, features = ["util"] }
thiserror = "1.0.50" thiserror = { workspace = true }
tracing = "0.1.40" tracing = { workspace = true, features = ["std"] }
borsh = {version = "1.2.1", default-features = false, features = ["derive", "std"], optional = true } borsh = { workspace = true, default-features = false, features = ["derive", "std"], optional = true }
[dev-dependencies] [dev-dependencies]
cuprate-test-utils = {path = "../../test-utils"} cuprate-test-utils = {path = "../../test-utils"}
hex = "0.4.3" hex = { workspace = true }
tokio = {version= "1.34.0", default-features = false, features = ["net", "rt-multi-thread", "rt", "macros"]} tokio = { workspace = true, features = ["net", "rt-multi-thread", "rt", "macros"]}
tracing-subscriber = "0.3" tracing-subscriber = { workspace = true }

View file

@ -7,7 +7,7 @@ edition = "2021"
monero-wire = {path = "../net/monero-wire"} monero-wire = {path = "../net/monero-wire"}
monero-p2p = {path = "../p2p/monero-p2p" } monero-p2p = {path = "../p2p/monero-p2p" }
futures = "0.3.29" futures = { workspace = true, features = ["std"] }
async-trait = "0.1.74" async-trait = { workspace = true }
borsh = {version = "1.2.1", features = ["derive"]} borsh = { workspace = true, features = ["derive"]}