marigold-dev / deku

MIT License
80 stars 16 forks source link

Integrate pollinate #567

Closed oteku closed 1 year ago

oteku commented 2 years ago

SUMMARY: Integrate pollinate lib to replace DEKU networking & gossip layer

MOTIVATION: Have a better networking layer in DEKU SCENARII:

Integrate pollinate:

DETAILED DESIGN:

@gsebil08 and @AngryStitch 's proposal:

Pollinate offers a way to receive and send messages over the network (via dm or gossip).

In order to isolate Deku from future Pollinate developments and to keep Deku as independant from Pollinate as possible, we offer to code a PROXY_POLLINATE in this way:

module type PROXY_POLLINATE = sig 
  val of_deku : PrenodeMessage.t -> PollinateMessage.t
  val of_pollinate : PollinateMessage.t -> PrenodeMessage.t 

  (* Transforms Deku messages into Pollinate messages. This is where the true dependency on Pollinate happens.   *)
  val handle_outgoing_messages : Pollinate.outbox -> PrenodeMessage.t list -> Pollinate.outbox

  (* Dispatches Pollinate messages to Deku  (different prenodes) *)
  val handle_ingoing_messages : Pollinate.inbox -> Pollinate.inbox * PrenodeMessage.t
end

A PrenodeMessage.t would look like:

PrenodeMessage.t = {
  category: category;  (* Consensus, Operation, ConsensusGovernance, ... *) 
  subcategory: string; (* Proposal, Precommit, Withdraw, AddValidator, ... *)
  payload: bytes;
  sender: Address.t;
  recipient: Address.t option;
 [...]
}

PrenodeMessages will be dispatched according to category to different prenodes. This will be the common interface to every prenode (ConsensusPrenode, ConsensusGovernancePrenode, …):

module type PRENODE = sig 
  type t

  val process_message : Message.t -> t -> t * Message.t list

  val tick : Timestep.t -> t -> t * Message.t list 
end 

Those prenodes will be responsible for parts of Deku: Consensus, ConsensusGovernance, BlockOperation (block by hash, block level, ...), Sync (snapshot, ...), ChainOperation (Withdraw, ...), ...

There will be the same number of category & prenodes.

Subcategory is the possible operation inside the category, this is directly linked to the flows.ml operation.

Plus side:

ALTERNATIVES: TODO

DRAWBACKS:

It will not be a small PR, there will be quite some work.

However, we should do this incrementally:

  1. Add PROXY_POLLINATE
  2. Add PrenodeMessage and PRENODE signature
  3. Add prenode by prenode until everything is out of flows.ml and http endpoints are gone

RELATED PRs:

d4hines commented 1 year ago

No longer using pollinate