bk_set.rs

Overview

This file provides functionality to update the block keeper sets based on changes specified in a common section of a block. It mainly contains a single function that processes changes to the block keeper sets, applying removals, additions, and future additions as indicated in the block's common section. These updates are crucial for maintaining the current and future sets of block keepers, which likely represent entities responsible for specific roles in the system.


Functions

update_block_keeper_set_from_common_section

pub(crate) fn update_block_keeper_set_from_common_section(
    block: &AckiNackiBlock,
    current_bk_set: Arc<BlockKeeperSet>,
    current_future_bk_set: Arc<BlockKeeperSet>,
) -> anyhow::Result<Option<(Arc<BlockKeeperSet>, Arc<BlockKeeperSet>)>>

Parameters:

Returns:

Description:

This function extracts block keeper set changes from the block's common section and applies them to clones of the current block keeper sets. The changes are processed in three phases:

  1. Removal of block keepers: Removes specified signers from the current block keeper set.

  2. Addition of block keepers: Adds specified signers to the current block keeper set and removes them from the future set if present.

  3. Addition of future block keepers: Adds specified signers to the future block keeper set.

Each phase iterates over the block_keeper_set_changes and applies the relevant modifications accordingly.

Usage Example:

let updated_sets = update_block_keeper_set_from_common_section(
    &block, 
    current_bk_set.clone(), 
    current_future_bk_set.clone()
)?;

if let Some((new_bk_set, new_future_bk_set)) = updated_sets {
    // Use updated sets for subsequent processing
}

Implementation Details:


Data Types and Interactions

The function uses these types to apply updates properly.


Interaction with Other System Components


Visual Diagram

flowchart TD
A[AckiNackiBlock] -->|get_common_section| B[CommonSection]
B -->|block_keeper_set_changes| C{Iterate Changes}
C --> D[Remove BlockKeepers]
C --> E[Add BlockKeepers]
C --> F[Add Future BlockKeepers]
subgraph Update Process
D --> G[Clone current_bk_set]
E --> G
F --> H[Clone current_future_bk_set]
E --> H
F --> H
end
G --> I[Remove signers]
E --> J[Insert signers]
F --> K[Insert future signers]
I & J & K --> L[Return updated sets]

This flowchart illustrates the function's process: obtaining changes from a block, iterating through removal, addition, and future addition changes, applying them to clones of the current sets, and finally returning the updated sets.


References