-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathconfiguration.rs
More file actions
1638 lines (1545 loc) · 68.2 KB
/
Copy pathconfiguration.rs
File metadata and controls
1638 lines (1545 loc) · 68.2 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
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
997
998
999
1000
// Copyright 2019 Conflux Foundation. All rights reserved.
// Conflux is free software and distributed under GNU General Public License.
// See http://www.gnu.org/licenses/
use std::{collections::BTreeMap, convert::TryInto, path::PathBuf, sync::Arc};
use cfx_rpc_builder::RpcModuleSelection;
use lazy_static::*;
use log::{error, warn};
use parking_lot::RwLock;
use rand::Rng;
use cfx_addr::{cfx_addr_decode, Network};
use cfx_executor::{machine::Machine, spec::CommonParams};
use cfx_internal_common::{
ChainIdParams, ChainIdParamsInner, ChainIdParamsOneChainInner,
};
use cfx_parameters::{
block::DEFAULT_TARGET_BLOCK_GAS_LIMIT, tx_pool::TXPOOL_DEFAULT_NONCE_BITS,
};
use cfx_rpc_cfx_types::{
address::USE_SIMPLE_RPC_ADDRESS, apis::ApiSet, RpcImplConfiguration,
};
use cfx_storage::{
defaults::DEFAULT_DEBUG_SNAPSHOT_CHECKER_THREADS, storage_dir,
ConsensusParam, ProvideExtraSnapshotSyncConfig, StorageConfiguration,
};
use cfx_types::{
parse_hex_string, Address, AllChainID, Space, SpaceMap, H256, U256,
};
use cfxcore::{
block_data_manager::{DataManagerConfiguration, DbType},
block_parameters::*,
cache_config::{
DEFAULT_INVALID_BLOCK_HASH_CACHE_SIZE_IN_COUNT,
DEFAULT_LEDGER_CACHE_SIZE,
DEFAULT_TARGET_DIFFICULTIES_CACHE_SIZE_IN_COUNT,
},
consensus::{
consensus_inner::consensus_executor::ConsensusExecutionConfiguration,
pivot_hint::PivotHintConfig, ConsensusConfig, ConsensusInnerConfig,
},
consensus_internal_parameters::*,
consensus_parameters::*,
light_protocol::LightNodeConfiguration,
sync::{ProtocolConfiguration, StateSyncConfiguration, SyncGraphConfig},
sync_parameters::*,
transaction_pool::TxPoolConfig,
NodeType,
};
use diem_types::term_state::{
pos_state_config::PosStateConfig, IN_QUEUE_LOCKED_VIEWS,
OUT_QUEUE_LOCKED_VIEWS, ROUND_PER_TERM, TERM_ELECTED_SIZE, TERM_MAX_SIZE,
};
use jsonrpsee::server::ServerConfigBuilder;
use metrics::MetricsConfiguration;
use network::DiscoveryConfiguration;
use primitives::block_header::CIP112_TRANSITION_HEIGHT;
use txgen::TransactionGeneratorConfig;
use crate::{HttpConfiguration, WsConfiguration};
lazy_static! {
pub static ref CHAIN_ID: RwLock<Option<ChainIdParams>> = Default::default();
}
const BLOCK_DB_DIR_NAME: &str = "blockchain_db";
const NET_CONFIG_DB_DIR_NAME: &str = "net_config";
// usage:
// ```
// build_config! {
// {
// (name, (type), default_value)
// ...
// }
// {
// (name, (type), default_value, converter)
// }
// }
// ```
// `converter` is a function used to convert a provided String to `Result<type,
// String>`. For each entry, field `name` of type `type` will be created in
// `RawConfiguration`, and it will be assigned to the value passed through
// commandline argument or configuration file. Commandline argument will
// override the configuration file if the parameter is given in both.
build_config! {
{
// Configs are grouped by section. Within one section configs should
// be kept in alphabetical order for the sake of indexing and maintenance.
//
// Some preset configurations.
//
// For both `test` and `dev` modes, we will
// * Set initial difficulty to 4
// * Allow calling test and debug rpc from public port
//
// `test` mode is for Conflux testing and debugging, we will
// * Add latency to peer connections
// * Skip handshake encryption check
// * Skip header timestamp verification
// * Handle NewBlockHash even in catch-up mode
// * Allow data propagation test
// * Allow setting genesis accounts and generate tx from secrets
//
// `dev` mode is for users to run a single node that automatically
// generates blocks with fixed intervals
// * You are expected to also set `jsonrpc_ws_port`,
// and `jsonrpc_http_port` if you want RPC functionalities.
// * generate blocks automatically without PoW.
// * Skip catch-up mode even there is no peer
//
(mode, (Option<String>), None)
// Development related section.
(debug_invalid_state_root, (bool), false)
(debug_invalid_state_root_epoch, (Option<String>), None)
(debug_dump_dir_invalid_state_root, (String), "./storage_db/debug_dump_invalid_state_root/".to_string())
// Controls block generation speed.
// Only effective in `dev` mode
(dev_block_interval_ms, (Option<u64>), None)
(dev_pack_tx_immediately, (Option<bool>), None)
(enable_state_expose, (bool), false)
(generate_tx, (bool), false)
(generate_tx_period_us, (Option<u64>), Some(100_000))
(log_conf, (Option<String>), None)
(log_file, (Option<String>), None)
(max_block_size_in_bytes, (usize), MAX_BLOCK_SIZE_IN_BYTES)
(evm_transaction_block_ratio,(u64),EVM_TRANSACTION_BLOCK_RATIO)
(evm_transaction_gas_ratio,(u64),EVM_TRANSACTION_GAS_RATIO)
(metrics_enabled, (bool), false)
(metrics_influxdb_host, (Option<String>), None)
(metrics_influxdb_db, (String), "conflux".into())
(metrics_influxdb_username, (Option<String>), None)
(metrics_influxdb_password, (Option<String>), None)
(metrics_influxdb_node, (Option<String>), None)
(metrics_output_file, (Option<String>), None)
(metrics_report_interval_ms, (u64), 3_000)
(metrics_prometheus_listen_addr, (Option<String>), None)
(profiling_listen_addr, (Option<String>), None)
(rocksdb_disable_wal, (bool), false)
(txgen_account_count, (usize), 10)
// Genesis section.
(adaptive_weight_beta, (u64), ADAPTIVE_WEIGHT_DEFAULT_BETA)
(anticone_penalty_ratio, (u64), ANTICONE_PENALTY_RATIO)
(chain_id, (Option<u32>), None)
(evm_chain_id, (Option<u32>), None)
(execute_genesis, (bool), true)
(default_transition_time, (Option<u64>), None)
// Snapshot Epoch Count is a consensus parameter. This flag overrides
// the parameter, which only take effect in `dev` mode.
(dev_snapshot_epoch_count, (u32), SNAPSHOT_EPOCHS_CAPACITY)
(era_epoch_count, (u64), ERA_DEFAULT_EPOCH_COUNT)
(heavy_block_difficulty_ratio, (u64), HEAVY_BLOCK_DEFAULT_DIFFICULTY_RATIO)
(genesis_accounts, (Option<String>), None)
(genesis_evm_secrets, (Option<String>), None)
(genesis_secrets, (Option<String>), None)
(pivot_hint_path, (Option<String>), None)
(pivot_hint_checksum, (Option<String>), None)
(initial_difficulty, (Option<u64>), None)
(referee_bound, (usize), REFEREE_DEFAULT_BOUND)
(timer_chain_beta, (u64), TIMER_CHAIN_DEFAULT_BETA)
(timer_chain_block_difficulty_ratio, (u64), TIMER_CHAIN_BLOCK_DEFAULT_DIFFICULTY_RATIO)
// FIXME: this is part of spec.
(transaction_epoch_bound, (u64), TRANSACTION_DEFAULT_EPOCH_BOUND)
// Hardfork section
// V1.1
(tanzanite_transition_height, (u64), TANZANITE_HEIGHT)
// V2.0
(hydra_transition_number, (Option<u64>), None)
(hydra_transition_height, (Option<u64>), None)
(cip43_init_end_number, (Option<u64>), None)
(cip78_patch_transition_number,(Option<u64>),None)
(cip90_transition_height,(Option<u64>),None)
(cip90_transition_number,(Option<u64>),None)
// V2.1
(dao_vote_transition_number, (Option<u64>), None)
(dao_vote_transition_height, (Option<u64>), None)
(cip105_transition_number, (Option<u64>), None)
(params_dao_vote_period, (u64), DAO_PARAMETER_VOTE_PERIOD)
// V2.2
(sigma_fix_transition_number, (Option<u64>), None)
// V2.3
(cip107_transition_number, (Option<u64>), None)
(cip112_transition_height, (Option<u64>), None)
(cip118_transition_number, (Option<u64>), None)
(cip119_transition_number, (Option<u64>), None)
// V2.4
(base_fee_burn_transition_number, (Option<u64>), None)
(base_fee_burn_transition_height, (Option<u64>), None)
(cip1559_transition_height, (Option<u64>), None)
(cip130_transition_height, (Option<u64>), None)
(cancun_opcodes_transition_number, (Option<u64>), None)
(min_native_base_price, (Option<u64>), None)
(min_eth_base_price, (Option<u64>), None)
// V2.5
(c2_fix_transition_height, (Option<u64>), None)
// V3.0
(eoa_code_transition_height, (Option<u64>), None)
(cip151_transition_height, (Option<u64>), None)
(cip645_transition_height, (Option<u64>), None)
(cip145_fix_transition_height, (Option<u64>), None)
// For test only
(align_evm_transition_height, (u64), u64::MAX)
// V3.1
(osaka_opcode_transition_height, (Option<u64>), None)
(cip166_transition_height, (Option<u64>), None)
(cip167_transition_height, (Option<u64>), None)
// Mining section.
(mining_author, (Option<String>), None)
(mining_type, (Option<String>), None)
(stratum_listen_address, (String), "127.0.0.1".into())
(stratum_port, (u16), 32525)
(stratum_secret, (Option<String>), None)
(use_octopus_in_test_mode, (bool), false)
(pow_problem_window_size, (usize), 1)
// Network section.
(jsonrpc_local_http_port, (Option<u16>), None)
(jsonrpc_local_ws_port, (Option<u16>), None)
(jsonrpc_ws_port, (Option<u16>), None)
(jsonrpc_http_port, (Option<u16>), None)
(jsonrpc_http_threads, (Option<usize>), None)
(jsonrpc_cors, (Option<String>), None)
(jsonrpc_http_keep_alive, (bool), false)
(jsonrpc_ws_max_payload_bytes, (usize), 30 * 1024 * 1024)
(jsonrpc_http_eth_port, (Option<u16>), None)
(jsonrpc_ws_eth_port, (Option<u16>), None)
(jsonrpc_max_request_body_size, (u32), 10 * 1024 * 1024)
(jsonrpc_max_response_body_size, (u32), 10 * 1024 * 1024)
(jsonrpc_max_connections, (u32), 100)
(jsonrpc_max_subscriptions_per_connection, (u32), 1024)
(jsonrpc_message_buffer_capacity, (u32), 1024)
// The network_id, if unset, defaults to the chain_id.
// Only override the network_id for local experiments,
// when user would like to keep the existing blockchain data
// but disconnect from the public network.
(network_id, (Option<u64>), None)
(rpc_enable_metrics, (bool), false)
(tcp_port, (u16), 32323)
(public_tcp_port, (Option<u16>), None)
(public_address, (Option<String>), None)
(udp_port, (Option<u16>), Some(32323))
(max_estimation_gas_limit, (Option<u64>), None)
(rpc_address_simple_mode, (bool), false)
// Network parameters section.
(blocks_request_timeout_ms, (u64), 20_000)
(check_request_period_ms, (u64), 1_000)
(chunk_size_byte, (u64), DEFAULT_CHUNK_SIZE)
(demote_peer_for_timeout, (bool), false)
(dev_allow_phase_change_without_peer, (bool), false)
(egress_queue_capacity, (usize), 256)
(egress_min_throttle, (usize), 10)
(egress_max_throttle, (usize), 64)
(expire_block_gc_period_s, (u64), 900)
(headers_request_timeout_ms, (u64), 10_000)
(heartbeat_period_interval_ms, (u64), 30_000)
(heartbeat_timeout_ms, (u64), 180_000)
(inflight_pending_tx_index_maintain_timeout_ms, (u64), 30_000)
(max_allowed_timeout_in_observing_period, (u64), 10)
(max_chunk_number_in_manifest, (usize), 500)
(max_downloading_chunks, (usize), 8)
(max_downloading_chunk_attempts, (usize), 5)
(max_downloading_manifest_attempts, (usize), 5)
(max_handshakes, (usize), 64)
(max_incoming_peers, (usize), 64)
(max_inflight_request_count, (u64), 64)
(max_outgoing_peers, (usize), 8)
(max_outgoing_peers_archive, (Option<usize>), None)
(max_peers_tx_propagation, (usize), 128)
(max_unprocessed_block_size_mb, (usize), (128))
(min_peers_tx_propagation, (usize), 8)
(min_phase_change_normal_peer_count, (usize), 3)
(received_tx_index_maintain_timeout_ms, (u64), 300_000)
(request_block_with_public, (bool), false)
(send_tx_period_ms, (u64), 1300)
(snapshot_candidate_request_timeout_ms, (u64), 10_000)
(snapshot_chunk_request_timeout_ms, (u64), 30_000)
(snapshot_manifest_request_timeout_ms, (u64), 30_000)
(sync_expire_block_timeout_s, (u64), 7200)
(throttling_conf, (Option<String>), None)
(timeout_observing_period_s, (u64), 600)
(transaction_request_timeout_ms, (u64), 30_000)
(tx_maintained_for_peer_timeout_ms, (u64), 600_000)
// Peer management section.
(bootnodes, (Option<String>), None)
(discovery_discover_node_count, (u32), 16)
(discovery_expire_time_s, (u64), 20)
(discovery_fast_refresh_timeout_ms, (u64), 10_000)
(discovery_find_node_timeout_ms, (u64), 2_000)
(discovery_housekeeping_timeout_ms, (u64), 1_000)
(discovery_max_nodes_ping, (usize), 32)
(discovery_ping_timeout_ms, (u64), 2_000)
(discovery_round_timeout_ms, (u64), 500)
(discovery_throttling_interval_ms, (u64), 1_000)
(discovery_throttling_limit_ping, (usize), 20)
(discovery_throttling_limit_find_nodes, (usize), 10)
(enable_discovery, (bool), true)
(netconf_dir, (Option<String>), None)
(net_key, (Option<String>), None)
(node_table_timeout_s, (u64), 300)
(node_table_promotion_timeout_s, (u64), 3 * 24 * 3600)
(session_ip_limits, (String), "1,8,4,2".into())
(subnet_quota, (usize), 128)
// Transaction cache/transaction pool section.
(tx_cache_index_maintain_timeout_ms, (u64), 300_000)
(tx_pool_size, (usize), 50_000)
(tx_pool_min_native_tx_gas_price, (Option<u64>), None)
(tx_pool_min_eth_tx_gas_price, (Option<u64>), None)
(tx_pool_nonce_bits, (usize), TXPOOL_DEFAULT_NONCE_BITS)
(tx_pool_allow_gas_over_half_block, (bool), false)
(max_packing_batch_gas_limit, (u64), 3_000_000)
(max_packing_batch_size, (usize), 50)
(packing_pool_degree, (u8), 4)
// Storage Section.
(additional_maintained_snapshot_count, (u32), 1)
// `None` for `additional_maintained*` means the data is never garbage collected.
(additional_maintained_block_body_epoch_count, (Option<usize>), None)
(additional_maintained_execution_result_epoch_count, (Option<usize>), None)
(additional_maintained_reward_epoch_count, (Option<usize>), None)
(additional_maintained_trace_epoch_count, (Option<usize>), None)
(additional_maintained_transaction_index_epoch_count, (Option<usize>), None)
(block_cache_gc_period_ms, (u64), 5_000)
(block_db_dir, (Option<String>), None)
(block_db_type, (String), "rocksdb".to_string())
(checkpoint_gc_time_in_era_count, (f64), 0.5)
// The conflux data dir, if unspecified, is the workdir where conflux is started.
(conflux_data_dir, (String), "./blockchain_data".to_string())
(enable_single_mpt_storage, (bool), false)
(ledger_cache_size, (usize), DEFAULT_LEDGER_CACHE_SIZE)
(invalid_block_hash_cache_size_in_count, (usize), DEFAULT_INVALID_BLOCK_HASH_CACHE_SIZE_IN_COUNT)
(rocksdb_cache_size, (Option<usize>), Some(128))
(rocksdb_compaction_profile, (Option<String>), None)
(storage_delta_mpts_cache_recent_lfu_factor, (f64), cfx_storage::defaults::DEFAULT_DELTA_MPTS_CACHE_RECENT_LFU_FACTOR)
(storage_delta_mpts_cache_size, (u32), cfx_storage::defaults::DEFAULT_DELTA_MPTS_CACHE_SIZE)
(storage_delta_mpts_cache_start_size, (u32), cfx_storage::defaults::DEFAULT_DELTA_MPTS_CACHE_START_SIZE)
(storage_delta_mpts_node_map_vec_size, (u32), cfx_storage::defaults::MAX_CACHED_TRIE_NODES_R_LFU_COUNTER)
(storage_delta_mpts_slab_idle_size, (u32), cfx_storage::defaults::DEFAULT_DELTA_MPTS_SLAB_IDLE_SIZE)
(storage_single_mpt_cache_size, (u32), cfx_storage::defaults::DEFAULT_DELTA_MPTS_CACHE_SIZE * 2)
(storage_single_mpt_cache_start_size, (u32), cfx_storage::defaults::DEFAULT_DELTA_MPTS_CACHE_START_SIZE * 2)
(storage_single_mpt_slab_idle_size, (u32), cfx_storage::defaults::DEFAULT_DELTA_MPTS_SLAB_IDLE_SIZE * 2)
(storage_max_open_snapshots, (u16), cfx_storage::defaults::DEFAULT_MAX_OPEN_SNAPSHOTS)
(storage_max_open_mpt_count, (u32), cfx_storage::defaults::DEFAULT_MAX_OPEN_MPT)
(strict_tx_index_gc, (bool), true)
(sync_state_starting_epoch, (Option<u64>), None)
(sync_state_epoch_gap, (Option<u64>), None)
(target_difficulties_cache_size_in_count, (usize), DEFAULT_TARGET_DIFFICULTIES_CACHE_SIZE_IN_COUNT)
// General/Unclassified section.
(account_provider_refresh_time_ms, (u64), 1000)
(check_phase_change_period_ms, (u64), 1000)
(enable_optimistic_execution, (bool), true)
(future_block_buffer_capacity, (usize), 32768)
(get_logs_filter_max_limit, (Option<usize>), None)
(get_logs_filter_max_epoch_range, (Option<u64>), None)
(get_logs_filter_max_block_number_range, (Option<u64>), None)
(get_logs_epoch_batch_size, (usize), 32)
(max_trans_count_received_in_catch_up, (u64), 60_000)
(persist_tx_index, (bool), false)
(persist_block_number_index, (bool), true)
(print_memory_usage_period_s, (Option<u64>), None)
(target_block_gas_limit, (u64), DEFAULT_TARGET_BLOCK_GAS_LIMIT)
(executive_trace, (bool), false)
(check_status_genesis, (bool), true)
(packing_gas_limit_block_count, (u64), 10)
(poll_lifetime_in_seconds, (Option<u32>), None)
// TreeGraph Section.
(is_consortium, (bool), false)
(pos_config_path, (Option<String>), Some("./pos_config/pos_config.yaml".to_string()))
(pos_genesis_pivot_decision, (Option<H256>), None)
(vrf_proposal_threshold, (U256), U256::from_str("1111111111111100000000000000000000000000000000000000000000000000").unwrap())
// Deferred epoch count before a confirmed epoch.
(pos_pivot_decision_defer_epoch_count, (u64), 50)
(cip113_pivot_decision_defer_epoch_count, (u64), 20)
(cip113_transition_height, (u64), u64::MAX)
(pos_reference_enable_height, (u64), u64::MAX)
(pos_initial_nodes_path, (String), "./pos_config/initial_nodes.json".to_string())
(pos_private_key_path, (String), "./pos_config/pos_key".to_string())
(pos_round_per_term, (u64), ROUND_PER_TERM)
(pos_term_max_size, (usize), TERM_MAX_SIZE)
(pos_term_elected_size, (usize), TERM_ELECTED_SIZE)
(pos_in_queue_locked_views, (u64), IN_QUEUE_LOCKED_VIEWS)
(pos_out_queue_locked_views, (u64), OUT_QUEUE_LOCKED_VIEWS)
(pos_cip99_transition_view, (u64), u64::MAX)
(pos_cip99_in_queue_locked_views, (u64), IN_QUEUE_LOCKED_VIEWS)
(pos_cip99_out_queue_locked_views, (u64), OUT_QUEUE_LOCKED_VIEWS)
(nonce_limit_transition_view, (u64), u64::MAX)
(pos_cip136_transition_view, (u64), u64::MAX)
(pos_cip136_in_queue_locked_views, (u64), IN_QUEUE_LOCKED_VIEWS)
(pos_cip136_out_queue_locked_views, (u64), OUT_QUEUE_LOCKED_VIEWS)
(pos_cip136_round_per_term, (u64), ROUND_PER_TERM)
(pos_cip156_transition_view, (u64), u64::MAX)
// 6 months with 30s rounds
(pos_cip156_dispute_locked_views, (u64), 6 * 30 * 24 * 60 * 2)
(pos_fix_cip156_transition_view, (u64), u64::MAX)
(dev_pos_private_key_encryption_password, (Option<String>), None)
(pos_started_as_voter, (bool), true)
// Light node section
(ln_epoch_request_batch_size, (Option<usize>), None)
(ln_epoch_request_timeout_sec, (Option<u64>), None)
(ln_header_request_batch_size, (Option<usize>), None)
(ln_header_request_timeout_sec, (Option<u64>), None)
(ln_max_headers_in_flight, (Option<usize>), None)
(ln_max_parallel_epochs_to_request, (Option<usize>), None)
(ln_num_epochs_to_request, (Option<usize>), None)
(ln_num_waiting_headers_threshold, (Option<usize>), None)
(keep_snapshot_before_stable_checkpoint, (bool), true)
(force_recompute_height_during_construct_pivot, (Option<u64>), None)
// The snapshot database consists of two tables: snapshot_key_value and snapshot_mpt. However, the size of snapshot_mpt is significantly larger than that of snapshot_key_value.
// When the configuration parameter use_isolated_db_for_mpt_table is set to true, the snapshot_mpt table will be located in a separate database.
(use_isolated_db_for_mpt_table, (bool), false)
// The use_isolated_db_for_mpt_table_height parameter is utilized to determine when to enable the use_isolated_db_for_mpt_table option.
// None: enabled since the next snapshot
// u64: enabled since the specified height
(use_isolated_db_for_mpt_table_height, (Option<u64>), None)
// Recover the latest MPT snapshot from the era checkpoint
(recovery_latest_mpt_snapshot, (bool), false)
(keep_era_genesis_snapshot, (bool), true)
// This is designed for fast node catch-up but has not been thoroughly tested. Do not use it in production environments.
(backup_mpt_snapshot, (bool), true)
}
{
// Development related section.
(
log_level, (LevelFilter), LevelFilter::Info, |l| {
LevelFilter::from_str(l)
.map_err(|_| format!("Invalid log level: {}", l))
}
)
// Genesis Section
// chain_id_params describes a complex setup where chain id can change over epochs.
// Usually this is needed to describe forks. This config overrides chain_id.
(chain_id_params, (Option<ChainIdParamsOneChainInner>), None,
ChainIdParamsOneChainInner::parse_config_str)
// Storage section.
(provide_more_snapshot_for_sync,
(Vec<ProvideExtraSnapshotSyncConfig>),
vec![ProvideExtraSnapshotSyncConfig::StableCheckpoint],
ProvideExtraSnapshotSyncConfig::parse_config_list)
(node_type, (Option<NodeType>), None, NodeType::from_str)
(public_rpc_apis, (ApiSet), ApiSet::Safe, ApiSet::from_str)
(public_evm_rpc_apis, (RpcModuleSelection), RpcModuleSelection::Evm, RpcModuleSelection::from_str)
(single_mpt_space, (Option<Space>), None, Space::from_str)
}
}
#[derive(Debug, Clone, Default)]
pub struct Configuration {
pub raw_conf: RawConfiguration,
}
impl Configuration {
pub fn parse(matches: &clap::ArgMatches) -> Result<Configuration, String> {
let mut raw_conf = RawConfiguration::parse(matches)?;
if matches.get_flag("archive") {
raw_conf.node_type = Some(NodeType::Archive);
} else if matches.get_flag("full") {
raw_conf.node_type = Some(NodeType::Full);
} else if matches.get_flag("light") {
raw_conf.node_type = Some(NodeType::Light);
}
CIP112_TRANSITION_HEIGHT
.set(raw_conf.cip112_transition_height.unwrap_or(u64::MAX))
.expect("called once");
USE_SIMPLE_RPC_ADDRESS
.set(raw_conf.rpc_address_simple_mode)
.expect("called once");
Ok(Configuration { raw_conf })
}
pub fn from_file(config_path: &str) -> Result<Configuration, String> {
Ok(Configuration {
raw_conf: RawConfiguration::from_file(config_path)?,
})
}
fn network_id(&self) -> u64 {
match self.raw_conf.network_id {
Some(x) => x,
// If undefined, the network id is set to the native space chain_id
// at genesis.
None => {
self.chain_id_params()
.read()
.get_chain_id(/* epoch_number = */ 0)
.in_native_space() as u64
}
}
}
pub fn net_config(&self) -> Result<NetworkConfiguration, String> {
let mut network_config = NetworkConfiguration::new_with_port(
self.network_id(),
self.raw_conf.tcp_port,
self.discovery_protocol(),
);
network_config.is_consortium = self.raw_conf.is_consortium;
network_config.discovery_enabled = self.raw_conf.enable_discovery;
network_config.boot_nodes = to_bootnodes(&self.raw_conf.bootnodes)
.map_err(|e| format!("failed to parse bootnodes: {}", e))?;
network_config.config_path = Some(match &self.raw_conf.netconf_dir {
Some(dir) => dir.clone(),
None => Path::new(&self.raw_conf.conflux_data_dir)
.join(NET_CONFIG_DB_DIR_NAME)
.into_os_string()
.into_string()
.unwrap(),
});
network_config.use_secret =
self.raw_conf.net_key.as_ref().map(|sec_str| {
parse_hex_string(sec_str)
.expect("net_key is not a valid secret string")
});
if let Some(addr) = self.raw_conf.public_address.clone() {
let addr_ip = if let Some(idx) = addr.find(":") {
warn!("Public address configuration should not contain port! (val = {}). Content after ':' is ignored.", &addr);
addr[0..idx].to_string()
} else {
addr
};
let addr_with_port = match self.raw_conf.public_tcp_port {
Some(port) => addr_ip + ":" + &port.to_string(),
None => addr_ip + ":" + &self.raw_conf.tcp_port.to_string(),
};
network_config.public_address =
match addr_with_port.to_socket_addrs().map(|mut i| i.next()) {
Ok(sock_addr) => sock_addr,
Err(_e) => {
warn!("public_address in config is invalid");
None
}
};
}
network_config.node_table_timeout =
Duration::from_secs(self.raw_conf.node_table_timeout_s);
network_config.connection_lifetime_for_promotion =
Duration::from_secs(self.raw_conf.node_table_promotion_timeout_s);
network_config.test_mode = self.is_test_mode();
network_config.subnet_quota = self.raw_conf.subnet_quota;
network_config.session_ip_limit_config =
self.raw_conf.session_ip_limits.clone().try_into().map_err(
|e| format!("failed to parse session ip limit config: {}", e),
)?;
network_config.fast_discovery_refresh_timeout = Duration::from_millis(
self.raw_conf.discovery_fast_refresh_timeout_ms,
);
network_config.discovery_round_timeout =
Duration::from_millis(self.raw_conf.discovery_round_timeout_ms);
network_config.housekeeping_timeout = Duration::from_millis(
self.raw_conf.discovery_housekeeping_timeout_ms,
);
network_config.max_handshakes = self.raw_conf.max_handshakes;
network_config.max_incoming_peers = self.raw_conf.max_incoming_peers;
network_config.max_outgoing_peers = self.raw_conf.max_outgoing_peers;
network_config.max_outgoing_peers_archive =
self.raw_conf.max_outgoing_peers_archive.unwrap_or(0);
Ok(network_config)
}
pub fn cache_config(&self) -> CacheConfig {
CacheConfig {
ledger: self.raw_conf.ledger_cache_size,
invalid_block_hashes_cache_size_in_count: self
.raw_conf
.invalid_block_hash_cache_size_in_count,
target_difficulties_cache_size_in_count: self
.raw_conf
.target_difficulties_cache_size_in_count,
}
}
pub fn db_config(&self) -> (PathBuf, DatabaseConfig) {
let db_dir: PathBuf = match &self.raw_conf.block_db_dir {
Some(dir) => dir.into(),
None => Path::new(&self.raw_conf.conflux_data_dir)
.join(BLOCK_DB_DIR_NAME),
};
if let Err(e) = fs::create_dir_all(&db_dir) {
panic!("Error creating database directory: {:?}", e);
}
let compact_profile =
match self.raw_conf.rocksdb_compaction_profile.as_ref() {
Some(p) => db::DatabaseCompactionProfile::from_str(p).unwrap(),
None => db::DatabaseCompactionProfile::default(),
};
let db_config = db::db_config(
&db_dir,
self.raw_conf.rocksdb_cache_size,
compact_profile,
NUM_COLUMNS,
self.raw_conf.rocksdb_disable_wal,
);
(db_dir, db_config)
}
pub fn chain_id_params(&self) -> ChainIdParams {
if CHAIN_ID.read().is_none() {
let mut to_init = CHAIN_ID.write();
if to_init.is_none() {
if let Some(_chain_id_params) = &self.raw_conf.chain_id_params {
unreachable!("Upgradable ChainId is not ready.")
// *to_init = Some(ChainIdParamsInner::new_from_inner(
// chain_id_params,
// ))
} else {
let chain_id = self
.raw_conf
.chain_id
.unwrap_or_else(|| rand::rng().random());
let evm_chain_id =
self.raw_conf.evm_chain_id.unwrap_or(chain_id);
*to_init = Some(ChainIdParamsInner::new_simple(
AllChainID::new(chain_id, evm_chain_id),
));
}
}
}
CHAIN_ID.read().as_ref().unwrap().clone()
}
pub fn consensus_config(&self) -> ConsensusConfig {
let enable_optimistic_execution = if DEFERRED_STATE_EPOCH_COUNT <= 1 {
false
} else {
self.raw_conf.enable_optimistic_execution
};
let pivot_hint_conf = match (
&self.raw_conf.pivot_hint_path,
&self.raw_conf.pivot_hint_checksum,
) {
(Some(path), Some(checksum)) => {
let checksum = H256::from_str(checksum)
.expect("Cannot parse `pivot_hint_checksum` as hex string");
Some(PivotHintConfig::new(path, checksum))
}
(None, None) => None,
_ => {
panic!("`pivot_hint_path` and `pivot_hint_checksum` must be both set or both unset");
}
};
let mut conf = ConsensusConfig {
chain_id: self.chain_id_params(),
inner_conf: ConsensusInnerConfig {
adaptive_weight_beta: self.raw_conf.adaptive_weight_beta,
heavy_block_difficulty_ratio: self
.raw_conf
.heavy_block_difficulty_ratio,
timer_chain_block_difficulty_ratio: self
.raw_conf
.timer_chain_block_difficulty_ratio,
timer_chain_beta: self.raw_conf.timer_chain_beta,
era_epoch_count: self.raw_conf.era_epoch_count,
enable_optimistic_execution,
enable_state_expose: self.raw_conf.enable_state_expose,
pos_pivot_decision_defer_epoch_count: self.raw_conf.pos_pivot_decision_defer_epoch_count,
cip113_pivot_decision_defer_epoch_count: self.raw_conf.cip113_pivot_decision_defer_epoch_count,
cip113_transition_height: self.raw_conf.cip113_transition_height,
debug_dump_dir_invalid_state_root: if self
.raw_conf
.debug_invalid_state_root
{
Some(
self.raw_conf.debug_dump_dir_invalid_state_root.clone(),
)
} else {
None
},
debug_invalid_state_root_epoch: self
.raw_conf
.debug_invalid_state_root_epoch.as_ref().map(|epoch_hex| H256::from_str(epoch_hex).expect("debug_invalid_state_root_epoch byte length is incorrect.")),
force_recompute_height_during_construct_pivot: self.raw_conf.force_recompute_height_during_construct_pivot,
recovery_latest_mpt_snapshot: self.raw_conf.recovery_latest_mpt_snapshot,
use_isolated_db_for_mpt_table: self.raw_conf.use_isolated_db_for_mpt_table,
},
bench_mode: false,
transaction_epoch_bound: self.raw_conf.transaction_epoch_bound,
referee_bound: self.raw_conf.referee_bound,
get_logs_epoch_batch_size: self.raw_conf.get_logs_epoch_batch_size,
get_logs_filter_max_epoch_range: self.raw_conf.get_logs_filter_max_epoch_range,
get_logs_filter_max_block_number_range: self.raw_conf.get_logs_filter_max_block_number_range,
get_logs_filter_max_limit: self.raw_conf.get_logs_filter_max_limit,
sync_state_starting_epoch: self.raw_conf.sync_state_starting_epoch,
sync_state_epoch_gap: self.raw_conf.sync_state_epoch_gap,
pivot_hint_conf,
};
match self.raw_conf.node_type {
Some(NodeType::Archive) => {
if conf.sync_state_starting_epoch.is_none() {
conf.sync_state_starting_epoch = Some(0);
}
}
_ => {
if conf.sync_state_epoch_gap.is_none() {
conf.sync_state_epoch_gap =
Some(CATCH_UP_EPOCH_LAG_THRESHOLD);
}
}
}
conf
}
pub fn pow_config(&self) -> ProofOfWorkConfig {
let stratum_secret =
self.raw_conf.stratum_secret.as_ref().map(|hex_str| {
parse_hex_string(hex_str)
.expect("Stratum secret should be 64-digit hex string")
});
ProofOfWorkConfig::new(
self.is_test_or_dev_mode(),
self.raw_conf.use_octopus_in_test_mode,
self.raw_conf.mining_type.as_ref().map_or_else(
|| {
// Enable stratum implicitly if `mining_author` is set.
if self.raw_conf.mining_author.is_some() {
"stratum"
} else {
"disable"
}
},
|s| s.as_str(),
),
self.raw_conf.initial_difficulty,
self.raw_conf.stratum_listen_address.clone(),
self.raw_conf.stratum_port,
stratum_secret,
self.raw_conf.pow_problem_window_size,
self.common_params().transition_heights.cip86,
)
}
pub fn verification_config(
&self, machine: Arc<Machine>,
) -> VerificationConfig {
VerificationConfig::new(
self.is_test_mode(),
self.raw_conf.referee_bound,
self.raw_conf.max_block_size_in_bytes,
self.raw_conf.transaction_epoch_bound,
self.raw_conf.tx_pool_nonce_bits,
self.raw_conf.pos_reference_enable_height,
machine,
)
}
pub fn tx_gen_config(&self) -> Option<TransactionGeneratorConfig> {
if self.is_test_or_dev_mode() &&
// FIXME: this is not a good condition to check.
self.raw_conf.genesis_secrets.is_some()
{
Some(TransactionGeneratorConfig::new(
self.raw_conf.generate_tx,
self.raw_conf.generate_tx_period_us.expect("has default"),
self.raw_conf.txgen_account_count,
))
} else {
None
}
}
pub fn storage_config(&self, node_type: &NodeType) -> StorageConfiguration {
let conflux_data_path = Path::new(&self.raw_conf.conflux_data_dir);
StorageConfiguration {
additional_maintained_snapshot_count: self
.raw_conf
.additional_maintained_snapshot_count,
consensus_param: ConsensusParam {
snapshot_epoch_count: if self.is_test_mode() {
self.raw_conf.dev_snapshot_epoch_count
} else {
SNAPSHOT_EPOCHS_CAPACITY
},
era_epoch_count: self.raw_conf.era_epoch_count,
},
debug_snapshot_checker_threads:
DEFAULT_DEBUG_SNAPSHOT_CHECKER_THREADS,
delta_mpts_cache_recent_lfu_factor: self
.raw_conf
.storage_delta_mpts_cache_recent_lfu_factor,
delta_mpts_cache_size: self.raw_conf.storage_delta_mpts_cache_size,
delta_mpts_cache_start_size: self
.raw_conf
.storage_delta_mpts_cache_start_size,
delta_mpts_node_map_vec_size: self
.raw_conf
.storage_delta_mpts_node_map_vec_size,
delta_mpts_slab_idle_size: self
.raw_conf
.storage_delta_mpts_slab_idle_size,
single_mpt_cache_start_size: self
.raw_conf
.storage_single_mpt_cache_start_size,
single_mpt_cache_size: self.raw_conf.storage_single_mpt_cache_size,
single_mpt_slab_idle_size: self
.raw_conf
.storage_single_mpt_slab_idle_size,
max_open_snapshots: self.raw_conf.storage_max_open_snapshots,
path_delta_mpts_dir: conflux_data_path
.join(&*storage_dir::DELTA_MPTS_DIR),
path_snapshot_dir: conflux_data_path
.join(&*storage_dir::SNAPSHOT_DIR),
path_snapshot_info_db: conflux_data_path
.join(&*storage_dir::SNAPSHOT_INFO_DB_PATH),
path_storage_dir: conflux_data_path
.join(&*storage_dir::STORAGE_DIR),
provide_more_snapshot_for_sync: self
.raw_conf
.provide_more_snapshot_for_sync
.clone(),
max_open_mpt_count: self.raw_conf.storage_max_open_mpt_count,
enable_single_mpt_storage: match node_type {
NodeType::Archive => self.raw_conf.enable_single_mpt_storage,
_ => {
if self.raw_conf.enable_single_mpt_storage {
error!("enable_single_mpt_storage is only supported for Archive nodes!")
}
false
}
},
single_mpt_space: self.raw_conf.single_mpt_space,
cip90a: self
.raw_conf
.cip90_transition_height
.unwrap_or(self.raw_conf.hydra_transition_height.unwrap_or(0)),
keep_snapshot_before_stable_checkpoint: self
.raw_conf
.keep_snapshot_before_stable_checkpoint,
use_isolated_db_for_mpt_table: self
.raw_conf
.use_isolated_db_for_mpt_table,
use_isolated_db_for_mpt_table_height: self
.raw_conf
.use_isolated_db_for_mpt_table_height,
keep_era_genesis_snapshot: self.raw_conf.keep_era_genesis_snapshot,
backup_mpt_snapshot: self.raw_conf.backup_mpt_snapshot,
}
}
pub fn protocol_config(&self) -> ProtocolConfiguration {
ProtocolConfiguration {
is_consortium: self.raw_conf.is_consortium,
send_tx_period: Duration::from_millis(
self.raw_conf.send_tx_period_ms,
),
check_request_period: Duration::from_millis(
self.raw_conf.check_request_period_ms,
),
check_phase_change_period: Duration::from_millis(
self.raw_conf.check_phase_change_period_ms,
),
heartbeat_period_interval: Duration::from_millis(
self.raw_conf.heartbeat_period_interval_ms,
),
block_cache_gc_period: Duration::from_millis(
self.raw_conf.block_cache_gc_period_ms,
),
expire_block_gc_period: Duration::from_secs(
self.raw_conf.expire_block_gc_period_s,
),
headers_request_timeout: Duration::from_millis(
self.raw_conf.headers_request_timeout_ms,
),
blocks_request_timeout: Duration::from_millis(
self.raw_conf.blocks_request_timeout_ms,
),
transaction_request_timeout: Duration::from_millis(
self.raw_conf.transaction_request_timeout_ms,
),
tx_maintained_for_peer_timeout: Duration::from_millis(
self.raw_conf.tx_maintained_for_peer_timeout_ms,
),
max_inflight_request_count: self
.raw_conf
.max_inflight_request_count,
request_block_with_public: self.raw_conf.request_block_with_public,
received_tx_index_maintain_timeout: Duration::from_millis(
self.raw_conf.received_tx_index_maintain_timeout_ms,
),
inflight_pending_tx_index_maintain_timeout: Duration::from_millis(
self.raw_conf.inflight_pending_tx_index_maintain_timeout_ms,
),
max_trans_count_received_in_catch_up: self
.raw_conf
.max_trans_count_received_in_catch_up,
min_peers_tx_propagation: self.raw_conf.min_peers_tx_propagation,
max_peers_tx_propagation: self.raw_conf.max_peers_tx_propagation,
max_downloading_chunks: self.raw_conf.max_downloading_chunks,
max_downloading_chunk_attempts: self
.raw_conf
.max_downloading_chunk_attempts,
test_mode: self.is_test_mode(),
dev_mode: self.is_dev_mode(),
throttling_config_file: self.raw_conf.throttling_conf.clone(),
snapshot_candidate_request_timeout: Duration::from_millis(
self.raw_conf.snapshot_candidate_request_timeout_ms,
),
snapshot_manifest_request_timeout: Duration::from_millis(
self.raw_conf.snapshot_manifest_request_timeout_ms,
),
snapshot_chunk_request_timeout: Duration::from_millis(
self.raw_conf.snapshot_chunk_request_timeout_ms,
),
chunk_size_byte: self.raw_conf.chunk_size_byte,
max_chunk_number_in_manifest: self
.raw_conf
.max_chunk_number_in_manifest,
timeout_observing_period_s: self
.raw_conf
.timeout_observing_period_s,
max_allowed_timeout_in_observing_period: self
.raw_conf
.max_allowed_timeout_in_observing_period,
demote_peer_for_timeout: self.raw_conf.demote_peer_for_timeout,
heartbeat_timeout: Duration::from_millis(
self.raw_conf.heartbeat_timeout_ms,
),
max_unprocessed_block_size: self
.raw_conf
.max_unprocessed_block_size_mb
* 1_000_000,
sync_expire_block_timeout: Duration::from_secs(
self.raw_conf.sync_expire_block_timeout_s,
),
allow_phase_change_without_peer: if self.is_dev_mode() {
true
} else {
self.raw_conf.dev_allow_phase_change_without_peer
},
min_phase_change_normal_peer_count: self
.raw_conf
.min_phase_change_normal_peer_count,
pos_genesis_pivot_decision: self
.raw_conf
.pos_genesis_pivot_decision
.expect("set to genesis if none"),
check_status_genesis: self.raw_conf.check_status_genesis,
pos_started_as_voter: self.raw_conf.pos_started_as_voter,
}
}
pub fn state_sync_config(&self) -> StateSyncConfiguration {
StateSyncConfiguration {
max_downloading_chunks: self.raw_conf.max_downloading_chunks,
candidate_request_timeout: Duration::from_millis(
self.raw_conf.snapshot_candidate_request_timeout_ms,
),
chunk_request_timeout: Duration::from_millis(
self.raw_conf.snapshot_chunk_request_timeout_ms,
),
manifest_request_timeout: Duration::from_millis(
self.raw_conf.snapshot_manifest_request_timeout_ms,
),
max_downloading_manifest_attempts: self
.raw_conf
.max_downloading_manifest_attempts,
}
}
pub fn data_mananger_config(&self) -> DataManagerConfiguration {
let mut conf = DataManagerConfiguration {
persist_tx_index: self.raw_conf.persist_tx_index,
persist_block_number_index: self
.raw_conf
.persist_block_number_index,
tx_cache_index_maintain_timeout: Duration::from_millis(
self.raw_conf.tx_cache_index_maintain_timeout_ms,
),
db_type: match self.raw_conf.block_db_type.as_str() {
"rocksdb" => DbType::Rocksdb,
"sqlite" => DbType::Sqlite,
_ => panic!("Invalid block_db_type parameter!"),
},
additional_maintained_block_body_epoch_count: self
.raw_conf
.additional_maintained_block_body_epoch_count,
additional_maintained_execution_result_epoch_count: self
.raw_conf
.additional_maintained_execution_result_epoch_count,
additional_maintained_reward_epoch_count: self