Skip to content

Conversation

@heijiLee
Copy link
Collaborator

Malachite Consensus Implementation Review

This document summarizes the Malachite consensus layer components that have been implemented so far.

Implemented Components

1. Context Creation Helper

create_context() - crates/consensus/src/engine.rs

Convenience function to create a CipherBFT context.

pub fn create_context(
    chain_id: impl Into<String>,
    validators: Vec<ConsensusValidator>,
    initial_height: Option<ConsensusHeight>,
) -> CipherBftContext

2. ConsensusParams Creation Helper

default_consensus_params() - crates/consensus/src/engine.rs

Creates Malachite's ConsensusParams from a CipherBFT context. Sets value_payload to ProposalOnly (for single-part Cut support).

pub fn default_consensus_params(
    ctx: &CipherBftContext,
    our_address: ConsensusAddress,
) -> ConsensusParams<CipherBftContext>

3. EngineConfig Creation Helper

default_engine_config_single_part() - crates/consensus/src/engine.rs

Creates a Malachite engine configuration for single-part proposals.

pub fn default_engine_config_single_part() -> EngineConsensusConfig

4. SigningProvider Implementation

ConsensusSigningProvider - crates/consensus/src/signing.rs

Bridges CipherBFT's Ed25519 keys with Malachite's SigningProvider trait. Implements signing and verification methods for Vote, Proposal, and ProposalPart.

pub struct ConsensusSigningProvider {
    signer: ConsensusSigner,
}

Architecture Overview

Component Status for MalachiteEngineBuilder

Component Status Helper Function
CipherBftContext ✅ Complete create_context()
ConsensusParams ✅ Complete default_consensus_params()
EngineConsensusConfig ✅ Complete default_engine_config_single_part()
SigningProvider ✅ Complete ConsensusSigningProvider::new()
NetworkRef ❌ Not implemented -
HostRef ❌ Not implemented -
WalRef ❌ Not implemented -

Usage Flow

let ctx = create_context("chain-id", validators, None);
let params = default_consensus_params(&ctx, our_address);
let engine_config = default_engine_config_single_part();
let signing_provider = Box::new(ConsensusSigningProvider::new(signer));

// Network, Host, WAL actors need to be created
let builder = MalachiteEngineBuilder::new(
    ctx, params, engine_config, signing_provider, network, host, wal,
);
let handles = builder.spawn().await?;

Next Steps

  1. Network Actor: Network actor for consensus message send/receive
  2. Host Actor: Handle AppMsg events (Cut fetch, execute, etc.)
  3. WAL Actor: Write-Ahead Log actor (codec and path configuration required)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants