bk_set_summary.rs

Overview

This file implements data structures and an HTTP handler for managing and serving summaries of "Bk" sets, which appear to represent collections of nodes identified by an owner address, public key, and epoch sequence number. The primary functionality includes creating summaries of current and future Bk sets, serializing them for JSON responses, maintaining an up-to-date snapshot of the summary, and providing an HTTP endpoint handler that responds with the Bk set summary in JSON format, with support for conditional requests based on modification time.


Data Structures and Types

BkSetSummary

A serializable struct representing a snapshot of a Bk set summary at a specific sequence number.


bk_vec_serde Module

Provides a custom serialization function for Vec<(String, [u8; 32], u64)> to ensure the public key bytes are hex-encoded strings in JSON output.


BkSetSummarySnapshot

A runtime snapshot holding the latest Bk set summary data and its update time.


BkSetSummaryResponse

A JSON-serializable response structure wrapping either a successful summary result or an error.


BkSummary

Represents a single node summary in the Bk set.


BkSetSummaryResult

Holds the full summary data for current and future Bk sets.


BkSetSummaryError

Represents an error response for the Bk set summary endpoint.


HTTP Handler: BkSetSummaryHandler

A generic HTTP handler implemented with the salvo framework to serve Bk set summary data.


Helper Function: render_error_response

Generates a JSON error response with an error code and optional message.


Interactions and Dependencies


Implementation Details and Algorithms


Visual Diagram: Structure of bk_set_summary.rs

classDiagram
class BkSetSummary {
+seq_no: u64
+current: Vec<(String, [u8;32], u64)>
+future: Vec<(String, [u8;32], u64)>
+new(bk_set: &ApiBkSet) BkSetSummary
}
class BkSetSummarySnapshot {
-update_time: SystemTime
-seq_no: u64
-nodes: Vec<(String, [u8;32], u64)>
-future_nodes: Vec<(String, [u8;32], u64)>
+new() BkSetSummarySnapshot
+replace(bk_update: BkSetSummary)
}
class BkSummary {
+node_id: String
+node_owner_pk: String
+epoch_start_seq_no: u64
}
class BkSetSummaryResult {
+bk_set: Vec<BkSummary>
+future_bk_set: Vec<BkSummary>
+seq_no: u64
+from(&BkSetSummarySnapshot) BkSetSummaryResult
}
class BkSetSummaryError {
+code: String
+message: String
}
class BkSetSummaryResponse {
+result: Option<BkSetSummaryResult>
+error: Option<BkSetSummaryError>
}
class BkSetSummaryHandler {
+new() BkSetSummaryHandler
+handle()
}
BkSetSummarySnapshot --> BkSetSummary : "updated from"
BkSetSummaryResult --> BkSetSummarySnapshot : "constructed from"
BkSetSummaryResponse --> BkSetSummaryResult : "contains"
BkSetSummaryResponse --> BkSetSummaryError : "contains"
BkSetSummaryHandler ..> BkSetSummaryResponse : "renders"

Notes on Usage within the System

For deeper understanding of the WebServer state management and ApiBkSet structure, refer to WebServer and ApiBkSet topics.