-
Notifications
You must be signed in to change notification settings - Fork 584
Use tx segments in delegation program #18182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martyall
wants to merge
6
commits into
compatible
Choose a base branch
from
martyall/issue-18123
base: compatible
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5de2885
refactor work_partitioner to expose make_zkapp_segments
martyall 8f3930e
add perform_partition to uptime_snark_worker functions
martyall f58eb9a
for uptime snark, if terminal tx is zkapp tx, only use last segment
martyall d23a655
better check for segment
martyall e73c974
PR suggestions
martyall 7f7a0de
push all logic in uptime_snark_worker in preparation to move all to n…
martyall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,6 +8,31 @@ open struct | |
| module Impl = Snark_worker.Impl | ||
| end | ||
|
|
||
| let extract_terminal_zk_segment ~(m : (module Transaction_snark.S)) ~witness | ||
| ~input ~zkapp_command ~staged_ledger_hash = | ||
| let staged_ledger_hash = Staged_ledger_hash.ledger_hash staged_ledger_hash in | ||
| let%bind.Result final_segment = | ||
| Work_partitioner.Snark_worker_shared.extract_zkapp_segment_works ~m ~input | ||
| ~witness ~zkapp_command | ||
| |> Result.map_error | ||
| ~f: | ||
| Work_partitioner.Snark_worker_shared.Failed_to_generate_inputs | ||
| .error_of_t | ||
| |> Result.map ~f:(function x -> | ||
| Work_partitioner.Snark_worker_shared.Zkapp_command_inputs | ||
| .read_all_proofs_from_disk x | ||
| |> Mina_stdlib.Nonempty_list.find ~f:(function _, _, s -> | ||
| Ledger_hash.(s.target.second_pass_ledger = staged_ledger_hash) ) ) | ||
| in | ||
| match final_segment with | ||
| | Some res -> | ||
| Ok res | ||
| | _ -> | ||
| Error | ||
| ( Error.of_string | ||
| @@ sprintf "Failed to find zkapp segment with target hash %s" | ||
| (Ledger_hash0.to_base58_check staged_ledger_hash) ) | ||
|
|
||
| module Worker = struct | ||
| module T = struct | ||
| module F = Rpc_parallel.Function | ||
|
|
@@ -18,6 +43,14 @@ module Worker = struct | |
| , Sok_message.t * Snark_work_lib.Spec.Single.Stable.Latest.t | ||
| , (Ledger_proof.t * Time.Span.t) Or_error.t ) | ||
| F.t | ||
| ; perform_partitioned : | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for later: it probably make sense to move code here back into snark worker. It seems now a uptime snark worker is just a regular snark worker, nothing fancy. |
||
| ( 'w | ||
| , Transaction_witness.Stable.Latest.t | ||
| * Mina_state.Snarked_ledger_state.Stable.Latest.t | ||
| * Zkapp_command.Stable.Latest.t | ||
| * Staged_ledger_hash.t | ||
| , (Ledger_proof.t * Time.Span.t) Or_error.t ) | ||
| F.t | ||
| } | ||
|
|
||
| module Worker_state = struct | ||
|
|
@@ -43,6 +76,41 @@ module Worker = struct | |
| let perform_single (state : Worker_state.t) (message, single_spec) = | ||
| Impl.perform_single ~message state single_spec | ||
|
|
||
| let perform_partitioned (state : Worker_state.t) | ||
| (witness, statement, zkapp_command, staged_ledger_hash) = | ||
| let zkapp_command = | ||
| Zkapp_command.write_all_proofs_to_disk | ||
| ~signature_kind:state.signature_kind | ||
| ~proof_cache_db:state.proof_cache_db zkapp_command | ||
| in | ||
| match state.proof_level_snark with | ||
| | Full (module S) -> | ||
| let%bind.Deferred.Or_error witness, spec, statement = | ||
| extract_terminal_zk_segment | ||
| ~m:(module S) | ||
| ~witness ~input:statement ~zkapp_command ~staged_ledger_hash | ||
| |> Deferred.return | ||
| in | ||
|
|
||
| Snark_worker.Impl.measure_runtime ~logger:state.logger | ||
| ~spec_json: | ||
| ( lazy | ||
| ( "zkapp_segment_spec" | ||
| , Transaction_snark.Zkapp_command_segment.Basic.Stable.Latest | ||
| .to_yojson spec ) ) | ||
| (fun () -> | ||
| let witness = | ||
| Transaction_witness.Zkapp_command_segment_witness | ||
| .write_all_proofs_to_disk witness | ||
| ~proof_cache_db:state.proof_cache_db | ||
| ~signature_kind:state.signature_kind | ||
| in | ||
| S.of_zkapp_command_segment_exn ~statement ~witness ~spec | ||
| |> Deferred.map ~f:(fun a -> Result.Ok a) ) | ||
| | _ -> | ||
| Deferred.Or_error.error_string | ||
| "Unexpected prover mode in uptime snark worker" | ||
|
|
||
| let functions = | ||
| let f (i, o, f) = | ||
| C.create_rpc | ||
|
|
@@ -57,6 +125,16 @@ module Worker = struct | |
| , [%bin_type_class: | ||
| (Ledger_proof.Stable.Latest.t * Time.Span.t) Or_error.t] | ||
| , perform_single ) | ||
| ; perform_partitioned = | ||
| f | ||
| ( [%bin_type_class: | ||
| Transaction_witness.Stable.Latest.t | ||
| * Mina_state.Snarked_ledger_state.Stable.Latest.t | ||
| * Zkapp_command.Stable.Latest.t | ||
| * Staged_ledger_hash.Stable.Latest.t] | ||
| , [%bin_type_class: | ||
| (Ledger_proof.Stable.Latest.t * Time.Span.t) Or_error.t] | ||
| , perform_partitioned ) | ||
| } | ||
|
|
||
| let init_worker_state (logger, constraint_constants) = | ||
|
|
@@ -123,3 +201,6 @@ let create ~logger ~constraint_constants ~pids : t Deferred.t = | |
|
|
||
| let perform_single { connection; _ } ((_message, _single_spec) as arg) = | ||
| Worker.Connection.run connection ~f:Worker.functions.perform_single ~arg | ||
|
|
||
| let perform_partitioned { connection; _ } arg = | ||
| Worker.Connection.run connection ~f:Worker.functions.perform_partitioned ~arg | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunate because the uptime snark worker state has its own transaction module derived from the same global constants. Ideally they would share one, but the setup makes it harder than its worth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, just move these code into snark worker & expose an interface specific for this case will solve the issue. Like a
perform_uptimethat just take last segment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there's still going to be semantical difference in that it'll no longer be interruptible. But the fact that we're using smaller data to construct this proof should make it less relevant.