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)

@heijiLee heijiLee marked this pull request as ready for review January 10, 2026 07:27
@heijiLee heijiLee requested a review from qj0r9j0vc2 January 10, 2026 08:46
@heijiLee heijiLee self-assigned this Jan 10, 2026
@qj0r9j0vc2 qj0r9j0vc2 self-requested a review January 11, 2026 10:55
Copy link
Member

@qj0r9j0vc2 qj0r9j0vc2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the solid foundation on Malachite integration. The feature-gated architecture and adapter pattern look great, and the README does a nice job explaining how everything fits together.

Before merging, please address the following:

Required Changes

1. Handle empty validator set gracefully

context.rs:103 - The select_proposer will panic on empty validator sets:

validator_set.get(idx).expect("validator_set must not be empty")

Please add validation at CipherBftContext::new() to return an error if the validator set is empty.

2. Fix CutProposalPart equality check

proposal.rs:94-98 - Current impl ignores first/last flags:

fn eq(&self, other: &Self) -> bool {
    self.cut.hash() == other.cut.hash()
        && self.first == other.first
        && self.last == other.last
}

Suggestions (non-blocking)

  • Add is_empty() to ConsensusValidatorSet (clippy will warn)
  • Wire ConsensusConfig timeouts into EngineConsensusConfig
  • Add unit tests for validator set sorting and encode functions

Let me know when these are addressed and I'll re-review. Great progress overall!

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.

3 participants