mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-04-22 22:08:13 +00:00
add docs + order imports
This commit is contained in:
parent
8c268aa841
commit
d71c5aaf7f
6 changed files with 37 additions and 23 deletions
binaries/cuprated/src
p2p/p2p/src
types/src
|
@ -27,8 +27,8 @@ const _: () = {
|
|||
|
||||
/// The killswitch activates if the current timestamp is ahead of this timestamp.
|
||||
///
|
||||
/// TODO: update this
|
||||
pub const KILLSWITCH_ACTIVATION_TIMESTAMP: u64 = u64::MAX;
|
||||
/// Sat Mar 01 2025 05:00:00 GMT+0000
|
||||
pub const KILLSWITCH_ACTIVATION_TIMESTAMP: u64 = 1740805200;
|
||||
|
||||
/// Check if the system clock is past a certain timestamp,
|
||||
/// if so, exit the entire program.
|
||||
|
|
|
@ -28,7 +28,7 @@ use cuprate_pruning::PruningSeed;
|
|||
use crate::{
|
||||
constants::{
|
||||
BLOCK_DOWNLOADER_REQUEST_TIMEOUT, EMPTY_CHAIN_ENTRIES_BEFORE_TOP_ASSUMED, LONG_BAN,
|
||||
MAX_BLOCK_BATCH_LEN, MAX_DOWNLOAD_FAILURES,
|
||||
MAX_BLOCK_BATCH_LEN, MAX_DOWNLOAD_FAILURES, MOST_RECENT_BATCH_WEIGHTS_FOR_BATCH_SIZE,
|
||||
},
|
||||
peer_set::{ClientDropGuard, PeerSetRequest, PeerSetResponse},
|
||||
};
|
||||
|
@ -602,7 +602,8 @@ where
|
|||
},
|
||||
)));
|
||||
|
||||
if self.most_recent_batch_sizes.len() > 100 {
|
||||
if self.most_recent_batch_sizes.len() > MOST_RECENT_BATCH_WEIGHTS_FOR_BATCH_SIZE
|
||||
{
|
||||
self.most_recent_batch_sizes.pop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
use cuprate_fixed_bytes::ByteArrayVec;
|
||||
use std::{cmp::min, collections::VecDeque, mem};
|
||||
|
||||
use cuprate_fixed_bytes::ByteArrayVec;
|
||||
use tower::{Service, ServiceExt};
|
||||
|
||||
use crate::block_downloader::{ChainSvcRequest, ChainSvcResponse};
|
||||
use crate::constants::MEDIUM_BAN;
|
||||
use cuprate_constants::block::MAX_BLOCK_HEIGHT_USIZE;
|
||||
use cuprate_p2p_core::{client::InternalPeerID, handles::ConnectionHandle, NetworkZone};
|
||||
use cuprate_pruning::PruningSeed;
|
||||
|
||||
use crate::{
|
||||
block_downloader::{ChainSvcRequest, ChainSvcResponse},
|
||||
constants::MEDIUM_BAN,
|
||||
};
|
||||
|
||||
/// A new chain entry to add to our chain tracker.
|
||||
#[derive(Debug)]
|
||||
pub struct ChainEntry<N: NetworkZone> {
|
||||
|
@ -55,8 +59,9 @@ pub(crate) enum ChainTrackerError {
|
|||
/// This struct allows following a single chain. It takes in [`ChainEntry`]s and
|
||||
/// allows getting [`BlocksToRetrieve`].
|
||||
pub(crate) struct ChainTracker<N: NetworkZone> {
|
||||
/// A list of [`ChainEntry`]s, in order.
|
||||
/// A list of [`ChainEntry`]s, in order, that we should request.
|
||||
valid_entries: VecDeque<ChainEntry<N>>,
|
||||
/// A list of [`ChainEntry`]s that are pending more [`ChainEntry`]s to check validity.
|
||||
unknown_entries: VecDeque<ChainEntry<N>>,
|
||||
/// The height of the first block, in the first entry in [`Self::entries`].
|
||||
first_height: usize,
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
use futures::{FutureExt, StreamExt};
|
||||
use indexmap::IndexMap;
|
||||
use monero_serai::{
|
||||
block::{Block, BlockHeader},
|
||||
transaction::{Input, Timelock, Transaction, TransactionPrefix},
|
||||
};
|
||||
use proptest::{collection::vec, prelude::*};
|
||||
use std::collections::VecDeque;
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
fmt::{Debug, Formatter},
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -14,6 +7,14 @@ use std::{
|
|||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use indexmap::IndexMap;
|
||||
use monero_serai::{
|
||||
block::{Block, BlockHeader},
|
||||
transaction::{Input, Timelock, Transaction, TransactionPrefix},
|
||||
};
|
||||
use proptest::{collection::vec, prelude::*};
|
||||
use tokio::{sync::mpsc, time::timeout};
|
||||
use tower::{buffer::Buffer, service_fn, Service, ServiceExt};
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ pub(crate) const MAX_DOWNLOAD_FAILURES: usize = 5;
|
|||
/// The amount of empty chain entries to receive before we assume we have found the top of the chain.
|
||||
pub(crate) const EMPTY_CHAIN_ENTRIES_BEFORE_TOP_ASSUMED: usize = 5;
|
||||
|
||||
/// The amount of most recent block batches we use to calculate batch size.
|
||||
pub(crate) const MOST_RECENT_BATCH_WEIGHTS_FOR_BATCH_SIZE: usize = 100;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -44,6 +44,9 @@ pub enum BlockchainReadRequest {
|
|||
/// The input is the block's height and the chain it is on.
|
||||
BlockHash(usize, Chain),
|
||||
|
||||
/// Request a range of block's hashes.
|
||||
///
|
||||
/// The input is the range of block heights and the chain it is on.
|
||||
BlockHashInRange(Range<usize>, Chain),
|
||||
|
||||
/// Request to check if we have a block and which [`Chain`] it is on.
|
||||
|
@ -137,9 +140,7 @@ pub enum BlockchainReadRequest {
|
|||
AltBlocksInChain(ChainId),
|
||||
|
||||
/// Get a [`Block`] by its height.
|
||||
Block {
|
||||
height: usize,
|
||||
},
|
||||
Block { height: usize },
|
||||
|
||||
/// Get a [`Block`] by its hash.
|
||||
BlockByHash([u8; 32]),
|
||||
|
@ -159,10 +160,7 @@ pub enum BlockchainReadRequest {
|
|||
/// `N` last blocks starting at particular height.
|
||||
///
|
||||
/// TODO: document fields after impl.
|
||||
CoinbaseTxSum {
|
||||
height: usize,
|
||||
count: u64,
|
||||
},
|
||||
CoinbaseTxSum { height: usize, count: u64 },
|
||||
|
||||
/// Get information on all alternative chains.
|
||||
AltChains,
|
||||
|
@ -180,6 +178,9 @@ pub enum BlockchainWriteRequest {
|
|||
/// Input is an already verified block.
|
||||
WriteBlock(VerifiedBlockInformation),
|
||||
|
||||
/// Request that a batch of blocks be written to the database.
|
||||
///
|
||||
/// Input is an already verified batch of blocks.
|
||||
BatchWriteBlocks(Vec<VerifiedBlockInformation>),
|
||||
|
||||
/// Write an alternative block to the database,
|
||||
|
@ -238,6 +239,9 @@ pub enum BlockchainResponse {
|
|||
/// Inner value is the hash of the requested block.
|
||||
BlockHash([u8; 32]),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::BlockHashInRange`].
|
||||
///
|
||||
/// Inner value is the hashes of the requested blocks, in order.
|
||||
BlockHashInRange(Vec<[u8; 32]>),
|
||||
|
||||
/// Response to [`BlockchainReadRequest::FindBlock`].
|
||||
|
|
Loading…
Reference in a new issue