### Ordering Example Help Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Displays further details and options for the ordering example script. ```bash ./run.sh -h ``` -------------------------------- ### Run Blockchain Example Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Starts the blockchain example with a specified number of nodes, assuming a specific network address is available for node discovery. ```bash cd ./examples/blockchain ./run.sh 5 ``` -------------------------------- ### Run Ordering Example Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Launches the ordering example with 2 working nodes and 2 faulty nodes that crash multiple times. Configures crash recovery delay and item creation counts. ```bash cd ./examples/ordering ./run.sh ``` -------------------------------- ### Blockchain Example Help Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Shows help information for the blockchain example, typically accessed via cargo run. ```bash cargo run -- --help ``` -------------------------------- ### Install Coverage Tools Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Installs necessary tools required for generating code coverage reports. ```bash install_cov_tools.sh ``` -------------------------------- ### Build AlephBFT Documentation Locally Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Instructions to build the AlephBFT documentation locally using mdBook. Ensure you have rustup installed. ```bash cargo install mdbook cd docs mdbook serve --open ``` -------------------------------- ### Pseudocode for getting blockchain data Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md This pseudocode illustrates how to retrieve the hash of the current 'tip' block in a blockchain, used for AlephBFT data handling. ```pseudocode def get_data(): let B be the tip of the longest chain extending from the most recently finalized block return Some(hash(B)) ``` -------------------------------- ### Get Data for Blockchain Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Fetches up to 100 transactions from the local transaction pool to form a new block. This function is used by the DataProvider. ```Python def get_data(): tx_list = [] while tx_pool.not_empty() and tx_list.len() < 100: tx = tx_pool.pop() tx_list.append(tx) return Some(tx_list) ``` -------------------------------- ### Run All Tests Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Executes all unit and integration tests for the AlephBFT library. ```bash cargo test --lib ``` -------------------------------- ### Pseudocode for handling incoming blocks Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md This pseudocode describes how to process newly received blocks, update message dependencies, and move messages to a ready state once all requirements are met. ```pseudocode def handle_incoming_block(B): block_hash = hash(B) for M in waiting_messages: if M depends on block_hash: remove the dependency if we don't have an ancestor B' of B: add a dependency on hash(B') and request it from random nodes if M has no more dependencies: move M to ready_messages ``` -------------------------------- ### Pseudocode for Creator Task Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md This pseudocode outlines the continuous task of a node to create new units. It iterates through rounds, checks if a unit can be created based on previous units, creates a new unit with specified parents and data, and broadcasts it. ```pseudocode def creator_task(): for r = 0, 1, 2, ...: loop: //since D is growing, the below if will eventually fire if can_create(r): Create a unit U of round r: Pick as its parents at least N-f units (from different creators) of round (r-1), including node k previous unit. Add the highest known units by all other creators. Poll the input stream for a fresh data item `d` and place it in `U` in the `data` field Send U to all other nodes sleep(CREATE_DELAY) break the inner loop ``` -------------------------------- ### Run Small Tests Only Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Skips medium integration tests and runs only the small unit tests for the AlephBFT library. ```bash cargo test --lib --skip medium ``` -------------------------------- ### Generate Coverage Report Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Creates a detailed code coverage report for each file after coverage data has been generated. ```bash cov_report.sh ``` -------------------------------- ### Add AlephBFT Crate to Dependencies Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md How to add the AlephBFT crate as a dependency in your Rust project's Cargo.toml file. ```toml [dependencies] aleph-bft = "^0.45" ``` -------------------------------- ### Generate Coverage Data Source: https://github.com/cardinal-cryptography/alephbft/blob/main/README.md Generates the raw data files needed for code coverage analysis. ```bash gen_cov_data.sh ``` -------------------------------- ### Pseudocode for data finalization Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md This pseudocode demonstrates the process of finalizing blocks based on received hashes, ensuring that all nodes agree on the order of finalized blocks. ```pseudocode def data_finalized(block_hash): let finalized = the highest finalized block so far // We have this block in local storage by the above filtering. let B be the block such that hash(B) == block_hash if finalized is an ancestor of B: finalize all the blocks on the path from finalized to B ``` -------------------------------- ### Pseudocode for Unit Creation Rules Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md This pseudocode defines the conditions under which an honest node can create a new unit. It checks the current round and the availability of units from the previous round created by the same node and other creators. ```pseudocode /* Written from the perspective of node k. D is a global variable denoting the set of units held by k. */ def can_create(r): if round == 0: return true if D does not contain a unit created by k in round r-1: return false if D contains less than N-f units from different creators in round r-1: return false return true ``` -------------------------------- ### Pseudocode for handling incoming network messages Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md This pseudocode outlines the logic for processing incoming network messages, including filtering based on included data and managing dependencies on block hashes. ```pseudocode def handle_incoming_message(M): let hashes = M.included_data() if we have all the blocks referred to by hashes: if we have all the ancestors of these blocks: add M to ready_messages return add M with it's required hashes to waiting_messages request all the blocks we don't have from random nodes ``` -------------------------------- ### OrderData Algorithm Pseudocode Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md This pseudocode outlines the OrderData algorithm, which computes a monotonically ordered sequence of data from a DAG. It iterates through rounds, selects a 'Head' unit, forms a batch of units below the head, and appends their data to the final order. The monotonicity property holds if the Head selection is also monotone. ```pseudocode def OrderData(D): order = [] batch = [] for r = 0, 1, 2, ... : let head = Head(r, D) if head is None: break let Some(U) = head new_batch = below(U) remove from new_batch the contents of batch[0], batch[1], ..., batch[r-1] sort new_batch using any canonical ordering batch[r] = new_batch let [U_1, U_2, ..., U_k] = new_batch order = order ++ [U_1.data, U_2.data, ..., U_k.data] return order ``` -------------------------------- ### Decide Procedure Logic Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md Determines a decision for unit 'U' in DAG 'D'. It returns Some(b) if any unit 'V' in 'D' results in DecideVia(U, V, D) returning Some(b). Otherwise, it returns None. It's guaranteed that all 'b' values will be the same if multiple 'V's satisfy the condition. ```python def Decide(U, D): if there exists any unit V in D such that DecideVia(U, V, D) == Some(b): // In this case it is guaranteed that all bs will be the same return Some(b) else: return None ``` -------------------------------- ### Rust Trait: DataProvider Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Defines the interface for providing data items to AlephBFT. Implementations should return `None` if no data is available to avoid halting unit creation. ```rust pub trait DataProvider { type Output: Data; async fn get_data(&mut self) -> Option; } ``` -------------------------------- ### Head Procedure Logic Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md Determines the head unit for a given round 'r' in the DAG 'D'. It returns None if the highest round in D is less than r+3, or the first unit in round 'r' that is decided true. If Decide returns None for any unit, Head also returns None. ```python def Head(r, D): if the highest round of a unit in D is < (r+3): return None let [U_1, U_2, ..., U_s] be the units in D of round r sorted according to some canonical order // The order is allowed to depend on r and on Head(r-1, D) for l = 1, 2, ..., s: if Decide(U_l, D) == Some(b): if b==true: return Some(U_l) else: continue the loop else: return None // The execution can never reach this line because at least one unit in round r must be decided true. ``` -------------------------------- ### Rust Trait: Keychain Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Defines the interface for cryptographic operations, including signing arbitrary data and verifying signatures. Implementations typically involve managing private and public keys. ```rust pub trait Keychain: Index + Clone + Send + Sync + 'static { type Signature: Signature; fn sign(&self, msg: &[u8]) -> Self::Signature; fn verify(&self, msg: &[u8], sgn: &Self::Signature, index: NodeIndex) -> bool; } ``` -------------------------------- ### Rust Trait: Network Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Defines the interface for network communication within AlephBFT. It includes methods for sending messages to specific or all recipients and asynchronously receiving network events. ```rust pub trait Network: Send { fn send(&self, data: NetworkData, recipient: Recipient); async fn next_event(&mut self) -> Option>; } ``` -------------------------------- ### Finalize Data for Blockchain Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Processes a list of transactions to form a new block and adds it to the blockchain. This function is used by the FinalizationHandler. ```Python def data_finalized(tx_list): let k be the number of the previous block remove duplicated from tx_list remove from tx_list all transactions that appeared in blocks B[0], B[1], ..., B[k] form block B[k+1] using tx_list as its content add B[k+1] to the blockchain ``` -------------------------------- ### Vote Function Logic Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md Calculates a vote for unit 'U' based on unit 'V' and DAG 'D'. It recursively calls itself for parents of 'V' if the round difference is greater than 1. Assumes V.round > U.round. ```python def Vote(U, V, D): // It is assumed that V.round > U.round round_diff = V.round - U.round if round_diff == 1: return [U belongs to parents(V)] else: let votes be the multiset of Vote(U, P, D) for P in parents(V) if votes are all the same, and equal to b: return b else: return CommonVote(round_diff) ``` -------------------------------- ### DecideVia Function Logic Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md Determines a decision for unit 'U' based on unit 'V' and DAG 'D'. It checks if a sufficient number of parent votes match the CommonVote for the given round difference. Requires a round difference of at least 3. ```python def DecideVia(U, V, D): round_diff = V.round - U.round if round_diff < 3: return None threshold = N-f cv = CommonVote(round_diff) let votes be the multiset of Vote(U, P, D) for P in parents(V) if among votes there are >= threshold votes equal to cv: return Some(cv) return None ``` -------------------------------- ### Rust Enum: Recipient Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Represents the possible recipients for network messages in AlephBFT. It can be either all nodes or a specific node identified by its index. ```rust pub enum Recipient { Everyone, Node(NodeIndex), } ``` -------------------------------- ### Rust Trait: FinalizationHandler Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/aleph_bft_api.md Defines the interface for handling finalized data items produced by AlephBFT. The `data_finalized` method is called with data in the order determined by the consensus. ```rust pub trait FinalizationHandler { fn data_finalized(&mut self, data: Data); } ``` -------------------------------- ### CommonVote Function Logic Source: https://github.com/cardinal-cryptography/alephbft/blob/main/docs/src/how_alephbft_does_it.md Determines a common vote based on the round difference. For round differences less than or equal to 4, it returns true except for a difference of 3, which returns false. For differences greater than 4, it returns true if the difference is odd, and false if even. ```python def CommonVote(round_diff): if round_diff <= 4: if round_diff == 3: return false else: return true else: return [(round_diff % 2) == 1] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.