Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Boog900 committed Jan 21, 2025
1 parent e884cd1 commit caab94c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion binaries/cuprated/src/blockchain/manager/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl super::BlockchainManager {
top_alt_block.chain_id,
))
.await
.expect("TODO")
.map_err(|e| anyhow::anyhow!(e))?
else {
unreachable!();
};
Expand Down
6 changes: 4 additions & 2 deletions binaries/cuprated/src/p2p/core_sync_service.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::future::{ready, Ready};
use std::task::{Context, Poll};
use std::{
future::{ready, Ready},
task::{Context, Poll},
};

use futures::{future::BoxFuture, FutureExt, TryFutureExt};
use tower::Service;
Expand Down
12 changes: 7 additions & 5 deletions binaries/cuprated/src/txpool/incoming_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use std::{
};

use bytes::Bytes;
use futures::{future::BoxFuture, FutureExt};
use monero_serai::transaction::Transaction;
use tower::{BoxError, Service, ServiceExt};

use cuprate_blockchain::service::BlockchainReadHandle;
use cuprate_consensus::transactions::{start_tx_verification, PrepTransactions};
use cuprate_consensus::{
Expand All @@ -28,12 +32,9 @@ use cuprate_txpool::{
transaction_blob_hash,
};
use cuprate_types::TransactionVerificationData;
use futures::{future::BoxFuture, FutureExt};
use monero_serai::transaction::Transaction;
use tower::{BoxError, Service, ServiceExt};

use crate::blockchain::ConsensusBlockchainReadHandle;
use crate::{
blockchain::ConsensusBlockchainReadHandle,
constants::PANIC_CRITICAL_SERVICE_ERROR,
p2p::CrossNetworkInternalPeerId,
signals::REORG_LOCK,
Expand Down Expand Up @@ -85,6 +86,7 @@ pub struct IncomingTxHandler {
pub(super) txpool_write_handle: TxpoolWriteHandle,
/// The txpool read handle.
pub(super) txpool_read_handle: TxpoolReadHandle,
/// The blockchain read handle.
pub(super) blockchain_read_handle: ConsensusBlockchainReadHandle,
}

Expand Down Expand Up @@ -305,7 +307,7 @@ async fn handle_valid_tx(
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR)
.call(TxpoolWriteRequest::AddTransaction {
tx,
tx: Box::new(tx),
state_stem: state.is_stem_stage(),
})
.await
Expand Down
7 changes: 4 additions & 3 deletions consensus/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
// FIXME: should we pull in a dependency just to link docs?
use monero_serai as _;

use arc_swap::Cache;
use futures::{channel::oneshot, FutureExt};
use monero_serai::block::Block;
use std::{
cmp::min,
collections::HashMap,
Expand All @@ -19,6 +16,10 @@ use std::{
sync::Arc,
task::{Context, Poll},
};

use arc_swap::Cache;
use futures::{channel::oneshot, FutureExt};
use monero_serai::block::Block;
use tokio::sync::mpsc;
use tokio_util::sync::PollSender;
use tower::Service;
Expand Down
13 changes: 7 additions & 6 deletions consensus/context/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! This module contains the async task that handles keeping track of blockchain context.
//! It holds all the context caches and handles [`tower::Service`] requests.
//!
use std::sync::Arc;

use arc_swap::ArcSwap;
use futures::channel::oneshot;
use std::sync::Arc;
use tokio::sync::mpsc;
use tower::ServiceExt;
use tracing::Instrument;
Expand All @@ -18,13 +18,14 @@ use cuprate_types::{
Chain, HardFork,
};

use crate::difficulty::DifficultyCache;
use crate::hardforks::HardForkState;
use crate::weight::BlockWeightsCache;
use crate::{
alt_chains::{get_alt_chain_difficulty_cache, get_alt_chain_weight_cache, AltChainMap},
rx_vms, BlockChainContextRequest, BlockChainContextResponse, BlockchainContext,
ContextCacheError, ContextConfig, Database, BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW,
difficulty::DifficultyCache,
hardforks::HardForkState,
rx_vms,
weight::BlockWeightsCache,
BlockChainContextRequest, BlockChainContextResponse, BlockchainContext, ContextCacheError,
ContextConfig, Database, BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW,
};

/// A request from the context service to the context task.
Expand Down
25 changes: 13 additions & 12 deletions consensus/src/block/batch_prepare.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::{collections::HashMap, sync::Arc};

use crate::batch_verifier::MultiThreadedBatchVerifier;
use crate::transactions::start_tx_verification;
use crate::{
block::{free::order_transactions, PreparedBlock, PreparedBlockExPow},
BlockChainContextRequest, BlockChainContextResponse, ExtendedConsensusError,
};
use cuprate_consensus_context::rx_vms::RandomXVm;
use cuprate_consensus_context::BlockchainContextService;
use monero_serai::{block::Block, transaction::Transaction};
use rayon::prelude::*;
use tower::{Service, ServiceExt};
use tracing::instrument;

use cuprate_consensus_context::{rx_vms::RandomXVm, BlockchainContextService};
use cuprate_consensus_rules::{
blocks::{check_block_pow, is_randomx_seed_height, randomx_seed_height, BlockError},
hard_forks::HardForkError,
Expand All @@ -16,10 +14,13 @@ use cuprate_consensus_rules::{
};
use cuprate_helper::asynch::rayon_spawn_async;
use cuprate_types::TransactionVerificationData;
use monero_serai::{block::Block, transaction::Transaction};
use rayon::prelude::*;
use tower::{Service, ServiceExt};
use tracing::instrument;

use crate::{
batch_verifier::MultiThreadedBatchVerifier,
block::{free::order_transactions, PreparedBlock, PreparedBlockExPow},
transactions::start_tx_verification,
BlockChainContextRequest, BlockChainContextResponse, ExtendedConsensusError,
};

/// Batch prepares a list of blocks for verification.
#[instrument(level = "debug", name = "batch_prep_blocks", skip_all, fields(amt = blocks.len()))]
Expand Down
3 changes: 1 addition & 2 deletions storage/txpool/src/service/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ pub enum TxpoolReadResponse {
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest
/// The transaction pool [`tower::Service`] write request type.
#[derive(Clone)]
#[expect(clippy::large_enum_variant)]
pub enum TxpoolWriteRequest {
/// Add a transaction to the pool.
///
/// Returns [`TxpoolWriteResponse::AddTransaction`].
AddTransaction {
/// The tx to add.
tx: TransactionVerificationData,
tx: Box<TransactionVerificationData>,
/// A [`bool`] denoting the routing state of this tx.
///
/// [`true`] if this tx is in the stem state.
Expand Down
1 change: 1 addition & 0 deletions types/src/transaction_verification_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl TxVersion {
pub enum CachedVerificationState {
/// The transaction has not been validated.
NotVerified,
/// The transaction was only validated semantically.
JustSemantic(HardFork),
/// The transaction is valid* if the block represented by this hash is in the blockchain and the [`HardFork`]
/// is the same.
Expand Down

0 comments on commit caab94c

Please sign in to comment.