-
Notifications
You must be signed in to change notification settings - Fork 128
Closed
Labels
applicationRelated to building applications on top of MalachiteRelated to building applications on top of MalachitecodeCode/implementation relatedCode/implementation relatedhelp wantedExtra attention is neededExtra attention is neededopen-sourceTasks required for open-sourcing the repositoryTasks required for open-sourcing the repository
Description
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:
- Implement
malachite_common::Contextand associated traits - Implement
malachite_actors::util::codec::NetworkCodec - Implement
Hostactor that can receivemalachite_actors::host::HostMsg<_>messages - Implement
malachite_node::Node- Initialize metrics
- Spawn a Mempool actor (optional)
- Spawn a GossipConsensus actor
- Spawn a Host actor
- Spawn a BlockSync actor
- Spawn a Consensus actor
- 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)
- Create a new
malachite-appcrate providing core functionality:- Re-export
malachite-commonundercommonmodule - Export
NetworkCodectrait
- Re-export
- Rename
malachite_node::Nodetrait toApplicationand move it to themalachite-appcrate
Actor-based apps (malachite-app-actor)
- Create a new
malachite-app-actorcrate- Exports
malachite_actorscrate underactorsmodule
- Exports
- Centralize actor spawn functions for spawning the actors listed above (except the host)
- Provide a
runfunction inmalachite-app-actorwhich:- Takes the
ContextandNetworkCodec - Takes a closure for spawning the Host actor
- Spawns all actors and return a reference to the Node actor
- Takes the
Channel-based apps (malachite-app-channel)
- Create a new
malachite-app-channelcrate - Define an internal
Hostactor which forwards messages through channel(s) - Provide a
runfunction which returns the channel(s) for the app to make use of
gRPC-based apps (malachite-app-grpc)
- Create a new
malachite-app-grpccrate - Define a
Hostactor which performs gRPC calls to a server - Provide a
runfunction 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
- How does this impact https://github.com/informalsystems/malachite/issues/373, and vice-versa?
- Should the
Hostactor be renamed toApplication?- Might be confusing if we have an
Applicationtrait as well. - Should the
Applicationtrait stay named Node so that we can useApplicationfor what is now the host?
- Might be confusing if we have an
- Should the
NetworkCodectrait be moved tomalachite-common?- It is only ever used in the
malachite-actorscrate
- It is only ever used in the
- Is it possible to implement both the
ContextandApplicationtraits 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
- 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
- Review and address open questions
- Create detailed technical specifications
- Implement proof-of-concept
- Gather feedback
greg-szabo
Metadata
Metadata
Assignees
Labels
applicationRelated to building applications on top of MalachiteRelated to building applications on top of MalachitecodeCode/implementation relatedCode/implementation relatedhelp wantedExtra attention is neededExtra attention is neededopen-sourceTasks required for open-sourcing the repositoryTasks required for open-sourcing the repository