Skip to content

Commit

Permalink
Merge pull request #13347 from MinaProtocol/feature/rm-token-snapp-fe…
Browse files Browse the repository at this point in the history
…atures
  • Loading branch information
psteckler authored Jun 7, 2023
2 parents e0d3c57 + a4be0a2 commit 757ec9f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 127 deletions.
2 changes: 0 additions & 2 deletions src/config/features/dev.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[%%define feature_tokens true]
[%%define feature_snapps true]
[%%define mainnet false]
2 changes: 0 additions & 2 deletions src/config/features/mainnet.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[%%define feature_tokens false]
[%%define feature_snapps false]
[%%define mainnet true]
2 changes: 0 additions & 2 deletions src/config/features/public_testnet.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[%%define feature_tokens false]
[%%define feature_snapps false]
[%%define mainnet false]
37 changes: 16 additions & 21 deletions src/lib/mina_base/account.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,23 @@ module Binable_arg = struct
end]
end

let check = Fn.id

[%%if not feature_snapps]

let check (t : Binable_arg.t) =
let t = check t in
match t.snapp with
| None ->
t
| Some _ ->
failwith "Snapp accounts not supported"

[%%endif]

[%%if not feature_tokens]

let check (t : Binable_arg.t) =
let t = check t in
if Token_id.equal Token_id.default t.token_id then t
else failwith "Token accounts not supported"

[%%endif]
let has_nondefault_token =
not @@ Token_id.equal Token_id.default t.token_id
in
let has_snapp = Option.is_some t.snapp in
let failure_statuses =
[ (has_nondefault_token, "Token_accounts_not_supported")
; (has_snapp, "Snapp accounts not supported")
]
|> List.filter ~f:(fun (b, _) -> b)
in
if List.is_empty failure_statuses then t
else
let failure_msg =
List.map failure_statuses ~f:snd |> String.concat ~sep:"; "
in
failwith failure_msg

[%%versioned_binable
module Stable = struct
Expand Down
44 changes: 0 additions & 44 deletions src/lib/mina_base/signed_command_payload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@ module Common = struct
end]
end

[%%if feature_tokens]

[%%versioned
module Stable = struct
module V1 = struct
type t =
( Currency.Fee.Stable.V1.t
, Public_key.Compressed.Stable.V1.t
, Token_id.Stable.V1.t
, Account_nonce.Stable.V1.t
, Global_slot.Stable.V1.t
, Memo.Stable.V1.t )
Poly.Stable.V1.t
[@@deriving compare, equal, sexp, hash, yojson]

let to_latest = Fn.id
end
end]

[%%else]

module Binable_arg = struct
[%%versioned
module Stable = struct
Expand Down Expand Up @@ -98,8 +77,6 @@ module Common = struct
end
end]

[%%endif]

let to_input ({ fee; fee_token; fee_payer_pk; nonce; valid_until; memo } : t)
=
let bitstring = Random_oracle.Input.bitstring in
Expand Down Expand Up @@ -207,25 +184,6 @@ module Body = struct
end]
end

[%%if feature_tokens]

[%%versioned
module Stable = struct
module V1 = struct
type t = Binable_arg.Stable.V1.t =
| Payment of Payment_payload.Stable.V1.t
| Stake_delegation of Stake_delegation.Stable.V1.t
| Create_new_token of New_token_payload.Stable.V1.t
| Create_token_account of New_account_payload.Stable.V1.t
| Mint_tokens of Minting_payload.Stable.V1.t
[@@deriving compare, equal, sexp, hash, yojson]

let to_latest = Fn.id
end
end]

[%%else]

let check (t : Binable_arg.t) =
let fail () =
failwithf !"Tokens disabled. Read %{sexp:Binable_arg.t}" t ()
Expand Down Expand Up @@ -264,8 +222,6 @@ module Body = struct
end
end]

[%%endif]

module Tag = Transaction_union_tag

let gen ?source_pk ~max_amount =
Expand Down
8 changes: 0 additions & 8 deletions src/lib/mina_base/snapp_command.ml
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,6 @@ module Binable_arg = struct
end]
end

[%%if feature_snapps]

include Binable_arg

[%%else]

[%%versioned_binable
module Stable = struct
module V1 = struct
Expand Down Expand Up @@ -447,8 +441,6 @@ module Stable = struct
end
end]

[%%endif]

type transfer =
{ source : Public_key.Compressed.t
; receiver : Public_key.Compressed.t
Expand Down
17 changes: 1 addition & 16 deletions src/lib/mina_base/token_id.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ let next = T.succ

let invalid = T.of_uint64 Unsigned.UInt64.zero

[%%if feature_tokens]

[%%versioned
module Stable = struct
module V1 = struct
type t = T.Stable.V1.t [@@deriving sexp, equal, compare, hash, yojson]

let to_latest = Fn.id
end
end]

[%%else]

let check x =
if T.equal x default || T.equal x (next default) then x
else failwith "Non-default tokens are disabled"
Expand All @@ -65,16 +52,14 @@ module Stable = struct
end
end]

[%%endif]
let gen = Quickcheck.Generator.return default

let gen_ge minimum =
Quickcheck.Generator.map
Int64.(gen_incl (min_value + minimum) max_value)
~f:(fun x ->
Int64.(x - min_value) |> Unsigned.UInt64.of_int64 |> T.of_uint64 )

let gen = gen_ge 1L

let gen_non_default = gen_ge 2L

let gen_with_invalid = gen_ge 0L
Expand Down
32 changes: 0 additions & 32 deletions src/lib/staged_ledger/staged_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -971,36 +971,6 @@ module T = struct
=
((a :> Transaction.t With_status.t list), b, c, d)

[%%if feature_snapps]

let check_commands ledger ~verifier (cs : User_command.t list) =
match
Or_error.try_with (fun () ->
List.map cs
~f:
(let open Ledger in
User_command.to_verifiable_exn ~ledger ~get ~location_of_account) )
with
| Error e ->
Deferred.return (Error e)
| Ok cs ->
let open Deferred.Or_error.Let_syntax in
let%map xs = Verifier.verify_commands verifier cs in
Result.all
(List.map xs ~f:(function
| `Valid x ->
Ok x
| `Invalid ->
Error
(Verifier.Failure.Verification_failed
(Error.of_string "verification failed on command") )
| `Valid_assuming _ ->
Error
(Verifier.Failure.Verification_failed
(Error.of_string "batch verification failed") ) ) )

[%%else]

(* imeckler: added this version because the call to the verifier was
causing super catchup to proceed more slowly than it could have otherwise.
Expand All @@ -1026,8 +996,6 @@ module T = struct
(Error.of_string "signature failed to verify") ) ) ) )
|> Deferred.Or_error.return

[%%endif]

let apply ?skip_verification ~constraint_constants t
(witness : Staged_ledger_diff.t) ~logger ~verifier ~current_state_view
~state_and_body_hash ~coinbase_receiver ~supercharge_coinbase =
Expand Down

0 comments on commit 757ec9f

Please sign in to comment.