Alphanet: dictator in the alpha protocol

This commit is contained in:
Benjamin Canou 2017-02-27 18:24:26 +01:00
parent dbbdaa1688
commit 1d13908152
11 changed files with 160 additions and 9 deletions

View File

@ -148,6 +148,19 @@ let faucet cctxt block ?force ~manager_pkh () =
~net ~id:manager_pkh () >>=? fun bytes -> ~net ~id:manager_pkh () >>=? fun bytes ->
originate cctxt ?force ~block bytes originate cctxt ?force ~block bytes
let dictate cctxt block command seckey =
Client_node_rpcs.Blocks.net cctxt block >>= fun net ->
Client_proto_rpcs.Helpers.Forge.Dictator.operation
cctxt block ~net command >>=? fun bytes ->
let signature = Ed25519.sign seckey bytes in
let signed_bytes = MBytes.concat bytes signature in
let oph = Operation_hash.hash_bytes [ signed_bytes ] in
Client_node_rpcs.inject_operation cctxt ~wait:true signed_bytes >>=? fun injected_oph ->
assert (Operation_hash.equal oph injected_oph) ;
cctxt.message "Operation successfully injected in the node." >>= fun () ->
cctxt.message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
return ()
let group = let group =
{ Cli_entries.name = "context" ; { Cli_entries.name = "context" ;
title = "Block contextual commands (see option -block)" } title = "Block contextual commands (see option -block)" }
@ -275,5 +288,33 @@ let commands () =
(fun c -> cctxt.message "New contract %a originated from a smart contract." (fun c -> cctxt.message "New contract %a originated from a smart contract."
Contract.pp c) Contract.pp c)
contracts >>= fun () -> return ()) >>= contracts >>= fun () -> return ()) >>=
Client_proto_rpcs.handle_error cctxt) Client_proto_rpcs.handle_error cctxt) ;
command ~desc: "Activate a protocol" begin
prefixes [ "activate" ; "protocol" ] @@
param ~name:"version" ~desc:"Protocol version (b58check)"
(fun _ p -> Lwt.return @@ Protocol_hash.of_b58check p) @@
prefixes [ "with" ; "key" ] @@
param ~name:"password" ~desc:"Dictator's key"
(fun _ key ->
Lwt.return (Environment.Ed25519.Secret_key.of_b58check key))
stop
end
(fun hash seckey cctxt ->
let block = Client_config.block () in
dictate cctxt block (Activate hash) seckey >>=
Client_proto_rpcs.handle_error cctxt) ;
command ~desc: "Fork a test protocol" begin
prefixes [ "fork" ; "test" ; "protocol" ] @@
param ~name:"version" ~desc:"Protocol version (b58check)"
(fun _ p -> Lwt.return (Protocol_hash.of_b58check p)) @@
prefixes [ "with" ; "key" ] @@
param ~name:"password" ~desc:"Dictator's key"
(fun _ key ->
Lwt.return (Environment.Ed25519.Secret_key.of_b58check key))
stop
end
(fun hash seckey cctxt ->
let block = Client_config.block () in
dictate cctxt block (Activate_testnet hash) seckey >>=
Client_proto_rpcs.handle_error cctxt) ;
] ]

View File

@ -236,6 +236,19 @@ module Helpers = struct
operations cctxt b ~net ~source operations cctxt b ~net ~source
Tezos_context.[Endorsement { block ; slot }] Tezos_context.[Endorsement { block ; slot }]
end end
module Dictator = struct
let operation cctxt
block ~net operation =
let op = Dictator_operation operation in
(call_error_service1 cctxt Services.Helpers.Forge.operations block
({net_id=net}, Sourced_operations op))
let activate cctxt
b ~net hash =
operation cctxt b ~net (Activate hash)
let activate_testnet cctxt
b ~net hash =
operation cctxt b ~net (Activate_testnet hash)
end
module Anonymous = struct module Anonymous = struct
let operations cctxt block ~net operations = let operations cctxt block ~net operations =
(call_error_service1 cctxt Services.Helpers.Forge.operations block (call_error_service1 cctxt Services.Helpers.Forge.operations block

View File

@ -238,6 +238,26 @@ module Helpers : sig
public_key_hash option -> public_key_hash option ->
MBytes.t tzresult Lwt.t MBytes.t tzresult Lwt.t
end end
module Dictator : sig
val operation:
Client_commands.context ->
block ->
net:Updater.Net_id.t ->
dictator_operation ->
MBytes.t tzresult Lwt.t
val activate:
Client_commands.context ->
block ->
net:Updater.Net_id.t ->
Protocol_hash.t ->
MBytes.t tzresult Lwt.t
val activate_testnet:
Client_commands.context ->
block ->
net:Updater.Net_id.t ->
Protocol_hash.t ->
MBytes.t tzresult Lwt.t
end
module Delegate : sig module Delegate : sig
val operations: val operations:
Client_commands.context -> Client_commands.context ->

View File

@ -1,7 +1,6 @@
{ {
"hash": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK", "hash": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK",
"modules": [ "modules": [
"Misc", "Misc",
"Tezos_hash", "Tezos_hash",

View File

@ -153,6 +153,17 @@ let apply_sourced_operation
ctxt delegate pred_block block_prio content) ctxt delegate pred_block block_prio content)
ctxt contents >>=? fun ctxt -> ctxt contents >>=? fun ctxt ->
return (ctxt, origination_nonce) return (ctxt, origination_nonce)
| Dictator_operation (Activate hash) ->
let dictator_pubkey = Constants.dictator_pubkey ctxt in
Operation.check_signature dictator_pubkey operation >>=? fun () ->
activate ctxt hash >>= fun ctxt ->
return (ctxt, origination_nonce)
| Dictator_operation (Activate_testnet hash) ->
let dictator_pubkey = Constants.dictator_pubkey ctxt in
Operation.check_signature dictator_pubkey operation >>=? fun () ->
set_test_protocol ctxt hash >>= fun ctxt ->
fork_test_network ctxt >>= fun ctxt ->
return (ctxt, origination_nonce)
let apply_anonymous_operation ctxt miner_contract origination_nonce kind = let apply_anonymous_operation ctxt miner_contract origination_nonce kind =
match kind with match kind with
@ -282,9 +293,12 @@ let compare_operations op1 op2 =
| Sourced_operations _, Anonymous_operations _ -> 1 | Sourced_operations _, Anonymous_operations _ -> 1
| Sourced_operations op1, Sourced_operations op2 -> | Sourced_operations op1, Sourced_operations op2 ->
match op1, op2 with match op1, op2 with
| Delegate_operations _, Manager_operations _ -> -1 | Delegate_operations _, (Manager_operations _ | Dictator_operation _) -> -1
| Manager_operations _, Delegate_operations _ -> 1 | Manager_operations _, Dictator_operation _ -> -1
| Dictator_operation _, Manager_operations _ -> 1
| (Manager_operations _ | Dictator_operation _), Delegate_operations _ -> 1
| Delegate_operations _, Delegate_operations _ -> 0 | Delegate_operations _, Delegate_operations _ -> 0
| Dictator_operation _, Dictator_operation _ -> 0
| Manager_operations op1, Manager_operations op2 -> begin | Manager_operations op1, Manager_operations op2 -> begin
(* Manager operations with smaller counter are pre-validated first. *) (* Manager operations with smaller counter are pre-validated first. *)
Int32.compare op1.counter op2.counter Int32.compare op1.counter op2.counter

View File

@ -43,6 +43,7 @@ type constants = {
instructions_per_transaction: int ; instructions_per_transaction: int ;
proof_of_work_threshold: int64 ; proof_of_work_threshold: int64 ;
bootstrap_keys: Ed25519.Public_key.t list ; bootstrap_keys: Ed25519.Public_key.t list ;
dictator_pubkey: Ed25519.Public_key.t ;
} }
let read_public_key s = let read_public_key s =
@ -69,7 +70,10 @@ let default = {
"9c328bddf6249bbe550121076194d99bbe60e5b1e144da4f426561b5d3bbc6ab" ; "9c328bddf6249bbe550121076194d99bbe60e5b1e144da4f426561b5d3bbc6ab" ;
"a3db517734e07ace089ad0a2388e7276fb9b114bd79259dd5c93b0c33d57d6a2" ; "a3db517734e07ace089ad0a2388e7276fb9b114bd79259dd5c93b0c33d57d6a2" ;
"6d2d52e62f1d48f3cf9badbc90cfe5f3aa600194bf21eda44b8e64698a82d341" ; "6d2d52e62f1d48f3cf9badbc90cfe5f3aa600194bf21eda44b8e64698a82d341" ;
] ] ;
dictator_pubkey =
read_public_key
"4d5373455738070434f214826d301a1c206780d7f789fcbf94c2149b2e0718cc";
} }
let opt (=) def v = if def = v then None else Some v let opt (=) def v = if def = v then None else Some v
@ -113,6 +117,9 @@ let constants_encoding =
and bootstrap_keys = and bootstrap_keys =
opt Compare_keys.(=) opt Compare_keys.(=)
default.bootstrap_keys c.bootstrap_keys default.bootstrap_keys c.bootstrap_keys
and dictator_pubkey =
opt Ed25519.Public_key.(=)
default.dictator_pubkey c.dictator_pubkey
in in
(( cycle_length, (( cycle_length,
voting_period_length, voting_period_length,
@ -122,7 +129,8 @@ let constants_encoding =
max_signing_slot, max_signing_slot,
instructions_per_transaction, instructions_per_transaction,
proof_of_work_threshold, proof_of_work_threshold,
bootstrap_keys), ()) ) bootstrap_keys,
dictator_pubkey), ()) )
(fun (( cycle_length, (fun (( cycle_length,
voting_period_length, voting_period_length,
time_before_reward, time_before_reward,
@ -131,7 +139,8 @@ let constants_encoding =
max_signing_slot, max_signing_slot,
instructions_per_transaction, instructions_per_transaction,
proof_of_work_threshold, proof_of_work_threshold,
bootstrap_keys), ()) -> bootstrap_keys,
dictator_pubkey), ()) ->
{ cycle_length = { cycle_length =
unopt default.cycle_length cycle_length ; unopt default.cycle_length cycle_length ;
voting_period_length = voting_period_length =
@ -152,10 +161,12 @@ let constants_encoding =
unopt default.proof_of_work_threshold proof_of_work_threshold ; unopt default.proof_of_work_threshold proof_of_work_threshold ;
bootstrap_keys = bootstrap_keys =
unopt default.bootstrap_keys bootstrap_keys ; unopt default.bootstrap_keys bootstrap_keys ;
dictator_pubkey =
unopt default.dictator_pubkey dictator_pubkey ;
} ) } )
Data_encoding.( Data_encoding.(
merge_objs merge_objs
(obj9 (obj10
(opt "cycle_length" int32) (opt "cycle_length" int32)
(opt "voting_period_length" int32) (opt "voting_period_length" int32)
(opt "time_before_reward" int64) (opt "time_before_reward" int64)
@ -164,7 +175,8 @@ let constants_encoding =
(opt "max_signing_slot" int31) (opt "max_signing_slot" int31)
(opt "instructions_per_transaction" int31) (opt "instructions_per_transaction" int31)
(opt "proof_of_work_threshold" int64) (opt "proof_of_work_threshold" int64)
(opt "bootstrap_keys" (list Ed25519.Public_key.encoding))) (opt "bootstrap_keys" (list Ed25519.Public_key.encoding))
(opt "dictator_pubkey" Ed25519.Public_key.encoding))
unit) unit)
type error += Constant_read of exn type error += Constant_read of exn

View File

@ -42,6 +42,7 @@ and sourced_operations =
source: Ed25519.Public_key.t ; source: Ed25519.Public_key.t ;
operations: delegate_operation list ; operations: delegate_operation list ;
} }
| Dictator_operation of dictator_operation
and manager_operation = and manager_operation =
| Transaction of { | Transaction of {
@ -78,6 +79,10 @@ and delegate_operation =
ballot: Vote_repr.ballot ; ballot: Vote_repr.ballot ;
} }
and dictator_operation =
| Activate of Protocol_hash.t
| Activate_testnet of Protocol_hash.t
and counter = Int32.t and counter = Int32.t
module Encoding = struct module Encoding = struct
@ -236,11 +241,40 @@ module Encoding = struct
| _ -> None) | _ -> None)
(fun (source, operations) -> Delegate_operations { source ; operations }) (fun (source, operations) -> Delegate_operations { source ; operations })
let dictator_kind_encoding =
let mk_case name args =
let open Data_encoding in
conv
(fun o -> ((), o))
(fun ((), o) -> o)
(merge_objs
(obj1 (req "network" (constant name)))
args) in
let open Data_encoding in
union ~tag_size:`Uint8 [
case ~tag:0
(mk_case "activate"
(obj1 (req "hash" Protocol_hash.encoding)))
(function (Activate hash) -> Some hash | _ -> None)
(fun hash -> Activate hash) ;
case ~tag:1
(mk_case "activate_testnet"
(obj1 (req "hash" Protocol_hash.encoding)))
(function (Activate_testnet hash) -> Some hash | _ -> None)
(fun hash -> Activate_testnet hash) ;
]
let dictator_kind_case tag =
case ~tag dictator_kind_encoding
(function Dictator_operation op -> Some op | _ -> None)
(fun op -> Dictator_operation op)
let signed_operations_case tag = let signed_operations_case tag =
case ~tag case ~tag
(union [ (union [
manager_kind_case 0 ; manager_kind_case 0 ;
delegate_kind_case 1 ; delegate_kind_case 1 ;
dictator_kind_case 2 ;
]) ])
(function Sourced_operations ops -> Some ops | _ -> None) (function Sourced_operations ops -> Some ops | _ -> None)
(fun ops -> Sourced_operations ops) (fun ops -> Sourced_operations ops)

View File

@ -42,6 +42,7 @@ and sourced_operations =
source: Ed25519.Public_key.t ; source: Ed25519.Public_key.t ;
operations: delegate_operation list ; operations: delegate_operation list ;
} }
| Dictator_operation of dictator_operation
and manager_operation = and manager_operation =
| Transaction of { | Transaction of {
@ -78,6 +79,10 @@ and delegate_operation =
ballot: Vote_repr.ballot ; ballot: Vote_repr.ballot ;
} }
and dictator_operation =
| Activate of Protocol_hash.t
| Activate_testnet of Protocol_hash.t
and counter = Int32.t and counter = Int32.t
type error += Cannot_parse_operation type error += Cannot_parse_operation

View File

@ -466,6 +466,10 @@ let check_signature ctxt signature shell contents =
| Sourced_operations (Delegate_operations { source }) -> | Sourced_operations (Delegate_operations { source }) ->
Operation.check_signature source Operation.check_signature source
{ signature ; shell ; contents ; hash = dummy_hash } { signature ; shell ; contents ; hash = dummy_hash }
| Sourced_operations (Dictator_operation _) ->
let key = Constants.dictator_pubkey ctxt in
Operation.check_signature key
{ signature ; shell ; contents ; hash = dummy_hash }
let parse_operations ctxt (shell, bytes, check) = let parse_operations ctxt (shell, bytes, check) =
Operation.parse_proto bytes >>=? fun (proto, signature) -> Operation.parse_proto bytes >>=? fun (proto, signature) ->

View File

@ -70,6 +70,9 @@ module Constants = struct
let proof_of_work_threshold c = let proof_of_work_threshold c =
let constants = Storage.constants c in let constants = Storage.constants c in
constants.proof_of_work_threshold constants.proof_of_work_threshold
let dictator_pubkey c =
let constants = Storage.constants c in
constants.dictator_pubkey
end end
module Public_key = struct module Public_key = struct

View File

@ -183,6 +183,7 @@ module Constants : sig
val max_signing_slot: context -> int val max_signing_slot: context -> int
val instructions_per_transaction: context -> int val instructions_per_transaction: context -> int
val proof_of_work_threshold: context -> int64 val proof_of_work_threshold: context -> int64
val dictator_pubkey: context -> Ed25519.Public_key.t
end end
@ -459,6 +460,7 @@ and sourced_operations =
source: public_key ; source: public_key ;
operations: delegate_operation list ; operations: delegate_operation list ;
} }
| Dictator_operation of dictator_operation
and manager_operation = and manager_operation =
| Transaction of { | Transaction of {
@ -495,6 +497,10 @@ and delegate_operation =
ballot: Vote.ballot ; ballot: Vote.ballot ;
} }
and dictator_operation =
| Activate of Protocol_hash.t
| Activate_testnet of Protocol_hash.t
and counter = Int32.t and counter = Int32.t
module Operation : sig module Operation : sig