Revert "Alpha: add a faucet counter to prevent replay."
This reverts commit 512fde82e4
.
This commit is contained in:
parent
2bc63854a8
commit
5d33b2ce22
@ -120,10 +120,8 @@ let originate_contract rpc_config
|
||||
|
||||
let faucet rpc_config block ?force ?branch ~manager_pkh () =
|
||||
get_branch rpc_config block branch >>=? fun (net_id, branch) ->
|
||||
Client_proto_rpcs.Context.faucet_counter rpc_config block >>=? fun pcounter ->
|
||||
let counter = Int32.succ pcounter in
|
||||
Client_proto_rpcs.Helpers.Forge.Anonymous.faucet
|
||||
rpc_config block ~net_id ~branch ~id:manager_pkh counter >>=? fun bytes ->
|
||||
rpc_config block ~net_id ~branch ~id:manager_pkh () >>=? fun bytes ->
|
||||
originate rpc_config ?force ~block bytes
|
||||
|
||||
let delegate_contract rpc_config
|
||||
|
@ -77,9 +77,6 @@ module Context = struct
|
||||
let next_level cctxt block =
|
||||
call_error_service1 cctxt Services.Context.next_level block ()
|
||||
|
||||
let faucet_counter cctxt block =
|
||||
call_error_service1 cctxt Services.Context.faucet_counter block ()
|
||||
|
||||
let voting_period_kind cctxt block =
|
||||
call_error_service1 cctxt Services.Context.voting_period_kind block ()
|
||||
|
||||
@ -262,9 +259,9 @@ module Helpers = struct
|
||||
block ~net_id ~branch ~level ~nonce () =
|
||||
operations cctxt block ~net_id ~branch [Seed_nonce_revelation { level ; nonce }]
|
||||
let faucet cctxt
|
||||
block ~net_id ~branch ~id counter =
|
||||
block ~net_id ~branch ~id () =
|
||||
let nonce = Sodium.Random.Bigbytes.generate 16 in
|
||||
operations cctxt block ~net_id ~branch [Faucet { id ; counter ; nonce }]
|
||||
operations cctxt block ~net_id ~branch [Faucet { id ; nonce }]
|
||||
end
|
||||
let empty_proof_of_work_nonce =
|
||||
MBytes.of_string
|
||||
|
@ -65,10 +65,6 @@ module Context : sig
|
||||
(** [next_level cctxt blk] returns the (protocol view of the) level
|
||||
of the successor of [blk]. *)
|
||||
|
||||
val faucet_counter:
|
||||
Client_rpcs.config ->
|
||||
block -> int32 tzresult Lwt.t
|
||||
|
||||
val voting_period_kind:
|
||||
Client_rpcs.config ->
|
||||
block -> Voting_period.kind tzresult Lwt.t
|
||||
@ -335,7 +331,7 @@ module Helpers : sig
|
||||
net_id:Net_id.t ->
|
||||
branch:Block_hash.t ->
|
||||
id:public_key_hash ->
|
||||
int32 -> MBytes.t tzresult Lwt.t
|
||||
unit -> MBytes.t tzresult Lwt.t
|
||||
end
|
||||
val block_proto_header:
|
||||
Client_rpcs.config ->
|
||||
|
@ -198,9 +198,7 @@ let apply_anonymous_operation ctxt miner_contract origination_nonce kind =
|
||||
ctxt contract Constants.seed_nonce_revelation_tip >>=? fun ctxt ->
|
||||
return (ctxt, origination_nonce)
|
||||
end
|
||||
| Faucet { id = manager ; counter } ->
|
||||
Contract.check_faucet_counter_increment ctxt counter >>=? fun () ->
|
||||
Contract.increment_faucet_counter ctxt >>=? fun ctxt ->
|
||||
| Faucet { id = manager } ->
|
||||
(* Free tez for all! *)
|
||||
begin
|
||||
match miner_contract with
|
||||
|
@ -13,8 +13,6 @@ type error +=
|
||||
| Cannot_pay_storage_fee of Contract_repr.contract * Tez_repr.t * Tez_repr.t (* `Temporary *)
|
||||
| Counter_in_the_past of Contract_repr.contract * int32 * int32 (* `Branch *)
|
||||
| Counter_in_the_future of Contract_repr.contract * int32 * int32 (* `Temporary *)
|
||||
| Faucet_counter_in_the_past of int32 * int32 (* `Branch *)
|
||||
| Faucet_counter_in_the_future of int32 * int32 (* `Temporary *)
|
||||
| Unspendable_contract of Contract_repr.contract (* `Permanent *)
|
||||
| Non_existing_contract of Contract_repr.contract (* `Temporary *)
|
||||
| Non_delegatable_contract of Contract_repr.contract (* `Permanent *)
|
||||
@ -107,36 +105,6 @@ let () =
|
||||
(req "found" int32))
|
||||
(function Counter_in_the_past (c, x, y) -> Some (c, x, y) | _ -> None)
|
||||
(fun (c, x, y) -> Counter_in_the_past (c, x, y)) ;
|
||||
register_error_kind
|
||||
`Temporary
|
||||
~id:"contract.faucet_counter_in_the_future"
|
||||
~title:"Invalid faucet counter (not yet reached) in a manager operation"
|
||||
~description:"An operation assumed a faucet counter in the future"
|
||||
~pp:(fun ppf (exp, found) ->
|
||||
Format.fprintf ppf
|
||||
"Faucet counter %ld not yet reached (expected %ld)"
|
||||
found exp)
|
||||
Data_encoding.
|
||||
(obj2
|
||||
(req "expected" int32)
|
||||
(req "found" int32))
|
||||
(function Faucet_counter_in_the_future (x, y) -> Some (x, y) | _ -> None)
|
||||
(fun (x, y) -> Faucet_counter_in_the_future (x, y)) ;
|
||||
register_error_kind
|
||||
`Branch
|
||||
~id:"contract.faucet_counter_in_the_past"
|
||||
~title:"Invalid faucet counter (already used) in a manager operation"
|
||||
~description:"An operation assumed a faucet counter in the past"
|
||||
~pp:(fun ppf (exp, found) ->
|
||||
Format.fprintf ppf
|
||||
"Faucet counter %ld already used (expected %ld)"
|
||||
found exp)
|
||||
Data_encoding.
|
||||
(obj2
|
||||
(req "expected" int32)
|
||||
(req "found" int32))
|
||||
(function Faucet_counter_in_the_past (x, y) -> Some (x, y) | _ -> None)
|
||||
(fun (x, y) -> Faucet_counter_in_the_past (x, y)) ;
|
||||
register_error_kind
|
||||
`Temporary
|
||||
~id:"contract.non_existing_contract"
|
||||
@ -260,23 +228,6 @@ let increment_counter c contract =
|
||||
Storage.Contract.Counter.get c contract >>=? fun contract_counter ->
|
||||
Storage.Contract.Counter.set c contract (Int32.succ contract_counter)
|
||||
|
||||
let get_faucet_counter c =
|
||||
Storage.Contract.Faucet_counter.get c
|
||||
|
||||
let check_faucet_counter_increment c counter =
|
||||
Storage.Contract.Faucet_counter.get c >>=? fun faucet_counter ->
|
||||
let expected = Int32.succ faucet_counter in
|
||||
if Compare.Int32.(expected = counter)
|
||||
then return ()
|
||||
else if Compare.Int32.(expected > counter) then
|
||||
fail (Faucet_counter_in_the_past (expected, counter))
|
||||
else
|
||||
fail (Faucet_counter_in_the_future (expected, counter))
|
||||
|
||||
let increment_faucet_counter c =
|
||||
Storage.Contract.Faucet_counter.get c >>=? fun faucet_counter ->
|
||||
Storage.Contract.Faucet_counter.set c (Int32.succ faucet_counter)
|
||||
|
||||
let get_script c contract =
|
||||
Storage.Contract.Code.get_option c contract >>=? fun code ->
|
||||
Storage.Contract.Storage.get_option c contract >>=? fun storage ->
|
||||
@ -416,5 +367,4 @@ let originate c nonce ~balance ~manager ?script ~delegate ~spendable ~delegatabl
|
||||
return (c, contract, nonce)
|
||||
|
||||
let init c =
|
||||
Storage.Contract.Faucet_counter.init c 0l >>=? fun c ->
|
||||
Storage.Contract.Global_counter.init c 0l
|
||||
|
@ -28,10 +28,6 @@ val list: Storage.t -> Contract_repr.t list tzresult Lwt.t
|
||||
val check_counter_increment: Storage.t -> Contract_repr.t -> int32 -> unit tzresult Lwt.t
|
||||
val increment_counter: Storage.t -> Contract_repr.t -> Storage.t tzresult Lwt.t
|
||||
|
||||
val get_faucet_counter: Storage.t -> int32 tzresult Lwt.t
|
||||
val check_faucet_counter_increment: Storage.t -> int32 -> unit tzresult Lwt.t
|
||||
val increment_faucet_counter: Storage.t -> Storage.t tzresult Lwt.t
|
||||
|
||||
val is_delegatable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t
|
||||
val is_spendable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t
|
||||
|
||||
|
@ -34,7 +34,6 @@ and anonymous_operation =
|
||||
}
|
||||
| Faucet of {
|
||||
id: Ed25519.Public_key_hash.t ;
|
||||
counter: counter ;
|
||||
nonce: MBytes.t ;
|
||||
}
|
||||
|
||||
@ -284,19 +283,18 @@ module Encoding = struct
|
||||
(fun ((), level, nonce) -> Seed_nonce_revelation { level ; nonce })
|
||||
|
||||
let faucet_encoding =
|
||||
(obj4
|
||||
(obj3
|
||||
(req "kind" (constant "faucet"))
|
||||
(req "id" Ed25519.Public_key_hash.encoding)
|
||||
(req "counter" int32)
|
||||
(req "nonce" (Fixed.bytes 16)))
|
||||
|
||||
let faucet_case tag =
|
||||
case ~tag faucet_encoding
|
||||
(function
|
||||
| Faucet { id ; counter ; nonce } -> Some ((), id, counter, nonce)
|
||||
| Faucet { id ; nonce } -> Some ((), id, nonce)
|
||||
| _ -> None
|
||||
)
|
||||
(fun ((), id, counter, nonce) -> Faucet { id ; counter ; nonce })
|
||||
(fun ((), id, nonce) -> Faucet { id ; nonce })
|
||||
|
||||
let unsigned_operation_case tag =
|
||||
case ~tag
|
||||
|
@ -34,7 +34,6 @@ and anonymous_operation =
|
||||
}
|
||||
| Faucet of {
|
||||
id: Ed25519.Public_key_hash.t ;
|
||||
counter: counter ;
|
||||
nonce: MBytes.t ;
|
||||
}
|
||||
|
||||
|
@ -161,13 +161,6 @@ module Context = struct
|
||||
describe ~title: "detailled level info" Level.encoding)
|
||||
RPC.Path.(custom_root / "context" / "next_level")
|
||||
|
||||
let faucet_counter custom_root =
|
||||
RPC.service
|
||||
~description: "Access the global faucet counter."
|
||||
~input: empty
|
||||
~output: (wrap_tzerror int32)
|
||||
RPC.Path.(custom_root / "context" / "faucet_counter")
|
||||
|
||||
let voting_period_kind custom_root =
|
||||
RPC.service
|
||||
~description: "Voting period kind for the current block"
|
||||
|
@ -158,8 +158,6 @@ let next_level ctxt =
|
||||
|
||||
let () = register0 Services.Context.next_level next_level
|
||||
|
||||
let () = register0 Services.Context.faucet_counter Contract.get_faucet_counter
|
||||
|
||||
let () =
|
||||
register0 Services.Context.voting_period_kind Vote.get_current_period_kind
|
||||
|
||||
|
@ -108,8 +108,6 @@ module Key = struct
|
||||
|
||||
let global_counter = store_root ["global_counter"]
|
||||
|
||||
let faucet_counter = store_root ["faucet_counter"]
|
||||
|
||||
let next_cycle_to_be_rewarded = store_root ["next_cycle_to_be_rewarded"]
|
||||
let rewards = store_root ["rewards"]
|
||||
|
||||
@ -267,14 +265,6 @@ module Contract = struct
|
||||
let encoding = Data_encoding.int32
|
||||
end)
|
||||
|
||||
module Faucet_counter =
|
||||
Make_single_data_storage(struct
|
||||
type value = int32
|
||||
let name = "faucet counter"
|
||||
let key = Key.faucet_counter
|
||||
let encoding = Data_encoding.int32
|
||||
end)
|
||||
|
||||
(** FIXME REMOVE : use 'list' *)
|
||||
module Set =
|
||||
Make_data_set_storage(struct
|
||||
|
@ -122,12 +122,6 @@ module Contract : sig
|
||||
val init : t -> int32 -> t tzresult Lwt.t
|
||||
end
|
||||
|
||||
module Faucet_counter : sig
|
||||
val get : t -> int32 tzresult Lwt.t
|
||||
val set : t -> int32 -> t tzresult Lwt.t
|
||||
val init : t -> int32 -> t tzresult Lwt.t
|
||||
end
|
||||
|
||||
(** The domain of alive contracts *)
|
||||
module Set : Data_set_storage
|
||||
with type value = Contract_repr.t
|
||||
|
@ -369,12 +369,6 @@ module Contract : sig
|
||||
val check_counter_increment:
|
||||
context -> contract -> int32 -> unit tzresult Lwt.t
|
||||
|
||||
val get_faucet_counter: context -> int32 tzresult Lwt.t
|
||||
|
||||
val check_faucet_counter_increment: context -> int32 -> unit tzresult Lwt.t
|
||||
|
||||
val increment_faucet_counter: context -> context tzresult Lwt.t
|
||||
|
||||
end
|
||||
|
||||
module Vote : sig
|
||||
@ -441,7 +435,6 @@ and anonymous_operation =
|
||||
}
|
||||
| Faucet of {
|
||||
id: Ed25519.Public_key_hash.t ;
|
||||
counter: counter ;
|
||||
nonce: MBytes.t ;
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,11 @@ depends: [
|
||||
"calendar"
|
||||
"cohttp" {>= "0.21" }
|
||||
"conduit"
|
||||
"ezjsonm" {= "0.4.3" }
|
||||
"git"
|
||||
"git-unix"
|
||||
"ipv6-multicast"
|
||||
"irmin-watcher" (* for `irmin.unix` *)
|
||||
"ezjsonm" {= "0.4.3" }
|
||||
"irmin" {>= "0.12" & < "1.0" }
|
||||
"lwt" {>= "3.0.0" }
|
||||
"lwt_ssl"
|
||||
|
Loading…
Reference in New Issue
Block a user