Alpha: simplify mining/endorsement slots RPCs.
This commit is contained in:
parent
b48187d43b
commit
215bd0e2d2
@ -111,8 +111,8 @@ let get_signing_slots cctxt ?max_priority block delegate level =
|
|||||||
?max_priority ~first_level:level ~last_level:level
|
?max_priority ~first_level:level ~last_level:level
|
||||||
block delegate () >>=? fun possibilities ->
|
block delegate () >>=? fun possibilities ->
|
||||||
let slots =
|
let slots =
|
||||||
List.map (fun (_,slot,_) -> slot)
|
List.map (fun (_,slot) -> slot)
|
||||||
@@ List.filter (fun (l, _, _) -> l = level) possibilities in
|
@@ List.filter (fun (l, _) -> l = level) possibilities in
|
||||||
return slots
|
return slots
|
||||||
|
|
||||||
let inject_endorsement cctxt
|
let inject_endorsement cctxt
|
||||||
|
@ -95,7 +95,7 @@ let forge_block cctxt block
|
|||||||
| `Set prio -> begin
|
| `Set prio -> begin
|
||||||
Client_proto_rpcs.Helpers.minimal_time
|
Client_proto_rpcs.Helpers.minimal_time
|
||||||
cctxt block ~prio () >>=? fun time ->
|
cctxt block ~prio () >>=? fun time ->
|
||||||
return (prio, Some time)
|
return (prio, time)
|
||||||
end
|
end
|
||||||
| `Auto (src_pkh, max_priority) ->
|
| `Auto (src_pkh, max_priority) ->
|
||||||
Client_proto_rpcs.Helpers.Rights.mining_rights_for_delegate cctxt
|
Client_proto_rpcs.Helpers.Rights.mining_rights_for_delegate cctxt
|
||||||
@ -114,20 +114,19 @@ let forge_block cctxt block
|
|||||||
Raw_level.pp level priority >>= fun () ->
|
Raw_level.pp level priority >>= fun () ->
|
||||||
begin
|
begin
|
||||||
match timestamp, minimal_timestamp with
|
match timestamp, minimal_timestamp with
|
||||||
| None, None -> failwith "Can't compute the expected timestamp"
|
| None, timestamp -> return timestamp
|
||||||
| None, timestamp | timestamp, None -> return timestamp
|
| Some timestamp, minimal_timestamp ->
|
||||||
| Some timestamp, Some minimal_timestamp ->
|
|
||||||
if timestamp < minimal_timestamp then
|
if timestamp < minimal_timestamp then
|
||||||
Error_monad.failwith
|
Error_monad.failwith
|
||||||
"Proposed timestamp %a is earlier than minimal timestamp %a"
|
"Proposed timestamp %a is earlier than minimal timestamp %a"
|
||||||
Time.pp_hum timestamp
|
Time.pp_hum timestamp
|
||||||
Time.pp_hum minimal_timestamp
|
Time.pp_hum minimal_timestamp
|
||||||
else
|
else
|
||||||
return (Some timestamp)
|
return timestamp
|
||||||
end >>=? fun timestamp ->
|
end >>=? fun timestamp ->
|
||||||
let request = List.length operations in
|
let request = List.length operations in
|
||||||
Client_node_rpcs.Blocks.preapply
|
Client_node_rpcs.Blocks.preapply
|
||||||
cctxt block ?timestamp ~sort operations >>=?
|
cctxt block ~timestamp ~sort operations >>=?
|
||||||
fun { operations ; fitness ; timestamp } ->
|
fun { operations ; fitness ; timestamp } ->
|
||||||
let valid = List.length operations.applied in
|
let valid = List.length operations.applied in
|
||||||
lwt_log_info "Found %d valid operations (%d refused) for timestamp %a"
|
lwt_log_info "Found %d valid operations (%d refused) for timestamp %a"
|
||||||
@ -245,11 +244,9 @@ let get_mining_slot cctxt
|
|||||||
pp_print_error errs ;
|
pp_print_error errs ;
|
||||||
Lwt.return_none
|
Lwt.return_none
|
||||||
| Ok slots ->
|
| Ok slots ->
|
||||||
let convert = function
|
let convert = fun (_lvl, slot, timestamp) ->
|
||||||
| (_,_,None) -> None
|
(timestamp, (bi, slot, delegate)) in
|
||||||
| (_lvl, slot, Some timestamp) ->
|
Lwt.return (Some (List.map convert slots)))
|
||||||
Some (timestamp, (bi, slot, delegate)) in
|
|
||||||
Lwt.return (Some (Utils.filter_map convert slots)))
|
|
||||||
delegates >>= fun slots ->
|
delegates >>= fun slots ->
|
||||||
let sorted_slots =
|
let sorted_slots =
|
||||||
List.sort
|
List.sort
|
||||||
|
@ -167,7 +167,8 @@ module Helpers = struct
|
|||||||
call_error_service2 cctxt Services.Helpers.levels block cycle ()
|
call_error_service2 cctxt Services.Helpers.levels block cycle ()
|
||||||
|
|
||||||
module Rights = struct
|
module Rights = struct
|
||||||
type slot = Raw_level.t * int * Time.t option
|
type mining_slot = Raw_level.t * int * Time.t
|
||||||
|
type endorsement_slot = Raw_level.t * int
|
||||||
let mining_rights_for_delegate cctxt
|
let mining_rights_for_delegate cctxt
|
||||||
b c ?max_priority ?first_level ?last_level () =
|
b c ?max_priority ?first_level ?last_level () =
|
||||||
call_error_service2 cctxt Services.Helpers.Rights.mining_rights_for_delegate
|
call_error_service2 cctxt Services.Helpers.Rights.mining_rights_for_delegate
|
||||||
|
@ -172,18 +172,19 @@ module Helpers : sig
|
|||||||
block -> Cycle.t -> (Raw_level.t * Raw_level.t) tzresult Lwt.t
|
block -> Cycle.t -> (Raw_level.t * Raw_level.t) tzresult Lwt.t
|
||||||
|
|
||||||
module Rights : sig
|
module Rights : sig
|
||||||
type slot = Raw_level.t * int * Time.t option
|
type mining_slot = Raw_level.t * int * Time.t
|
||||||
|
type endorsement_slot = Raw_level.t * int
|
||||||
val mining_rights_for_delegate:
|
val mining_rights_for_delegate:
|
||||||
Client_commands.context ->
|
Client_commands.context ->
|
||||||
block -> public_key_hash ->
|
block -> public_key_hash ->
|
||||||
?max_priority:int -> ?first_level:Raw_level.t ->
|
?max_priority:int -> ?first_level:Raw_level.t ->
|
||||||
?last_level:Raw_level.t -> unit ->
|
?last_level:Raw_level.t -> unit ->
|
||||||
(slot list) tzresult Lwt.t
|
(mining_slot list) tzresult Lwt.t
|
||||||
val endorsement_rights_for_delegate:
|
val endorsement_rights_for_delegate:
|
||||||
Client_commands.context ->
|
Client_commands.context ->
|
||||||
block -> public_key_hash ->
|
block -> public_key_hash ->
|
||||||
?max_priority:int -> ?first_level:Raw_level.t -> ?last_level:Raw_level.t -> unit ->
|
?max_priority:int -> ?first_level:Raw_level.t -> ?last_level:Raw_level.t -> unit ->
|
||||||
(slot list) tzresult Lwt.t
|
(endorsement_slot list) tzresult Lwt.t
|
||||||
end
|
end
|
||||||
|
|
||||||
module Forge : sig
|
module Forge : sig
|
||||||
|
@ -422,11 +422,16 @@ module Helpers = struct
|
|||||||
(opt "first_level" Raw_level.encoding)
|
(opt "first_level" Raw_level.encoding)
|
||||||
(opt "last_level" Raw_level.encoding))
|
(opt "last_level" Raw_level.encoding))
|
||||||
|
|
||||||
let slot_encoding =
|
let endorsement_slot_encoding =
|
||||||
|
(obj2
|
||||||
|
(req "level" Raw_level.encoding)
|
||||||
|
(req "priority" int31))
|
||||||
|
|
||||||
|
let mining_slot_encoding =
|
||||||
(obj3
|
(obj3
|
||||||
(req "level" Raw_level.encoding)
|
(req "level" Raw_level.encoding)
|
||||||
(req "priority" int31)
|
(req "priority" int31)
|
||||||
(opt "timestamp" Timestamp.encoding))
|
(req "timestamp" Timestamp.encoding))
|
||||||
|
|
||||||
let mining_rights custom_root =
|
let mining_rights custom_root =
|
||||||
RPC.service
|
RPC.service
|
||||||
@ -472,7 +477,7 @@ module Helpers = struct
|
|||||||
RPC.service
|
RPC.service
|
||||||
~description: "Future mining rights for a given delegate."
|
~description: "Future mining rights for a given delegate."
|
||||||
~input: slots_range_encoding
|
~input: slots_range_encoding
|
||||||
~output: (wrap_tzerror (Data_encoding.list slot_encoding))
|
~output: (wrap_tzerror (Data_encoding.list mining_slot_encoding))
|
||||||
RPC.Path.(custom_root / "helpers" / "rights"
|
RPC.Path.(custom_root / "helpers" / "rights"
|
||||||
/ "mining" / "delegate" /: Context.Key.public_key_hash_arg )
|
/ "mining" / "delegate" /: Context.Key.public_key_hash_arg )
|
||||||
|
|
||||||
@ -526,7 +531,7 @@ module Helpers = struct
|
|||||||
RPC.service
|
RPC.service
|
||||||
~description: "Compute endorsement rights for a given delegate."
|
~description: "Compute endorsement rights for a given delegate."
|
||||||
~input: slots_range_encoding
|
~input: slots_range_encoding
|
||||||
~output: (wrap_tzerror @@ Data_encoding.list slot_encoding)
|
~output: (wrap_tzerror @@ Data_encoding.list endorsement_slot_encoding)
|
||||||
RPC.Path.(custom_root / "helpers" / "rights"
|
RPC.Path.(custom_root / "helpers" / "rights"
|
||||||
/ "endorsement" / "delegate" /: Context.Key.public_key_hash_arg )
|
/ "endorsement" / "delegate" /: Context.Key.public_key_hash_arg )
|
||||||
|
|
||||||
|
@ -339,13 +339,12 @@ let mining_rights_for_delegate
|
|||||||
Mining.first_mining_priorities
|
Mining.first_mining_priorities
|
||||||
ctxt ~max_priority contract level >>=? fun priorities ->
|
ctxt ~max_priority contract level >>=? fun priorities ->
|
||||||
let raw_level = level.level in
|
let raw_level = level.level in
|
||||||
Lwt_list.map_p
|
Error_monad.map_s
|
||||||
(fun priority ->
|
(fun priority ->
|
||||||
Tezos_context.Timestamp.get_current ctxt >>= fun timestamp ->
|
Tezos_context.Timestamp.get_current ctxt >>= fun timestamp ->
|
||||||
Mining.minimal_time ctxt priority timestamp >>= function
|
Mining.minimal_time ctxt priority timestamp >>=? fun time ->
|
||||||
| Ok time -> Lwt.return (raw_level, Int32.to_int priority, Some time)
|
return (raw_level, Int32.to_int priority, time))
|
||||||
| Error _ -> Lwt.return (raw_level, Int32.to_int priority, None))
|
priorities >>=? fun priorities ->
|
||||||
priorities >>= fun priorities ->
|
|
||||||
return (priorities @ t)
|
return (priorities @ t)
|
||||||
in
|
in
|
||||||
loop min_level
|
loop min_level
|
||||||
@ -410,7 +409,7 @@ let endorsement_rights_for_delegate
|
|||||||
let raw_level = level.level in
|
let raw_level = level.level in
|
||||||
let slots =
|
let slots =
|
||||||
List.rev_map
|
List.rev_map
|
||||||
(fun slot -> (raw_level, Int32.to_int slot, None))
|
(fun slot -> (raw_level, Int32.to_int slot))
|
||||||
slots in
|
slots in
|
||||||
return (List.rev_append slots t)
|
return (List.rev_append slots t)
|
||||||
in
|
in
|
||||||
|
Loading…
Reference in New Issue
Block a user