Skip to content

Commit

Permalink
refactor(storage): remove unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafbeef committed Feb 21, 2024
1 parent 28b2438 commit 164ad12
Show file tree
Hide file tree
Showing 24 changed files with 24 additions and 421 deletions.
10 changes: 2 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["consensus", "constansts", "core", "network", "util", "storage", "block-util"]
members = ["consensus", "core", "network", "util", "storage", "block-util"]

[profile.release]
debug = true
Expand Down
5 changes: 2 additions & 3 deletions block-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ahash = "0.8.8"
anyhow = "1.0.79"
bytes = "1.5.0"
dashmap = "5.5.3"
everscale-types = "0.1.0-rc.6"
hex = "0.4.3"
libc = "0.2.153"
Expand All @@ -19,8 +17,9 @@ serde = { version = "1.0.196", features = ["derive"] }
sha2 = "0.10.8"
smallvec = "1.13.1"
thiserror = "1.0.57"
tokio = { version = "1.36.0", features = ["sync", "time"] }
tracing = "0.1.40"

tycho-util = { path = "../util" }

[lints]
workspace = true
6 changes: 2 additions & 4 deletions block-util/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node
//
// Changes:
// - replaced old `failure` crate with `anyhow`
use anyhow::{anyhow, Context, Result};
use everscale_types::models::*;
use everscale_types::prelude::*;
use sha2::Digest;

use tycho_util::FastHashMap;

use crate::*;

pub type BlockStuffAug = WithArchiveData<BlockStuff>;
Expand Down
138 changes: 1 addition & 137 deletions block-util/src/block_proof.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node
//
// Changes:
// - replaced old `failure` crate with `anyhow`
use anyhow::{anyhow, Context, Result};
use everscale_types::merkle::*;
use everscale_types::models::*;
Expand Down Expand Up @@ -451,8 +447,6 @@ pub fn check_with_master_state(
pub struct ValidatorSubsetInfo {
pub validators: Vec<ValidatorDescription>,
pub short_hash: u32,
#[cfg(feature = "venom")]
pub collator_range: Option<ton_block::CollatorRange>,
}

impl ValidatorSubsetInfo {
Expand All @@ -469,136 +463,6 @@ impl ValidatorSubsetInfo {
Ok(ValidatorSubsetInfo {
validators,
short_hash,
#[cfg(feature = "venom")]
collator_range: None,
})
}

#[cfg(feature = "venom")]
pub fn compute_for_workchain_venom(
validator_set: &ton_block::ValidatorSet,
block_id: &ton_block::BlockIdExt,
shard_hashes: &ton_block::ShardHashes,
cc_seqno: u32,
) -> Result<ValidatorSubsetInfo> {
let possible_validators =
compute_possible_collator_ranges(shard_hashes, &block_id.shard_id, block_id.seq_no)?;
get_validator_descrs_by_collator_range(validator_set, cc_seqno, &possible_validators)
}

// pub fn compute_validator_set(&self, cc_seqno: u32) -> Result<ton_block::ValidatorSet> {
// ton_block::ValidatorSet::with_cc_seqno(0, 0, 0, cc_seqno, self.validators.clone())
// }
}

#[cfg(feature = "venom")]
pub fn compute_possible_collator_ranges(
shards: &ton_block::ShardHashes,
shard_id: &ton_block::ShardIdent,
block_seqno: u32,
) -> Result<Vec<ton_block::CollatorRange>> {
let mut possible_validators: Vec<ton_block::CollatorRange> = Vec::new();

shards.iterate_shards_for_workchain(shard_id.workchain_id(), |ident, descr| {
let Some(collators) = descr.collators else {
anyhow::bail!("{} has no collator info", ident);
};

if let Some(rng) = compute_collator_range(&collators, &ident, shard_id, block_seqno)? {
if !possible_validators.contains(&rng) {
possible_validators.push(rng);
}
}
Ok(true)
})?;

Ok(possible_validators)
}

#[cfg(feature = "venom")]
fn get_validator_descrs_by_collator_range(
vset: &ton_block::ValidatorSet,
cc_seqno: u32,
possible_validators: &[ton_block::CollatorRange],
) -> Result<ValidatorSubsetInfo> {
let Some(range) = possible_validators.first() else {
anyhow::bail!("No possible validators found");
};

anyhow::ensure!(
possible_validators.len() == 1,
"Too many validators for collating block",
);

let Some(validator) = vset.list().get(range.collator as usize) else {
anyhow::bail!(
"No validator no {} in validator set {vset:?}",
range.collator
)
};

let mut subset = Vec::new();
subset.push(validator.clone());

let short_hash = ton_block::ValidatorSet::calc_subset_hash_short(subset.as_slice(), cc_seqno)?;
Ok(ValidatorSubsetInfo {
validators: subset,
short_hash,
collator_range: Some(range.clone()),
})
}

#[cfg(feature = "venom")]
fn compute_collator_range(
collators: &ton_block::ShardCollators,
current_shard: &ton_block::ShardIdent,
block_shard: &ton_block::ShardIdent,
block_seqno: u32,
) -> Result<Option<ton_block::CollatorRange>> {
// Current shard
let mut shards_to_check = Vec::from([(*current_shard, collators.current.clone())]);
// The shard was same or will be same
if collators.prev2.is_none() {
shards_to_check.push((*current_shard, collators.prev.clone()));
}
if collators.next2.is_none() {
shards_to_check.push((*current_shard, collators.next.clone()));
}
// The shard was split or will be merged
if !current_shard.is_full() {
if collators.prev2.is_none() {
shards_to_check.push((current_shard.merge()?, collators.prev.clone()));
}
if collators.next2.is_none() {
shards_to_check.push((current_shard.merge()?, collators.next.clone()));
}
}
// The shard was merged or will be split
if current_shard.can_split() {
let (l, r) = current_shard.split()?;
if let Some(prev2) = &collators.prev2 {
shards_to_check.push((l, collators.prev.clone()));
shards_to_check.push((r, prev2.clone()));
}
if let Some(next2) = &collators.next2 {
shards_to_check.push((l, collators.next.clone()));
shards_to_check.push((r, next2.clone()));
}
}

shards_to_check.retain(|(id, range)| {
id == block_shard && range.start <= block_seqno && block_seqno <= range.finish
});

if let Some((id, rng)) = shards_to_check.first() {
anyhow::ensure!(
shards_to_check.len() == 1,
"Impossilbe state: shard {}, block {} corresponds to two different ranges: ({},{:?}) and {:?}",
current_shard, block_seqno, id, rng, shards_to_check.get(1)
);

Ok(Some((*rng).clone()))
} else {
Ok(None)
}
}
}
11 changes: 0 additions & 11 deletions block-util/src/conversions.rs

This file was deleted.

49 changes: 0 additions & 49 deletions block-util/src/extensions.rs

This file was deleted.

10 changes: 0 additions & 10 deletions block-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::collections::{HashMap, HashSet};

pub use archive_package::*;
pub use block::*;
pub use block_proof::*;
pub use mapped_file::*;
pub use operations_pool::*;
pub use package_entry_id::*;
pub use progress_bar::*;
pub use shard_state::*;
Expand All @@ -17,7 +14,6 @@ mod archive_package;
mod block;
mod block_proof;
mod mapped_file;
mod operations_pool;
mod package_entry_id;
mod progress_bar;
mod shard_state;
Expand All @@ -26,12 +22,6 @@ mod stored_value;
mod top_blocks;
mod with_archive_data;

pub type FastHashSet<K> = HashSet<K, FastHasherState>;
pub type FastHashMap<K, V> = HashMap<K, V, FastHasherState>;
pub type FastDashSet<K> = dashmap::DashSet<K, FastHasherState>;
pub type FastDashMap<K, V> = dashmap::DashMap<K, V, FastHasherState>;
pub type FastHasherState = ahash::RandomState;

#[derive(Default, Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub struct CacheStats {
pub hits: u64,
Expand Down
Loading

0 comments on commit 164ad12

Please sign in to comment.