Skip to content

Commit bacf920

Browse files
authored
Merge branch 'develop' into master
2 parents cd5b92e + e51aed1 commit bacf920

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2159
-427
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ src/main/resources/META-INF/
5151
/output_witness/
5252
output*
5353
nodeId.properties
54+
Wallet

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ TRON Protocol and the TVM allow anyone to develop DAPPs for themselves or their
6363
* JDK 1.8 (JDK 1.9+ are not supported yet)
6464
* On Linux Ubuntu system (e.g. Ubuntu 16.04.4 LTS), ensure that the machine has [__Oracle JDK 8__](https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04), instead of having __Open JDK 8__ in the system. If you are building the source code by using __Open JDK 8__, you will get [__Build Failed__](https://github.com/tronprotocol/java-tron/issues/337) result.
6565

66-
## Getting the code
66+
## Getting the code with git
6767

6868
* Use Git from the Terminal, see the [Setting up Git](https://help.github.com/articles/set-up-git/) and [Fork a Repo](https://help.github.com/articles/fork-a-repo/) articles.
6969
* develop branch: the newnest code
@@ -78,6 +78,42 @@ git checkout -t origin/master
7878

7979
* If you'd rather not use Git, [Download the ZIP](https://github.com/tronprotocol/java-tron/archive/develop.zip)
8080

81+
## Including java-tron as dependency
82+
83+
* If you don't want to checkout the code and build the project, you can include it directly as a dependency
84+
85+
**Using gradle:**
86+
87+
```
88+
repositories {
89+
maven { url 'https://jitpack.io' }
90+
}
91+
dependencies {
92+
implementation 'com.github.tronprotocol:java-tron:develop-SNAPSHOT'
93+
}
94+
```
95+
96+
**Using maven:**
97+
98+
```xml
99+
...
100+
<repositories>
101+
<repository>
102+
<id>jitpack.io</id>
103+
<url>https://jitpack.io</url>
104+
</repository>
105+
</repositories>
106+
...
107+
<dependency>
108+
<groupId>com.github.tronprotocol</groupId>
109+
<artifactId>java-tron</artifactId>
110+
<version>develop-SNAPSHOT</version><!--You can use any of the tag/branch name available-->
111+
</dependency>
112+
```
113+
114+
115+
116+
81117
## Building from source code
82118

83119
* Build in the Terminal
@@ -477,6 +513,10 @@ Then observe whether block synchronization success,If synchronization successf
477513
478514
Read the [Quick Start](http://wiki.tron.network/en/latest/Quick_Start.html).
479515
516+
# Advanced Configurations
517+
518+
Read the [Advanced Configurations](src/main/java/org/tron/core/config/README.md).
519+
480520
# Community
481521
482522
* [Slack](https://join.slack.com/t/tronfoundation/shared_invite/enQtMzAzNzg4NTI4NDM3LTAyZGQzMzEzMjNkNDU0ZjNkNTA4OTYyNTA5YWZmYjE3MTEyOWZhNzljNzQwODM3NDQ0OWRiMTIyMDhlYzgyOGQ)

build.gradle

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,29 @@ apply plugin: 'application'
2222
apply plugin: 'checkstyle'
2323
apply plugin: 'com.github.johnrengelman.shadow'
2424
apply plugin: "jacoco"
25+
apply plugin: 'maven-publish'
2526

2627
sourceCompatibility = 1.8
2728
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
2829
mainClassName = 'org.tron.program.FullNode'
2930

31+
publishing {
32+
publications {
33+
mavenJava(MavenPublication) {
34+
from components.java
35+
artifact sourceJar
36+
}
37+
}
38+
repositories {
39+
mavenLocal()
40+
}
41+
}
42+
43+
task sourceJar(type: Jar, dependsOn: classes) {
44+
classifier 'sources'
45+
from sourceSets.main.allSource
46+
}
47+
3048
repositories {
3149
maven { url 'http://mvnrepository.com' }
3250
mavenLocal()
@@ -268,8 +286,8 @@ def binaryRelease(taskName, jarName, mainClass) {
268286
}
269287
}
270288

271-
272289
artifacts {
273290
archives(binaryRelease('buildSolidityNodeJar', 'SolidityNode', 'org.tron.program.SolidityNode'),
274-
binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode'))
275-
}
291+
binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode'),
292+
binaryRelease('buildKeystoreFactoryJar', 'KeystoreFactory', 'org.tron.program.KeystoreFactory'))
293+
}

jitpack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
install:
2+
- ./gradlew build publishToMavenLocal -x test

src/main/java/org/tron/core/actuator/WitnessCreateActuator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ private void createWitness(final WitnessCreateContract witnessCreateContract)
121121
.get(witnessCapsule.createDbKey());
122122
accountCapsule.setIsWitness(true);
123123
this.dbManager.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
124-
dbManager.adjustBalance(witnessCreateContract.getOwnerAddress().toByteArray(),
125-
-dbManager.getDynamicPropertiesStore().getAccountUpgradeCost());
124+
long cost = dbManager.getDynamicPropertiesStore().getAccountUpgradeCost();
125+
dbManager.adjustBalance(witnessCreateContract.getOwnerAddress().toByteArray(), -cost);
126126

127-
dbManager.adjustBalance(this.dbManager.getAccountStore().getBlackhole().createDbKey(),
128-
+dbManager.getDynamicPropertiesStore().getAccountUpgradeCost());
127+
dbManager.adjustBalance(this.dbManager.getAccountStore().getBlackhole().createDbKey(), +cost);
128+
129+
dbManager.getDynamicPropertiesStore().addTotalCreateWitnessCost(cost);
129130
}
130131
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Advanced Configurations
2+
3+
we provide some configuration items for LevelDB and gRPC in `config.conf` file, for fine-grained performance tuning.
4+
You may custom these items only if you have deep understanding on them, otherwise keep them as default.
5+
6+
## LevelDB
7+
8+
You can custom LevelDB options in the `storage` part of `config.conf`, which looks like:
9+
10+
```
11+
storage {
12+
# Directory for storing persistent data
13+
14+
db.directory = "database",
15+
index.directory = "index",
16+
17+
# You can custom these 14 databases' configs:
18+
19+
# account, account-index, asset-issue, block, block-index,
20+
# block_KDB, peers, properties, recent-block, trans,
21+
# utxo, votes, witness, witness_schedule.
22+
23+
# Otherwise, db configs will remain defualt and data will be stored in
24+
# the path of "output-directory" or which is set by "-d" ("--output-directory").
25+
26+
# Attention: name is a required field that must be set !!!
27+
properties = [
28+
{
29+
name = "account",
30+
path = "/path/to/accout", // relative or absolute path
31+
createIfMissing = true,
32+
paranoidChecks = true,
33+
verifyChecksums = true,
34+
compressionType = 1, // 0 - no compression, 1 - compressed with snappy
35+
blockSize = 4096, // 4 KB = 4 * 1024 B
36+
writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
37+
cacheSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
38+
maxOpenFiles = 100
39+
}
40+
]
41+
42+
}
43+
44+
```
45+
46+
As shown in the example above, the data of database `accout` will be stored in the path of `/path/to/accout/database` while the index be stored in `/path/to/accout/index`. And, the example also shows our default value of LevelDB options from `createIfMissing` to `maxOpenFiles`. You can just refer to the docs of [LevelDB](https://github.com/google/leveldb/blob/master/doc/index.md#performance) to figure out details of these options.
47+
48+
## gRPC
49+
50+
You can custom gPRC options in the `node.rpc` part of `config.conf`, which looks like:
51+
52+
```
53+
node {
54+
rpc {
55+
port = 50051
56+
57+
# Number of gRPC thread, default availableProcessors / 2
58+
# thread = 16
59+
60+
# The maximum number of concurrent calls permitted for each incoming connection
61+
# maxConcurrentCallsPerConnection =
62+
63+
# The HTTP/2 flow control window, default 1MB
64+
# flowControlWindow =
65+
66+
# Connection being idle for longer than which will be gracefully terminated
67+
maxConnectionIdleInMillis = 60000
68+
69+
# Connection lasting longer than which will be gracefully terminated
70+
# maxConnectionAgeInMillis =
71+
72+
# The maximum message size allowed to be received on the server, default 4MB
73+
# maxMessageSize =
74+
75+
# The maximum size of header list allowed to be received, default 8192
76+
# maxHeaderListSize =
77+
}
78+
}
79+
```
80+
81+
You may refer to the source code of `io.grpc.netty.NettyServerBuilder` class to see details or just make a decision according to the brief comments above.

src/main/java/org/tron/core/config/args/Account.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
import com.google.protobuf.ByteString;
1919
import java.io.Serializable;
20+
import java.util.Arrays;
21+
2022
import lombok.Getter;
2123
import org.apache.commons.lang3.StringUtils;
2224
import org.tron.common.utils.ByteArray;
25+
import org.tron.common.utils.StringUtil;
2326
import org.tron.core.Wallet;
2427
import org.tron.protos.Protocol.AccountType;
2528

@@ -49,7 +52,7 @@ public class Account implements Serializable {
4952
public void setAddress(final byte[] address) {
5053
if (!Wallet.addressValid(address)){
5154
throw new IllegalArgumentException(
52-
"The address(" + address + ") must be a 21 bytes.");
55+
"The address(" + StringUtil.createReadableString(address) + ") must be a 21 bytes.");
5356
}
5457
this.address = address;
5558
}

src/main/java/org/tron/core/config/args/Args.java

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.beust.jcommander.Parameter;
55
import com.typesafe.config.Config;
66
import com.typesafe.config.ConfigObject;
7+
78
import java.io.BufferedReader;
89
import java.io.File;
910
import java.io.FileReader;
@@ -21,6 +22,9 @@
2122
import java.util.Optional;
2223
import java.util.Properties;
2324
import java.util.stream.Collectors;
25+
26+
import io.grpc.internal.GrpcUtil;
27+
import io.grpc.netty.NettyServerBuilder;
2428
import lombok.Getter;
2529
import lombok.NoArgsConstructor;
2630
import lombok.Setter;
@@ -32,10 +36,14 @@
3236
import org.tron.common.crypto.ECKey;
3337
import org.tron.common.overlay.discover.Node;
3438
import org.tron.core.Constant;
39+
import org.tron.common.utils.ByteArray;
3540
import org.tron.core.Wallet;
3641
import org.tron.core.config.Configuration;
3742
import org.tron.core.config.Parameter.ChainConstant;
3843
import org.tron.core.db.AccountStore;
44+
import org.tron.keystore.CipherException;
45+
import org.tron.keystore.Credentials;
46+
import org.tron.keystore.WalletUtils;
3947

4048
@Slf4j
4149
@NoArgsConstructor
@@ -170,6 +178,30 @@ public class Args {
170178
@Parameter(names = {"--rpc-thread"}, description = "Num of gRPC thread")
171179
private int rpcThreadNum;
172180

181+
@Getter
182+
@Setter
183+
private int maxConcurrentCallsPerConnection;
184+
185+
@Getter
186+
@Setter
187+
private int flowControlWindow;
188+
189+
@Getter
190+
@Setter
191+
private long maxConnectionIdleInMillis;
192+
193+
@Getter
194+
@Setter
195+
private long maxConnectionAgeInMillis;
196+
197+
@Getter
198+
@Setter
199+
private int maxMessageSize;
200+
201+
@Getter
202+
@Setter
203+
private int maxHeaderListSize;
204+
173205
@Getter
174206
@Setter
175207
@Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread")
@@ -252,7 +284,6 @@ public static void setParam(final String[] args, final String confFileName) {
252284
INSTANCE.setLocalWitnesses(new LocalWitnesses(INSTANCE.privateKey));
253285
logger.debug("Got privateKey from cmd");
254286
} else if (config.hasPath("localwitness")) {
255-
256287
INSTANCE.localWitnesses = new LocalWitnesses();
257288
List<String> localwitness = config.getStringList("localwitness");
258289
if (localwitness.size() > 1) {
@@ -261,6 +292,30 @@ public static void setParam(final String[] args, final String confFileName) {
261292
}
262293
INSTANCE.localWitnesses.setPrivateKeys(localwitness);
263294
logger.debug("Got privateKey from config.conf");
295+
} else if (config.hasPath("localwitnesskeystore")) {
296+
INSTANCE.localWitnesses = new LocalWitnesses();
297+
List<String> privateKeys = new ArrayList<String>();
298+
if (INSTANCE.isWitness()) {
299+
List<String> localwitness = config.getStringList("localwitnesskeystore");
300+
if (localwitness.size() > 0) {
301+
String fileName = System.getProperty("user.dir") + "/" + localwitness.get(0);
302+
System.out.println("Please input your password.");
303+
String password = WalletUtils.inputPassword();
304+
try {
305+
Credentials credentials = WalletUtils
306+
.loadCredentials(password, new File(fileName));
307+
ECKey ecKeyPair = credentials.getEcKeyPair();
308+
String prikey = ByteArray.toHexString(ecKeyPair.getPrivKeyBytes());
309+
privateKeys.add(prikey);
310+
} catch (IOException e) {
311+
logger.warn(e.getMessage());
312+
} catch (CipherException e) {
313+
logger.warn(e.getMessage());
314+
}
315+
}
316+
}
317+
INSTANCE.localWitnesses.setPrivateKeys(privateKeys);
318+
logger.debug("Got privateKey from keystore");
264319
}
265320

266321
if (INSTANCE.isWitness() && CollectionUtils.isEmpty(INSTANCE.localWitnesses.getPrivateKeys())) {
@@ -270,11 +325,11 @@ public static void setParam(final String[] args, final String confFileName) {
270325
INSTANCE.storage = new Storage();
271326
INSTANCE.storage.setDbDirectory(Optional.ofNullable(INSTANCE.storageDbDirectory)
272327
.filter(StringUtils::isNotEmpty)
273-
.orElse(config.getString("storage.db.directory")));
328+
.orElse(Storage.getDbDirectoryFromConfig(config)));
274329

275330
INSTANCE.storage.setIndexDirectory(Optional.ofNullable(INSTANCE.storageIndexDirectory)
276331
.filter(StringUtils::isNotEmpty)
277-
.orElse(config.getString("storage.index.directory")));
332+
.orElse(Storage.getIndexDirectoryFromConfig(config)));
278333

279334
INSTANCE.storage.setPropertyMapFromConfig(config);
280335

@@ -360,6 +415,24 @@ public static void setParam(final String[] args, final String confFileName) {
360415
config.hasPath("node.rpc.thread") ? config.getInt("node.rpc.thread")
361416
: Runtime.getRuntime().availableProcessors() / 2;
362417

418+
INSTANCE.maxConcurrentCallsPerConnection = config.hasPath("node.rpc.maxConcurrentCallsPerConnection") ?
419+
config.getInt("node.rpc.maxConcurrentCallsPerConnection") : Integer.MAX_VALUE;
420+
421+
INSTANCE.flowControlWindow = config.hasPath("node.rpc.flowControlWindow") ?
422+
config.getInt("node.rpc.flowControlWindow") : NettyServerBuilder.DEFAULT_FLOW_CONTROL_WINDOW;
423+
424+
INSTANCE.maxConnectionIdleInMillis = config.hasPath("node.rpc.maxConnectionIdleInMillis") ?
425+
config.getLong("node.rpc.maxConnectionIdleInMillis") : Long.MAX_VALUE;
426+
427+
INSTANCE.maxConnectionAgeInMillis = config.hasPath("node.rpc.maxConnectionAgeInMillis") ?
428+
config.getLong("node.rpc.maxConnectionAgeInMillis") : Long.MAX_VALUE;
429+
430+
INSTANCE.maxMessageSize = config.hasPath("node.rpc.maxMessageSize") ?
431+
config.getInt("node.rpc.maxMessageSize") : GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
432+
433+
INSTANCE.maxHeaderListSize = config.hasPath("node.rpc.maxHeaderListSize") ?
434+
config.getInt("node.rpc.maxHeaderListSize") : GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;
435+
363436
INSTANCE.maintenanceTimeInterval =
364437
config.hasPath("block.maintenanceTimeInterval") ? config
365438
.getInt("block.maintenanceTimeInterval") : 21600000L;

0 commit comments

Comments
 (0)