Alpha/Client: use block metadata
This commit is contained in:
parent
d6f79edae2
commit
acc76d22a8
@ -9,7 +9,7 @@ client using this command ``tezos-admin-client rpc (get|post) <url>``.
|
|||||||
|
|
||||||
For instance, if you wish to request the current balance of a given
|
For instance, if you wish to request the current balance of a given
|
||||||
block and contract, you can call the associated RPC via the command :
|
block and contract, you can call the associated RPC via the command :
|
||||||
``$ tezos-admin-client rpc post
|
``$ tezos-admin-client rpc get
|
||||||
/blocks/<block_id>/proto/context/contracts/<contract_id>/balance``.
|
/blocks/<block_id>/proto/context/contracts/<contract_id>/balance``.
|
||||||
|
|
||||||
A RPC may takes an *input* and generates an *output* both in JSON
|
A RPC may takes an *input* and generates an *output* both in JSON
|
||||||
|
@ -382,7 +382,7 @@ run_shell() {
|
|||||||
display_head() {
|
display_head() {
|
||||||
assert_node_uptodate
|
assert_node_uptodate
|
||||||
exec_docker tezos-client rpc get /chains/main/blocks/head
|
exec_docker tezos-client rpc get /chains/main/blocks/head
|
||||||
exec_docker tezos-client rpc post /chains/main/blocks/head/context/level with {}
|
exec_docker tezos-client rpc get /chains/main/blocks/head/metadata/protocol_data/level
|
||||||
}
|
}
|
||||||
|
|
||||||
## Main ####################################################################
|
## Main ####################################################################
|
||||||
|
@ -40,8 +40,8 @@ assert_propagation_level() {
|
|||||||
level=$1
|
level=$1
|
||||||
printf "\n\nAsserting all nodes have reached level %s\n" "$level"
|
printf "\n\nAsserting all nodes have reached level %s\n" "$level"
|
||||||
for client in "${client_instances[@]}"; do
|
for client in "${client_instances[@]}"; do
|
||||||
( $client rpc post /chains/main/blocks/head/context/level with {} \
|
( $client rpc get /chains/main/blocks/head/header/shell/level \
|
||||||
| assert_in_output "\"level\": $level" ) \
|
| assert_in_output "$level" ) \
|
||||||
|| exit 2
|
|| exit 2
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ let info cctxt ?(chain = `Main) block =
|
|||||||
cctxt ~chain ~block () >>=? fun next_protocol ->
|
cctxt ~chain ~block () >>=? fun next_protocol ->
|
||||||
Block_services.Metadata.protocol_hash
|
Block_services.Metadata.protocol_hash
|
||||||
cctxt ~chain ~block () >>=? fun protocol ->
|
cctxt ~chain ~block () >>=? fun protocol ->
|
||||||
Alpha_services.Context.level cctxt (chain, block) >>=? fun level ->
|
Block_services.Metadata.protocol_data cctxt ~chain ~block () >>=? fun { level } ->
|
||||||
let { Tezos_base.Block_header.predecessor ; fitness ; timestamp ; _ } = header in
|
let { Tezos_base.Block_header.predecessor ; fitness ; timestamp ; _ } = header in
|
||||||
return { hash ; chain_id ; predecessor ; fitness ;
|
return { hash ; chain_id ; predecessor ; fitness ;
|
||||||
timestamp ; protocol ; next_protocol ; level }
|
timestamp ; protocol ; next_protocol ; level }
|
||||||
@ -50,7 +50,7 @@ let monitor_heads cctxt ?next_protocols chain =
|
|||||||
|
|
||||||
let blocks_from_cycle cctxt ?(chain = `Main) block cycle =
|
let blocks_from_cycle cctxt ?(chain = `Main) block cycle =
|
||||||
Block_services.hash cctxt ~chain ~block () >>=? fun hash ->
|
Block_services.hash cctxt ~chain ~block () >>=? fun hash ->
|
||||||
Alpha_services.Context.level cctxt (chain, block) >>=? fun level ->
|
Block_services.Metadata.protocol_data cctxt ~chain ~block () >>=? fun { level } ->
|
||||||
Alpha_services.Helpers.levels cctxt (chain, block) cycle >>=? fun (first, last) ->
|
Alpha_services.Helpers.levels cctxt (chain, block) cycle >>=? fun (first, last) ->
|
||||||
let length = Int32.to_int (Raw_level.diff level.level first) in
|
let length = Int32.to_int (Raw_level.diff level.level first) in
|
||||||
Chain_services.Blocks.list cctxt ~heads:[hash] ~length () >>=? fun blocks ->
|
Chain_services.Blocks.list cctxt ~heads:[hash] ~length () >>=? fun blocks ->
|
||||||
|
@ -132,7 +132,8 @@ let forge_endorsement (cctxt : #Proto_alpha.full)
|
|||||||
?(chain = `Main) block
|
?(chain = `Main) block
|
||||||
~src_sk ?slots ?max_priority src_pk =
|
~src_sk ?slots ?max_priority src_pk =
|
||||||
let src_pkh = Signature.Public_key.hash src_pk in
|
let src_pkh = Signature.Public_key.hash src_pk in
|
||||||
Alpha_services.Context.level cctxt (chain, block) >>=? fun { level } ->
|
Block_services.Metadata.protocol_data
|
||||||
|
cctxt ~chain ~block () >>=? fun { level = { level } } ->
|
||||||
begin
|
begin
|
||||||
match slots with
|
match slots with
|
||||||
| Some slots -> return slots
|
| Some slots -> return slots
|
||||||
|
@ -156,7 +156,7 @@ let forge_block cctxt ?(chain = `Main) block
|
|||||||
return (priority, time)
|
return (priority, time)
|
||||||
end
|
end
|
||||||
| `Auto (src_pkh, max_priority, free_baking) ->
|
| `Auto (src_pkh, max_priority, free_baking) ->
|
||||||
Alpha_services.Context.next_level cctxt (chain, block) >>=? fun { level } ->
|
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun { level } ->
|
||||||
Alpha_services.Delegate.Baker.rights_for_delegate cctxt
|
Alpha_services.Delegate.Baker.rights_for_delegate cctxt
|
||||||
?max_priority
|
?max_priority
|
||||||
~first_level:level
|
~first_level:level
|
||||||
@ -393,7 +393,7 @@ let compute_timeout { future_slots } =
|
|||||||
|
|
||||||
let get_unrevealed_nonces
|
let get_unrevealed_nonces
|
||||||
(cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block =
|
(cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block =
|
||||||
Alpha_services.Context.next_level cctxt (chain, block) >>=? fun level ->
|
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun level ->
|
||||||
let cur_cycle = level.cycle in
|
let cur_cycle = level.cycle in
|
||||||
match Cycle.pred cur_cycle with
|
match Cycle.pred cur_cycle with
|
||||||
| None -> return []
|
| None -> return []
|
||||||
@ -404,8 +404,8 @@ let get_unrevealed_nonces
|
|||||||
Client_baking_nonces.find cctxt hash >>=? function
|
Client_baking_nonces.find cctxt hash >>=? function
|
||||||
| None -> return None
|
| None -> return None
|
||||||
| Some nonce ->
|
| Some nonce ->
|
||||||
Alpha_services.Context.level
|
Block_services.Metadata.protocol_data
|
||||||
cctxt (chain, `Hash (hash, 0)) >>=? fun level ->
|
cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { level } ->
|
||||||
if force then
|
if force then
|
||||||
return (Some (hash, (level.level, nonce)))
|
return (Some (hash, (level.level, nonce)))
|
||||||
else
|
else
|
||||||
@ -492,7 +492,7 @@ let bake (cctxt : #Proto_alpha.full) state =
|
|||||||
(fun (timestamp, (bi, priority, delegate)) ->
|
(fun (timestamp, (bi, priority, delegate)) ->
|
||||||
let chain = `Hash bi.Client_baking_blocks.chain_id in
|
let chain = `Hash bi.Client_baking_blocks.chain_id in
|
||||||
let block = `Hash (bi.hash, 0) in
|
let block = `Hash (bi.hash, 0) in
|
||||||
Alpha_services.Context.next_level cctxt (chain, block) >>=? fun next_level ->
|
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun next_level ->
|
||||||
let timestamp =
|
let timestamp =
|
||||||
if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then
|
if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then
|
||||||
Time.now ()
|
Time.now ()
|
||||||
|
@ -21,7 +21,7 @@ let bake_block (cctxt : #Proto_alpha.full)
|
|||||||
return src_sk
|
return src_sk
|
||||||
| Some sk -> return sk
|
| Some sk -> return sk
|
||||||
end >>=? fun src_sk ->
|
end >>=? fun src_sk ->
|
||||||
Alpha_services.Context.next_level cctxt (chain, block) >>=? fun level ->
|
Alpha_services.Helpers.next_level cctxt (chain, block) >>=? fun level ->
|
||||||
let seed_nonce, seed_nonce_hash =
|
let seed_nonce, seed_nonce_hash =
|
||||||
if level.expected_commitment then
|
if level.expected_commitment then
|
||||||
let seed_nonce = Client_baking_forge.generate_seed_nonce () in
|
let seed_nonce = Client_baking_forge.generate_seed_nonce () in
|
||||||
|
@ -146,8 +146,9 @@ let init ?exe ?vote ?rpc_port () =
|
|||||||
activate_alpha ?vote () >>=? fun hash ->
|
activate_alpha ?vote () >>=? fun hash ->
|
||||||
return (pid, hash)
|
return (pid, hash)
|
||||||
|
|
||||||
let level block =
|
let level (chain, block) =
|
||||||
Alpha_services.Context.level !rpc_ctxt block
|
Block_services.Metadata.protocol_data !rpc_ctxt ~chain ~block () >>=? fun { level } ->
|
||||||
|
return level
|
||||||
|
|
||||||
let rpc_raw_context block path depth =
|
let rpc_raw_context block path depth =
|
||||||
Block_services.Context.Raw.read !rpc_ctxt ~block ~depth path
|
Block_services.Context.Raw.read !rpc_ctxt ~block ~depth path
|
||||||
@ -335,11 +336,13 @@ module Protocol = struct
|
|||||||
open Account
|
open Account
|
||||||
|
|
||||||
let voting_period_kind ?(block = `Head 0) () =
|
let voting_period_kind ?(block = `Head 0) () =
|
||||||
Alpha_services.Context.voting_period_kind !rpc_ctxt (`Main, block)
|
Block_services.Metadata.protocol_data
|
||||||
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { voting_period_kind } ->
|
||||||
|
return voting_period_kind
|
||||||
|
|
||||||
let proposals ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) proposals =
|
let proposals ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) proposals =
|
||||||
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
|
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
|
||||||
Alpha_services.Context.next_level
|
Alpha_services.Helpers.next_level
|
||||||
!rpc_ctxt (`Main, block) >>=? fun next_level ->
|
!rpc_ctxt (`Main, block) >>=? fun next_level ->
|
||||||
let shell = { Tezos_base.Operation.branch = hash } in
|
let shell = { Tezos_base.Operation.branch = hash } in
|
||||||
let contents =
|
let contents =
|
||||||
@ -351,7 +354,7 @@ module Protocol = struct
|
|||||||
|
|
||||||
let ballot ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) ~proposal ballot =
|
let ballot ?(block = `Head 0) ~src:({ pkh; sk } : Account.t) ~proposal ballot =
|
||||||
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
|
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
|
||||||
Alpha_services.Context.next_level
|
Alpha_services.Helpers.next_level
|
||||||
!rpc_ctxt (`Main, block) >>=? fun next_level ->
|
!rpc_ctxt (`Main, block) >>=? fun next_level ->
|
||||||
let shell = { Tezos_base.Operation.branch = hash } in
|
let shell = { Tezos_base.Operation.branch = hash } in
|
||||||
let contents =
|
let contents =
|
||||||
@ -495,11 +498,12 @@ module Assert = struct
|
|||||||
block_proto h
|
block_proto h
|
||||||
|
|
||||||
let check_voting_period_kind ?msg ~block kind =
|
let check_voting_period_kind ?msg ~block kind =
|
||||||
Alpha_services.Context.voting_period_kind !rpc_ctxt (`Main, block)
|
Block_services.Metadata.protocol_data
|
||||||
>>=? fun current_kind ->
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { voting_period_kind } ->
|
||||||
return @@ equal
|
return @@ equal
|
||||||
?msg
|
?msg
|
||||||
current_kind kind
|
voting_period_kind
|
||||||
|
kind
|
||||||
|
|
||||||
let is_none ?(msg="") x =
|
let is_none ?(msg="") x =
|
||||||
if x <> None then fail "None" "Some _" msg
|
if x <> None then fail "None" "Some _" msg
|
||||||
@ -512,7 +516,7 @@ module Baking = struct
|
|||||||
|
|
||||||
let bake block (contract: Account.t) operations =
|
let bake block (contract: Account.t) operations =
|
||||||
let ctxt = (new wrap_full (no_write_context ~block !rpc_config)) in
|
let ctxt = (new wrap_full (no_write_context ~block !rpc_config)) in
|
||||||
Alpha_services.Context.next_level ctxt (`Main, block) >>=? fun level ->
|
Alpha_services.Helpers.next_level ctxt (`Main, block) >>=? fun level ->
|
||||||
let seed_nonce_hash =
|
let seed_nonce_hash =
|
||||||
if level.Level.expected_commitment then
|
if level.Level.expected_commitment then
|
||||||
let seed_nonce =
|
let seed_nonce =
|
||||||
@ -546,7 +550,9 @@ module Endorse = struct
|
|||||||
src_sk
|
src_sk
|
||||||
slot =
|
slot =
|
||||||
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
|
Block_services.hash !rpc_ctxt ~block () >>=? fun hash ->
|
||||||
Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun { level } ->
|
Block_services.Metadata.protocol_data
|
||||||
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { level } ->
|
||||||
|
let level = level.level in
|
||||||
let shell = { Tezos_base.Operation.branch = hash } in
|
let shell = { Tezos_base.Operation.branch = hash } in
|
||||||
let contents =
|
let contents =
|
||||||
Consensus_operation
|
Consensus_operation
|
||||||
@ -570,7 +576,9 @@ module Endorse = struct
|
|||||||
?slot
|
?slot
|
||||||
(contract : Account.t)
|
(contract : Account.t)
|
||||||
block =
|
block =
|
||||||
Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun { level } ->
|
Block_services.Metadata.protocol_data
|
||||||
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { level } ->
|
||||||
|
let level = level.level in
|
||||||
begin
|
begin
|
||||||
match slot with
|
match slot with
|
||||||
| Some slot -> return slot
|
| Some slot -> return slot
|
||||||
@ -597,7 +605,8 @@ module Endorse = struct
|
|||||||
in
|
in
|
||||||
let { Account.b1 ; b2 ; b3 ; b4 ; b5 } = Account.bootstrap_accounts in
|
let { Account.b1 ; b2 ; b3 ; b4 ; b5 } = Account.bootstrap_accounts in
|
||||||
let result = Array.make 16 b1 in
|
let result = Array.make 16 b1 in
|
||||||
Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun level ->
|
Block_services.Metadata.protocol_data
|
||||||
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { level } ->
|
||||||
let level = level.level in
|
let level = level.level in
|
||||||
get_endorser_list result b1 level block >>=? fun () ->
|
get_endorser_list result b1 level block >>=? fun () ->
|
||||||
get_endorser_list result b2 level block >>=? fun () ->
|
get_endorser_list result b2 level block >>=? fun () ->
|
||||||
@ -609,9 +618,10 @@ module Endorse = struct
|
|||||||
let endorsement_rights
|
let endorsement_rights
|
||||||
?(max_priority = 1024)
|
?(max_priority = 1024)
|
||||||
(contract : Account.t) block =
|
(contract : Account.t) block =
|
||||||
Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun level ->
|
Block_services.Metadata.protocol_data
|
||||||
let delegate = contract.pkh in
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { level } ->
|
||||||
let level = level.level in
|
let level = level.level in
|
||||||
|
let delegate = contract.pkh in
|
||||||
Alpha_services.Delegate.Endorser.rights_for_delegate
|
Alpha_services.Delegate.Endorser.rights_for_delegate
|
||||||
!rpc_ctxt
|
!rpc_ctxt
|
||||||
~max_priority
|
~max_priority
|
||||||
@ -622,8 +632,9 @@ module Endorse = struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
let display_level block =
|
let display_level block =
|
||||||
Alpha_services.Context.level !rpc_ctxt (`Main, block) >>=? fun lvl ->
|
Block_services.Metadata.protocol_data
|
||||||
Format.eprintf "Level: %a@." Level.pp_full lvl ;
|
!rpc_ctxt ~chain:`Main ~block () >>=? fun { level } ->
|
||||||
|
Format.eprintf "Level: %a@." Level.pp_full level ;
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
let endorsement_security_deposit block =
|
let endorsement_security_deposit block =
|
||||||
|
@ -19,7 +19,8 @@ val init :
|
|||||||
forked Tezos node and the block info of the block from where the
|
forked Tezos node and the block info of the block from where the
|
||||||
tests will begin. *)
|
tests will begin. *)
|
||||||
|
|
||||||
val level : Chain_services.chain * Block_services.block -> Alpha_context.Level.t tzresult Lwt.t
|
val level:
|
||||||
|
Chain_services.chain * Block_services.block -> Alpha_context.Level.t tzresult Lwt.t
|
||||||
|
|
||||||
(** Calls the rpc service raw_context using the right rpc context *)
|
(** Calls the rpc service raw_context using the right rpc context *)
|
||||||
val rpc_raw_context : Block_services.block -> string list -> int ->
|
val rpc_raw_context : Block_services.block -> string list -> int ->
|
||||||
|
@ -11,62 +11,6 @@ open Alpha_context
|
|||||||
|
|
||||||
let custom_root = RPC_path.open_root
|
let custom_root = RPC_path.open_root
|
||||||
|
|
||||||
module Context = struct
|
|
||||||
|
|
||||||
module S = struct
|
|
||||||
|
|
||||||
open Data_encoding
|
|
||||||
|
|
||||||
let level =
|
|
||||||
RPC_service.post_service
|
|
||||||
~description: "Detailled level information for the current block"
|
|
||||||
~query: RPC_query.empty
|
|
||||||
~input: empty
|
|
||||||
~output: Level.encoding
|
|
||||||
RPC_path.(custom_root / "context" / "level")
|
|
||||||
|
|
||||||
let next_level =
|
|
||||||
RPC_service.post_service
|
|
||||||
~description: "Detailled level information for the next block"
|
|
||||||
~query: RPC_query.empty
|
|
||||||
~input: empty
|
|
||||||
~output: Level.encoding
|
|
||||||
RPC_path.(custom_root / "context" / "next_level")
|
|
||||||
|
|
||||||
let voting_period_kind =
|
|
||||||
RPC_service.post_service
|
|
||||||
~description: "Voting period kind for the current block"
|
|
||||||
~query: RPC_query.empty
|
|
||||||
~input: empty
|
|
||||||
~output:
|
|
||||||
(obj1 (req "voting_period_kind" Voting_period.kind_encoding))
|
|
||||||
RPC_path.(custom_root / "context" / "voting_period_kind")
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
let () =
|
|
||||||
let open Services_registration in
|
|
||||||
register0 S.level begin fun ctxt () () ->
|
|
||||||
return (Level.current ctxt)
|
|
||||||
end ;
|
|
||||||
register0 S.next_level begin fun ctxt () () ->
|
|
||||||
return (Level.succ ctxt (Level.current ctxt))
|
|
||||||
end ;
|
|
||||||
register0 S.voting_period_kind begin fun ctxt () () ->
|
|
||||||
Vote.get_current_period_kind ctxt
|
|
||||||
end
|
|
||||||
|
|
||||||
let level ctxt block =
|
|
||||||
RPC_context.make_call0 S.level ctxt block () ()
|
|
||||||
|
|
||||||
let next_level ctxt block =
|
|
||||||
RPC_context.make_call0 S.next_level ctxt block () ()
|
|
||||||
|
|
||||||
let voting_period_kind ctxt block =
|
|
||||||
RPC_context.make_call0 S.voting_period_kind ctxt block () ()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module Nonce = struct
|
module Nonce = struct
|
||||||
|
|
||||||
type info =
|
type info =
|
||||||
@ -93,23 +37,12 @@ module Nonce = struct
|
|||||||
|
|
||||||
module S = struct
|
module S = struct
|
||||||
|
|
||||||
open Data_encoding
|
|
||||||
|
|
||||||
let get =
|
let get =
|
||||||
RPC_service.post_service
|
RPC_service.get_service
|
||||||
~description: "Info about the nonce of a previous block."
|
~description: "Info about the nonce of a previous block."
|
||||||
~query: RPC_query.empty
|
~query: RPC_query.empty
|
||||||
~input: empty
|
|
||||||
~output: info_encoding
|
~output: info_encoding
|
||||||
RPC_path.(custom_root / "context" / "nonce" /: Raw_level.arg)
|
RPC_path.(custom_root / "context" / "nonces" /: Raw_level.arg)
|
||||||
|
|
||||||
let hash =
|
|
||||||
RPC_service.post_service
|
|
||||||
~description: "Hash of the current block's nonce."
|
|
||||||
~query: RPC_query.empty
|
|
||||||
~input: empty
|
|
||||||
~output: Nonce_hash.encoding
|
|
||||||
RPC_path.(custom_root / "context" / "nonce")
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -122,20 +55,11 @@ module Nonce = struct
|
|||||||
| Ok (Unrevealed { nonce_hash ; _ }) ->
|
| Ok (Unrevealed { nonce_hash ; _ }) ->
|
||||||
return (Missing nonce_hash)
|
return (Missing nonce_hash)
|
||||||
| Error _ -> return Forgotten
|
| Error _ -> return Forgotten
|
||||||
end ;
|
|
||||||
register0 S.hash begin fun ctxt () () ->
|
|
||||||
let level = Level.current ctxt in
|
|
||||||
Nonce.get ctxt level >>=? function
|
|
||||||
| Unrevealed { nonce_hash ; _ } -> return nonce_hash
|
|
||||||
| _ -> assert false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let get ctxt block level =
|
let get ctxt block level =
|
||||||
RPC_context.make_call1 S.get ctxt block level () ()
|
RPC_context.make_call1 S.get ctxt block level () ()
|
||||||
|
|
||||||
let hash ctxt block =
|
|
||||||
RPC_context.make_call0 S.hash ctxt block () ()
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Contract = Contract_services
|
module Contract = Contract_services
|
||||||
|
@ -9,31 +9,8 @@
|
|||||||
|
|
||||||
open Alpha_context
|
open Alpha_context
|
||||||
|
|
||||||
module Context : sig
|
|
||||||
|
|
||||||
val level:
|
|
||||||
'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t
|
|
||||||
(** [level cctxt blk] returns the (protocol view of the) level of
|
|
||||||
[blk]. *)
|
|
||||||
|
|
||||||
val next_level:
|
|
||||||
'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t
|
|
||||||
(** [next_level cctxt blk] returns the (protocol view of the) level
|
|
||||||
of the successor of [blk]. *)
|
|
||||||
|
|
||||||
val voting_period_kind:
|
|
||||||
'a #RPC_context.simple -> 'a -> Voting_period.kind shell_tzresult Lwt.t
|
|
||||||
(** [voting_period_kind cctxt blk] returns the voting period kind
|
|
||||||
of [blk]. *)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module Nonce : sig
|
module Nonce : sig
|
||||||
|
|
||||||
val hash:
|
|
||||||
'a #RPC_context.simple ->
|
|
||||||
'a -> Nonce_hash.t shell_tzresult Lwt.t
|
|
||||||
|
|
||||||
type info =
|
type info =
|
||||||
| Revealed of Nonce.t
|
| Revealed of Nonce.t
|
||||||
| Missing of Nonce_hash.t
|
| Missing of Nonce_hash.t
|
||||||
|
@ -40,6 +40,14 @@ module S = struct
|
|||||||
|
|
||||||
let custom_root = RPC_path.(open_root / "helpers")
|
let custom_root = RPC_path.(open_root / "helpers")
|
||||||
|
|
||||||
|
let next_level =
|
||||||
|
RPC_service.post_service
|
||||||
|
~description: "Detailled level information for the next block"
|
||||||
|
~query: RPC_query.empty
|
||||||
|
~input: empty
|
||||||
|
~output: Level.encoding
|
||||||
|
RPC_path.(custom_root / "next_level")
|
||||||
|
|
||||||
let minimal_timestamp =
|
let minimal_timestamp =
|
||||||
RPC_service.post_service
|
RPC_service.post_service
|
||||||
~description: "Minimal timestamp for the next block."
|
~description: "Minimal timestamp for the next block."
|
||||||
@ -173,6 +181,9 @@ end
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
let open Services_registration in
|
let open Services_registration in
|
||||||
|
register0 S.next_level begin fun ctxt () () ->
|
||||||
|
return (Level.succ ctxt (Level.current ctxt))
|
||||||
|
end ;
|
||||||
register0 S.minimal_timestamp begin fun ctxt () slot ->
|
register0 S.minimal_timestamp begin fun ctxt () slot ->
|
||||||
let timestamp = Alpha_context.Timestamp.current ctxt in
|
let timestamp = Alpha_context.Timestamp.current ctxt in
|
||||||
let slot = match slot with None -> 0 | Some p -> p in
|
let slot = match slot with None -> 0 | Some p -> p in
|
||||||
@ -243,6 +254,9 @@ let () =
|
|||||||
return (first.level, last.level)
|
return (first.level, last.level)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let next_level ctxt block =
|
||||||
|
RPC_context.make_call0 S.next_level ctxt block () ()
|
||||||
|
|
||||||
let minimal_time ctxt ?priority block =
|
let minimal_time ctxt ?priority block =
|
||||||
RPC_context.make_call0 S.minimal_timestamp ctxt block () priority
|
RPC_context.make_call0 S.minimal_timestamp ctxt block () priority
|
||||||
|
|
||||||
|
@ -13,6 +13,11 @@ type error +=
|
|||||||
| Cannot_parse_operation (* `Branch *)
|
| Cannot_parse_operation (* `Branch *)
|
||||||
| Cant_parse_block_header
|
| Cant_parse_block_header
|
||||||
|
|
||||||
|
val next_level:
|
||||||
|
'a #RPC_context.simple -> 'a -> Level.t shell_tzresult Lwt.t
|
||||||
|
(** [next_level cctxt blk] returns the (protocol view of the) level
|
||||||
|
of the successor of [blk]. *)
|
||||||
|
|
||||||
val minimal_time:
|
val minimal_time:
|
||||||
'a #RPC_context.simple ->
|
'a #RPC_context.simple ->
|
||||||
?priority:int -> 'a -> Time.t shell_tzresult Lwt.t
|
?priority:int -> 'a -> Time.t shell_tzresult Lwt.t
|
||||||
|
@ -139,7 +139,7 @@ module Forge = struct
|
|||||||
| Error _ -> assert false
|
| Error _ -> assert false
|
||||||
end >>=? fun fitness ->
|
end >>=? fun fitness ->
|
||||||
begin
|
begin
|
||||||
Alpha_services.Context.next_level (rpc_ctxt) pred >>|? function
|
Alpha_services.Helpers.next_level (rpc_ctxt) pred >>|? function
|
||||||
| { expected_commitment = true } -> Some (fst (Proto_Nonce.generate ()))
|
| { expected_commitment = true } -> Some (fst (Proto_Nonce.generate ()))
|
||||||
| { expected_commitment = false } -> None
|
| { expected_commitment = false } -> None
|
||||||
end >>=? fun seed_nonce_hash ->
|
end >>=? fun seed_nonce_hash ->
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
((name tezos_alpha_test_helpers)
|
((name tezos_alpha_test_helpers)
|
||||||
(libraries (tezos-base
|
(libraries (tezos-base
|
||||||
tezos-stdlib-unix
|
tezos-stdlib-unix
|
||||||
|
tezos-shell-services
|
||||||
tezos-protocol-environment
|
tezos-protocol-environment
|
||||||
tezos-protocol-alpha
|
tezos-protocol-alpha
|
||||||
alcotest-lwt))
|
alcotest-lwt))
|
||||||
(flags (:standard -w -9-32 -safe-string
|
(flags (:standard -w -9-32 -safe-string
|
||||||
-open Tezos_base__TzPervasives
|
-open Tezos_base__TzPervasives
|
||||||
-open Tezos_stdlib_unix))))
|
-open Tezos_stdlib_unix
|
||||||
|
-open Tezos_shell_services))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
((name runtest_indent)
|
((name runtest_indent)
|
||||||
|
@ -13,6 +13,11 @@ module Alpha_environment = Tezos_protocol_environment_memory.MakeV1(Name)()
|
|||||||
type alpha_error = Alpha_environment.Error_monad.error
|
type alpha_error = Alpha_environment.Error_monad.error
|
||||||
type 'a alpha_tzresult = 'a Alpha_environment.Error_monad.tzresult
|
type 'a alpha_tzresult = 'a Alpha_environment.Error_monad.tzresult
|
||||||
|
|
||||||
include Tezos_protocol_alpha.Functor.Make(Alpha_environment)
|
module Proto = Tezos_protocol_alpha.Functor.Make(Alpha_environment)
|
||||||
|
module Block_services = struct
|
||||||
|
include Block_services
|
||||||
|
include Block_services.Make(Proto)(Proto)
|
||||||
|
end
|
||||||
|
include Proto
|
||||||
|
|
||||||
module M = Alpha_environment.Lift(Main)
|
module M = Alpha_environment.Lift(Main)
|
||||||
|
Loading…
Reference in New Issue
Block a user