2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
type operation = Operation_hash.t
|
|
|
|
let max_operation_data_length = 42
|
|
|
|
|
2016-10-19 22:47:04 +04:00
|
|
|
let max_block_length = 42
|
2016-09-08 21:13:10 +04:00
|
|
|
let max_number_of_operations = 42
|
|
|
|
|
|
|
|
let parse_operation h _ = Ok h
|
|
|
|
|
2016-10-20 20:54:16 +04:00
|
|
|
let compare_operations _ _ = 0
|
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
type validation_state = {
|
|
|
|
context : Context.t ;
|
|
|
|
fitness : Int64.t ;
|
|
|
|
}
|
|
|
|
|
|
|
|
let current_context { context } =
|
|
|
|
return context
|
2017-02-25 21:01:27 +04:00
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
module Fitness = struct
|
2017-02-25 21:01:27 +04:00
|
|
|
|
|
|
|
type error += Invalid_fitness
|
|
|
|
type error += Invalid_fitness2
|
|
|
|
|
|
|
|
let int64_to_bytes i =
|
|
|
|
let b = MBytes.create 8 in
|
|
|
|
MBytes.set_int64 b 0 i;
|
|
|
|
b
|
|
|
|
|
|
|
|
let int64_of_bytes b =
|
|
|
|
if Compare.Int.(MBytes.length b <> 8) then
|
|
|
|
fail Invalid_fitness2
|
|
|
|
else
|
|
|
|
return (MBytes.get_int64 b 0)
|
|
|
|
|
|
|
|
let from_int64 fitness =
|
2017-04-10 14:14:11 +04:00
|
|
|
[ int64_to_bytes fitness ]
|
2017-02-25 21:01:27 +04:00
|
|
|
|
|
|
|
let to_int64 = function
|
2017-04-10 14:14:11 +04:00
|
|
|
| [ fitness ] -> int64_of_bytes fitness
|
2017-02-25 21:01:27 +04:00
|
|
|
| [] -> return 0L
|
|
|
|
| _ -> fail Invalid_fitness
|
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
let get { fitness } = fitness
|
2017-02-25 21:01:27 +04:00
|
|
|
|
|
|
|
end
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-10-20 20:54:16 +04:00
|
|
|
let precheck_block
|
|
|
|
~ancestor_context:_
|
|
|
|
~ancestor_timestamp:_
|
2017-04-10 14:14:11 +04:00
|
|
|
raw_block =
|
2017-04-19 21:21:23 +04:00
|
|
|
Fitness.to_int64 raw_block.Block_header.shell.fitness >>=? fun _ ->
|
2016-10-20 20:54:16 +04:00
|
|
|
return ()
|
|
|
|
|
|
|
|
let begin_application
|
2017-04-10 14:14:11 +04:00
|
|
|
~predecessor_context:context
|
2016-10-20 20:54:16 +04:00
|
|
|
~predecessor_timestamp:_
|
2017-04-10 14:14:11 +04:00
|
|
|
~predecessor_fitness:_
|
|
|
|
raw_block =
|
2017-04-19 21:21:23 +04:00
|
|
|
Fitness.to_int64 raw_block.Block_header.shell.fitness >>=? fun fitness ->
|
2017-04-10 14:14:11 +04:00
|
|
|
return { context ; 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:pred_fitness
|
2016-10-20 20:54:16 +04:00
|
|
|
~predecessor:_
|
2017-04-26 17:01:39 +04:00
|
|
|
~timestamp:_
|
|
|
|
?proto_header:_ () =
|
2017-11-13 19:34:00 +04:00
|
|
|
Fitness.to_int64 pred_fitness >>=? fun pred_fitness ->
|
2017-04-10 14:14:11 +04:00
|
|
|
let fitness = Int64.succ pred_fitness in
|
|
|
|
return { context ; fitness }
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
let apply_operation ctxt _ =
|
|
|
|
return ctxt
|
|
|
|
|
|
|
|
let finalize_block ctxt =
|
2017-04-10 14:14:11 +04:00
|
|
|
let fitness = Fitness.get ctxt in
|
|
|
|
let message = Some (Format.asprintf "fitness <- %Ld" fitness) in
|
|
|
|
let fitness = Fitness.from_int64 fitness in
|
2017-04-18 13:29:14 +04:00
|
|
|
return { Updater.message ; context = ctxt.context ; fitness ;
|
2017-11-19 17:38:36 +04:00
|
|
|
max_operations_ttl = 0 ; max_operation_data_length = 0 ;
|
|
|
|
max_number_of_operations = [] }
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let rpc_services = Services.rpc_services
|
|
|
|
|
|
|
|
let configure_sandbox ctxt _ = Lwt.return (Ok ctxt)
|