round_time.rs

Overview

This file implements a time calculation mechanism for rounds in a block-based system. It defines a RoundTime structure that manages multiple "buckets" of round durations, allowing the calculation of a current round number and the remaining time within that round based on an elapsed duration from the parent block. The design accommodates varying round durations and iteration counts using configurable buckets, enabling flexible round time modeling that can adapt to different system requirements.

Structures and Core Components

RoundBucket

RoundTime

CalculateRoundResult

Helper Function: div_with_reminder

Implementation Details and Algorithms

Interaction with Other Parts of the Application

Tests

Mermaid Diagram: Structure of round_time.rs

classDiagram
class RoundBucket {
- round_duration: Duration
- max_number_of_loops: u32
}
class RoundTime {
- buckets: Vec<RoundBucket>
- default_bucket: Duration
+ linear(min_round_duration: Duration, step: Duration, max_round_duration: Duration) RoundTime
+ calculate_round(duration_from_parent_block: Duration, block_bk_set_size: u16) CalculateRoundResult
}
class CalculateRoundResult {
+ round: BlockRound
+ round_remaining_time: Duration
}
RoundTime --> "0..*" RoundBucket
RoundTime ..> CalculateRoundResult

This diagram shows the relationships between the core data structures and their key methods in this file.