Client/Genesis: let's use 'preapply'.
This will be mandatory once the context hash is stored in block header.
This commit is contained in:
parent
e850648894
commit
881186c58f
@ -23,24 +23,14 @@ let call_error_service1 rpc_config s block a1 =
|
|||||||
| Ok (Ok v) -> return v
|
| Ok (Ok v) -> return v
|
||||||
| Error _ as err -> Lwt.return err
|
| Error _ as err -> Lwt.return err
|
||||||
|
|
||||||
let forge_block
|
let bake rpc_config ?(timestamp = Time.now ()) block command seckey =
|
||||||
rpc_config block net_id ?(timestamp = Time.now ()) command fitness =
|
|
||||||
let block = Client_rpcs.last_baked_block block in
|
let block = Client_rpcs.last_baked_block block in
|
||||||
Client_node_rpcs.Blocks.info rpc_config block >>=? fun pred ->
|
let proto_header = Data_encoding.Binary.to_bytes Data.Command.encoding command in
|
||||||
let proto_level =
|
Client_node_rpcs.Blocks.preapply
|
||||||
match command with
|
rpc_config block ~timestamp ~proto_header [] >>=? fun { shell_header } ->
|
||||||
| Data.Command.Activate _ -> 1
|
let blk =
|
||||||
| Data.Command.Activate_testnet _ -> 0 in
|
Data_encoding.Binary.to_bytes Block_header.encoding
|
||||||
call_service1 rpc_config
|
{ shell = shell_header ; proto = proto_header } in
|
||||||
Services.Forge.block block
|
|
||||||
((net_id, Int32.succ pred.level, proto_level,
|
|
||||||
pred.hash, timestamp, fitness), command)
|
|
||||||
|
|
||||||
let bake rpc_config ?timestamp block command fitness seckey =
|
|
||||||
let block = Client_rpcs.last_baked_block block in
|
|
||||||
Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi ->
|
|
||||||
forge_block
|
|
||||||
rpc_config ?timestamp block bi.net_id command fitness >>=? fun blk ->
|
|
||||||
let signed_blk = Ed25519.Signature.append seckey blk in
|
let signed_blk = Ed25519.Signature.append seckey blk in
|
||||||
Client_node_rpcs.inject_block rpc_config signed_blk []
|
Client_node_rpcs.inject_block rpc_config signed_blk []
|
||||||
|
|
||||||
@ -87,7 +77,8 @@ let commands () =
|
|||||||
let fitness =
|
let fitness =
|
||||||
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
||||||
bake cctxt ?timestamp cctxt#block
|
bake cctxt ?timestamp cctxt#block
|
||||||
(Activate { protocol = hash ; validation_passes }) fitness seckey >>=? fun hash ->
|
(Activate { protocol = hash ; validation_passes ; fitness })
|
||||||
|
seckey >>=? fun hash ->
|
||||||
cctxt#answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
cctxt#answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
end ;
|
end ;
|
||||||
@ -96,11 +87,7 @@ let commands () =
|
|||||||
args
|
args
|
||||||
(prefixes [ "fork" ; "test" ; "protocol" ]
|
(prefixes [ "fork" ; "test" ; "protocol" ]
|
||||||
@@ Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)"
|
@@ Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)"
|
||||||
@@ prefixes [ "with" ; "fitness" ]
|
@@ prefixes [ "with" ; "passes" ]
|
||||||
@@ param ~name:"fitness"
|
|
||||||
~desc:"Hardcoded fitness of the first block (integer)"
|
|
||||||
int64_parameter
|
|
||||||
@@ prefixes [ "and" ; "passes" ]
|
|
||||||
@@ param ~name:"passes"
|
@@ param ~name:"passes"
|
||||||
~desc:"Hardcoded number of validation passes (integer)"
|
~desc:"Hardcoded number of validation passes (integer)"
|
||||||
int_parameter
|
int_parameter
|
||||||
@ -108,14 +95,12 @@ let commands () =
|
|||||||
@@ Ed25519.Secret_key.param
|
@@ Ed25519.Secret_key.param
|
||||||
~name:"password" ~desc:"Dictator's key"
|
~name:"password" ~desc:"Dictator's key"
|
||||||
@@ stop)
|
@@ stop)
|
||||||
begin fun timestamp hash fitness validation_passes seckey cctxt ->
|
begin fun timestamp hash validation_passes seckey cctxt ->
|
||||||
let fitness =
|
|
||||||
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
|
||||||
bake cctxt ?timestamp cctxt#block
|
bake cctxt ?timestamp cctxt#block
|
||||||
(Activate_testnet { protocol = hash ;
|
(Activate_testnet { protocol = hash ;
|
||||||
validation_passes ;
|
validation_passes ;
|
||||||
delay = Int64.mul 24L 3600L })
|
delay = Int64.mul 24L 3600L })
|
||||||
fitness seckey >>=? fun hash ->
|
seckey >>=? fun hash ->
|
||||||
cctxt#answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
cctxt#answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
end ;
|
end ;
|
||||||
|
@ -14,7 +14,6 @@ val bake:
|
|||||||
?timestamp: Time.t ->
|
?timestamp: Time.t ->
|
||||||
Client_node_rpcs.Blocks.block ->
|
Client_node_rpcs.Blocks.block ->
|
||||||
Data.Command.t ->
|
Data.Command.t ->
|
||||||
Fitness.t ->
|
|
||||||
Environment.Ed25519.Secret_key.t ->
|
Environment.Ed25519.Secret_key.t ->
|
||||||
Block_hash.t tzresult Lwt.t
|
Block_hash.t tzresult Lwt.t
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ module Command = struct
|
|||||||
| Activate of {
|
| Activate of {
|
||||||
protocol: Protocol_hash.t ;
|
protocol: Protocol_hash.t ;
|
||||||
validation_passes: int ;
|
validation_passes: int ;
|
||||||
|
fitness: Fitness.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
(* Activate a protocol as a testnet *)
|
(* Activate a protocol as a testnet *)
|
||||||
@ -37,16 +38,17 @@ module Command = struct
|
|||||||
union ~tag_size:`Uint8 [
|
union ~tag_size:`Uint8 [
|
||||||
case (Tag 0)
|
case (Tag 0)
|
||||||
(mk_case "activate"
|
(mk_case "activate"
|
||||||
(obj2
|
(obj3
|
||||||
(req "hash" Protocol_hash.encoding)
|
(req "hash" Protocol_hash.encoding)
|
||||||
(req "validation_passes" uint8)
|
(req "validation_passes" uint8)
|
||||||
|
(req "fitness" Fitness.encoding)
|
||||||
))
|
))
|
||||||
(function
|
(function
|
||||||
| Activate { protocol ; validation_passes } ->
|
| Activate { protocol ; validation_passes ; fitness} ->
|
||||||
Some (protocol, validation_passes)
|
Some (protocol, validation_passes, fitness)
|
||||||
| _ -> None)
|
| _ -> None)
|
||||||
(fun (protocol, validation_passes) ->
|
(fun (protocol, validation_passes, fitness) ->
|
||||||
Activate { protocol ; validation_passes }) ;
|
Activate { protocol ; validation_passes ; fitness }) ;
|
||||||
case (Tag 1)
|
case (Tag 1)
|
||||||
(mk_case "activate_testnet"
|
(mk_case "activate_testnet"
|
||||||
(obj3
|
(obj3
|
||||||
|
@ -81,17 +81,9 @@ let precheck_block
|
|||||||
Lwt.return (parse_block raw_block) >>=? fun _ ->
|
Lwt.return (parse_block raw_block) >>=? fun _ ->
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
let begin_application
|
let prepare_application ctxt command timestamp fitness =
|
||||||
~predecessor_context:ctxt
|
match command with
|
||||||
~predecessor_timestamp:_
|
| Data.Command.Activate { protocol = hash ; validation_passes ; fitness } ->
|
||||||
~predecessor_fitness:_
|
|
||||||
raw_block =
|
|
||||||
Data.Init.may_initialize ctxt >>=? fun ctxt ->
|
|
||||||
Lwt.return (parse_block raw_block) >>=? fun block ->
|
|
||||||
check_signature ctxt block >>=? fun () ->
|
|
||||||
let fitness = raw_block.shell.fitness in
|
|
||||||
match block.command with
|
|
||||||
| Data.Command.Activate { protocol = hash ; validation_passes } ->
|
|
||||||
let message =
|
let message =
|
||||||
Some (Format.asprintf "activate %a" Protocol_hash.pp_short hash) in
|
Some (Format.asprintf "activate %a" Protocol_hash.pp_short hash) in
|
||||||
Updater.activate ctxt hash >>= fun ctxt ->
|
Updater.activate ctxt hash >>= fun ctxt ->
|
||||||
@ -103,7 +95,7 @@ let begin_application
|
|||||||
| Activate_testnet { protocol = hash ; validation_passes ; delay } ->
|
| Activate_testnet { protocol = hash ; validation_passes ; delay } ->
|
||||||
let message =
|
let message =
|
||||||
Some (Format.asprintf "activate testnet %a" Protocol_hash.pp_short hash) in
|
Some (Format.asprintf "activate testnet %a" Protocol_hash.pp_short hash) in
|
||||||
let expiration = Time.add raw_block.shell.timestamp delay in
|
let expiration = Time.add timestamp delay in
|
||||||
Updater.fork_test_network ctxt ~protocol:hash ~expiration >>= fun ctxt ->
|
Updater.fork_test_network ctxt ~protocol:hash ~expiration >>= fun ctxt ->
|
||||||
return { Updater.message ; context = ctxt ; fitness ;
|
return { Updater.message ; context = ctxt ; fitness ;
|
||||||
max_operations_ttl = 0 ;
|
max_operations_ttl = 0 ;
|
||||||
@ -111,21 +103,40 @@ let begin_application
|
|||||||
Array.to_list (Array.make validation_passes 0) ;
|
Array.to_list (Array.make validation_passes 0) ;
|
||||||
max_operation_data_length = 0 }
|
max_operation_data_length = 0 }
|
||||||
|
|
||||||
|
|
||||||
|
let begin_application
|
||||||
|
~predecessor_context:ctxt
|
||||||
|
~predecessor_timestamp:_
|
||||||
|
~predecessor_fitness:_
|
||||||
|
raw_block =
|
||||||
|
Data.Init.may_initialize ctxt >>=? fun ctxt ->
|
||||||
|
Lwt.return (parse_block raw_block) >>=? fun block ->
|
||||||
|
check_signature ctxt block >>=? fun () ->
|
||||||
|
prepare_application ctxt block.command block.shell.timestamp block.shell.fitness
|
||||||
|
|
||||||
let begin_construction
|
let begin_construction
|
||||||
~predecessor_context:context
|
~predecessor_context:ctxt
|
||||||
~predecessor_timestamp:_
|
~predecessor_timestamp:_
|
||||||
~predecessor_level:_
|
~predecessor_level:_
|
||||||
~predecessor_fitness:fitness
|
~predecessor_fitness:fitness
|
||||||
~predecessor:_
|
~predecessor:_
|
||||||
~timestamp:_
|
~timestamp
|
||||||
?proto_header:_
|
?proto_header
|
||||||
() =
|
() =
|
||||||
(* Dummy result. *)
|
match proto_header with
|
||||||
return { Updater.message = None ; context ;
|
| None ->
|
||||||
fitness ; max_operations_ttl = 0 ;
|
(* Dummy result. *)
|
||||||
max_operation_data_length = 0 ;
|
return { Updater.message = None ; context = ctxt ;
|
||||||
max_number_of_operations = [] ;
|
fitness ; max_operations_ttl = 0 ;
|
||||||
}
|
max_operation_data_length = 0 ;
|
||||||
|
max_number_of_operations = [] ;
|
||||||
|
}
|
||||||
|
| Some command ->
|
||||||
|
match Data_encoding.Binary.of_bytes Data.Command.encoding command with
|
||||||
|
| None -> failwith "Failed to parse proto header"
|
||||||
|
| Some command ->
|
||||||
|
Data.Init.may_initialize ctxt >>=? fun ctxt ->
|
||||||
|
prepare_application ctxt command timestamp fitness
|
||||||
|
|
||||||
let apply_operation _vctxt _ =
|
let apply_operation _vctxt _ =
|
||||||
Lwt.return (Error []) (* absurd *)
|
Lwt.return (Error []) (* absurd *)
|
||||||
|
@ -69,7 +69,8 @@ let rpc_services : Updater.rpc_context RPC_directory.t =
|
|||||||
(fun _ctxt () ((_net_id, level, proto_level, predecessor,
|
(fun _ctxt () ((_net_id, level, proto_level, predecessor,
|
||||||
timestamp, fitness), command) ->
|
timestamp, fitness), command) ->
|
||||||
let shell = { Block_header.level ; proto_level ; predecessor ;
|
let shell = { Block_header.level ; proto_level ; predecessor ;
|
||||||
timestamp ; fitness ; validation_passes = 0 ; operations_hash } in
|
timestamp ; fitness ; validation_passes = 0 ;
|
||||||
|
operations_hash } in
|
||||||
let bytes = Data.Command.forge shell command in
|
let bytes = Data.Command.forge shell command in
|
||||||
RPC_answer.return bytes) in
|
RPC_answer.return bytes) in
|
||||||
dir
|
dir
|
||||||
|
@ -42,8 +42,9 @@ let activate_alpha () =
|
|||||||
let fitness = Fitness_repr.from_int64 0L in
|
let fitness = Fitness_repr.from_int64 0L in
|
||||||
Tezos_embedded_client_genesis.Client_proto_main.bake
|
Tezos_embedded_client_genesis.Client_proto_main.bake
|
||||||
(new Client_rpcs.http_ctxt !rpc_config) (`Head 0)
|
(new Client_rpcs.http_ctxt !rpc_config) (`Head 0)
|
||||||
(Activate { protocol = Client_proto_main.protocol ; validation_passes = 1})
|
(Activate { protocol = Client_proto_main.protocol ; validation_passes = 1 ;
|
||||||
fitness dictator_sk
|
fitness })
|
||||||
|
dictator_sk
|
||||||
|
|
||||||
let init ?(sandbox = "sandbox.json") ?rpc_port () =
|
let init ?(sandbox = "sandbox.json") ?rpc_port () =
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user