Source file configuration.ml
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
type mode =
| Observer
| Accuser
| Bailout
| Batcher
| Maintenance
| Operator
| Custom
type operation_kind = Publish | Add_messages | Cement | Timeout | Refute
type purpose = Operating | Batching | Cementing
let operation_kinds = [Publish; Add_messages; Cement; Timeout; Refute]
let purposes = [Operating; Batching; Cementing]
module Operation_kind_map = Map.Make (struct
type t = operation_kind
let compare = Stdlib.compare
end)
module Operator_purpose_map = Map.Make (struct
type t = purpose
let compare = Stdlib.compare
end)
type operators = Signature.Public_key_hash.t Operator_purpose_map.t
type fee_parameters = Injector_sigs.fee_parameter Operation_kind_map.t
type batcher = {
simulate : bool;
min_batch_elements : int;
min_batch_size : int;
max_batch_elements : int;
max_batch_size : int option;
}
type injector = {retention_period : int; attempts : int; injection_ttl : int}
type t = {
sc_rollup_address : Tezos_crypto.Hashed.Smart_rollup_address.t;
boot_sector_file : string option;
sc_rollup_node_operators : operators;
rpc_addr : string;
rpc_port : int;
metrics_addr : string option;
reconnection_delay : float;
fee_parameters : fee_parameters;
mode : mode;
loser_mode : Loser_mode.t;
dal_node_endpoint : Uri.t option;
dac_observer_endpoint : Uri.t option;
dac_timeout : Z.t option;
batcher : batcher;
injector : injector;
l1_blocks_cache_size : int;
l2_blocks_cache_size : int;
prefetch_blocks : int option;
log_kernel_debug : bool;
}
type error +=
| Missing_mode_operators of {mode : string; missing_operators : string list}
let () =
register_error_kind
~id:"sc_rollup.node.missing_mode_operators"
~title:"Missing operators for the chosen mode"
~description:"Missing operators for the chosen mode."
~pp:(fun ppf (mode, missing_operators) ->
Format.fprintf
ppf
"@[<hov>Missing operators %a for mode %s.@]"
(Format.pp_print_list
~pp_sep:(fun ppf () -> Format.fprintf ppf ",@ ")
Format.pp_print_string)
missing_operators
mode)
`Permanent
Data_encoding.(
obj2 (req "mode" string) (req "missing_operators" (list string)))
(function
| Missing_mode_operators {mode; missing_operators} ->
Some (mode, missing_operators)
| _ -> None)
(fun (mode, missing_operators) ->
Missing_mode_operators {mode; missing_operators})
let default_data_dir =
Filename.concat (Sys.getenv "HOME") ".tezos-smart-rollup-node"
let storage_dir = "storage"
let context_dir = "context"
let default_storage_dir data_dir = Filename.concat data_dir storage_dir
let default_context_dir data_dir = Filename.concat data_dir context_dir
let config_filename ~data_dir = Filename.concat data_dir "config.json"
let default_rpc_addr = "127.0.0.1"
let default_rpc_port = 8932
let default_metrics_port = 9933
let default_reconnection_delay = 2.0
let mutez mutez = {Injector_sigs.mutez}
let tez t = mutez Int64.(mul (of_int t) 1_000_000L)
let default_minimal_fees = mutez 100L
let default_minimal_nanotez_per_gas_unit = Q.of_int 100
let default_minimal_nanotez_per_byte = Q.of_int 1000
let default_force_low_fee = false
let default_fee_cap = tez 1
let default_burn_cap = mutez 0L
let default_fee = function
| Cement -> tez 1
| Publish -> tez 2
| Add_messages ->
tez 1
| Timeout -> tez 2
| Refute ->
tez 5
let default_burn = function
| Publish ->
tez 1
| Add_messages -> tez 0
| Cement -> tez 0
| Timeout -> tez 0
| Refute ->
tez 1
let default_fee_parameter ?operation_kind () =
let fee_cap, burn_cap =
match operation_kind with
| None -> (default_fee_cap, default_burn_cap)
| Some kind -> (default_fee kind, default_burn kind)
in
{
Injector_sigs.minimal_fees = default_minimal_fees;
minimal_nanotez_per_byte = default_minimal_nanotez_per_byte;
minimal_nanotez_per_gas_unit = default_minimal_nanotez_per_gas_unit;
force_low_fee = default_force_low_fee;
fee_cap;
burn_cap;
}
let default_fee_parameters =
List.fold_left
(fun acc operation_kind ->
Operation_kind_map.add
operation_kind
(default_fee_parameter ~operation_kind ())
acc)
Operation_kind_map.empty
operation_kinds
let default_batcher_simulate = true
let default_batcher_min_batch_elements = 10
let default_batcher_min_batch_size = 10
let default_batcher_max_batch_elements = max_int
let default_batcher =
{
simulate = default_batcher_simulate;
min_batch_elements = default_batcher_min_batch_elements;
min_batch_size = default_batcher_min_batch_size;
max_batch_elements = default_batcher_max_batch_elements;
max_batch_size = None;
}
let default_injector =
{retention_period = 2048; attempts = 100; injection_ttl = 120}
let max_injector_retention_period =
5 * 8192
let default_l1_blocks_cache_size = 64
let default_l2_blocks_cache_size = 64
let operation_kinds_of_purpose = function
| Batching -> [Add_messages]
| Cementing -> [Cement]
| Operating -> [Publish; Refute; Timeout]
let string_of_operation_kind = function
| Publish -> "publish"
| Add_messages -> "add_messages"
| Cement -> "cement"
| Timeout -> "timeout"
| Refute -> "refute"
let operation_kind_of_string = function
| "publish" -> Some Publish
| "add_messages" -> Some Add_messages
| "cement" -> Some Cement
| "timeout" -> Some Timeout
| "refute" -> Some Refute
| _ -> None
let operation_kind_of_string_exn s =
match operation_kind_of_string s with
| Some p -> p
| None -> invalid_arg ("operation_kind_of_string " ^ s)
let string_of_purpose = function
| Operating -> "operating"
| Batching -> "batching"
| Cementing -> "cementing"
let purpose_of_string = function
| "operating" | "publish" | "refute" | "timeout" -> Some Operating
| "batching" | "add_messages" -> Some Batching
| "cementing" | "cement" -> Some Cementing
| _ -> None
let purpose_of_string_exn s =
match purpose_of_string s with
| Some p -> p
| None -> invalid_arg ("purpose_of_string " ^ s)
let make_purpose_map ~default bindings =
let map = Operator_purpose_map.of_seq @@ List.to_seq bindings in
match default with
| None -> map
| Some default ->
List.fold_left
(fun map purpose ->
Operator_purpose_map.update purpose (fun _ -> Some default) map)
map
purposes
let dictionary_encoding (keys : 'k list) (string_of_key : 'k -> string)
(key_of_string : string -> 'k) (value_encoding : 'k -> 'v Data_encoding.t) :
('k * 'v) list Data_encoding.t =
let open Data_encoding in
let schema =
let open Json_schema in
let value_schema key = Data_encoding.Json.schema (value_encoding key) in
let value_schema_r key = root (value_schema key) in
let kind =
Object
{
properties =
List.map
(fun key -> (string_of_key key, value_schema_r key, false, None))
keys;
pattern_properties = [];
additional_properties = None;
min_properties = 0;
max_properties = None;
schema_dependencies = [];
property_dependencies = [];
}
in
update
(element kind)
(value_schema
(List.hd keys |> WithExceptions.Option.get ~loc:__LOC__)
)
in
conv
~schema
(fun map ->
let fields =
map
|> List.map (fun (k, v) ->
( string_of_key k,
Data_encoding.Json.construct (value_encoding k) v ))
in
`O fields)
(function
| `O fields ->
List.map
(fun (k, v) ->
let k = key_of_string k in
(k, Data_encoding.Json.destruct (value_encoding k) v))
fields
| _ -> assert false)
Data_encoding.Json.encoding
let operator_purpose_map_encoding encoding =
let open Data_encoding in
conv
Operator_purpose_map.bindings
(fun l -> List.to_seq l |> Operator_purpose_map.of_seq)
(dictionary_encoding
purposes
string_of_purpose
purpose_of_string_exn
encoding)
let operation_kind_map_encoding encoding =
let open Data_encoding in
conv
Operation_kind_map.bindings
(fun l -> List.to_seq l |> Operation_kind_map.of_seq)
(dictionary_encoding
operation_kinds
string_of_operation_kind
operation_kind_of_string_exn
encoding)
let operators_encoding =
operator_purpose_map_encoding (fun _ -> Signature.Public_key_hash.encoding)
let tez_encoding =
let open Data_encoding in
let decode {Injector_sigs.mutez} = Z.of_int64 mutez in
let encode =
Json.wrap_error (fun i -> {Injector_sigs.mutez = Z.to_int64 i})
in
Data_encoding.def
"mutez"
~title:"A millionth of a tez"
~description:"One million mutez make a tez (1 tez = 1e6 mutez)"
(conv decode encode n)
let nanotez_encoding =
let open Data_encoding in
def
"nanotez"
~title:"A thousandth of a mutez"
~description:"One thousand nanotez make a mutez (1 tez = 1e9 nanotez)"
(conv
(fun q -> (q.Q.num, q.Q.den))
(fun (num, den) -> {Q.num; den})
(tup2 z z))
let fee_parameter_encoding operation_kind =
let open Data_encoding in
conv
(fun {
Injector_sigs.minimal_fees;
minimal_nanotez_per_byte;
minimal_nanotez_per_gas_unit;
force_low_fee;
fee_cap;
burn_cap;
} ->
( minimal_fees,
minimal_nanotez_per_byte,
minimal_nanotez_per_gas_unit,
force_low_fee,
fee_cap,
burn_cap ))
(fun ( minimal_fees,
minimal_nanotez_per_byte,
minimal_nanotez_per_gas_unit,
force_low_fee,
fee_cap,
burn_cap ) ->
{
minimal_fees;
minimal_nanotez_per_byte;
minimal_nanotez_per_gas_unit;
force_low_fee;
fee_cap;
burn_cap;
})
(obj6
(dft
"minimal-fees"
~description:"Exclude operations with lower fees"
tez_encoding
default_minimal_fees)
(dft
"minimal-nanotez-per-byte"
~description:"Exclude operations with lower fees per byte"
nanotez_encoding
default_minimal_nanotez_per_byte)
(dft
"minimal-nanotez-per-gas-unit"
~description:"Exclude operations with lower gas fees"
nanotez_encoding
default_minimal_nanotez_per_gas_unit)
(dft
"force-low-fee"
~description:
"Don't check that the fee is lower than the estimated default"
bool
default_force_low_fee)
(dft
"fee-cap"
~description:"The fee cap"
tez_encoding
(default_fee operation_kind))
(dft
"burn-cap"
~description:"The burn cap"
tez_encoding
(default_burn operation_kind)))
let fee_parameters_encoding = operation_kind_map_encoding fee_parameter_encoding
let modes = [Observer; Batcher; Maintenance; Operator; Custom; Bailout]
let string_of_mode = function
| Observer -> "observer"
| Accuser -> "accuser"
| Bailout -> "bailout"
| Batcher -> "batcher"
| Maintenance -> "maintenance"
| Operator -> "operator"
| Custom -> "custom"
let mode_of_string = function
| "observer" -> Ok Observer
| "accuser" -> Ok Accuser
| "bailout" -> Ok Bailout
| "batcher" -> Ok Batcher
| "maintenance" -> Ok Maintenance
| "operator" -> Ok Operator
| "custom" -> Ok Custom
| _ -> Error [Exn (Failure "Invalid mode")]
let description_of_mode = function
| Observer -> "Only follows the chain, reconstructs and interprets inboxes"
| Accuser ->
"Only publishes commitments for conflicts and play refutation games"
| Bailout -> "Only defends and cements, does not publish any new commitments"
| Batcher -> "Accepts transactions in its queue and batches them on the L1"
| Maintenance ->
"Follows the chain and publishes commitments, cement and refute"
| Operator -> "Equivalent to maintenance + batcher"
| Custom ->
"In this mode, only operations that have a corresponding operator/signer \
are injected"
let mode_encoding =
Data_encoding.string_enum
[
("observer", Observer);
("accuser", Accuser);
("bailout", Bailout);
("batcher", Batcher);
("maintenance", Maintenance);
("operator", Operator);
("custom", Custom);
]
let batcher_encoding =
let open Data_encoding in
conv_with_guard
(fun {
simulate;
min_batch_elements;
min_batch_size;
max_batch_elements;
max_batch_size;
} ->
( simulate,
min_batch_elements,
min_batch_size,
max_batch_elements,
max_batch_size ))
(fun ( simulate,
min_batch_elements,
min_batch_size,
max_batch_elements,
max_batch_size ) ->
let open Result_syntax in
let error_when c s = if c then Error s else return_unit in
let* () =
error_when (min_batch_size <= 0) "min_batch_size must be positive"
in
let* () =
match max_batch_size with
| Some m when m < min_batch_size ->
Error "max_batch_size must be greater than min_batch_size"
| _ -> return_unit
in
let* () =
error_when (min_batch_elements <= 0) "min_batch_size must be positive"
in
let+ () =
error_when
(max_batch_elements < min_batch_elements)
"max_batch_elements must be greater than min_batch_elements"
in
{
simulate;
min_batch_elements;
min_batch_size;
max_batch_elements;
max_batch_size;
})
@@ obj5
(dft "simulate" bool default_batcher_simulate)
(dft "min_batch_elements" int31 default_batcher_min_batch_elements)
(dft "min_batch_size" int31 default_batcher_min_batch_size)
(dft "max_batch_elements" int31 default_batcher_max_batch_elements)
(opt "max_batch_size" int31)
let injector_encoding : injector Data_encoding.t =
let open Data_encoding in
conv
(fun {retention_period; attempts; injection_ttl} ->
(retention_period, attempts, injection_ttl))
(fun (retention_period, attempts, injection_ttl) ->
if retention_period > max_injector_retention_period then
Format.ksprintf
Stdlib.failwith
"injector.retention_period should be smaller than %d"
max_injector_retention_period ;
if injection_ttl < 1 then
Stdlib.failwith "injector.injection_ttl should be at least 1" ;
{retention_period; attempts; injection_ttl})
@@ obj3
(dft "retention_period" uint16 default_injector.retention_period)
(dft "attempts" uint16 default_injector.attempts)
(dft "injection_ttl" uint16 default_injector.injection_ttl)
let encoding : t Data_encoding.t =
let open Data_encoding in
conv
(fun {
sc_rollup_address;
boot_sector_file;
sc_rollup_node_operators;
rpc_addr;
rpc_port;
metrics_addr;
reconnection_delay;
fee_parameters;
mode;
loser_mode;
dal_node_endpoint;
dac_observer_endpoint;
dac_timeout;
batcher;
injector;
l1_blocks_cache_size;
l2_blocks_cache_size;
prefetch_blocks;
log_kernel_debug;
} ->
( ( sc_rollup_address,
boot_sector_file,
sc_rollup_node_operators,
rpc_addr,
rpc_port,
metrics_addr,
reconnection_delay,
fee_parameters,
mode,
loser_mode ),
( dal_node_endpoint,
dac_observer_endpoint,
dac_timeout,
batcher,
injector,
l1_blocks_cache_size,
l2_blocks_cache_size,
prefetch_blocks,
log_kernel_debug ) ))
(fun ( ( sc_rollup_address,
boot_sector_file,
sc_rollup_node_operators,
rpc_addr,
rpc_port,
metrics_addr,
reconnection_delay,
fee_parameters,
mode,
loser_mode ),
( dal_node_endpoint,
dac_observer_endpoint,
dac_timeout,
batcher,
injector,
l1_blocks_cache_size,
l2_blocks_cache_size,
prefetch_blocks,
log_kernel_debug ) ) ->
{
sc_rollup_address;
boot_sector_file;
sc_rollup_node_operators;
rpc_addr;
rpc_port;
metrics_addr;
reconnection_delay;
fee_parameters;
mode;
loser_mode;
dal_node_endpoint;
dac_observer_endpoint;
dac_timeout;
batcher;
injector;
l1_blocks_cache_size;
l2_blocks_cache_size;
prefetch_blocks;
log_kernel_debug;
})
(merge_objs
(obj10
(req
"smart-rollup-address"
~description:"Smart rollup address"
Tezos_crypto.Hashed.Smart_rollup_address.encoding)
(opt "boot-sector" ~description:"Boot sector" string)
(req
"smart-rollup-node-operator"
~description:
"Operators that sign operations of the smart rollup, by purpose"
operators_encoding)
(dft "rpc-addr" ~description:"RPC address" string default_rpc_addr)
(dft "rpc-port" ~description:"RPC port" uint16 default_rpc_port)
(opt "metrics-addr" ~description:"Metrics address" string)
(dft
"reconnection_delay"
~description:
"The reconnection (to the tezos node) delay in seconds"
float
default_reconnection_delay)
(dft
"fee-parameters"
~description:
"The fee parameters for each purpose used when injecting \
operations in L1"
fee_parameters_encoding
default_fee_parameters)
(req
~description:"The mode for this rollup node"
"mode"
mode_encoding)
(dft
"loser-mode"
~description:
"If enabled, the rollup node will issue wrong commitments (for \
test only!)"
Loser_mode.encoding
Loser_mode.no_failures))
(obj9
(opt "DAL node endpoint" Tezos_rpc.Encoding.uri_encoding)
(opt "dac-observer-client" Tezos_rpc.Encoding.uri_encoding)
(opt "dac-timeout" Data_encoding.z)
(dft "batcher" batcher_encoding default_batcher)
(dft "injector" injector_encoding default_injector)
(dft "l1_blocks_cache_size" int31 default_l1_blocks_cache_size)
(dft "l2_blocks_cache_size" int31 default_l2_blocks_cache_size)
(opt "prefetch_blocks" int31)
(dft "log-kernel-debug" Data_encoding.bool false)))
let check_mode config =
let open Result_syntax in
let check_purposes purposes =
let missing_operators =
List.filter
(fun p ->
not (Operator_purpose_map.mem p config.sc_rollup_node_operators))
purposes
in
if missing_operators <> [] then
let mode = string_of_mode config.mode in
let missing_operators = List.map string_of_purpose missing_operators in
tzfail (Missing_mode_operators {mode; missing_operators})
else return_unit
in
let narrow_purposes purposes =
let* () = check_purposes purposes in
let sc_rollup_node_operators =
Operator_purpose_map.filter
(fun op_purpose _ -> List.mem ~equal:Stdlib.( = ) op_purpose purposes)
config.sc_rollup_node_operators
in
return {config with sc_rollup_node_operators}
in
match config.mode with
| Observer -> narrow_purposes []
| Batcher -> narrow_purposes [Batching]
| Accuser -> narrow_purposes [Operating]
| Bailout -> narrow_purposes [Operating; Cementing]
| Maintenance -> narrow_purposes [Operating; Cementing]
| Operator -> narrow_purposes [Operating; Cementing; Batching]
| Custom -> return config
let refutation_player_buffer_levels = 5
let loser_warning_message config =
if config.loser_mode <> Loser_mode.no_failures then
Format.printf
{|
************ WARNING *************
This rollup node is in loser mode.
This should be used for test only!
************ WARNING *************
|}
let save ~force ~data_dir config =
loser_warning_message config ;
let open Lwt_result_syntax in
let json = Data_encoding.Json.construct encoding config in
let config_file = config_filename ~data_dir in
let*! exists = Lwt_unix.file_exists config_file in
if exists && not force then
failwith
"Configuration file %S already exists. Use --force to overwrite."
config_file
else
let*! () = Lwt_utils_unix.create_dir data_dir in
Lwt_utils_unix.Json.write_file config_file json
let load ~data_dir =
let open Lwt_result_syntax in
let+ json = Lwt_utils_unix.Json.read_file (config_filename ~data_dir) in
let config = Data_encoding.Json.destruct encoding json in
loser_warning_message config ;
config
module Cli = struct
let make_operators sc_rollup_node_operators =
let purposed_operators, default_operators =
List.partition_map
(function
| `Purpose p_operator -> Left p_operator
| `Default operator -> Right operator)
sc_rollup_node_operators
in
let default_operator =
match default_operators with
| [] -> None
| [default_operator] -> Some default_operator
| _ -> Stdlib.failwith "Multiple default operators"
in
make_purpose_map purposed_operators ~default:default_operator
let configuration_from_args ~rpc_addr ~rpc_port ~metrics_addr ~loser_mode
~reconnection_delay ~dal_node_endpoint ~dac_observer_endpoint ~dac_timeout
~injector_retention_period ~injector_attempts ~injection_ttl ~mode
~sc_rollup_address ~boot_sector_file ~sc_rollup_node_operators
~log_kernel_debug =
let sc_rollup_node_operators = make_operators sc_rollup_node_operators in
let config =
{
sc_rollup_address;
boot_sector_file;
sc_rollup_node_operators;
rpc_addr = Option.value ~default:default_rpc_addr rpc_addr;
rpc_port = Option.value ~default:default_rpc_port rpc_port;
reconnection_delay =
Option.value ~default:default_reconnection_delay reconnection_delay;
dal_node_endpoint;
dac_observer_endpoint;
dac_timeout;
metrics_addr;
fee_parameters = Operation_kind_map.empty;
mode;
loser_mode = Option.value ~default:Loser_mode.no_failures loser_mode;
batcher = default_batcher;
injector =
{
retention_period =
Option.value
~default:default_injector.retention_period
injector_retention_period;
attempts =
Option.value ~default:default_injector.attempts injector_attempts;
injection_ttl =
Option.value ~default:default_injector.injection_ttl injection_ttl;
};
l1_blocks_cache_size = default_l1_blocks_cache_size;
l2_blocks_cache_size = default_l2_blocks_cache_size;
prefetch_blocks = None;
log_kernel_debug;
}
in
check_mode config
let patch_configuration_from_args configuration ~rpc_addr ~rpc_port
~metrics_addr ~loser_mode ~reconnection_delay ~dal_node_endpoint
~dac_observer_endpoint ~dac_timeout ~injector_retention_period
~injector_attempts ~injection_ttl ~mode ~sc_rollup_address
~boot_sector_file ~sc_rollup_node_operators ~log_kernel_debug =
let new_sc_rollup_node_operators =
make_operators sc_rollup_node_operators
in
let sc_rollup_node_operators =
Operator_purpose_map.merge
(fun _purpose -> Option.either)
new_sc_rollup_node_operators
configuration.sc_rollup_node_operators
in
let configuration =
{
configuration with
sc_rollup_address =
Option.value
~default:configuration.sc_rollup_address
sc_rollup_address;
boot_sector_file =
Option.either boot_sector_file configuration.boot_sector_file;
sc_rollup_node_operators;
mode = Option.value ~default:configuration.mode mode;
rpc_addr = Option.value ~default:configuration.rpc_addr rpc_addr;
rpc_port = Option.value ~default:configuration.rpc_port rpc_port;
dal_node_endpoint =
Option.either dal_node_endpoint configuration.dal_node_endpoint;
dac_observer_endpoint =
Option.either
dac_observer_endpoint
configuration.dac_observer_endpoint;
dac_timeout = Option.either dac_timeout configuration.dac_timeout;
reconnection_delay =
Option.value
~default:configuration.reconnection_delay
reconnection_delay;
injector =
{
retention_period =
Option.value
~default:default_injector.retention_period
injector_retention_period;
attempts =
Option.value ~default:default_injector.attempts injector_attempts;
injection_ttl =
Option.value ~default:default_injector.injection_ttl injection_ttl;
};
loser_mode = Option.value ~default:configuration.loser_mode loser_mode;
metrics_addr = Option.either metrics_addr configuration.metrics_addr;
log_kernel_debug = log_kernel_debug || configuration.log_kernel_debug;
}
in
check_mode configuration
let create_or_read_config ~data_dir ~rpc_addr ~rpc_port ~metrics_addr
~loser_mode ~reconnection_delay ~dal_node_endpoint ~dac_observer_endpoint
~dac_timeout ~injector_retention_period ~injector_attempts ~injection_ttl
~mode ~sc_rollup_address ~boot_sector_file ~sc_rollup_node_operators
~log_kernel_debug =
let open Lwt_result_syntax in
let open Filename.Infix in
let* () =
let*! identity_file_in_data_dir_exists =
Lwt_unix.file_exists (data_dir // "identity.json")
in
if identity_file_in_data_dir_exists then
failwith
"Invalid data directory. This is a data directory for an Octez node, \
please choose a different directory for the smart rollup node data."
else return_unit
in
let config_file = config_filename ~data_dir in
let*! exists_config = Lwt_unix.file_exists config_file in
if exists_config then
let* configuration = load ~data_dir in
let*? configuration =
patch_configuration_from_args
configuration
~rpc_addr
~rpc_port
~metrics_addr
~loser_mode
~reconnection_delay
~dal_node_endpoint
~dac_observer_endpoint
~dac_timeout
~injector_retention_period
~injector_attempts
~injection_ttl
~mode
~sc_rollup_address
~boot_sector_file
~sc_rollup_node_operators
~log_kernel_debug
in
return configuration
else
let*? mode =
Option.value_e
mode
~error:
(TzTrace.make
@@ error_of_fmt
"Argument --mode is required when configuration file is not \
present.")
in
let*? sc_rollup_address =
Option.value_e
sc_rollup_address
~error:
(TzTrace.make
@@ error_of_fmt
"Argument --rollup is required when configuration file is not \
present.")
in
let*? config =
configuration_from_args
~rpc_addr
~rpc_port
~metrics_addr
~loser_mode
~reconnection_delay
~dal_node_endpoint
~dac_observer_endpoint
~dac_timeout
~injector_retention_period
~injector_attempts
~injection_ttl
~mode
~sc_rollup_address
~boot_sector_file
~sc_rollup_node_operators
~log_kernel_debug
in
return config
end