-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ml
More file actions
146 lines (128 loc) · 5.09 KB
/
Copy pathmain.ml
File metadata and controls
146 lines (128 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
(* Tezos Protocol Implementation - Protocol Signature Instance *)
open Hash
open Error_monad
type operation = Tezos_context.operation
let parse_operation = Tezos_context.Operation.parse
let max_operation_data_length =
Tezos_context.Operation.max_operation_data_length
let max_number_of_operations =
Tezos_context.Constants.max_number_of_operations
let max_block_length =
Tezos_context.Block_header.max_header_length
let rpc_services = Services_registration.rpc_services
type validation_mode =
| Application of {
block_header : Tezos_context.Block_header.t ;
miner : Tezos_context.public_key_hash ;
}
| Partial_construction of {
predecessor : Block_hash.t ;
}
| Full_construction of {
predecessor : Block_hash.t ;
block_proto_header : Tezos_context.Block_header.proto_header ;
miner : Tezos_context.public_key_hash ;
}
type validation_state =
{ mode : validation_mode ;
ctxt : Tezos_context.t ;
op_count : int }
(*
let current_context { ctxt } =
return (Tezos_context.finalize ctxt).context
*)
let precheck_block
~ancestor_context:_
~ancestor_timestamp:_
raw_block =
Lwt.return (Tezos_context.Block_header.parse raw_block) >>=? fun _ ->
(* TODO: decide what other properties should be checked *)
return ()
let begin_application
~predecessor_context:ctxt
~predecessor_timestamp:pred_timestamp
~predecessor_fitness:pred_fitness
raw_block =
Lwt.return (Tezos_context.Block_header.parse raw_block) >>=? fun block_header ->
let level = block_header.shell.level in
let fitness = pred_fitness in
let timestamp = block_header.shell.timestamp in
Tezos_context.init ~level ~timestamp ~fitness ctxt >>=? fun ctxt ->
Apply.begin_application
ctxt block_header pred_timestamp >>=? fun (ctxt, miner) ->
let mode = Application { block_header ; miner } in
return { mode ; ctxt ; op_count = 0 }
let begin_construction
~predecessor_context:ctxt
~predecessor_timestamp:pred_timestamp
~predecessor_level:pred_level
~predecessor_fitness:pred_fitness
~predecessor
~timestamp
?proto_header
() =
let level = Int32.succ pred_level in
let fitness = pred_fitness in
Tezos_context.init ~timestamp ~level ~fitness ctxt >>=? fun ctxt ->
begin
match proto_header with
| None ->
Apply.begin_partial_construction ctxt >>=? fun ctxt ->
let mode = Partial_construction { predecessor } in
return (mode, ctxt)
| Some proto_header ->
Apply.begin_full_construction
ctxt pred_timestamp
proto_header >>=? fun (ctxt, block_proto_header, miner) ->
let mode =
Full_construction { predecessor ; miner ; block_proto_header } in
return (mode, ctxt)
end >>=? fun (mode, ctxt) ->
return { mode ; ctxt ; op_count = 0 }
let apply_operation ({ mode ; ctxt ; op_count } as data) operation =
let pred_block, block_prio, miner_contract =
match mode with
| Partial_construction { predecessor } ->
predecessor, 0, None
| Application
{ miner ; block_header = { shell = { predecessor } ;
proto = block_proto_header } }
| Full_construction { predecessor ; block_proto_header ; miner } ->
predecessor,
block_proto_header.priority,
Some (Tezos_context.Contract.default_contract miner) in
Apply.apply_operation
ctxt miner_contract pred_block block_prio operation
>>=? fun (ctxt, _contracts, _ignored_script_error) ->
let op_count = op_count + 1 in
return { data with ctxt ; op_count }
let finalize_block { mode ; ctxt ; op_count } = match mode with
| Partial_construction _ ->
(* let ctxt = Tezos_context.finalize ctxt in *)
return ctxt
| Application
{ miner ; block_header = { proto = block_proto_header } }
| Full_construction { block_proto_header ; miner } ->
Apply.finalize_application ctxt block_proto_header miner >>=? fun ctxt ->
let { level } : Tezos_context.Level.t =
Tezos_context. Level.current ctxt in
let priority = block_proto_header.priority in
let level = Tezos_context.Raw_level.to_int32 level in
let fitness = Tezos_context.Fitness.current ctxt in
let commit_message =
Format.asprintf
"lvl %ld, fit %Ld, prio %d, %d ops"
level fitness priority op_count in
(* let ctxt = Tezos_context.finalize ~commit_message ctxt in *)
return ctxt
let compare_operations op1 op2 =
Apply.compare_operations op1 op2
let configure_sandbox = Tezos_context.configure_sandbox