mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-02-03 19:56:32 +00:00
fix merge
This commit is contained in:
parent
2b8bc4d67f
commit
5709111144
11 changed files with 19 additions and 37 deletions
|
@ -35,9 +35,9 @@ prop_compose! {
|
||||||
fn arb_full_hf_votes()
|
fn arb_full_hf_votes()
|
||||||
(
|
(
|
||||||
// we can't use HardFork as for some reason it overflows the stack, so we use u8.
|
// we can't use HardFork as for some reason it overflows the stack, so we use u8.
|
||||||
votes in any::<[u8; TEST_WINDOW_SIZE as usize]>()
|
votes in any::<[u8; TEST_WINDOW_SIZE]>()
|
||||||
) -> HFVotes {
|
) -> HFVotes {
|
||||||
let mut vote_count = HFVotes::new(TEST_WINDOW_SIZE as usize);
|
let mut vote_count = HFVotes::new(TEST_WINDOW_SIZE);
|
||||||
for vote in votes {
|
for vote in votes {
|
||||||
vote_count.add_vote_for_hf(&HardFork::from_vote(vote % 17));
|
vote_count.add_vote_for_hf(&HardFork::from_vote(vote % 17));
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,10 +130,10 @@ pub(crate) fn ring_ct_semantic_checks(
|
||||||
let rct_type = proofs.rct_type();
|
let rct_type = proofs.rct_type();
|
||||||
|
|
||||||
check_rct_type(&rct_type, *hf, tx_hash)?;
|
check_rct_type(&rct_type, *hf, tx_hash)?;
|
||||||
check_output_range_proofs(&proofs, verifier)?;
|
check_output_range_proofs(proofs, verifier)?;
|
||||||
|
|
||||||
if rct_type != RctType::AggregateMlsagBorromean {
|
if rct_type != RctType::AggregateMlsagBorromean {
|
||||||
simple_type_balances(&proofs)?;
|
simple_type_balances(proofs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -135,11 +135,7 @@ impl DifficultyCache {
|
||||||
numb_blocks: usize,
|
numb_blocks: usize,
|
||||||
database: D,
|
database: D,
|
||||||
) -> Result<(), ExtendedConsensusError> {
|
) -> Result<(), ExtendedConsensusError> {
|
||||||
let Some(retained_blocks) = self
|
let Some(retained_blocks) = self.timestamps.len().checked_sub(numb_blocks) else {
|
||||||
.timestamps
|
|
||||||
.len()
|
|
||||||
.checked_sub(usize::try_from(numb_blocks).unwrap())
|
|
||||||
else {
|
|
||||||
// More blocks to pop than we have in the cache, so just restart a new cache.
|
// More blocks to pop than we have in the cache, so just restart a new cache.
|
||||||
*self = Self::init_from_chain_height(
|
*self = Self::init_from_chain_height(
|
||||||
self.last_accounted_height - numb_blocks + 1,
|
self.last_accounted_height - numb_blocks + 1,
|
||||||
|
|
|
@ -79,12 +79,8 @@ impl HardForkState {
|
||||||
|
|
||||||
let block_start = chain_height.saturating_sub(config.window);
|
let block_start = chain_height.saturating_sub(config.window);
|
||||||
|
|
||||||
let votes = get_votes_in_range(
|
let votes =
|
||||||
database.clone(),
|
get_votes_in_range(database.clone(), block_start..chain_height, config.window).await?;
|
||||||
block_start..chain_height,
|
|
||||||
usize::try_from(config.window).unwrap(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if chain_height > config.window {
|
if chain_height > config.window {
|
||||||
debug_assert_eq!(votes.total_votes(), config.window)
|
debug_assert_eq!(votes.total_votes(), config.window)
|
||||||
|
|
|
@ -101,17 +101,11 @@ impl BlockWeightsCache {
|
||||||
|
|
||||||
Ok(BlockWeightsCache {
|
Ok(BlockWeightsCache {
|
||||||
short_term_block_weights: rayon_spawn_async(move || {
|
short_term_block_weights: rayon_spawn_async(move || {
|
||||||
RollingMedian::from_vec(
|
RollingMedian::from_vec(short_term_block_weights, config.short_term_window)
|
||||||
short_term_block_weights,
|
|
||||||
usize::try_from(config.short_term_window).unwrap(),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.await,
|
.await,
|
||||||
long_term_weights: rayon_spawn_async(move || {
|
long_term_weights: rayon_spawn_async(move || {
|
||||||
RollingMedian::from_vec(
|
RollingMedian::from_vec(long_term_weights, config.long_term_window)
|
||||||
long_term_weights,
|
|
||||||
usize::try_from(config.long_term_window).unwrap(),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.await,
|
.await,
|
||||||
tip_height: chain_height - 1,
|
tip_height: chain_height - 1,
|
||||||
|
|
|
@ -65,7 +65,7 @@ async fn calculate_diff_3000000_3002000() -> Result<(), tower::BoxError> {
|
||||||
let mut db_builder = DummyDatabaseBuilder::default();
|
let mut db_builder = DummyDatabaseBuilder::default();
|
||||||
for (cum_dif, timestamp) in DIF_3000000_3002000
|
for (cum_dif, timestamp) in DIF_3000000_3002000
|
||||||
.iter()
|
.iter()
|
||||||
.take(cfg.total_block_count() as usize)
|
.take(cfg.total_block_count())
|
||||||
{
|
{
|
||||||
db_builder.add_block(
|
db_builder.add_block(
|
||||||
DummyBlockExtendedHeader::default().with_difficulty_info(*timestamp, *cum_dif),
|
DummyBlockExtendedHeader::default().with_difficulty_info(*timestamp, *cum_dif),
|
||||||
|
|
|
@ -173,8 +173,8 @@ impl Service<BCReadRequest> for DummyDatabase {
|
||||||
BCResponse::BlockHash(hash)
|
BCResponse::BlockHash(hash)
|
||||||
}
|
}
|
||||||
BCReadRequest::BlockExtendedHeaderInRange(range, _) => {
|
BCReadRequest::BlockExtendedHeaderInRange(range, _) => {
|
||||||
let mut end = usize::try_from(range.end).unwrap();
|
let mut end = range.end;
|
||||||
let mut start = usize::try_from(range.start).unwrap();
|
let mut start = range.start;
|
||||||
|
|
||||||
if let Some(dummy_height) = dummy_height {
|
if let Some(dummy_height) = dummy_height {
|
||||||
let block_len = blocks.read().unwrap().len();
|
let block_len = blocks.read().unwrap().len();
|
||||||
|
|
|
@ -130,13 +130,10 @@ impl TransactionVerificationData {
|
||||||
match &tx {
|
match &tx {
|
||||||
Transaction::V1 { prefix, .. } => {
|
Transaction::V1 { prefix, .. } => {
|
||||||
for input in &prefix.inputs {
|
for input in &prefix.inputs {
|
||||||
match input {
|
if let Input::ToKey { amount, .. } = input {
|
||||||
Input::ToKey { amount, .. } => {
|
fee = fee
|
||||||
fee = fee
|
.checked_add(amount.unwrap_or(0))
|
||||||
.checked_add(amount.unwrap_or(0))
|
.ok_or(TransactionError::InputsOverflow)?;
|
||||||
.ok_or(TransactionError::InputsOverflow)?;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ mod tests {
|
||||||
start_height,
|
start_height,
|
||||||
block_batch: BlockBatch {
|
block_batch: BlockBatch {
|
||||||
blocks: vec![],
|
blocks: vec![],
|
||||||
size: start_height as usize,
|
size: start_height,
|
||||||
peer_handle,
|
peer_handle,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,15 +171,12 @@ impl<N: NetworkZone> ChainTracker<N> {
|
||||||
// - index of the next pruned block for this seed
|
// - index of the next pruned block for this seed
|
||||||
let end_idx = min(
|
let end_idx = min(
|
||||||
min(entry.ids.len(), max_blocks),
|
min(entry.ids.len(), max_blocks),
|
||||||
usize::try_from(
|
|
||||||
pruning_seed
|
pruning_seed
|
||||||
.get_next_pruned_block(self.first_height, CRYPTONOTE_MAX_BLOCK_HEIGHT)
|
.get_next_pruned_block(self.first_height, CRYPTONOTE_MAX_BLOCK_HEIGHT)
|
||||||
.expect("We use local values to calculate height which should be below the sanity limit")
|
.expect("We use local values to calculate height which should be below the sanity limit")
|
||||||
// Use a big value as a fallback if the seed does no pruning.
|
// Use a big value as a fallback if the seed does no pruning.
|
||||||
.unwrap_or(CRYPTONOTE_MAX_BLOCK_HEIGHT)
|
.unwrap_or(CRYPTONOTE_MAX_BLOCK_HEIGHT)
|
||||||
- self.first_height,
|
- self.first_height,
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if end_idx == 0 {
|
if end_idx == 0 {
|
||||||
|
|
|
@ -25,6 +25,7 @@ use crate::{
|
||||||
pub fn chain_height(
|
pub fn chain_height(
|
||||||
table_block_heights: &impl DatabaseRo<BlockHeights>,
|
table_block_heights: &impl DatabaseRo<BlockHeights>,
|
||||||
) -> Result<BlockHeight, RuntimeError> {
|
) -> Result<BlockHeight, RuntimeError> {
|
||||||
|
#[allow(clippy::cast_possible_truncation)] // we enforce 64-bit
|
||||||
table_block_heights.len().map(|height| height as usize)
|
table_block_heights.len().map(|height| height as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ pub fn top_block_height(
|
||||||
) -> Result<BlockHeight, RuntimeError> {
|
) -> Result<BlockHeight, RuntimeError> {
|
||||||
match table_block_heights.len()? {
|
match table_block_heights.len()? {
|
||||||
0 => Err(RuntimeError::KeyNotFound),
|
0 => Err(RuntimeError::KeyNotFound),
|
||||||
|
#[allow(clippy::cast_possible_truncation)] // we enforce 64-bit
|
||||||
height => Ok(height as usize - 1),
|
height => Ok(height as usize - 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue