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
|
||||
| Error _ as err -> Lwt.return err
|
||||
|
||||
let forge_block
|
||||
rpc_config block net_id ?(timestamp = Time.now ()) command fitness =
|
||||
let bake rpc_config ?(timestamp = Time.now ()) block command seckey =
|
||||
let block = Client_rpcs.last_baked_block block in
|
||||
Client_node_rpcs.Blocks.info rpc_config block >>=? fun pred ->
|
||||
let proto_level =
|
||||
match command with
|
||||
| Data.Command.Activate _ -> 1
|
||||
| Data.Command.Activate_testnet _ -> 0 in
|
||||
call_service1 rpc_config
|
||||
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 proto_header = Data_encoding.Binary.to_bytes Data.Command.encoding command in
|
||||
Client_node_rpcs.Blocks.preapply
|
||||
rpc_config block ~timestamp ~proto_header [] >>=? fun { shell_header } ->
|
||||
let blk =
|
||||
Data_encoding.Binary.to_bytes Block_header.encoding
|
||||
{ shell = shell_header ; proto = proto_header } in
|
||||
let signed_blk = Ed25519.Signature.append seckey blk in
|
||||
Client_node_rpcs.inject_block rpc_config signed_blk []
|
||||
|
||||
@ -87,7 +77,8 @@ let commands () =
|
||||
let fitness =
|
||||
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
||||
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 () ->
|
||||
return ()
|
||||
end ;
|
||||
@ -96,11 +87,7 @@ let commands () =
|
||||
args
|
||||
(prefixes [ "fork" ; "test" ; "protocol" ]
|
||||
@@ Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)"
|
||||
@@ prefixes [ "with" ; "fitness" ]
|
||||
@@ param ~name:"fitness"
|
||||
~desc:"Hardcoded fitness of the first block (integer)"
|
||||
int64_parameter
|
||||
@@ prefixes [ "and" ; "passes" ]
|
||||
@@ prefixes [ "with" ; "passes" ]
|
||||
@@ param ~name:"passes"
|
||||
~desc:"Hardcoded number of validation passes (integer)"
|
||||
int_parameter
|
||||
@ -108,14 +95,12 @@ let commands () =
|
||||
@@ Ed25519.Secret_key.param
|
||||
~name:"password" ~desc:"Dictator's key"
|
||||
@@ stop)
|
||||
begin fun timestamp hash fitness validation_passes seckey cctxt ->
|
||||
let fitness =
|
||||
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
||||
begin fun timestamp hash validation_passes seckey cctxt ->
|
||||
bake cctxt ?timestamp cctxt#block
|
||||
(Activate_testnet { protocol = hash ;
|
||||
validation_passes ;
|
||||
delay = Int64.mul 24L 3600L })
|
||||
fitness seckey >>=? fun hash ->
|
||||
seckey >>=? fun hash ->
|
||||
cctxt#answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
||||
return ()
|
||||
end ;
|
||||
|
@ -14,7 +14,6 @@ val bake:
|
||||
?timestamp: Time.t ->
|
||||
Client_node_rpcs.Blocks.block ->
|
||||
Data.Command.t ->
|
||||
Fitness.t ->
|
||||
Environment.Ed25519.Secret_key.t ->
|
||||
Block_hash.t tzresult Lwt.t
|
||||
|
||||
|
@ -14,6 +14,7 @@ module Command = struct
|
||||
| Activate of {
|
||||
protocol: Protocol_hash.t ;
|
||||
validation_passes: int ;
|
||||
fitness: Fitness.t ;
|
||||
}
|
||||
|
||||
(* Activate a protocol as a testnet *)
|
||||
@ -37,16 +38,17 @@ module Command = struct
|
||||
union ~tag_size:`Uint8 [
|
||||
case (Tag 0)
|
||||
(mk_case "activate"
|
||||
(obj2
|
||||
(obj3
|
||||
(req "hash" Protocol_hash.encoding)
|
||||
(req "validation_passes" uint8)
|
||||
(req "fitness" Fitness.encoding)
|
||||
))
|
||||
(function
|
||||
| Activate { protocol ; validation_passes } ->
|
||||
Some (protocol, validation_passes)
|
||||
| Activate { protocol ; validation_passes ; fitness} ->
|
||||
Some (protocol, validation_passes, fitness)
|
||||
| _ -> None)
|
||||
(fun (protocol, validation_passes) ->
|
||||
Activate { protocol ; validation_passes }) ;
|
||||
(fun (protocol, validation_passes, fitness) ->
|
||||
Activate { protocol ; validation_passes ; fitness }) ;
|
||||
case (Tag 1)
|
||||
(mk_case "activate_testnet"
|
||||
(obj3
|
||||
|
@ -81,17 +81,9 @@ let precheck_block
|
||||
Lwt.return (parse_block raw_block) >>=? fun _ ->
|
||||
return ()
|
||||
|
||||
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 () ->
|
||||
let fitness = raw_block.shell.fitness in
|
||||
match block.command with
|
||||
| Data.Command.Activate { protocol = hash ; validation_passes } ->
|
||||
let prepare_application ctxt command timestamp fitness =
|
||||
match command with
|
||||
| Data.Command.Activate { protocol = hash ; validation_passes ; fitness } ->
|
||||
let message =
|
||||
Some (Format.asprintf "activate %a" Protocol_hash.pp_short hash) in
|
||||
Updater.activate ctxt hash >>= fun ctxt ->
|
||||
@ -103,7 +95,7 @@ let begin_application
|
||||
| Activate_testnet { protocol = hash ; validation_passes ; delay } ->
|
||||
let message =
|
||||
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 ->
|
||||
return { Updater.message ; context = ctxt ; fitness ;
|
||||
max_operations_ttl = 0 ;
|
||||
@ -111,21 +103,40 @@ let begin_application
|
||||
Array.to_list (Array.make validation_passes 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
|
||||
~predecessor_context:context
|
||||
~predecessor_context:ctxt
|
||||
~predecessor_timestamp:_
|
||||
~predecessor_level:_
|
||||
~predecessor_fitness:fitness
|
||||
~predecessor:_
|
||||
~timestamp:_
|
||||
?proto_header:_
|
||||
~timestamp
|
||||
?proto_header
|
||||
() =
|
||||
match proto_header with
|
||||
| None ->
|
||||
(* Dummy result. *)
|
||||
return { Updater.message = None ; context ;
|
||||
return { Updater.message = None ; context = ctxt ;
|
||||
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 _ =
|
||||
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,
|
||||
timestamp, fitness), command) ->
|
||||
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
|
||||
RPC_answer.return bytes) in
|
||||
dir
|
||||
|
@ -42,8 +42,9 @@ let activate_alpha () =
|
||||
let fitness = Fitness_repr.from_int64 0L in
|
||||
Tezos_embedded_client_genesis.Client_proto_main.bake
|
||||
(new Client_rpcs.http_ctxt !rpc_config) (`Head 0)
|
||||
(Activate { protocol = Client_proto_main.protocol ; validation_passes = 1})
|
||||
fitness dictator_sk
|
||||
(Activate { protocol = Client_proto_main.protocol ; validation_passes = 1 ;
|
||||
fitness })
|
||||
dictator_sk
|
||||
|
||||
let init ?(sandbox = "sandbox.json") ?rpc_port () =
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user