Skip to content

Commit

Permalink
refactor(block-stride): wip refactor before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Apr 18, 2024
1 parent 8287685 commit 35b2a7c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 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
Expand Up @@ -98,7 +98,7 @@ tycho-util = { path = "./util" }
# NOTE: use crates.io dependency when it is released
# https://github.com/sagebind/castaway/issues/18
castaway = { git = "https://github.com/sagebind/castaway.git" }
everscale-types = { git = "https://github.com/broxus/everscale-types.git", branch = "0xdeafbeef/push-xrvxlsnspsok" }
everscale-types = { git = "https://github.com/broxus/everscale-types.git" }

[workspace.lints.rust]
future_incompatible = "warn"
Expand Down
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ tracing-test = { workspace = true }

[lints]
workspace = true

[features]
test = []
4 changes: 2 additions & 2 deletions core/src/block_strider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl BlocksGraph {
#[cfg(test)]
mod test {
use super::state::InMemoryBlockStriderState;
use super::subscriber::PrintSubscriber;
use super::subscriber::test::PrintSubscriber;
use super::test_provider::TestBlockProvider;
use crate::block_strider::BlockStrider;

Expand All @@ -331,7 +331,7 @@ mod test {
provider.validate();

let subscriber = PrintSubscriber;
let state = InMemoryBlockStriderState::new(provider.first_master_block());
let state = InMemoryBlockStriderState::with_initial_id(provider.first_master_block());

let strider = BlockStrider::builder()
.with_state(state)
Expand Down
8 changes: 3 additions & 5 deletions core/src/block_strider/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl BlockStriderState for Arc<Storage> {
fn load_last_traversed_master_block_id(&self) -> BlockId {
self.node_state()
.load_last_mc_block_id()
.expect("Db is not initialized")
.expect("db is not initialized")
}

fn is_traversed(&self, block_id: &BlockId) -> bool {
Expand All @@ -34,15 +34,14 @@ impl BlockStriderState for Arc<Storage> {
}
}

#[cfg(test)]
pub struct InMemoryBlockStriderState {
last_traversed_master_block_id: parking_lot::Mutex<BlockId>,
// TODO: Use topblocks here.
traversed_blocks: tycho_util::FastDashSet<BlockId>,
}

#[cfg(test)]
impl InMemoryBlockStriderState {
pub fn new(id: BlockId) -> Self {
pub fn with_initial_id(id: BlockId) -> Self {
let traversed_blocks = tycho_util::FastDashSet::default();
traversed_blocks.insert(id);

Expand All @@ -53,7 +52,6 @@ impl InMemoryBlockStriderState {
}
}

#[cfg(test)]
impl BlockStriderState for InMemoryBlockStriderState {
fn load_last_traversed_master_block_id(&self) -> BlockId {
*self.last_traversed_master_block_id.lock()
Expand Down
2 changes: 1 addition & 1 deletion core/src/block_strider/state_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub mod test {
use super::super::test_provider::archive_provider::ArchiveProvider;
use super::*;

use crate::block_strider::subscriber::PrintSubscriber;
use crate::block_strider::subscriber::test::PrintSubscriber;
use crate::block_strider::BlockStrider;
use everscale_types::cell::HashBytes;
use everscale_types::models::BlockId;
Expand Down
27 changes: 15 additions & 12 deletions core/src/block_strider/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,22 @@ impl<T1: BlockSubscriber, T2: BlockSubscriber> BlockSubscriber for FanoutBlockSu
}
}

#[cfg(test)]
pub struct PrintSubscriber;
#[cfg(any(test, feature = "test"))]
pub mod test {
use super::*;

#[cfg(test)]
impl BlockSubscriber for PrintSubscriber {
type HandleBlockFut = future::Ready<anyhow::Result<()>>;
pub struct PrintSubscriber;

fn handle_block(
&self,
block: &BlockStuff,
_state: Option<&ShardStateStuff>,
) -> Self::HandleBlockFut {
println!("Handling block: {:?}", block.id());
future::ready(Ok(()))
impl BlockSubscriber for PrintSubscriber {
type HandleBlockFut = future::Ready<anyhow::Result<()>>;

fn handle_block(
&self,
block: &BlockStuff,
_state: Option<&ShardStateStuff>,
) -> Self::HandleBlockFut {
tracing::info!("handling block: {:?}", block.id());
future::ready(Ok(()))
}
}
}
5 changes: 5 additions & 0 deletions util/src/test/logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
pub fn init_logger(test_name: &str) {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::new("debug"))
.try_init()
.ok();

tracing::info!("{test_name}");

std::panic::set_hook(Box::new(|info| {
Expand Down

0 comments on commit 35b2a7c

Please sign in to comment.