2017-02-24 18:38:42 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-02-25 21:10:29 +04:00
|
|
|
type error += Parsing_error
|
|
|
|
type error += Invalid_signature
|
|
|
|
|
|
|
|
let () =
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"parsing_error"
|
|
|
|
~title:"Parsing error"
|
|
|
|
~description:"Raised when a block header has not been parsed correctly"
|
|
|
|
~pp:(fun ppf () -> Format.fprintf ppf "Block header parsing error")
|
|
|
|
Data_encoding.empty
|
|
|
|
(function Parsing_error -> Some () | _ -> None)
|
|
|
|
(fun () -> Parsing_error)
|
|
|
|
|
|
|
|
let () =
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"invalid_signature"
|
|
|
|
~title:"Invalid signature"
|
|
|
|
~description:"Raised when the provided signature is invalid"
|
|
|
|
~pp:(fun ppf () -> Format.fprintf ppf "Invalid signature")
|
|
|
|
Data_encoding.empty
|
|
|
|
(function Invalid_signature -> Some () | _ -> None)
|
|
|
|
(fun () -> Invalid_signature)
|
2017-02-24 18:38:42 +04:00
|
|
|
|
2016-10-20 20:54:16 +04:00
|
|
|
type operation = unit
|
2017-02-24 18:38:42 +04:00
|
|
|
let max_operation_data_length = 0
|
2017-02-25 21:10:29 +04:00
|
|
|
let parse_operation _h _op = Error []
|
2016-10-20 20:54:16 +04:00
|
|
|
let compare_operations _ _ = 0
|
2017-02-24 18:38:42 +04:00
|
|
|
let max_number_of_operations = 0
|
|
|
|
|
2017-02-25 21:10:29 +04:00
|
|
|
type block = {
|
|
|
|
shell: Updater.shell_block ;
|
|
|
|
command: Data.Command.t ;
|
2017-02-28 05:56:40 +04:00
|
|
|
signature: Ed25519.Signature.t ;
|
2017-02-25 21:10:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let max_block_length =
|
2017-04-10 23:14:17 +04:00
|
|
|
Data_encoding.Binary.length
|
|
|
|
Data.Command.encoding
|
|
|
|
(Activate_testnet (Protocol_hash.hash_bytes [], 0L))
|
|
|
|
+
|
|
|
|
begin
|
|
|
|
match Data_encoding.Binary.fixed_length Ed25519.Signature.encoding with
|
|
|
|
| None -> assert false
|
|
|
|
| Some len -> len
|
|
|
|
end
|
2017-02-25 21:10:29 +04:00
|
|
|
|
2016-10-20 20:54:16 +04:00
|
|
|
let parse_block { Updater.shell ; proto } : block tzresult =
|
2017-02-25 21:10:29 +04:00
|
|
|
match Data_encoding.Binary.of_bytes Data.Command.signed_encoding proto with
|
|
|
|
| None -> Error [Parsing_error]
|
2017-02-25 21:01:27 +04:00
|
|
|
| Some (command, signature) -> Ok { shell ; command ; signature }
|
2017-02-25 21:10:29 +04:00
|
|
|
|
|
|
|
let check_signature ctxt { shell ; command ; signature } =
|
|
|
|
let bytes = Data.Command.forge shell command in
|
|
|
|
Data.Pubkey.get_pubkey ctxt >>= fun public_key ->
|
|
|
|
fail_unless
|
2017-02-28 05:56:40 +04:00
|
|
|
(Ed25519.Signature.check public_key signature bytes)
|
2017-02-25 21:10:29 +04:00
|
|
|
Invalid_signature
|
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
type validation_state = Updater.validation_result
|
2016-10-20 20:54:16 +04:00
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
let current_context ({ context } : validation_state) =
|
|
|
|
return context
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
let precheck_block
|
|
|
|
~ancestor_context:_
|
|
|
|
~ancestor_timestamp:_
|
|
|
|
raw_block =
|
|
|
|
Lwt.return (parse_block raw_block) >>=? fun _ ->
|
|
|
|
return ()
|
|
|
|
|
|
|
|
let begin_application
|
|
|
|
~predecessor_context:ctxt
|
|
|
|
~predecessor_timestamp:_
|
2017-04-10 14:14:11 +04:00
|
|
|
~predecessor_fitness:_
|
2016-10-20 20:54:16 +04:00
|
|
|
raw_block =
|
2017-04-10 14:14:11 +04:00
|
|
|
Data.Init.may_initialize ctxt >>=? fun ctxt ->
|
2016-10-20 20:54:16 +04:00
|
|
|
Lwt.return (parse_block raw_block) >>=? fun block ->
|
2017-04-10 14:14:11 +04:00
|
|
|
check_signature ctxt block >>=? fun () ->
|
|
|
|
let fitness = raw_block.shell.fitness in
|
|
|
|
match block.command with
|
|
|
|
| Data.Command.Activate hash ->
|
|
|
|
let message =
|
|
|
|
Some (Format.asprintf "activate %a" Protocol_hash.pp_short hash) in
|
|
|
|
Updater.activate ctxt hash >>= fun ctxt ->
|
|
|
|
return { Updater.message ; context = ctxt ; fitness }
|
2017-04-10 23:14:17 +04:00
|
|
|
| Activate_testnet (hash, delay) ->
|
2017-04-10 14:14:11 +04:00
|
|
|
let message =
|
|
|
|
Some (Format.asprintf "activate testnet %a" Protocol_hash.pp_short hash) in
|
2017-04-10 23:14:17 +04:00
|
|
|
let expiration = Time.add raw_block.shell.timestamp delay in
|
|
|
|
Updater.fork_test_network ctxt hash expiration >>= fun ctxt ->
|
2017-04-10 14:14:11 +04:00
|
|
|
return { Updater.message ; context = ctxt ; fitness }
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
let begin_construction
|
2017-04-10 14:14:11 +04:00
|
|
|
~predecessor_context:context
|
2016-10-20 20:54:16 +04:00
|
|
|
~predecessor_timestamp:_
|
2017-04-10 15:01:22 +04:00
|
|
|
~predecessor_level:_
|
2017-04-10 14:14:11 +04:00
|
|
|
~predecessor_fitness:fitness
|
2016-10-20 20:54:16 +04:00
|
|
|
~predecessor:_
|
|
|
|
~timestamp:_ =
|
2017-04-10 14:14:11 +04:00
|
|
|
(* Dummy result. *)
|
|
|
|
return { Updater.message = None ; context ; fitness }
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
let apply_operation _vctxt _ =
|
|
|
|
Lwt.return (Error []) (* absurd *)
|
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
let finalize_block state = return state
|
2017-02-24 18:38:42 +04:00
|
|
|
|
|
|
|
let rpc_services = Services.rpc_services
|
|
|
|
|
2017-02-25 21:10:29 +04:00
|
|
|
let configure_sandbox = Data.Init.configure_sandbox
|