Skip to content

Commit

Permalink
Merge pull request #7672 from MinaProtocol/feature/log-recursive-add-…
Browse files Browse the repository at this point in the history
…exn-fails

Verify cmds before recursively adding to the pool, throw useful errors
  • Loading branch information
mrmr1993 authored Jan 25, 2021
2 parents 18a035c + 7c21aca commit ad37d5b
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/lib/network_pool/indexed_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ module Command_error = struct
[@@deriving sexp_of, to_yojson]
end

exception Command_error of Command_error.t

let () =
Sexplib.Conv.Exn_converter.add [%extension_constructor Command_error]
(function
| Command_error t ->
Sexp.List [Sexp.Atom "Command_error"; Command_error.sexp_of_t t]
| _ ->
(* Reaching this branch indicates a bug in sexplib. *)
assert false )

(* Compute the total currency required from the sender to execute a command.
Returns None in case of overflow.
*)
Expand Down Expand Up @@ -868,17 +879,22 @@ let rec add_from_gossip_exn :
Transaction_hash.User_command_with_valid_signature.t Sequence.t]
dropped
(F_sequence.to_seq drop_queue) ;
let%bind cmd = verified () in
(* Add the new transaction *)
let%bind cmd, t'', _ =
match add_from_gossip_exn t' ~verify cmd0 current_nonce balance with
match
add_from_gossip_exn t' ~verify (`Checked cmd) current_nonce balance
with
| Ok (v, t'', dropped') ->
(* We've already removed them, so this should always be empty. *)
assert (Sequence.is_empty dropped') ;
Result.Ok (v, t'', dropped)
| Error (Insufficient_funds _ as err) ->
Error err (* C2 *)
| _ ->
failwith "recursive add_exn failed"
| Error ((Insufficient_funds _ | Overflow) as err) ->
Error err
(* C2 *)
(* C4 *)
| Error err ->
raise (Command_error err)
in
let drop_head, drop_tail = Option.value_exn (Sequence.next dropped) in
let increment =
Expand Down Expand Up @@ -922,8 +938,8 @@ let rec add_from_gossip_exn :
fee increment.
*)
go t' increment dropped (Some dropped') current_nonce
| _ ->
failwith "recursive add_exn failed" )
| Error err ->
raise (Command_error err) )
in
go t'' increment drop_tail None current_nonce
in
Expand Down

0 comments on commit ad37d5b

Please sign in to comment.