65 lines
2.4 KiB
OCaml
65 lines
2.4 KiB
OCaml
![]() |
(**************************************************************************)
|
||
|
(* *)
|
||
|
(* Copyright (c) 2014 - 2018. *)
|
||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||
|
(* *)
|
||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||
|
(* *)
|
||
|
(**************************************************************************)
|
||
|
|
||
|
open Proto_alpha
|
||
|
open Alpha_context
|
||
|
|
||
|
module Main = Alpha_environment.Lift(Main)
|
||
|
|
||
|
type incremental = {
|
||
|
predecessor: Client_baking_blocks.block_info ;
|
||
|
context : Context.t ;
|
||
|
state: Main.validation_state ;
|
||
|
rev_operations: Operation.packed list ;
|
||
|
header: Tezos_base.Block_header.shell_header ;
|
||
|
}
|
||
|
|
||
|
let load_context ~context_path =
|
||
|
Context.init ~readonly:true context_path
|
||
|
|
||
|
let begin_construction (_cctxt : #Proto_alpha.full) index predecessor =
|
||
|
let { Client_baking_blocks.context } = predecessor in
|
||
|
Context.checkout_exn index context >>= fun context ->
|
||
|
let timestamp = Time.now () in
|
||
|
let predecessor_hash = predecessor.hash in
|
||
|
(* Shell_services.Blocks.header cctxt ~chain:`Main ~block:(`Hash (predecessor_hash, 0)) ()
|
||
|
* >>=? fun { shell ; _ } -> *)
|
||
|
let header : Tezos_base.Block_header.shell_header = Tezos_base.Block_header.{
|
||
|
predecessor = predecessor_hash ;
|
||
|
proto_level = 0 (* shell.proto_level *) ;
|
||
|
validation_passes = 0 (* shell.validation_passes *) ;
|
||
|
fitness = predecessor.fitness (* shell.fitness *) ;
|
||
|
timestamp ;
|
||
|
level = 0l (* shell.level *) ;
|
||
|
context = Context_hash.zero ;
|
||
|
operations_hash = Operation_list_list_hash.zero ;
|
||
|
} in
|
||
|
Main.begin_construction
|
||
|
~predecessor_context: context
|
||
|
~predecessor_timestamp: header.timestamp
|
||
|
~predecessor_fitness: header.fitness
|
||
|
~predecessor_level: header.level
|
||
|
~predecessor:predecessor_hash
|
||
|
~timestamp
|
||
|
() >>=? fun state ->
|
||
|
return {
|
||
|
predecessor ;
|
||
|
context ;
|
||
|
state ;
|
||
|
rev_operations = [] ;
|
||
|
header ;
|
||
|
}
|
||
|
|
||
|
let add_operation st ( op : Operation.packed ) =
|
||
|
Main.apply_operation st.state op >>=? fun (state, _) ->
|
||
|
return { st with state ; rev_operations = op :: st.rev_operations }
|
||
|
|
||
|
let finalize_construction inc =
|
||
|
Main.finalize_block inc.state >>=? fun _ -> return ()
|