Matej Pavlovic
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Managing Time through a dedicated abstraction * Status: proposed * Deciders: @matejpavlovic, @sergefdrv, @dnkolegov * Date: 2022-05-02 (last update) ## Context and Problem Statement Time is currently represented by *Tick* events periodically injected in the modules. Each module counts the ticks to obtain a notion of time and acts accordingly. This makes it inconvenient for the programmer to use time (e.g. for implementing timeouts), having to implement logic to explicitly deal with Tick events (e.g. counting them). It would be better to have access to higher-level time abstractions like timeouts when implementing protocols. ## Decision Drivers * Simplicity of reasoning about the implemented protocol * Traceability, reproducibility (deterministic execution), and ease of debugging of the protocol * Programming convenience, code readability * Simplicity of use of the Mir library for the consumer ## Considered Options ### Separate *Timer* module: Replace the *Tick* abstraction by a higher-level *Timer* module with 2 main functionalities: - **Delay**: Emits a given event after a given amount of time. - **Repeat**: Repeatedly emits a given event with a given frequency until stopped. If the protocol (or any other module) wishes to invoke one of the Timer functions, it emits a corresponding `Delay` or `Repeat` event that the Node routes to the *Timer* module. The event includes, apart from the delay / period, the event to be later emitted by the *Timer* module. Similarly to WAL entries, each invocation of the Timer would be labeled with a "retention index" that could, the same way as the WAL, be garbage-collected, canceling all future event emissions associated with a certain (or lower) retention index. Note that this approach does not introduce any non-determinism in the protocol execution, as the time is still implemented as delayed injection of events. The same sequence of events still deterministically induces exactly the same behavior of the prtocol implementation. In this sense, the the separate timer module is equivalent to inserting *Ticks* in the protocol module. The only difference is that the protocol does not have to perform the counting itself - it happens in a separate *Timer* module #### Example: view change timeout in a PBFT instance in ISS At initialization of a PBFT instance, the PBFT protocol must set a "view change timer" after the expiration of which it enters view change, unless it delivers a batch with sequence number 0 before the expiration. 1. Thus, at initilization of the PBFT protocol, the Protocol module creates 2 Events: - `vct := ViewChangeTimeout{Sn: 0}` - `d := Delay{DelayedEvent: vct, Duration: 5000}` Note that the `Delay` event contains the `ViewChangeTimeout` event for sequence number 0. 2. The Protocol module emits the `Delay` event and the Node implementation saves it in the buffer of the event loop of the Node. 3. Eventually, the Node implementation reads the `Delay` event from the buffer and routes it to the *Timer* module (by calling `applyEvent(d)` on the *Timer* module). 4. The *Timer* module locally saves the `ViewChangeTimeout` event contained in the `Delay` event and sets up an OS-level physical timer for a time that corresponds to 5000 time units (e.g. milliseconds). 5. When the operating system timer expires, the *Timer* module emits the associated `ViewChangeTimeout` event that the Node implementation saves in the buffer of the event loop. 7. Eventually, the Node implementation picks up the `ViewChangeTimeout` from the buffer and submits it to the Protocol module (by calling `applyEvent(vct)` on the Protocol module). 8. On application of the `ViewChangeTimeout` event, the protocol checks whether batch 0 has already been committed. - If yes, it ignores the event. (Note that this makes explicit cancellation of the timeout on committing batch 0 unnecessary.) - If not, it enters view change. *Note*: In practice, there might be more meta-information attached to the events from this example, which are omitted for clarity. ### Protocol-local *Timer* abstraction on top of *Ticks* Keep the *Ticks* but implement a *Timer* object in a separate package that would expose higher-level functionalities similar to (or same as) the ones described above. A *Timer* can be instantiated by a protocol implementation (only one is generally needed) The protocol implementation would only need to feed *Ticks* to the abstraction (and nothing else but the abstraction). ## Decision Outcome Chosen option: **Separate *Timer* Module**, because it either improves on, or at least does not compromise any of the above decision drivers, removes the necessity of *Ticks* altogether and more naturally addresses the common use case of using a timer as a follow-up event. ### Positive Consequences See "Good" points below. ### Negative Consequences <!-- optional --> See "Bad" points below. ## Pros and Cons of the Options ### Separate *Timer* module * Good, because it improves on programming convenience and code readability and does not sacrifice traceability, reproducibility, or simplicity of reasoning about implemented algorithms. * Good, because it improves simplicity of use for the library consumer, who does not need to care about explicitly passing *Ticks* to the Node instance. * Good, because the implementation of the algorithm does not need to deal with *Ticks* at all. * Good, because it naturally supports the common use case of using a timer as a follow-up event, without having to implement additional protocol logic. For example, if the protocol needs to periodically start sending a message only after another event is persisted in the WAL, it can achieve this by simply emitting one event with a follow-up event attached to it. * Bad, because it increases the complexity of the core Node framework by introducing another module. ### Protocol-local *Timer* abstraction on top of *Ticks* * Good, because it improves on programming convenience (although a bit less than Option 1) and code readability and does not sacrifice traceability, reproducibility, or simplicity of reasoning about implemented algorithms. * Good, because it does not necessitate any new modules. * Good, because if used in sub-modules (e.g. an ISS SB instance), garbage-collection and canceling timers comes "for free" together with the garbage-collection of the sub-module. * Bad, because setting of timers that depend on the execution of another event is not naturally supported and needs to be explicitly implemented every time in the protocol code. * Bad, because it requires augmenting the WAL by a feedback mechanism to explicitly notify the protocol about having persisted the required events. Otherwise, setting timers is hard (if not impossible) to make dependent on the execution of WAL events. (But admittedly, it is likely that the WAL feedback mechanism will be necessary in the future anyway, regardless of timers.) * Bad, because of making it harder to use natural untis of time in the protocol configuration, since tick counting depends on the tick interval determined somewhere else.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully