execution_time.rs

Overview

This file provides utilities for managing and adjusting execution time limits and production timeouts within a system that processes blocks and messages. It contains logic to dynamically correct production timeout values based on recent execution durations, and it encapsulates rules for determining execution deadlines and message timeouts during block production and verification phases.

The file primarily defines two structs:

Structs and Their Functionality

ProductionTimeoutCorrection

Manages a correction factor for production timeouts, which adjusts dynamically based on the actual duration of the last production cycle.

Fields

Implementations

Methods

Implementation Details

The correction logic attempts to keep the production timeout aligned with the actual production durations observed. If the last duration exceeds the desired timeout, the correction is decreased by 10 ms, lowering the timeout. If the production was significantly shorter (more than 20 ms less than desired), the correction is increased by 5 ms, allowing more time. The correction is capped so it cannot reduce the timeout by more than 90% of the desired duration, preventing overly aggressive timeout reductions.


ExecutionTimeLimits

Encapsulates time limits related to block processing and message execution, including deadlines for block production and optional differentiated timeouts for specific "alternative" messages.

Fields

Constants

Methods

Implementation Details

This struct facilitates flexible timeout management by allowing differentiated timeouts for specific messages, useful in scenarios where some messages require special handling or extended/shortened execution windows. The use of Instant for deadlines allows efficient comparison with the current time to enforce deadlines.


Interaction with Other System Components


Visual Diagram

classDiagram
class ProductionTimeoutCorrection {
-last_production_duration: i64
-correction: i64
+report_last_production()
+get_production_timeout()
+get_correction()
}
class ExecutionTimeLimits {
-block_deadline: Option<Instant>
-default_message_timeout: Option<Duration>
-alternative_message_timeout: Option<Duration>
-alternative_messages: Option<HashSet<UInt256>>
+new()
+production()
+verification()
+add_alternative_message()
+block_deadline()
+get_message_timeout()
}

This diagram illustrates the two main structs with their core fields and exposed methods, highlighting their encapsulated responsibilities related to execution timing and timeout adjustment.