Repository navigation
Expand file tree
/
Copy pathArgs.java
More file actions
1276 lines (1048 loc) · 42.8 KB
/
Copy pathArgs.java
File metadata and controls
1276 lines (1048 loc) · 42.8 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
package org.tron.core.config.args;
import static java.lang.Math.max;
import static java.lang.System.exit;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigObject;
import io.grpc.internal.GrpcUtil;
import io.grpc.netty.NettyServerBuilder;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.spongycastle.util.encoders.Hex;
import org.springframework.stereotype.Component;
import org.tron.common.crypto.ECKey;
import org.tron.common.logsfilter.EventPluginConfig;
import org.tron.common.logsfilter.FilterQuery;
import org.tron.common.logsfilter.TriggerConfig;
import org.tron.common.overlay.discover.node.Node;
import org.tron.common.storage.RocksDbSettings;
import org.tron.common.utils.ByteArray;
import org.tron.core.Constant;
import org.tron.core.Wallet;
import org.tron.core.config.Configuration;
import org.tron.core.config.Parameter.ChainConstant;
import org.tron.core.config.Parameter.NetConstants;
import org.tron.core.db.AccountStore;
import org.tron.core.db.backup.DbBackupConfig;
import org.tron.keystore.CipherException;
import org.tron.keystore.Credentials;
import org.tron.keystore.WalletUtils;
import org.tron.program.Version;
@Slf4j(topic = "app")
@NoArgsConstructor
@Component
public class Args {
private static final Args INSTANCE = new Args();
@Parameter(names = {"-c", "--config"}, description = "Config File")
private String shellConfFileName = "";
@Parameter(names = {"-d", "--output-directory"}, description = "Directory")
private String outputDirectory = "output-directory";
@Getter
@Parameter(names = {"--log-config"})
private String logbackPath = "";
@Getter
@Parameter(names = {"-h", "--help"}, help = true, description = "HELP message")
private boolean help = false;
@Getter
@Setter
@Parameter(names = {"-w", "--witness"})
private boolean witness = false;
@Getter
@Setter
@Parameter(names = {"--support-constant"})
private boolean supportConstant = false;
@Getter
@Setter
@Parameter(names = {"--debug"})
private boolean debug = false;
@Getter
@Setter
@Parameter(names = {"--min-time-ratio"})
private double minTimeRatio = 0.0;
@Getter
@Setter
@Parameter(names = {"--max-time-ratio"})
private double maxTimeRatio = calcMaxTimeRatio();
@Getter
@Setter
@Parameter(names = {"--long-running-time"})
private int longRunningTime = 10;
@Getter
@Parameter(description = "--seed-nodes")
private List<String> seedNodes = new ArrayList<>();
@Parameter(names = {"-p", "--private-key"}, description = "private-key")
private String privateKey = "";
@Parameter(names = {"--witness-address"}, description = "witness-address")
private String witnessAddress = "";
@Parameter(names = {"--password"}, description = "password")
private String password;
@Parameter(names = {"--storage-db-directory"}, description = "Storage db directory")
private String storageDbDirectory = "";
@Parameter(names = {"--storage-db-version"}, description = "Storage db version.(1 or 2)")
private String storageDbVersion = "";
@Parameter(names = {
"--storage-db-engine"}, description = "Storage db engine.(leveldb or rocksdb)")
private String storageDbEngine = "";
@Parameter(names = {
"--storage-db-synchronous"}, description = "Storage db is synchronous or not.(true or flase)")
private String storageDbSynchronous = "";
@Parameter(names = {"--storage-index-directory"}, description = "Storage index directory")
private String storageIndexDirectory = "";
@Parameter(names = {"--storage-index-switch"}, description = "Storage index switch.(on or off)")
private String storageIndexSwitch = "";
@Parameter(names = {
"--storage-transactionHistory-switch"}, description = "Storage transaction history switch.(on or off)")
private String storageTransactionHistoreSwitch = "";
@Getter
@Parameter(names = {"--fast-forward"})
private boolean fastForward = false;
@Getter
private Storage storage;
@Getter
private Overlay overlay;
@Getter
private SeedNode seedNode;
@Getter
private GenesisBlock genesisBlock;
@Getter
@Setter
private String chainId;
@Getter
@Setter
private LocalWitnesses localWitnesses = new LocalWitnesses();
@Getter
@Setter
private boolean needSyncCheck;
@Getter
@Setter
private boolean nodeDiscoveryEnable;
@Getter
@Setter
private boolean nodeDiscoveryPersist;
@Getter
@Setter
private int nodeConnectionTimeout;
@Getter
@Setter
private List<Node> activeNodes;
@Getter
@Setter
private List<Node> passiveNodes;
@Getter
@Setter
private List<Node> fastForwardNodes;
@Getter
@Setter
private int nodeChannelReadTimeout;
@Getter
@Setter
private int nodeMaxActiveNodes;
@Getter
@Setter
private int nodeMaxActiveNodesWithSameIp;
@Getter
@Setter
private int minParticipationRate;
@Getter
@Setter
private int nodeListenPort;
@Getter
@Setter
private String nodeDiscoveryBindIp;
@Getter
@Setter
private String nodeExternalIp;
@Getter
@Setter
private boolean nodeDiscoveryPublicHomeNode;
@Getter
@Setter
private long nodeP2pPingInterval;
// @Getter
// @Setter
// private long syncNodeCount;
@Getter
@Setter
@Parameter(names = {"--save-internaltx"})
private boolean saveInternalTx;
@Getter
@Setter
private int nodeP2pVersion;
@Getter
@Setter
private String p2pNodeId;
//If you are running a solidity node for java tron, this flag is set to true
@Getter
@Setter
private boolean solidityNode = false;
@Getter
@Setter
private int rpcPort;
@Getter
@Setter
private int rpcOnSolidityPort;
@Getter
@Setter
private int fullNodeHttpPort;
@Getter
@Setter
private int solidityHttpPort;
@Getter
@Setter
@Parameter(names = {"--rpc-thread"}, description = "Num of gRPC thread")
private int rpcThreadNum;
@Getter
@Setter
@Parameter(names = {"--solidity-thread"}, description = "Num of solidity thread")
private int solidityThreads;
@Getter
@Setter
private int maxConcurrentCallsPerConnection;
@Getter
@Setter
private int flowControlWindow;
@Getter
@Setter
private long maxConnectionIdleInMillis;
@Getter
@Setter
private int blockProducedTimeOut;
@Getter
@Setter
private long netMaxTrxPerSecond;
@Getter
@Setter
private long maxConnectionAgeInMillis;
@Getter
@Setter
private int maxMessageSize;
@Getter
@Setter
private int maxHeaderListSize;
@Getter
@Setter
@Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread")
private int validateSignThreadNum;
@Getter
@Setter
private long maintenanceTimeInterval; // (ms)
@Getter
@Setter
private long proposalExpireTime; // (ms)
@Getter
@Setter
private int checkFrozenTime; // for test only
@Getter
@Setter
private long allowCreationOfContracts; //committee parameter
@Getter
@Setter
private long allowAdaptiveEnergy; //committee parameter
@Getter
@Setter
private long allowDelegateResource; //committee parameter
@Getter
@Setter
private long allowSameTokenName; //committee parameter
@Getter
@Setter
private long allowTvmTransferTrc10; //committee parameter
@Getter
@Setter
private int tcpNettyWorkThreadNum;
@Getter
@Setter
private int udpNettyWorkThreadNum;
@Getter
@Setter
@Parameter(names = {"--trust-node"}, description = "Trust node addr")
private String trustNodeAddr;
@Getter
@Setter
private boolean walletExtensionApi;
@Getter
@Setter
private int backupPriority;
@Getter
@Setter
private int backupPort;
@Getter
@Setter
private List<String> backupMembers;
@Getter
@Setter
private double connectFactor;
@Getter
@Setter
private double activeConnectFactor;
@Getter
@Setter
private double disconnectNumberFactor;
@Getter
@Setter
private double maxConnectNumberFactor;
@Getter
@Setter
private long receiveTcpMinDataLength;
@Getter
@Setter
private boolean isOpenFullTcpDisconnect;
@Getter
@Setter
private int allowMultiSign;
@Getter
@Setter
private boolean vmTrace;
@Getter
@Setter
private boolean needToUpdateAsset;
@Getter
@Setter
private String trxReferenceBlock;
@Getter
@Setter
private int minEffectiveConnection;
@Getter
@Setter
private long allowZKSnarkTransaction; //committee parameter
@Getter
@Setter
private long blockNumForEneryLimit;
@Getter
@Setter
@Parameter(names = {"--es"})
private boolean eventSubscribe = false;
@Getter
private EventPluginConfig eventPluginConfig;
@Getter
private FilterQuery eventFilter;
@Getter
@Setter
private long trxExpirationTimeInMilliseconds; // (ms)
@Getter
private DbBackupConfig dbBackupConfig;
@Getter
private RocksDbSettings rocksDBCustomSettings;
@Parameter(names = {"-v", "--version"}, description = "output code version", help = true)
private boolean version;
public static void clearParam() {
INSTANCE.outputDirectory = "output-directory";
INSTANCE.help = false;
INSTANCE.witness = false;
INSTANCE.seedNodes = new ArrayList<>();
INSTANCE.privateKey = "";
INSTANCE.witnessAddress = "";
INSTANCE.storageDbDirectory = "";
INSTANCE.storageIndexDirectory = "";
INSTANCE.storageIndexSwitch = "";
// FIXME: INSTANCE.storage maybe null ?
if (INSTANCE.storage != null) {
// WARNING: WILL DELETE DB STORAGE PATHS
INSTANCE.storage.deleteAllStoragePaths();
INSTANCE.storage = null;
}
INSTANCE.overlay = null;
INSTANCE.seedNode = null;
INSTANCE.genesisBlock = null;
INSTANCE.chainId = null;
INSTANCE.localWitnesses = null;
INSTANCE.needSyncCheck = false;
INSTANCE.nodeDiscoveryEnable = false;
INSTANCE.nodeDiscoveryPersist = false;
INSTANCE.nodeConnectionTimeout = 0;
INSTANCE.activeNodes = Collections.emptyList();
INSTANCE.passiveNodes = Collections.emptyList();
INSTANCE.fastForwardNodes = Collections.emptyList();
INSTANCE.nodeChannelReadTimeout = 0;
INSTANCE.nodeMaxActiveNodes = 30;
INSTANCE.nodeMaxActiveNodesWithSameIp = 2;
INSTANCE.minParticipationRate = 0;
INSTANCE.nodeListenPort = 0;
INSTANCE.nodeDiscoveryBindIp = "";
INSTANCE.nodeExternalIp = "";
INSTANCE.nodeDiscoveryPublicHomeNode = false;
INSTANCE.nodeP2pPingInterval = 0L;
//INSTANCE.syncNodeCount = 0;
INSTANCE.nodeP2pVersion = 0;
INSTANCE.rpcPort = 0;
INSTANCE.rpcOnSolidityPort = 0;
INSTANCE.fullNodeHttpPort = 0;
INSTANCE.solidityHttpPort = 0;
INSTANCE.maintenanceTimeInterval = 0;
INSTANCE.proposalExpireTime = 0;
INSTANCE.checkFrozenTime = 1;
INSTANCE.allowCreationOfContracts = 0;
INSTANCE.allowAdaptiveEnergy = 0;
INSTANCE.allowTvmTransferTrc10 = 0;
INSTANCE.allowDelegateResource = 0;
INSTANCE.allowSameTokenName = 0;
INSTANCE.tcpNettyWorkThreadNum = 0;
INSTANCE.udpNettyWorkThreadNum = 0;
INSTANCE.p2pNodeId = "";
INSTANCE.solidityNode = false;
INSTANCE.trustNodeAddr = "";
INSTANCE.walletExtensionApi = false;
INSTANCE.connectFactor = 0.3;
INSTANCE.activeConnectFactor = 0.1;
INSTANCE.disconnectNumberFactor = 0.4;
INSTANCE.maxConnectNumberFactor = 0.8;
INSTANCE.receiveTcpMinDataLength = 2048;
INSTANCE.isOpenFullTcpDisconnect = false;
INSTANCE.supportConstant = false;
INSTANCE.debug = false;
INSTANCE.minTimeRatio = 0.0;
INSTANCE.maxTimeRatio = 5.0;
INSTANCE.longRunningTime = 10;
INSTANCE.allowZKSnarkTransaction = 0;
INSTANCE.allowMultiSign = 0;
INSTANCE.trxExpirationTimeInMilliseconds = 0;
}
/**
* set parameters.
*/
public static void setParam(final String[] args, final String confFileName) {
JCommander.newBuilder().addObject(INSTANCE).build().parse(args);
if (INSTANCE.version) {
JCommander.getConsole().println(Version.getVersion() + "\n" + Version.versionName + "\n" + Version.versionCode);
exit(0);
}
Config config = Configuration.getByFileName(INSTANCE.shellConfFileName, confFileName);
if (config.hasPath("net.type") && "testnet".equalsIgnoreCase(config.getString("net.type"))) {
Wallet.setAddressPreFixByte(Constant.ADD_PRE_FIX_BYTE_TESTNET);
Wallet.setAddressPreFixString(Constant.ADD_PRE_FIX_STRING_TESTNET);
} else {
Wallet.setAddressPreFixByte(Constant.ADD_PRE_FIX_BYTE_MAINNET);
Wallet.setAddressPreFixString(Constant.ADD_PRE_FIX_STRING_MAINNET);
}
if (StringUtils.isNoneBlank(INSTANCE.privateKey)) {
INSTANCE.setLocalWitnesses(new LocalWitnesses(INSTANCE.privateKey));
if (StringUtils.isNoneBlank(INSTANCE.witnessAddress)) {
byte[] bytes = Wallet.decodeFromBase58Check(INSTANCE.witnessAddress);
if (bytes != null) {
INSTANCE.localWitnesses.setWitnessAccountAddress(bytes);
logger.debug("Got localWitnessAccountAddress from cmd");
} else {
INSTANCE.witnessAddress = "";
logger.warn("The localWitnessAccountAddress format is incorrect, ignored");
}
}
INSTANCE.localWitnesses.initWitnessAccountAddress();
logger.debug("Got privateKey from cmd");
} else if (config.hasPath("localwitness")) {
INSTANCE.localWitnesses = new LocalWitnesses();
List<String> localwitness = config.getStringList("localwitness");
if (localwitness.size() > 1) {
logger.warn("localwitness size must be one, get the first one");
localwitness = localwitness.subList(0, 1);
}
INSTANCE.localWitnesses.setPrivateKeys(localwitness);
if (config.hasPath("localWitnessAccountAddress")) {
byte[] bytes = Wallet.decodeFromBase58Check(config.getString("localWitnessAccountAddress"));
if (bytes != null) {
INSTANCE.localWitnesses.setWitnessAccountAddress(bytes);
logger.debug("Got localWitnessAccountAddress from config.conf");
} else {
logger.warn("The localWitnessAccountAddress format is incorrect, ignored");
}
}
INSTANCE.localWitnesses.initWitnessAccountAddress();
logger.debug("Got privateKey from config.conf");
} else if (config.hasPath("localwitnesskeystore")) {
INSTANCE.localWitnesses = new LocalWitnesses();
List<String> privateKeys = new ArrayList<String>();
if (INSTANCE.isWitness()) {
List<String> localwitness = config.getStringList("localwitnesskeystore");
if (localwitness.size() > 0) {
String fileName = System.getProperty("user.dir") + "/" + localwitness.get(0);
String password;
if (StringUtils.isEmpty(INSTANCE.password)) {
System.out.println("Please input your password.");
password = WalletUtils.inputPassword();
} else {
password = INSTANCE.password;
INSTANCE.password = null;
}
try {
Credentials credentials = WalletUtils
.loadCredentials(password, new File(fileName));
ECKey ecKeyPair = credentials.getEcKeyPair();
String prikey = ByteArray.toHexString(ecKeyPair.getPrivKeyBytes());
privateKeys.add(prikey);
} catch (IOException e) {
logger.error(e.getMessage());
logger.error("Witness node start faild!");
exit(-1);
} catch (CipherException e) {
logger.error(e.getMessage());
logger.error("Witness node start faild!");
exit(-1);
}
}
}
INSTANCE.localWitnesses.setPrivateKeys(privateKeys);
logger.debug("Got privateKey from keystore");
}
if (INSTANCE.isWitness() && CollectionUtils.isEmpty(INSTANCE.localWitnesses.getPrivateKeys())) {
logger.warn("This is a witness node,but localWitnesses is null");
}
if (config.hasPath("vm.supportConstant")) {
INSTANCE.supportConstant = config.getBoolean("vm.supportConstant");
}
if (config.hasPath("vm.minTimeRatio")) {
INSTANCE.minTimeRatio = config.getDouble("vm.minTimeRatio");
}
if (config.hasPath("vm.maxTimeRatio")) {
INSTANCE.maxTimeRatio = config.getDouble("vm.maxTimeRatio");
}
if (config.hasPath("vm.longRunningTime")) {
INSTANCE.longRunningTime = config.getInt("vm.longRunningTime");
}
INSTANCE.storage = new Storage();
INSTANCE.storage.setDbVersion(Optional.ofNullable(INSTANCE.storageDbVersion)
.filter(StringUtils::isNotEmpty)
.map(Integer::valueOf)
.orElse(Storage.getDbVersionFromConfig(config)));
INSTANCE.storage.setDbEngine(Optional.ofNullable(INSTANCE.storageDbEngine)
.filter(StringUtils::isNotEmpty)
.orElse(Storage.getDbEngineFromConfig(config)));
if ("ROCKSDB".equals(INSTANCE.storage.getDbEngine().toUpperCase())
&& INSTANCE.storage.getDbVersion() == 1) {
throw new RuntimeException("db.version = 1 is not supported by ROCKSDB engine.");
}
INSTANCE.storage.setDbSync(Optional.ofNullable(INSTANCE.storageDbSynchronous)
.filter(StringUtils::isNotEmpty)
.map(Boolean::valueOf)
.orElse(Storage.getDbVersionSyncFromConfig(config)));
INSTANCE.storage.setDbDirectory(Optional.ofNullable(INSTANCE.storageDbDirectory)
.filter(StringUtils::isNotEmpty)
.orElse(Storage.getDbDirectoryFromConfig(config)));
INSTANCE.storage.setIndexDirectory(Optional.ofNullable(INSTANCE.storageIndexDirectory)
.filter(StringUtils::isNotEmpty)
.orElse(Storage.getIndexDirectoryFromConfig(config)));
INSTANCE.storage.setIndexSwitch(Optional.ofNullable(INSTANCE.storageIndexSwitch)
.filter(StringUtils::isNotEmpty)
.orElse(Storage.getIndexSwitchFromConfig(config)));
INSTANCE.storage
.setTransactionHistoreSwitch(Optional.ofNullable(INSTANCE.storageTransactionHistoreSwitch)
.filter(StringUtils::isNotEmpty)
.orElse(Storage.getTransactionHistoreSwitchFromConfig(config)));
INSTANCE.storage.setPropertyMapFromConfig(config);
INSTANCE.seedNode = new SeedNode();
INSTANCE.seedNode.setIpList(Optional.ofNullable(INSTANCE.seedNodes)
.filter(seedNode -> 0 != seedNode.size())
.orElse(config.getStringList("seed.node.ip.list")));
if (config.hasPath("genesis.block")) {
INSTANCE.genesisBlock = new GenesisBlock();
INSTANCE.genesisBlock.setTimestamp(config.getString("genesis.block.timestamp"));
INSTANCE.genesisBlock.setParentHash(config.getString("genesis.block.parentHash"));
if (config.hasPath("genesis.block.assets")) {
INSTANCE.genesisBlock.setAssets(getAccountsFromConfig(config));
AccountStore.setAccount(config);
}
if (config.hasPath("genesis.block.witnesses")) {
INSTANCE.genesisBlock.setWitnesses(getWitnessesFromConfig(config));
}
} else {
INSTANCE.genesisBlock = GenesisBlock.getDefault();
}
INSTANCE.needSyncCheck =
config.hasPath("block.needSyncCheck") && config.getBoolean("block.needSyncCheck");
INSTANCE.nodeDiscoveryEnable =
config.hasPath("node.discovery.enable") && config.getBoolean("node.discovery.enable");
INSTANCE.nodeDiscoveryPersist =
config.hasPath("node.discovery.persist") && config.getBoolean("node.discovery.persist");
INSTANCE.nodeConnectionTimeout =
config.hasPath("node.connection.timeout") ? config.getInt("node.connection.timeout") * 1000
: 0;
INSTANCE.activeNodes = getNodes(config, "node.active");
INSTANCE.passiveNodes = getNodes(config, "node.passive");
INSTANCE.fastForwardNodes = getNodes(config, "node.fastForward");
INSTANCE.nodeChannelReadTimeout =
config.hasPath("node.channel.read.timeout") ? config.getInt("node.channel.read.timeout")
: 0;
INSTANCE.nodeMaxActiveNodes =
config.hasPath("node.maxActiveNodes") ? config.getInt("node.maxActiveNodes") : 30;
INSTANCE.nodeMaxActiveNodesWithSameIp =
config.hasPath("node.maxActiveNodesWithSameIp") ? config
.getInt("node.maxActiveNodesWithSameIp") : 2;
INSTANCE.minParticipationRate =
config.hasPath("node.minParticipationRate") ? config.getInt("node.minParticipationRate")
: 0;
INSTANCE.nodeListenPort =
config.hasPath("node.listen.port") ? config.getInt("node.listen.port") : 0;
bindIp(config);
externalIp(config);
INSTANCE.nodeDiscoveryPublicHomeNode =
config.hasPath("node.discovery.public.home.node") && config
.getBoolean("node.discovery.public.home.node");
INSTANCE.nodeP2pPingInterval =
config.hasPath("node.p2p.pingInterval") ? config.getLong("node.p2p.pingInterval") : 0;
//
// INSTANCE.syncNodeCount =
// config.hasPath("sync.node.count") ? config.getLong("sync.node.count") : 0;
INSTANCE.nodeP2pVersion =
config.hasPath("node.p2p.version") ? config.getInt("node.p2p.version") : 0;
INSTANCE.rpcPort =
config.hasPath("node.rpc.port") ? config.getInt("node.rpc.port") : 50051;
INSTANCE.rpcOnSolidityPort =
config.hasPath("node.rpc.solidityPort") ? config.getInt("node.rpc.solidityPort") : 50061;
INSTANCE.fullNodeHttpPort =
config.hasPath("node.http.fullNodePort") ? config.getInt("node.http.fullNodePort") : 8090;
INSTANCE.solidityHttpPort =
config.hasPath("node.http.solidityPort") ? config.getInt("node.http.solidityPort") : 8091;
INSTANCE.rpcThreadNum =
config.hasPath("node.rpc.thread") ? config.getInt("node.rpc.thread")
: Runtime.getRuntime().availableProcessors() / 2;
INSTANCE.solidityThreads =
config.hasPath("node.solidity.threads") ? config.getInt("node.solidity.threads")
: Runtime.getRuntime().availableProcessors();
INSTANCE.maxConcurrentCallsPerConnection =
config.hasPath("node.rpc.maxConcurrentCallsPerConnection") ?
config.getInt("node.rpc.maxConcurrentCallsPerConnection") : Integer.MAX_VALUE;
INSTANCE.flowControlWindow = config.hasPath("node.rpc.flowControlWindow") ?
config.getInt("node.rpc.flowControlWindow")
: NettyServerBuilder.DEFAULT_FLOW_CONTROL_WINDOW;
INSTANCE.maxConnectionIdleInMillis = config.hasPath("node.rpc.maxConnectionIdleInMillis") ?
config.getLong("node.rpc.maxConnectionIdleInMillis") : Long.MAX_VALUE;
INSTANCE.blockProducedTimeOut = config.hasPath("node.blockProducedTimeOut") ?
config.getInt("node.blockProducedTimeOut") : ChainConstant.BLOCK_PRODUCED_TIME_OUT;
if (INSTANCE.blockProducedTimeOut < 30) {
INSTANCE.blockProducedTimeOut = 30;
}
if (INSTANCE.blockProducedTimeOut > 100) {
INSTANCE.blockProducedTimeOut = 100;
}
INSTANCE.netMaxTrxPerSecond = config.hasPath("node.netMaxTrxPerSecond") ?
config.getInt("node.netMaxTrxPerSecond") : NetConstants.NET_MAX_TRX_PER_SECOND;
INSTANCE.maxConnectionAgeInMillis = config.hasPath("node.rpc.maxConnectionAgeInMillis") ?
config.getLong("node.rpc.maxConnectionAgeInMillis") : Long.MAX_VALUE;
INSTANCE.maxMessageSize = config.hasPath("node.rpc.maxMessageSize") ?
config.getInt("node.rpc.maxMessageSize") : GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
INSTANCE.maxHeaderListSize = config.hasPath("node.rpc.maxHeaderListSize") ?
config.getInt("node.rpc.maxHeaderListSize") : GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;
INSTANCE.maintenanceTimeInterval =
config.hasPath("block.maintenanceTimeInterval") ? config
.getInt("block.maintenanceTimeInterval") : 21600000L;
INSTANCE.proposalExpireTime =
config.hasPath("block.proposalExpireTime") ? config
.getInt("block.proposalExpireTime") : 259200000L;
INSTANCE.checkFrozenTime =
config.hasPath("block.checkFrozenTime") ? config
.getInt("block.checkFrozenTime") : 1;
INSTANCE.allowCreationOfContracts =
config.hasPath("committee.allowCreationOfContracts") ? config
.getInt("committee.allowCreationOfContracts") : 0;
INSTANCE.allowMultiSign =
config.hasPath("committee.allowMultiSign") ? config
.getInt("committee.allowMultiSign") : 0;
INSTANCE.allowAdaptiveEnergy =
config.hasPath("committee.allowAdaptiveEnergy") ? config
.getInt("committee.allowAdaptiveEnergy") : 0;
INSTANCE.allowDelegateResource =
config.hasPath("committee.allowDelegateResource") ? config
.getInt("committee.allowDelegateResource") : 0;
INSTANCE.allowSameTokenName =
config.hasPath("committee.allowSameTokenName") ? config
.getInt("committee.allowSameTokenName") : 0;
INSTANCE.allowTvmTransferTrc10 =
config.hasPath("committee.allowTvmTransferTrc10") ? config
.getInt("committee.allowTvmTransferTrc10") : 0;
INSTANCE.tcpNettyWorkThreadNum = config.hasPath("node.tcpNettyWorkThreadNum") ? config
.getInt("node.tcpNettyWorkThreadNum") : 0;
INSTANCE.udpNettyWorkThreadNum = config.hasPath("node.udpNettyWorkThreadNum") ? config
.getInt("node.udpNettyWorkThreadNum") : 1;
if (StringUtils.isEmpty(INSTANCE.trustNodeAddr)) {
INSTANCE.trustNodeAddr =
config.hasPath("node.trustNode") ? config.getString("node.trustNode") : null;
}
INSTANCE.validateSignThreadNum = config.hasPath("node.validateSignThreadNum") ? config
.getInt("node.validateSignThreadNum") : Runtime.getRuntime().availableProcessors() / 2;
INSTANCE.walletExtensionApi =
config.hasPath("node.walletExtensionApi") && config.getBoolean("node.walletExtensionApi");
INSTANCE.connectFactor =
config.hasPath("node.connectFactor") ? config.getDouble("node.connectFactor") : 0.3;
INSTANCE.activeConnectFactor = config.hasPath("node.activeConnectFactor") ?
config.getDouble("node.activeConnectFactor") : 0.1;
INSTANCE.disconnectNumberFactor = config.hasPath("node.disconnectNumberFactor") ?
config.getDouble("node.disconnectNumberFactor") : 0.4;
INSTANCE.maxConnectNumberFactor = config.hasPath("node.maxConnectNumberFactor") ?
config.getDouble("node.maxConnectNumberFactor") : 0.8;
INSTANCE.receiveTcpMinDataLength = config.hasPath("node.receiveTcpMinDataLength") ?
config.getLong("node.receiveTcpMinDataLength") : 2048;
INSTANCE.isOpenFullTcpDisconnect = config.hasPath("node.isOpenFullTcpDisconnect") && config
.getBoolean("node.isOpenFullTcpDisconnect");
INSTANCE.needToUpdateAsset =
config.hasPath("storage.needToUpdateAsset") ? config
.getBoolean("storage.needToUpdateAsset")
: true;
INSTANCE.trxReferenceBlock = config.hasPath("trx.reference.block") ?
config.getString("trx.reference.block") : "head";
INSTANCE.trxExpirationTimeInMilliseconds =
config.hasPath("trx.expiration.timeInMilliseconds")
&& config.getLong("trx.expiration.timeInMilliseconds") > 0 ?
config.getLong("trx.expiration.timeInMilliseconds")
: Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
INSTANCE.minEffectiveConnection = config.hasPath("node.rpc.minEffectiveConnection") ?
config.getInt("node.rpc.minEffectiveConnection") : 1;
INSTANCE.blockNumForEneryLimit = config.hasPath("enery.limit.block.num") ?
config.getInt("enery.limit.block.num") : 4727890L;
INSTANCE.vmTrace =
config.hasPath("vm.vmTrace") ? config
.getBoolean("vm.vmTrace") : false;
INSTANCE.saveInternalTx =
config.hasPath("vm.saveInternalTx") && config.getBoolean("vm.saveInternalTx");
INSTANCE.allowZKSnarkTransaction =
config.hasPath("committee.allowZKSnarkTransaction") ? config
.getInt("committee.allowZKSnarkTransaction") : 0;
INSTANCE.eventPluginConfig =
config.hasPath("event.subscribe") ?
getEventPluginConfig(config) : null;
INSTANCE.eventFilter =
config.hasPath("event.subscribe.filter") ? getEventFilter(config) : null;
initBackupProperty(config);
if ("ROCKSDB".equals(Args.getInstance().getStorage().getDbEngine().toUpperCase())) {
initRocksDbBackupProperty(config);
initRocksDbSettings(config);
}
logConfig();
}
private static List<Witness> getWitnessesFromConfig(final com.typesafe.config.Config config) {
return config.getObjectList("genesis.block.witnesses").stream()
.map(Args::createWitness)
.collect(Collectors.toCollection(ArrayList::new));
}
private static Witness createWitness(final ConfigObject witnessAccount) {
final Witness witness = new Witness();
witness.setAddress(
Wallet.decodeFromBase58Check(witnessAccount.get("address").unwrapped().toString()));
witness.setUrl(witnessAccount.get("url").unwrapped().toString());
witness.setVoteCount(witnessAccount.toConfig().getLong("voteCount"));
return witness;
}
private static List<Account> getAccountsFromConfig(final com.typesafe.config.Config config) {
return config.getObjectList("genesis.block.assets").stream()
.map(Args::createAccount)
.collect(Collectors.toCollection(ArrayList::new));
}
private static Account createAccount(final ConfigObject asset) {
final Account account = new Account();
account.setAccountName(asset.get("accountName").unwrapped().toString());
account.setAccountType(asset.get("accountType").unwrapped().toString());
account.setAddress(Wallet.decodeFromBase58Check(asset.get("address").unwrapped().toString()));
account.setBalance(asset.get("balance").unwrapped().toString());
return account;
}
public static Args getInstance() {
return INSTANCE;
}
/**
* Get storage path by name of database
*
* @param dbName name of database
* @return path of that database
*/
public String getOutputDirectoryByDbName(String dbName) {
String path = storage.getPathByDbName(dbName);
if (!StringUtils.isBlank(path)) {
return path;
}
return getOutputDirectory();
}
/**
* get output directory.
*/
public String getOutputDirectory() {
if (!this.outputDirectory.equals("") && !this.outputDirectory.endsWith(File.separator)) {
return this.outputDirectory + File.separator;
}
return this.outputDirectory;
}
private static List<Node> getNodes(final com.typesafe.config.Config config, String path) {
if (!config.hasPath(path)) {
return Collections.emptyList();
}
List<Node> ret = new ArrayList<>();
List<String> list = config.getStringList(path);
for (String configString : list) {
Node n = Node.instanceOf(configString);
ret.add(n);
}
return ret;
}
private static void privateKey(final com.typesafe.config.Config config) {
if (config.hasPath("private.key")) {
INSTANCE.privateKey = config.getString("private.key");
if (INSTANCE.privateKey.length() != ChainConstant.PRIVATE_KEY_LENGTH) {
throw new RuntimeException(
"The peer.privateKey needs to be Hex encoded and 32 byte length");
}
} else {
INSTANCE.privateKey = getGeneratedNodePrivateKey();
}
}