Skip to content
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

Submit snark work using graphql #16366

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions graphql_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "ProofBundle",
"description": "Proof bundle for a given spec in json format",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "RosettaTransaction",
Expand Down Expand Up @@ -5490,6 +5500,38 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "sendProofBundle",
"description": "Transaction SNARKs for a given spec",
"args": [
{
"name": "input",
"description":
"Proof bundle for a given spec in json format including fees and prover public key",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ProofBundle",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
36 changes: 36 additions & 0 deletions src/lib/mina_graphql/mina_graphql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,41 @@ module Mutations = struct
Error "Internal error: response from transaction pool was malformed"
)

let add_snark_work =
io_field "sendProofBundle" ~doc:"Transaction SNARKs for a given spec"
~args:
Arg.
[ arg "input"
~doc:
"Proof bundle for a given spec in json format including fees \
and prover public key"
~typ:(non_null Types.Input.ProofBundleInput.arg_typ)
]
~typ:(non_null string)
~resolve:(fun { ctx = mina; _ } ()
(proof_bundle :
Ledger_proof.t
Snark_work_lib.Work.Result_without_metrics.t ) ->
let solved_work =
Network_pool.Snark_pool.Resource_pool.Diff.Add_solved_work
( proof_bundle.statements
, { proof = proof_bundle.proofs
; fee = { fee = proof_bundle.fee; prover = proof_bundle.prover }
} )
in
match%map Mina_lib.add_work_graphql mina solved_work with
| Ok
( `Broadcasted
, Network_pool.Snark_pool.Resource_pool.Diff.Add_solved_work _
, _ ) ->
Ok "Accepted"
| Error err ->
Error (Error.to_string_hum err)
| Ok _ ->
Error
"Internal error: Transaction proofs could not be added to the \
pool" )

let export_logs =
io_field "exportLogs" ~doc:"Export daemon logs to tar archive"
~args:Arg.[ arg "basename" ~typ:string ]
Expand Down Expand Up @@ -1006,6 +1041,7 @@ module Mutations = struct
; archive_precomputed_block
; archive_extensional_block
; send_rosetta_transaction
; add_snark_work
]

module Itn = struct
Expand Down
15 changes: 15 additions & 0 deletions src/lib/mina_graphql/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,21 @@ module Input = struct
Yojson.Safe.to_basic @@ Mina_base.Zkapp_command.to_json x )
end

module ProofBundleInput = struct
type input = Ledger_proof.t Snark_work_lib.Work.Result_without_metrics.t

let arg_typ =
scalar "ProofBundle" ~doc:"Proof bundle for a given spec in json format"
~coerce:(fun json ->
let json = Utils.to_yojson json in
Snark_work_lib.Work.Result_without_metrics.of_yojson
Ledger_proof.of_yojson json )
~to_json:(fun (res : input) ->
Snark_work_lib.Work.Result_without_metrics.to_yojson
Ledger_proof.to_yojson res
|> Yojson.Safe.to_basic )
end

module PrecomputedBlock = struct
type input = Mina_block.Precomputed.t

Expand Down
7 changes: 7 additions & 0 deletions src/lib/mina_lib/mina_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,13 @@ let add_work t (work : Snark_worker_lib.Work.Result.t) =
(Network_pool.Snark_pool.Resource_pool.Diff.of_result work, cb)
|> Deferred.don't_wait_for

let add_work_graphql t diff =
let results_ivar = Ivar.create () in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an ivar necessary here? Can we not just bind the deferred value and return?

Copy link
Member

@svv232 svv232 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure a an Ivar push makes sense as a validation call back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the purpose of this callback was to check the validation status and handle it appropriately for a given message.

Copy link
Member Author

@deepthiskumar deepthiskumar Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an ivar necessary here? Can we not just bind the deferred value and return?

Yes, if you want to return the status of the operation- whether the completed work was broadcasted or not.

I thought the purpose of this callback was to check the validation status and handle it appropriately for a given message.

Not sure what the discrepancy is here. The validation status is returned to the grapqhl request and as for the message, it would either be added to the pool or not

Network_pool.Snark_pool.Local_sink.push t.pipes.snark_local_sink
(diff, Ivar.fill results_ivar)
|> Deferred.don't_wait_for ;
Ivar.read results_ivar

let get_current_nonce t aid =
match
Participating_state.active
Expand Down
8 changes: 8 additions & 0 deletions src/lib/mina_lib/mina_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ val work_selection_method : t -> (module Work_selector.Selection_method_intf)

val add_work : t -> Snark_worker.Work.Result.t -> unit

val add_work_graphql :
t
-> Network_pool.Snark_pool.Resource_pool.Diff.t
-> ( [ `Broadcasted | `Not_broadcasted ]
* Network_pool.Snark_pool.Resource_pool.Diff.t
* Network_pool.Snark_pool.Resource_pool.Diff.rejected )
Deferred.Or_error.t

val snark_job_state : t -> Work_selector.State.t

val get_current_nonce :
Expand Down
10 changes: 10 additions & 0 deletions src/lib/snark_work_lib/work.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ module Result = struct
end
end]
end

module Result_without_metrics = struct
type 'proof t =
{ proofs : 'proof One_or_two.t
; statements : Transaction_snark.Statement.t One_or_two.t
; prover : Signature_lib.Public_key.Compressed.t
; fee : Currency.Fee.t
}
[@@deriving yojson]
end