Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to experimental monero oxide api #386

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cb8c482
add specific method for context
Boog900 Jan 17, 2025
14a53ca
add new statemachine for tx verification
Boog900 Jan 19, 2025
7a0f015
fix consensus crates build
Boog900 Jan 19, 2025
7228bda
working builds
Boog900 Jan 19, 2025
b86e0a9
Merge branch 'main' into imporve-consensus-api
Boog900 Jan 19, 2025
da938b9
fix CI
Boog900 Jan 19, 2025
6e8e580
add docs
Boog900 Jan 20, 2025
b680d8d
fix CI
Boog900 Jan 20, 2025
dc63950
fix docs
Boog900 Jan 20, 2025
e884cd1
fix clippy
Boog900 Jan 20, 2025
caab94c
cleanup
Boog900 Jan 21, 2025
a425713
add docs to `blockchain_context`
Boog900 Jan 21, 2025
2756d96
fix doc tests
Boog900 Jan 21, 2025
918d818
add output cache
Boog900 Jan 24, 2025
fe3f6ac
new monero-serai
Boog900 Jan 25, 2025
26fbde2
todo
Boog900 Jan 25, 2025
51b4a3e
todo
Boog900 Jan 26, 2025
4e805b3
Revert "new monero-serai"
Boog900 Jan 29, 2025
241b7fc
use indexmap to request outputs
Boog900 Feb 9, 2025
6cb3ec1
Merge branch 'main' into batch-outputs
Boog900 Feb 9, 2025
5054f4a
clean up
Boog900 Feb 22, 2025
cb43a73
fix typos
Boog900 Feb 22, 2025
da884b3
fix CI
Boog900 Feb 22, 2025
8cf2210
fix cargo hack
Boog900 Feb 22, 2025
eedbd55
fix reorgs
Boog900 Feb 22, 2025
6c7424e
check if a block is already present before adding it to the alt block…
Boog900 Feb 22, 2025
dfdd8f4
fmt
Boog900 Feb 25, 2025
e1d1f61
update to new monero oxide API
Boog900 Feb 25, 2025
c43fab3
fmt & fix cache
Boog900 Feb 25, 2025
57ce4b5
update config values
Boog900 Feb 25, 2025
c9261b3
fix tests
Boog900 Feb 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ futures = { version = "0.3", default-features = false }
hex = { version = "0.4", default-features = false }
hex-literal = { version = "0.4", default-features = false }
indexmap = { version = "2", default-features = false }
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "e6fdef6", default-features = false }
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "29f904d", default-features = false }
paste = { version = "1", default-features = false }
pin-project = { version = "1", default-features = false }
randomx-rs = { git = "https://github.com/Cuprate/randomx-rs.git", rev = "0028464", default-features = false }
Expand All @@ -144,8 +144,8 @@ tracing-subscriber = { version = "0.3", default-features = false }
tracing = { version = "0.1", default-features = false }

## workspace.dev-dependencies
monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "e6fdef6" }
monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "e6fdef6" }
monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "29f904d" }
monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "29f904d" }
tempfile = { version = "3" }
pretty_assertions = { version = "1" }
proptest = { version = "1" }
Expand Down
4 changes: 2 additions & 2 deletions binaries/cuprated/Cuprated.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ peer_save_period = { secs = 90, nanos = 0 }
## The block downloader config.
[p2p.block_downloader]
## The size of the buffer of sequential blocks waiting to be verified and added to the chain (bytes).
buffer_bytes = 50_000_000
buffer_bytes = 1_000_000_000
## The size of the queue of blocks which are waiting for a parent block to be downloaded (bytes).
in_progress_queue_bytes = 50_000_000
in_progress_queue_bytes = 500_000_000
## The target size of a batch of blocks (bytes), must not exceed 100MB.
target_batch_bytes = 10_000_000
## The amount of time between checking the pool of connected peers for free peers to download blocks.
Expand Down
35 changes: 28 additions & 7 deletions binaries/cuprated/src/blockchain/manager/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ impl super::BlockchainManager {
/// This function will panic if any internal service returns an unexpected error that we cannot
/// recover from or if the incoming batch contains no blocks.
async fn handle_incoming_block_batch_main_chain(&mut self, batch: BlockBatch) {
let Ok(prepped_blocks) =
batch_prepare_main_chain_blocks(batch.blocks, &mut self.blockchain_context_service)
.await
let Ok((prepped_blocks, mut output_cache)) = batch_prepare_main_chain_blocks(
batch.blocks,
&mut self.blockchain_context_service,
self.blockchain_read_handle.clone(),
)
.await
else {
batch.peer_handle.ban_peer(LONG_BAN);
self.stop_current_block_downloader.notify_one();
Expand All @@ -181,6 +184,7 @@ impl super::BlockchainManager {
txs,
&mut self.blockchain_context_service,
self.blockchain_read_handle.clone(),
Some(&mut output_cache),
)
.await
else {
Expand Down Expand Up @@ -267,12 +271,28 @@ impl super::BlockchainManager {
block: Block,
prepared_txs: HashMap<[u8; 32], TransactionVerificationData>,
) -> Result<AddAltBlock, anyhow::Error> {
// Check if a block already exists.
let BlockchainResponse::FindBlock(chain) = self
.blockchain_read_handle
.ready()
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR)
.call(BlockchainReadRequest::FindBlock(block.hash()))
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR)
else {
unreachable!();
};

if chain.is_some() {
// The block could also be in the main-chain here under some circumstances.
return Ok(AddAltBlock::Cached);
}

let alt_block_info =
sanity_check_alt_block(block, prepared_txs, self.blockchain_context_service.clone())
.await?;

// TODO: check in consensus crate if alt block with this hash already exists.

// If this alt chain has more cumulative difficulty, reorg.
if alt_block_info.cumulative_difficulty
> self
Expand Down Expand Up @@ -404,6 +424,7 @@ impl super::BlockchainManager {
prepped_txs,
&mut self.blockchain_context_service,
self.blockchain_read_handle.clone(),
None,
)
.await?;

Expand Down Expand Up @@ -431,7 +452,7 @@ impl super::BlockchainManager {
.iter()
.flat_map(|tx| {
tx.tx.prefix().inputs.iter().map(|input| match input {
Input::ToKey { key_image, .. } => key_image.compress().0,
Input::ToKey { key_image, .. } => key_image.0,
Input::Gen(_) => unreachable!(),
})
})
Expand Down Expand Up @@ -474,7 +495,7 @@ impl super::BlockchainManager {

/// The result from successfully adding an alt-block.
enum AddAltBlock {
/// The alt-block was cached.
/// The alt-block was cached or was already present in the DB.
Cached,
/// The chain was reorged.
Reorged,
Expand Down
2 changes: 1 addition & 1 deletion binaries/cuprated/src/blockchain/syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration};

use futures::StreamExt;
use tokio::{
sync::{mpsc, Notify},
sync::{mpsc, oneshot, Notify},
time::interval,
};
use tower::{Service, ServiceExt};
Expand Down
4 changes: 2 additions & 2 deletions binaries/cuprated/src/config/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl From<BlockDownloaderConfig> for cuprate_p2p::block_downloader::BlockDownloa
impl Default for BlockDownloaderConfig {
fn default() -> Self {
Self {
buffer_bytes: 50_000_000,
in_progress_queue_bytes: 50_000_000,
buffer_bytes: 1_000_000_000,
in_progress_queue_bytes: 500_000_000,
check_client_pool_interval: Duration::from_secs(30),
target_batch_bytes: 10_000_000,
}
Expand Down
5 changes: 3 additions & 2 deletions binaries/cuprated/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
reason = "TODO: remove after v1.0.0"
)]

use std::mem;
use std::sync::Arc;
use std::{mem, sync::Arc};

use tokio::sync::mpsc;
use tower::{Service, ServiceExt};
use tracing::level_filters::LevelFilter;
Expand All @@ -27,6 +27,7 @@ use cuprate_consensus_context::{
BlockChainContextRequest, BlockChainContextResponse, BlockchainContextService,
};
use cuprate_helper::time::secs_to_hms;
use cuprate_types::blockchain::BlockchainWriteRequest;

use crate::{
config::Config, constants::PANIC_CRITICAL_SERVICE_ERROR, logging::CupratedTracingFilter,
Expand Down
6 changes: 4 additions & 2 deletions binaries/cuprated/src/rpc/request/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use std::{
};

use anyhow::Error;
use indexmap::{IndexMap, IndexSet};
use monero_serai::block::Block;
use tower::{Service, ServiceExt};

use cuprate_blockchain::{service::BlockchainReadHandle, types::AltChainInfo};
use cuprate_helper::cast::{u64_to_usize, usize_to_u64};
use cuprate_types::{
blockchain::{BlockchainReadRequest, BlockchainResponse},
output_cache::OutputCache,
Chain, ChainInfo, CoinbaseTxSum, ExtendedBlockHeader, HardFork, MinerData,
OutputHistogramEntry, OutputHistogramInput, OutputOnChain,
};
Expand Down Expand Up @@ -185,8 +187,8 @@ pub(crate) async fn generated_coins(
/// [`BlockchainReadRequest::Outputs`]
pub(crate) async fn outputs(
blockchain_read: &mut BlockchainReadHandle,
outputs: HashMap<u64, HashSet<u64>>,
) -> Result<HashMap<u64, HashMap<u64, OutputOnChain>>, Error> {
outputs: IndexMap<u64, IndexSet<u64>>,
) -> Result<OutputCache, Error> {
let BlockchainResponse::Outputs(outputs) = blockchain_read
.ready()
.await?
Expand Down
1 change: 1 addition & 0 deletions binaries/cuprated/src/txpool/incoming_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async fn handle_incoming_txs(
context.current_adjusted_timestamp_for_time_lock(),
context.current_hf,
blockchain_read_handle,
None,
)
.verify()
.await
Expand Down
2 changes: 1 addition & 1 deletion books/architecture/src/resources/cap/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ There are "synchronization primitives" that help with this, common ones being:
- [Channels](https://en.wikipedia.org/wiki/Channel_(programming))
- [Atomics](https://en.wikipedia.org/wiki/Linearizability#Primitive_atomic_instructions)

These tools are relatively easy to use in isolation, but trickier to do so when considering the entire system. It is not uncommon for _the_ bottleneck to be the [poor orchastration](https://en.wikipedia.org/wiki/Starvation_(computer_science)) of these primitives.
These tools are relatively easy to use in isolation, but trickier to do so when considering the entire system. It is not uncommon for _the_ bottleneck to be the [poor orchestration](https://en.wikipedia.org/wiki/Starvation_(computer_science)) of these primitives.

## Analogy
A common analogy for a parallel system is an intersection.
Expand Down
1 change: 1 addition & 0 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ monero-serai = { workspace = true, features = ["std"] }
rayon = { workspace = true }
thread_local = { workspace = true }

indexmap = { workspace = true, features = ["std"] }
hex = { workspace = true }
rand = { workspace = true }

Expand Down
Loading
Loading