Skip to content

docs: add missing doc comments for public functions #2084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/walrus-core/src/encoding/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ pub fn source_symbols_per_blob(
.expect("product of two u16 always fits into a u32")
}

/// Extracts the data portion from an [`EncodingPacket`].
///
/// The packet is split into its header and payload components, and
/// this function returns the payload part as a `Vec<u8>`.
#[inline]
pub fn packet_to_data(packet: EncodingPacket) -> Vec<u8> {
packet.split().1
Expand Down
4 changes: 4 additions & 0 deletions crates/walrus-service/src/common/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ pub(crate) struct MetricsMiddlewareState {
}

impl MetricsMiddlewareState {
/// Creates a new [`MetricsMiddlewareState`] with initialized HTTP metrics and task monitors.
pub fn new(registry: &Registry) -> Self {
Self {
inner: Arc::new(MetricsMiddlewareStateInner {
Expand Down Expand Up @@ -512,6 +513,9 @@ impl<E> BodyVisitor<Bytes, E> for ResponseBodyVisitor {
pub(crate) struct CurrentEpochMetric(GenericGauge<AtomicU64>);

impl CurrentEpochMetric {
/// Creates a new [`CurrentEpochMetric`] with default configuration.
///
/// The metric records the current Walrus epoch under the name `walrus_current_epoch`.
pub fn new() -> Self {
Self(walrus_utils::metrics::create_metric!(
GenericGauge<AtomicU64>,
Expand Down
6 changes: 6 additions & 0 deletions crates/walrus-service/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ where
Fut: Future,
F: FnOnce(Option<&Fut::Output>) -> [&'static str; N],
{
/// Creates a new [`Observe`] wrapper around a future.
///
/// This function takes:
/// - `inner`: The future to observe,
/// - `histograms`: A Prometheus histogram vector for timing,
/// - `get_labels`: A closure to generate label values from the output of the future.
pub fn new(inner: Fut, histograms: HistogramVec, get_labels: F) -> Self {
Self {
inner,
Expand Down
12 changes: 12 additions & 0 deletions crates/walrus-service/src/node/committee/committee_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,35 @@ impl Default for NodeCommitteeServiceBuilder {
}

impl NodeCommitteeServiceBuilder {
/// Sets the local public identity key for the node.
pub fn local_identity(mut self, id: PublicKey) -> Self {
self.local_identity = Some(id);
self
}

/// Sets the configuration to be used for the committee service.
pub fn config(mut self, config: CommitteeServiceConfig) -> Self {
self.config = config;
self
}

/// Registers a Prometheus metrics registry to enable metrics tracking.
pub fn metrics_registry(mut self, registry: &Registry) -> Self {
self.registry = Some(registry.clone());
self
}

/// Sets a custom RNG instance for testing purposes.
#[cfg(test)]
pub fn randomness(mut self, rng: StdRng) -> Self {
self.rng = rng;
self
}

/// Builds a `NodeCommitteeService` using the provided committee lookup service.
///
/// Automatically creates a default node service factory (with or without metrics),
/// and passes it to `build_with_factory`.
pub async fn build<S>(
self,
lookup_service: S,
Expand All @@ -112,6 +120,9 @@ impl NodeCommitteeServiceBuilder {
.await
}

/// Builds a `NodeCommitteeService` using a custom node service factory and lookup service.
///
/// This method provides fine-grained control over the service instantiation process.
pub async fn build_with_factory<T, S, F>(
self,
lookup_service: S,
Expand Down Expand Up @@ -158,6 +169,7 @@ pub(crate) struct NodeCommitteeService<T = RemoteStorageNode> {
}

impl NodeCommitteeService<RemoteStorageNode> {
/// Creates a new [`NodeCommitteeServiceBuilder`] with default settings.
pub fn builder() -> NodeCommitteeServiceBuilder {
Default::default()
}
Expand Down
1 change: 1 addition & 0 deletions crates/walrus-service/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ struct SimStorageNodeConfigLoader {

#[cfg(msim)]
impl SimStorageNodeConfigLoader {
/// Creates a new [`SimStorageNodeConfigLoader`] with the given shared configuration.
pub fn new(config: Arc<RwLock<StorageNodeConfig>>) -> Self {
Self { config }
}
Expand Down
7 changes: 7 additions & 0 deletions crates/walrus-storage-node-client/src/client/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ struct RequestMonitor {
}

impl RequestMonitor {
/// Creates a new [`RequestMonitor`] for the given HTTP request.
///
/// This function initializes metrics, tracing spans, and tracking state needed
/// to monitor the request lifecycle until a response is received.
pub fn new(request: &Request, url_template: &'static str, metrics: HttpClientMetrics) -> Self {
let labels = HttpLabels::new(request, url_template);
let request_body_size = request
Expand All @@ -412,6 +416,9 @@ impl RequestMonitor {
}
}

/// Returns a reference to the HTTP tracing span, if available.
///
/// Useful for instrumentation or propagating the span context.
pub fn http_span(&self) -> Option<&Span> {
self.inner.as_ref().map(|inner| &inner.http_span)
}
Expand Down