diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 00000000..8ddf4f0e
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,637 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 4
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1722869508802
+
+
+ 1722869508802
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1722869881493
+
+
+
+ 1722869881493
+
+
+
+ 1722870056808
+
+
+
+ 1722870056808
+
+
+
+ 1722870767745
+
+
+
+ 1722870767745
+
+
+
+ 1722871328779
+
+
+
+ 1722871328779
+
+
+
+ 1722906207310
+
+
+
+ 1722906207310
+
+
+
+ 1722907656548
+
+
+
+ 1722907656548
+
+
+
+ 1722992299543
+
+
+
+ 1722992299543
+
+
+
+ 1722992779351
+
+
+
+ 1722992779351
+
+
+
+ 1722994414575
+
+
+
+ 1722994414575
+
+
+
+ 1723040367937
+
+
+
+ 1723040367937
+
+
+
+ 1723125824866
+
+
+
+ 1723125824866
+
+
+
+ 1723127416195
+
+
+
+ 1723127416195
+
+
+
+ 1723133261401
+
+
+
+ 1723133261401
+
+
+
+ 1723148800683
+
+
+
+ 1723148800683
+
+
+
+ 1723159166301
+
+
+
+ 1723159166301
+
+
+
+ 1723159709038
+
+
+
+ 1723159709038
+
+
+
+ 1723225457199
+
+
+
+ 1723225457199
+
+
+
+ 1723249397528
+
+
+
+ 1723249397528
+
+
+
+ 1723250798381
+
+
+
+ 1723250798381
+
+
+
+ 1723251564499
+
+
+
+ 1723251564499
+
+
+
+ 1723251946498
+
+
+
+ 1723251946498
+
+
+
+ 1723499207124
+
+
+
+ 1723499207124
+
+
+
+ 1723500679410
+
+
+
+ 1723500679410
+
+
+
+ 1723500847360
+
+
+
+ 1723500847360
+
+
+
+ 1723501335763
+
+
+
+ 1723501335763
+
+
+
+ 1723512507585
+
+
+
+ 1723512507585
+
+
+
+ 1723767027153
+
+
+
+ 1723767027153
+
+
+
+ 1723767615139
+
+
+
+ 1723767615139
+
+
+
+ 1723768785884
+
+
+
+ 1723768785884
+
+
+
+ 1723771471205
+
+
+
+ 1723771471205
+
+
+
+ 1723816913395
+
+
+
+ 1723816913395
+
+
+
+ 1724168407863
+
+
+
+ 1724168407864
+
+
+
+ 1724252529611
+
+
+
+ 1724252529611
+
+
+
+ 1724253642047
+
+
+
+ 1724253642047
+
+
+
+ 1724254915004
+
+
+
+ 1724254915004
+
+
+
+ 1724255395365
+
+
+
+ 1724255395365
+
+
+
+ 1724255786382
+
+
+
+ 1724255786382
+
+
+
+ 1724258898859
+
+
+
+ 1724258898859
+
+
+
+ 1724267338063
+
+
+
+ 1724267338063
+
+
+
+ 1724282276348
+
+
+
+ 1724282276348
+
+
+
+ 1724282489662
+
+
+
+ 1724282489662
+
+
+
+ 1724282501646
+
+
+
+ 1724282501646
+
+
+
+ 1724282545275
+
+
+
+ 1724282545275
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 58b66fe6..22e7fdd0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -939,6 +939,7 @@ dependencies = [
"clap",
"cuprate-blockchain",
"cuprate-consensus",
+ "cuprate-cryptonight",
"cuprate-p2p",
"cuprate-p2p-core",
"cuprate-types",
@@ -949,6 +950,7 @@ dependencies = [
"tokio",
"tower",
"tracing",
+ "tracing-subscriber",
]
[[package]]
@@ -983,7 +985,7 @@ dependencies = [
[[package]]
name = "dalek-ff-group"
version = "0.4.1"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"crypto-bigint",
"curve25519-dalek",
@@ -1138,7 +1140,7 @@ dependencies = [
[[package]]
name = "flexible-transcript"
version = "0.3.2"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"blake2",
"digest",
@@ -1802,7 +1804,7 @@ dependencies = [
[[package]]
name = "monero-address"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"monero-io",
@@ -1815,7 +1817,7 @@ dependencies = [
[[package]]
name = "monero-borromean"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"monero-generators",
@@ -1828,7 +1830,7 @@ dependencies = [
[[package]]
name = "monero-bulletproofs"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"monero-generators",
@@ -1843,7 +1845,7 @@ dependencies = [
[[package]]
name = "monero-clsag"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"dalek-ff-group",
@@ -1863,7 +1865,7 @@ dependencies = [
[[package]]
name = "monero-generators"
version = "0.4.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"dalek-ff-group",
@@ -1877,7 +1879,7 @@ dependencies = [
[[package]]
name = "monero-io"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"std-shims",
@@ -1886,7 +1888,7 @@ dependencies = [
[[package]]
name = "monero-mlsag"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"monero-generators",
@@ -1900,7 +1902,7 @@ dependencies = [
[[package]]
name = "monero-primitives"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"monero-generators",
@@ -1913,7 +1915,7 @@ dependencies = [
[[package]]
name = "monero-rpc"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"async-trait",
"curve25519-dalek",
@@ -1930,7 +1932,7 @@ dependencies = [
[[package]]
name = "monero-serai"
version = "0.1.4-alpha"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"curve25519-dalek",
"hex-literal",
@@ -1948,7 +1950,7 @@ dependencies = [
[[package]]
name = "monero-simple-request-rpc"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"async-trait",
"digest_auth",
@@ -1958,6 +1960,16 @@ dependencies = [
"tokio",
]
+[[package]]
+name = "nu-ansi-term"
+version = "0.46.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
+dependencies = [
+ "overload",
+ "winapi",
+]
+
[[package]]
name = "num-traits"
version = "0.2.19"
@@ -2005,6 +2017,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
+[[package]]
+name = "overload"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
+
[[package]]
name = "page_size"
version = "0.6.0"
@@ -2607,6 +2625,15 @@ dependencies = [
"keccak",
]
+[[package]]
+name = "sharded-slab"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
+dependencies = [
+ "lazy_static",
+]
+
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
@@ -2619,7 +2646,7 @@ dependencies = [
[[package]]
name = "simple-request"
version = "0.1.0"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"http-body-util",
"hyper",
@@ -2675,7 +2702,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "std-shims"
version = "0.1.1"
-source = "git+https://github.com/Cuprate/serai.git?rev=d5205ce#d5205ce2319e09414eb91d12cf38e83a08165f79"
+source = "git+https://github.com/Cuprate/serai.git?rev=50686e8#50686e84022edbd0065d2af655ea4aa5faf486b8"
dependencies = [
"hashbrown",
"spin",
@@ -2974,6 +3001,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
+ "valuable",
+]
+
+[[package]]
+name = "tracing-log"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
+dependencies = [
+ "log",
+ "once_cell",
+ "tracing-core",
]
[[package]]
@@ -2982,7 +3021,12 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
+ "nu-ansi-term",
+ "sharded-slab",
+ "smallvec",
+ "thread_local",
"tracing-core",
+ "tracing-log",
]
[[package]]
@@ -3062,6 +3106,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
+[[package]]
+name = "valuable"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
+
[[package]]
name = "version_check"
version = "0.9.4"
diff --git a/Cargo.toml b/Cargo.toml
index 06b49a0a..e1f068eb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,7 +65,7 @@ futures = { version = "0.3.29", default-features = false }
hex = { version = "0.4.3", default-features = false }
hex-literal = { version = "0.4", default-features = false }
indexmap = { version = "2.2.5", default-features = false }
-monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce", default-features = false }
+monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "50686e8", default-features = false }
paste = { version = "1.0.14", default-features = false }
pin-project = { version = "1.1.3", default-features = false }
randomx-rs = { git = "https://github.com/Cuprate/randomx-rs.git", rev = "0028464", default-features = false }
@@ -85,8 +85,8 @@ tracing-subscriber = { version = "0.3.17", default-features = false }
tracing = { version = "0.1.40", default-features = false }
## workspace.dev-dependencies
-monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce" }
-monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce" }
+monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "50686e8" }
+monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "50686e8" }
tempfile = { version = "3" }
pretty_assertions = { version = "1.4.0" }
proptest = { version = "1" }
diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml
index 74eb2d59..c01e2cca 100644
--- a/binaries/cuprated/Cargo.toml
+++ b/binaries/cuprated/Cargo.toml
@@ -13,6 +13,7 @@ cuprate-blockchain = { path = "../../storage/blockchain" }
cuprate-p2p = { path = "../../p2p/p2p" }
cuprate-p2p-core = { path = "../../p2p/p2p-core" }
cuprate-types = { path = "../../types" }
+cuprate-cryptonight = { path = "../../cryptonight" }
rayon = { workspace = true }
futures = { workspace = true }
@@ -23,6 +24,13 @@ thiserror = { workspace = true }
hex = { workspace = true }
clap = { workspace = true, features = ["default", "derive"] }
+tracing-subscriber = { workspace = true, features = ["default"] }
#[lints]
#workspace = true
+
+[profile.dev]
+panic = 'abort'
+
+[profile.release]
+panic = 'abort'
diff --git a/binaries/cuprated/src/blockchain.rs b/binaries/cuprated/src/blockchain.rs
index a9af7d72..c0b7e6ce 100644
--- a/binaries/cuprated/src/blockchain.rs
+++ b/binaries/cuprated/src/blockchain.rs
@@ -8,18 +8,64 @@ use crate::blockchain::types::{
ConsensusBlockchainReadHandle,
};
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
-use cuprate_consensus::{
- BlockChainContextService, BlockVerifierService, ContextConfig, TxVerifierService,
-};
+use cuprate_consensus::{generate_genesis_block, BlockChainContextService, ContextConfig};
+use cuprate_cryptonight::cryptonight_hash_v0;
use cuprate_p2p::block_downloader::BlockDownloaderConfig;
use cuprate_p2p::NetworkInterface;
-use cuprate_p2p_core::ClearNet;
+use cuprate_p2p_core::{ClearNet, Network};
+use cuprate_types::blockchain::{
+ BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest,
+};
+use cuprate_types::VerifiedBlockInformation;
use tokio::sync::mpsc;
+use tower::{Service, ServiceExt};
mod manager;
mod syncer;
mod types;
+pub async fn check_add_genesis(
+ blockchain_read_handle: &mut BlockchainReadHandle,
+ blockchain_write_handle: &mut BlockchainWriteHandle,
+ network: &Network,
+) {
+ if blockchain_read_handle
+ .ready()
+ .await
+ .unwrap()
+ .call(BlockchainReadRequest::ChainHeight)
+ .await
+ .is_ok()
+ {
+ return;
+ }
+
+ let genesis = generate_genesis_block(network);
+
+ blockchain_write_handle
+ .ready()
+ .await
+ .unwrap()
+ .call(BlockchainWriteRequest::WriteBlock(
+ VerifiedBlockInformation {
+ block_blob: genesis.serialize(),
+ txs: vec![],
+ block_hash: genesis.hash(),
+ pow_hash: cryptonight_hash_v0(&genesis.serialize_pow_hash()),
+ height: 0,
+ generated_coins: genesis.miner_transaction.prefix().outputs[0]
+ .amount
+ .unwrap(),
+ weight: genesis.miner_transaction.weight(),
+ long_term_weight: genesis.miner_transaction.weight(),
+ cumulative_difficulty: 1,
+ block: genesis,
+ },
+ ))
+ .await
+ .unwrap();
+}
+
pub async fn init_consensus(
blockchain_read_handle: BlockchainReadHandle,
context_config: ContextConfig,
diff --git a/binaries/cuprated/src/blockchain/manager.rs b/binaries/cuprated/src/blockchain/manager.rs
index 5a526a59..e13c9073 100644
--- a/binaries/cuprated/src/blockchain/manager.rs
+++ b/binaries/cuprated/src/blockchain/manager.rs
@@ -39,18 +39,20 @@ impl BlockchainManager {
}
pub async fn run(mut self, mut batch_rx: Receiver) {
- tokio::select! {
- Some(batch) = batch_rx.recv() => {
- handle_incoming_block_batch(
- batch,
- &mut self.block_verifier_service,
- &mut self.blockchain_context_service,
- &mut self.blockchain_read_handle,
- &mut self.blockchain_write_handle
- ).await;
- }
- else => {
- todo!("Exit the BC manager")
+ loop {
+ tokio::select! {
+ Some(batch) = batch_rx.recv() => {
+ handle_incoming_block_batch(
+ batch,
+ &mut self.block_verifier_service,
+ &mut self.blockchain_context_service,
+ &mut self.blockchain_read_handle,
+ &mut self.blockchain_write_handle
+ ).await;
+ }
+ else => {
+ todo!("TODO: exit the BC manager")
+ }
}
}
}
diff --git a/binaries/cuprated/src/blockchain/manager/batch_handler.rs b/binaries/cuprated/src/blockchain/manager/batch_handler.rs
index f080f310..c4a3d6e5 100644
--- a/binaries/cuprated/src/blockchain/manager/batch_handler.rs
+++ b/binaries/cuprated/src/blockchain/manager/batch_handler.rs
@@ -41,6 +41,16 @@ pub async fn handle_incoming_block_batch(
.first()
.expect("Block batch should not be empty");
+ handle_incoming_block_batch_main_chain(
+ batch,
+ block_verifier_service,
+ blockchain_context_service,
+ blockchain_write_handle,
+ )
+ .await;
+
+ // TODO: alt block to the DB
+ /*
match blockchain_read_handle
.oneshot(BlockchainReadRequest::FindBlock(
first_block.header.previous,
@@ -67,6 +77,8 @@ pub async fn handle_incoming_block_batch(
Ok(_) => panic!("Blockchain service returned incorrect response"),
}
+
+ */
}
async fn handle_incoming_block_batch_main_chain(
@@ -90,7 +102,12 @@ async fn handle_incoming_block_batch_main_chain(
+ 'static,
TxV::Future: Send + 'static,
{
- let Ok(VerifyBlockResponse::MainChainBatchPrepped(prepped)) = block_verifier_service
+ info!(
+ "Handling batch to main chain height: {}",
+ batch.blocks.first().unwrap().0.number().unwrap()
+ );
+
+ let VerifyBlockResponse::MainChainBatchPrepped(prepped) = block_verifier_service
.ready()
.await
.expect("TODO")
@@ -98,21 +115,21 @@ async fn handle_incoming_block_batch_main_chain(
blocks: batch.blocks,
})
.await
+ .unwrap()
else {
- info!("Error verifying batch, banning peer");
- todo!()
+ panic!("Incorrect response!");
};
for (block, txs) in prepped {
- let Ok(VerifyBlockResponse::MainChain(verified_block)) = block_verifier_service
+ let VerifyBlockResponse::MainChain(verified_block) = block_verifier_service
.ready()
.await
.expect("TODO")
.call(VerifyBlockRequest::MainChainPrepped { block, txs })
.await
+ .unwrap()
else {
- info!("Error verifying batch, banning peer");
- todo!()
+ panic!("Incorrect response!");
};
blockchain_context_service
diff --git a/binaries/cuprated/src/main.rs b/binaries/cuprated/src/main.rs
index 4d205a15..5ccb8382 100644
--- a/binaries/cuprated/src/main.rs
+++ b/binaries/cuprated/src/main.rs
@@ -1,4 +1,10 @@
+use crate::blockchain::check_add_genesis;
use clap::Parser;
+use cuprate_p2p::block_downloader::BlockDownloaderConfig;
+use cuprate_p2p::P2PConfig;
+use cuprate_p2p_core::Network;
+use std::time::Duration;
+use tracing::Level;
mod blockchain;
mod config;
@@ -11,7 +17,11 @@ struct Args {}
fn main() {
let _args = Args::parse();
- let (bc_read_handle, bc_write_handle, _) =
+ tracing_subscriber::fmt()
+ .with_max_level(Level::DEBUG)
+ .init();
+
+ let (mut bc_read_handle, mut bc_write_handle, _) =
cuprate_blockchain::service::init(cuprate_blockchain::config::Config::default()).unwrap();
let async_rt = tokio::runtime::Builder::new_multi_thread()
@@ -20,13 +30,38 @@ fn main() {
.unwrap();
async_rt.block_on(async move {
- let (block_verifier, tx_verifier, context_svc) = blockchain::init_consensus(
- bc_read_handle,
+ check_add_genesis(&mut bc_read_handle, &mut bc_write_handle, &Network::Mainnet).await;
+
+ let (block_verifier, _tx_verifier, context_svc) = blockchain::init_consensus(
+ bc_read_handle.clone(),
cuprate_consensus::ContextConfig::main_net(),
)
.await
.unwrap();
- //blockchain::init_blockchain_manager()
+ let net = cuprate_p2p::initialize_network(
+ p2p::request_handler::P2pProtocolRequestHandler,
+ p2p::core_sync_svc::CoreSyncService(context_svc.clone()),
+ p2p::dummy_config(),
+ )
+ .await
+ .unwrap();
+
+ blockchain::init_blockchain_manager(
+ net,
+ BlockDownloaderConfig {
+ buffer_size: 50_000_000,
+ in_progress_queue_size: 50_000_000,
+ check_client_pool_interval: Duration::from_secs(45),
+ target_batch_size: 10_000_000,
+ initial_batch_size: 1,
+ },
+ bc_write_handle,
+ bc_read_handle,
+ context_svc,
+ block_verifier,
+ );
+
+ tokio::time::sleep(Duration::MAX).await;
});
}
diff --git a/binaries/cuprated/src/p2p.rs b/binaries/cuprated/src/p2p.rs
index f5b72ba3..0560320b 100644
--- a/binaries/cuprated/src/p2p.rs
+++ b/binaries/cuprated/src/p2p.rs
@@ -2,4 +2,28 @@
//!
//! Will handle initiating the P2P and contains a protocol request handler.
-mod request_handler;
+use cuprate_p2p::AddressBookConfig;
+use cuprate_p2p_core::Network;
+use std::time::Duration;
+
+pub mod core_sync_svc;
+pub mod request_handler;
+
+pub fn dummy_config() -> cuprate_p2p::P2PConfig {
+ cuprate_p2p::P2PConfig {
+ network: Network::Mainnet,
+ outbound_connections: 64,
+ extra_outbound_connections: 0,
+ max_inbound_connections: 0,
+ gray_peers_percent: 0.7,
+ server_config: None,
+ p2p_port: 0,
+ rpc_port: 0,
+ address_book_config: AddressBookConfig {
+ max_white_list_length: 1000,
+ max_gray_list_length: 5000,
+ peer_store_file: "p2p_state.bin".into(),
+ peer_save_period: Duration::from_secs(60),
+ },
+ }
+}
diff --git a/binaries/cuprated/src/p2p/core_sync_svc.rs b/binaries/cuprated/src/p2p/core_sync_svc.rs
new file mode 100644
index 00000000..34c91e47
--- /dev/null
+++ b/binaries/cuprated/src/p2p/core_sync_svc.rs
@@ -0,0 +1,51 @@
+use cuprate_blockchain::cuprate_database::RuntimeError;
+use cuprate_blockchain::service::BlockchainReadHandle;
+use cuprate_consensus::{
+ BlockChainContextRequest, BlockChainContextResponse, BlockChainContextService,
+};
+use cuprate_p2p_core::services::{CoreSyncDataRequest, CoreSyncDataResponse};
+use cuprate_p2p_core::CoreSyncData;
+use cuprate_types::blockchain::BlockchainReadRequest;
+use futures::future::{BoxFuture, MapErr, MapOk};
+use futures::{FutureExt, TryFutureExt};
+use std::task::{Context, Poll};
+use tower::Service;
+
+#[derive(Clone)]
+pub struct CoreSyncService(pub BlockChainContextService);
+
+impl Service for CoreSyncService {
+ type Response = CoreSyncDataResponse;
+ type Error = tower::BoxError;
+ type Future = MapOk<
+ >::Future,
+ fn(BlockChainContextResponse) -> CoreSyncDataResponse,
+ >;
+
+ fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> {
+ self.0.poll_ready(cx)
+ }
+
+ fn call(&mut self, _: CoreSyncDataRequest) -> Self::Future {
+ self.0
+ .call(BlockChainContextRequest::GetContext)
+ .map_ok(|res| {
+ let BlockChainContextResponse::Context(ctx) = res else {
+ panic!("blockchain context service returned wrong response.");
+ };
+
+ let raw_ctx = ctx.unchecked_blockchain_context();
+
+ // TODO: the hardfork here should be the version of the top block not the current HF,
+ // on HF boundaries these will be different.
+ CoreSyncDataResponse(CoreSyncData::new(
+ raw_ctx.cumulative_difficulty,
+ // TODO:
+ raw_ctx.chain_height as u64,
+ 0,
+ raw_ctx.top_hash,
+ raw_ctx.current_hf.as_u8(),
+ ))
+ })
+ }
+}
diff --git a/binaries/cuprated/src/p2p/request_handler.rs b/binaries/cuprated/src/p2p/request_handler.rs
index 8b137891..76554e92 100644
--- a/binaries/cuprated/src/p2p/request_handler.rs
+++ b/binaries/cuprated/src/p2p/request_handler.rs
@@ -1 +1,33 @@
+use cuprate_p2p_core::{ProtocolRequest, ProtocolResponse};
+use futures::future::BoxFuture;
+use futures::FutureExt;
+use std::task::{Context, Poll};
+use tower::Service;
+use tracing::trace;
+#[derive(Clone)]
+pub struct P2pProtocolRequestHandler;
+
+impl Service for P2pProtocolRequestHandler {
+ type Response = ProtocolResponse;
+ type Error = tower::BoxError;
+ type Future = BoxFuture<'static, Result>;
+
+ fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> {
+ Poll::Ready(Ok(()))
+ }
+
+ fn call(&mut self, req: ProtocolRequest) -> Self::Future {
+ match req {
+ ProtocolRequest::GetObjects(_) => trace!("TODO: GetObjects"),
+ ProtocolRequest::GetChain(_) => trace!("TODO: GetChain"),
+ ProtocolRequest::FluffyMissingTxs(_) => trace!("TODO: FluffyMissingTxs"),
+ ProtocolRequest::GetTxPoolCompliment(_) => trace!("TODO: GetTxPoolCompliment"),
+ ProtocolRequest::NewBlock(_) => trace!("TODO: NewBlock"),
+ ProtocolRequest::NewFluffyBlock(_) => trace!("TODO: NewFluffyBlock"),
+ ProtocolRequest::NewTransactions(_) => trace!("TODO: NewTransactions"),
+ }
+
+ async { Ok(ProtocolResponse::NA) }.boxed()
+ }
+}
diff --git a/consensus/src/block.rs b/consensus/src/block.rs
index 7297a5a6..b33b5857 100644
--- a/consensus/src/block.rs
+++ b/consensus/src/block.rs
@@ -123,7 +123,7 @@ impl PreparedBlock {
///
/// The randomX VM must be Some if RX is needed or this will panic.
/// The randomX VM must also be initialised with the correct seed.
- fn new(
+ pub fn new(
block: Block,
randomx_vm: Option<&R>,
) -> Result {
diff --git a/consensus/src/lib.rs b/consensus/src/lib.rs
index 2c69e667..29f59038 100644
--- a/consensus/src/lib.rs
+++ b/consensus/src/lib.rs
@@ -27,6 +27,7 @@ pub use context::{
pub use transactions::{TxVerifierService, VerifyTxRequest, VerifyTxResponse};
// re-export.
+pub use cuprate_consensus_rules::genesis::generate_genesis_block;
pub use cuprate_types::blockchain::{BlockchainReadRequest, BlockchainResponse};
/// An Error returned from one of the consensus services.
diff --git a/consensus/src/transactions.rs b/consensus/src/transactions.rs
index 91de67cd..82d3100e 100644
--- a/consensus/src/transactions.rs
+++ b/consensus/src/transactions.rs
@@ -393,6 +393,10 @@ async fn verify_transactions_decoy_info(
where
D: Database + Clone + Sync + Send + 'static,
{
+ if hf == HardFork::V1 {
+ return Ok(());
+ }
+
batch_get_decoy_info(&txs, hf, database)
.await?
.try_for_each(|decoy_info| decoy_info.and_then(|di| Ok(check_decoy_info(&di, &hf)?)))?;
diff --git a/consensus/src/transactions/free.rs b/consensus/src/transactions/free.rs
index 02c52358..67b675a4 100644
--- a/consensus/src/transactions/free.rs
+++ b/consensus/src/transactions/free.rs
@@ -78,7 +78,8 @@ pub fn tx_fee(tx: &Transaction) -> Result {
}
for output in &prefix.outputs {
- fee.checked_sub(output.amount.unwrap_or(0))
+ fee = fee
+ .checked_sub(output.amount.unwrap_or(0))
.ok_or(TransactionError::OutputsTooHigh)?;
}
}
diff --git a/p2p/p2p-core/src/lib.rs b/p2p/p2p-core/src/lib.rs
index 83cc4d2e..1f7e631a 100644
--- a/p2p/p2p-core/src/lib.rs
+++ b/p2p/p2p-core/src/lib.rs
@@ -79,6 +79,7 @@ pub use protocol::*;
use services::*;
//re-export
pub use cuprate_helper::network::Network;
+pub use cuprate_wire::CoreSyncData;
/// The direction of a connection.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
diff --git a/p2p/p2p/src/config.rs b/p2p/p2p/src/config.rs
index 90d7f8ff..98bef68e 100644
--- a/p2p/p2p/src/config.rs
+++ b/p2p/p2p/src/config.rs
@@ -1,8 +1,9 @@
-use cuprate_address_book::AddressBookConfig;
use cuprate_helper::network::Network;
use cuprate_p2p_core::NetworkZone;
use cuprate_wire::{common::PeerSupportFlags, BasicNodeData};
+pub use cuprate_address_book::AddressBookConfig;
+
/// P2P config.
#[derive(Clone, Debug)]
pub struct P2PConfig {
diff --git a/p2p/p2p/src/lib.rs b/p2p/p2p/src/lib.rs
index 82ecfce7..6f95948f 100644
--- a/p2p/p2p/src/lib.rs
+++ b/p2p/p2p/src/lib.rs
@@ -33,7 +33,7 @@ mod sync_states;
use block_downloader::{BlockBatch, BlockDownloaderConfig, ChainSvcRequest, ChainSvcResponse};
pub use broadcast::{BroadcastRequest, BroadcastSvc};
use client_pool::ClientPoolDropGuard;
-pub use config::P2PConfig;
+pub use config::{AddressBookConfig, P2PConfig};
use connection_maintainer::MakeConnectionRequest;
/// Initializes the P2P [`NetworkInterface`] for a specific [`NetworkZone`].
diff --git a/p2p_state.bin b/p2p_state.bin
new file mode 100644
index 00000000..bf2d673d
Binary files /dev/null and b/p2p_state.bin differ