-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parallel proving of transactions (#227)
* Add analytics to the sequencer * Add analytics gql api * Add average fee to analytics * Add prover for txn snark * Make prover general * Add prover client * Fix da diff timestamp backwards compatibility * Add round robin to prover client * Implement timeout and retry into prover client * Add provers to the sequencer cli * Add connection error handling * Add remaining proofs to the prover * Remove dependency on circuits in sequencer * Remove sequencer module functor * Add parallel prover library * Ensure correct ordering of commits * Add context to the parallel prover * Renam prover to merger * Integrate into the sequencer * Clean up old snark queue * Fix pool size check * Add round robin again * Add requeuing * Cleanup parallel merger * Add spec for parallel merger * Add prover spec * Typos * More typos
- Loading branch information
1 parent
c27a7a3
commit c3f4ef2
Showing
26 changed files
with
3,463 additions
and
2,370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Parallel merger | ||
|
||
## Abstraction | ||
|
||
This is a library used by sequencer to parallelize the merging of transaction snarks. | ||
It tries to abstract away from the actual logic of sequencer, so it accepts 3 modules as arguments into the functor. | ||
All of them have `type t` that represents a witness and `process` function that takes a witness and returns a deferred result. | ||
|
||
Context is a module that is used by sequencer to provide handles to the e.g. `da_client` or `prover_client` and also takes care of persisting and restarting the proving process in case of a sequencer restart. | ||
|
||
```ocaml | ||
Context : sig | ||
type t | ||
end | ||
``` | ||
|
||
```ocaml | ||
Merge : sig | ||
type t | ||
val process : Context.t -> t -> t -> t Deferred.t | ||
end | ||
``` | ||
|
||
```ocaml | ||
Base : sig | ||
type t | ||
val process : Context.t -> t -> Merge.t Deferred.t | ||
end | ||
``` | ||
|
||
```ocaml | ||
Commit : sig | ||
type t | ||
val process : Context.t -> t -> Merge.t -> unit Deferred.t | ||
end | ||
``` | ||
|
||
## Inner workings | ||
|
||
```ocaml | ||
module Tree = struct | ||
type t = | ||
{ mutable jobs : Job_status.t With_id.t list | ||
; mutable closed : bool (** No new jobs can be added *) | ||
; finished : Finished_job.t Ivar.t (** All jobs are done *) | ||
; ready_to_commit : unit Ivar.t (** All jobs are done and ready to commit *) | ||
} | ||
end | ||
module Forest = struct | ||
type t = { mutable trees : Tree.t list } | ||
end | ||
``` | ||
|
||
Proving of transactions is done in a forest of trees, where each tree consists of one batch of transactions to commit. | ||
The tree is represented by a list of jobs. It's list because we care only about actionable jobs and not the nodes that have already been proven or don't have a witness yet. | ||
|
||
### Job | ||
|
||
```ocaml | ||
module Available_job = struct | ||
type t = Base of Base.t | Merge of Merge.t * Merge.t | ||
end | ||
module Finished_job = struct | ||
type t = Merge.t | ||
end | ||
module Job_status = struct | ||
type t = Todo of Available_job.t | Done of Finished_job.t | ||
end | ||
``` | ||
|
||
The whole logic implemented revolves around 2 rules: | ||
|
||
1. If there is a `Todo` job, process it. | ||
2. If there are 2 `Done` jobs next to each other in one tree, merge them. | ||
|
||
## Adding a job | ||
|
||
```ocaml | ||
let add_job t ctx ~(data : Base.t) | ||
``` | ||
|
||
Adding a job creates a `Todo (Base witness)` job at the end of a last tree and calls a process function. | ||
After completion it is transformed into a `Done (Merge witness)` job by `finish_job_exn` function, and checks if it created an opportunity to merge. | ||
Opportunity to merge are two consecutive `Done (Merge witness)` jobs in one tree. | ||
Finished job can create only one opportunity to merge. If there is one, create new `Todo (Merge (fst, snd))` job and process it. | ||
|
||
Additionally all the jobs have unique id, so we can track them. | ||
|
||
```ocaml | ||
module With_id = struct | ||
type 'd t = { id : string; value : 'd } [@@deriving sexp, yojson] | ||
end | ||
``` | ||
|
||
## Committing | ||
|
||
```ocaml | ||
let commit t ctx ~commit_witness | ||
``` | ||
|
||
Sequencer can commit a tree at any time. Committing in proving context means that current tree should be closed (no new jobs added) and once it's all proven it should be committed. | ||
Closing a tree means that there needs to be a new tree created where all the new jobs will go to. | ||
Commit function will: | ||
|
||
1. Close the last tree and create a new one. | ||
2. Wait for the previous tree to finish (because of the order of commits). | ||
3. Wait until there is only one `Done (Merge w)` job left in the list. | ||
4. Call `Commit.process` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(env | ||
(_ | ||
(flags | ||
(:standard -w -4)))) | ||
|
||
(library | ||
(name parallel_merger) | ||
(inline_tests) | ||
(libraries async core_kernel yojson sexplib sexplib0) | ||
(preprocess | ||
(pps ppx_jane ppx_mina))) |
Oops, something went wrong.