Skip to content

code: Streamline the process of creating a Malachite-based application  #547

@romac

Description

@romac

This proposal outlines a strategy to streamline the process of defining and running applications on top of Malachite.

Background

Currently, implementing a Malachite application requires multiple manual steps and detailed knowledge of the framework's internals.
This creates unnecessary complexity and potential barriers to adoption.

Current implementation

To develop an application on Malachite, the following steps are currently required:

  1. Implement malachite_common::Context and associated traits
  2. Implement malachite_actors::util::codec::NetworkCodec
  3. Implement Host actor that can receive malachite_actors::host::HostMsg<_> messages
  4. Implement malachite_node::Node
    1. Initialize metrics
    2. Spawn a Mempool actor (optional)
    3. Spawn a GossipConsensus actor
    4. Spawn a Host actor
    5. Spawn a BlockSync actor
    6. Spawn a Consensus actor
    7. Spawn a Node actor

Proposed solution

The solution introduces three distinct integration patterns (actor, channel, and gRPC) through four new crates:

Common functionality (malachite-app)

  1. Create a new malachite-app crate providing core functionality:
    • Re-export malachite-common under common module
    • Export NetworkCodec trait
  2. Rename malachite_node::Node trait to Application and move it to the malachite-app crate

Actor-based apps (malachite-app-actor)

  1. Create a new malachite-app-actor crate
    • Exports malachite_actors crate under actors module
  2. Centralize actor spawn functions for spawning the actors listed above (except the host)
  3. Provide a run function in malachite-app-actor which:
    • Takes the Context and NetworkCodec
    • Takes a closure for spawning the Host actor
    • Spawns all actors and return a reference to the Node actor

Channel-based apps (malachite-app-channel)

  1. Create a new malachite-app-channel crate
  2. Define an internal Host actor which forwards messages through channel(s)
  3. Provide a run function which returns the channel(s) for the app to make use of

gRPC-based apps (malachite-app-grpc)

  1. Create a new malachite-app-grpc crate
  2. Define a Host actor which performs gRPC calls to a server
  3. Provide a run function which takes the gRPC server address and starts the host

Benefits

  • Simplified application development
  • Multiple integration patterns
  • Reduced boilerplate code
  • Clearer separation of concerns
  • Improved maintainability

Open Questions

  1. How does this impact https://github.com/informalsystems/malachite/issues/373, and vice-versa?
  2. Should the Host actor be renamed to Application?
    • Might be confusing if we have an Application trait as well.
    • Should the Application trait stay named Node so that we can use Application for what is now the host?
  3. Should the NetworkCodec trait be moved to malachite-common?
    • It is only ever used in the malachite-actors crate
  4. Is it possible to implement both the Context and Application traits on the same struct? Or is it more flexible to define two structures, one for the context and one for the app?
    • Probably best to keep them separate
  5. Should we also propose a trait-based interface, in addition to the actor, channel and RPC interfaces?

Related concerns

  • For users wanting to write their own node based on malachite-consensus, we should ensure that the crate re-exports everything needed, without users having to pull multiple crates.

Next Steps

  1. Review and address open questions
  2. Create detailed technical specifications
  3. Implement proof-of-concept
  4. Gather feedback

Metadata

Metadata

Labels

applicationRelated to building applications on top of MalachitecodeCode/implementation relatedhelp wantedExtra attention is neededopen-sourceTasks required for open-sourcing the repository

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions