Skip to content

Commit

Permalink
Configure crawler partition.
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Feb 20, 2024
1 parent 5ad0fde commit 7018c83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/bin/avail-light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ async fn run(shutdown: Controller<String>) -> Result<()> {

#[cfg(feature = "crawl")]
if cfg.crawl.crawl_block {
let partition = cfg.crawl.crawl_block_matrix_partition;
tokio::task::spawn(shutdown.with_cancel(avail_light::crawl_client::run(
crawler_rpc_event_receiver,
p2p_client.clone(),
cfg.crawl.crawl_block_delay,
ot_metrics.clone(),
cfg.crawl.crawl_block_mode,
partition.unwrap_or(avail_light::crawl_client::ENTIRE_BLOCK),
)));
}

Expand Down
14 changes: 10 additions & 4 deletions src/crawl_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
rpc::{self, Event},
},
telemetry::{MetricValue, Metrics},
types::{self, Delay},
types::{self, block_matrix_partition_format, Delay},
};
use kate_recovery::matrix::Partition;
use serde::{Deserialize, Serialize};
Expand All @@ -15,7 +15,7 @@ use std::{
use tokio::sync::broadcast;
use tracing::{error, info};

const ENTIRE_BLOCK: Partition = Partition {
pub const ENTIRE_BLOCK: Partition = Partition {
number: 1,
fraction: 1,
};
Expand All @@ -37,6 +37,9 @@ pub struct CrawlConfig {
pub crawl_block_delay: u64,
/// Crawl block mode. Available modes are "cells", "rows" and "both" (default: "cells")
pub crawl_block_mode: CrawlMode,
/// Fraction and number of the block matrix part to crawl (e.g. 2/20 means second 1/20 part of a matrix) (default: None)
#[serde(with = "block_matrix_partition_format")]
pub crawl_block_matrix_partition: Option<Partition>,
}

impl Default for CrawlConfig {
Expand All @@ -45,6 +48,7 @@ impl Default for CrawlConfig {
crawl_block: false,
crawl_block_delay: 20,
crawl_block_mode: CrawlMode::Cells,
crawl_block_matrix_partition: None,
}
}
}
Expand All @@ -55,6 +59,7 @@ pub async fn run(
delay: u64,
metrics: Arc<impl Metrics>,
mode: CrawlMode,
partition: Partition,
) {
info!("Starting crawl client...");

Expand Down Expand Up @@ -88,7 +93,7 @@ pub async fn run(
if matches!(mode, CrawlMode::Cells | CrawlMode::Both) {
let positions = block
.dimensions
.iter_extended_partition_positions(&ENTIRE_BLOCK)
.iter_extended_partition_positions(&partition)
.collect::<Vec<_>>();

let total = positions.len();
Expand All @@ -99,9 +104,10 @@ pub async fn run(
.len();

let success_rate = fetched as f64 / total as f64;
let partition = format!("{}/{}", partition.number, partition.fraction);
info!(
block_number,
success_rate, total, fetched, "Fetched block cells",
partition, success_rate, total, fetched, "Fetched block cells",
);
let _ = metrics
.record(MetricValue::CrawlCellsSuccessRate(success_rate))
Expand Down

0 comments on commit 7018c83

Please sign in to comment.