Skip to content

Commit 9b3be3f

Browse files
authored
Merge branch 'tronprotocol:develop' into develop
2 parents cfec5b1 + 0f65763 commit 9b3be3f

31 files changed

Lines changed: 647 additions & 86 deletions

README.md

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -65,72 +65,70 @@ TRON enables large-scale development and engagement. With over 2000 transactions
6565
# Building the source
6666
Building java-tron requires `git` and `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
6767

68-
## Getting the Source Code
68+
Clone the repo and switch to the `master` branch
6969

7070
```bash
7171
$ git clone https://github.com/tronprotocol/java-tron.git
72+
$ cd java-tron
7273
$ git checkout -t origin/master
7374
```
74-
75-
## Build
76-
75+
then run the following command to build java-tron, the `FullNode.jar` file can be found in `java-tron/build/libs/` after build successful.
7776
```bash
78-
$ cd java-tron
7977
$ ./gradlew clean build -x test
8078
```
8179

82-
The `FullNode.jar` file can be found in `java-tron/build/libs/FullNode.jar` after build successful.
8380

8481
# Running java-tron
85-
86-
Get the mainnet configurate file: [main_net_config.conf](https://github.com/tronprotocol/tron-deployment/blob/master/main_net_config.conf), other network configuration files can be find [here](https://github.com/tronprotocol/tron-deployment).
87-
8882
Running java-tron requires `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
8983

84+
Get the mainnet configurate file: [main_net_config.conf](https://github.com/tronprotocol/tron-deployment/blob/master/main_net_config.conf), other network configuration files can be find [here](https://github.com/tronprotocol/tron-deployment).
9085
## Hardware Requirements
91-
* Minimum:
92-
* CPU with 8 cores
93-
* 16GB RAM
94-
* 1TB free storage space to sync the Mainnet
95-
* Recommended:
96-
* CPU with 16+ cores(32+ cores for a super representative)
97-
* 32+ GB RAM(64+ GB for a super representative)
98-
* High Performance SSD with at least 1.5TB free space
99-
* 100+ MB/s download Internet service
86+
Minimum:
87+
* CPU with 8 cores
88+
* 16GB RAM
89+
* 1TB free storage space to sync the Mainnet
90+
91+
Recommended:
92+
* CPU with 16+ cores(32+ cores for a super representative)
93+
* 32GB+ RAM(64GB+ for a super representative)
94+
* High Performance SSD with at least 1.5TB free space
95+
* 100+ MB/s download Internet service
10096

10197

10298
## Running a full node for mainnet
103-
Full node has full historical data, it is the entry point into the TRON network , it can be used by other processes as a gateway into the TRON network via HTTP and GRPC endpoints. You can interact with the TRON network through full node:transfer assets, deploy contracts, interact with contracts and so on. `-c ` parameter specifies a configuration file to run a full node:
99+
Full node has full historical data, it is the entry point into the TRON network , it can be used by other processes as a gateway into the TRON network via HTTP and GRPC endpoints. You can interact with the TRON network through full node:transfer assets, deploy contracts, interact with contracts and so on. `-c ` parameter specifies a configuration file to run a full node:
104100
```bash
105101
$ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
106-
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:MaxDirectMemorySize=1G \
107-
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log \
108-
-XX:+UseConcMarkSweepGC -XX:NewRatio=2 \
109-
-XX:+CMSScavengeBeforeRemark -XX:+ParallelRefProcEnabled \
110-
-XX:+HeapDumpOnOutOfMemoryError \
111-
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
112-
-jar FullNode.jar -c main_net_config.conf >> start.log 2>&1 &
102+
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
103+
-XX:MaxDirectMemorySize=1G -XX:+PrintGCDetails \
104+
-XX:+PrintGCDateStamps -Xloggc:gc.log \
105+
-XX:+UseConcMarkSweepGC -XX:NewRatio=2 \
106+
-XX:+CMSScavengeBeforeRemark -XX:+ParallelRefProcEnabled \
107+
-XX:+HeapDumpOnOutOfMemoryError \
108+
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
109+
-jar FullNode.jar -c main_net_config.conf >> start.log 2>&1 &
113110
```
114-
## Running a super representative node for mainnet
115-
Adding the `--witness` parameter to the startup command, full node will run as a super representative node. The super representative node supports all the functions of the full node and also supports block production. Before running, make sure you have a super representative account and get votes from others,once the number of obtained votes ranks in the top 27, your super representative node will participate in block production.
111+
## Running a super representative node for mainnet
112+
Adding the `--witness` parameter to the startup command, full node will run as a super representative node. The super representative node supports all the functions of the full node and also supports block production. Before running, make sure you have a super representative account and get votes from others,once the number of obtained votes ranks in the top 27, your super representative node will participate in block production.
116113

117-
Fill in the private key of super representative address into the `localwitness` list in the `main_net_config.conf`, here is an example:
114+
Fill in the private key of super representative address into the `localwitness` list in the `main_net_config.conf`, here is an example:
118115
```
119116
localwitness = [
120117
650950B193DDDDB35B6E48912DD28F7AB0E7140C1BFDEFD493348F02295BD812
121118
]
122119
```
123120

124-
then run the following command to start the node:
121+
then run the following command to start the node:
125122
```bash
126123
$ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
127-
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:MaxDirectMemorySize=1G \
128-
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log \
129-
-XX:+UseConcMarkSweepGC -XX:NewRatio=2 \
130-
-XX:+CMSScavengeBeforeRemark -XX:+ParallelRefProcEnabled \
131-
-XX:+HeapDumpOnOutOfMemoryError \
132-
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
133-
-jar FullNode.jar --witness -c main_net_config.conf >> start.log 2>&1 &
124+
-XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m \
125+
-XX:MaxDirectMemorySize=1G -XX:+PrintGCDetails \
126+
-XX:+PrintGCDateStamps -Xloggc:gc.log \
127+
-XX:+UseConcMarkSweepGC -XX:NewRatio=2 \
128+
-XX:+CMSScavengeBeforeRemark -XX:+ParallelRefProcEnabled \
129+
-XX:+HeapDumpOnOutOfMemoryError \
130+
-XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
131+
-jar FullNode.jar --witness -c main_net_config.conf >> start.log 2>&1 &
134132
```
135133

136134
## Quick Start Tool
@@ -143,16 +141,16 @@ Here are some common use cases of the scripting tool
143141

144142
For more details, please refer to the tool [guide](./shell.md).
145143

146-
## Run inside Docker container
144+
## Run inside Docker container
147145

148146
One of the quickest ways to get `java-tron` up and running on your machine is by using Docker:
149147
```shell
150148
$ docker run -d --name="java-tron" \
151-
-v /your_path/output-directory:/java-tron/output-directory \
152-
-v /your_path/logs:/java-tron/logs \
153-
-p 8090:8090 -p 18888:18888 -p 50051:50051 \
154-
tronprotocol/java-tron \
155-
-c /java-tron/config/main_net_config.conf
149+
-v /your_path/output-directory:/java-tron/output-directory \
150+
-v /your_path/logs:/java-tron/logs \
151+
-p 8090:8090 -p 18888:18888 -p 50051:50051 \
152+
tronprotocol/java-tron \
153+
-c /java-tron/config/main_net_config.conf
156154
```
157155

158156
This will mount the `output-directory` and `logs` directories on the host, the docker.sh tool can also be used to simplify the use of docker, see more [here](docker/docker.md).
@@ -165,9 +163,8 @@ This will mount the `output-directory` and `logs` directories on the host, the d
165163
[tronprotocol/allcoredev](https://gitter.im/tronprotocol/allcoredev) is the official Gitter channel for developers.
166164

167165
# Contribution
168-
If you'd like to contribute to java-tron, please read the following instructions.
166+
Thank you for considering to help out with the source code! If you'd like to contribute to java-tron, please see the [Contribution Guide](./CONTRIBUTING.md) for more details.
169167

170-
- [Contribution](./CONTRIBUTING.md)
171168

172169
# Resources
173170
* [Medium](https://medium.com/@coredevs) java-tron's official technical articles are published there.
@@ -180,3 +177,11 @@ If you'd like to contribute to java-tron, please read the following instructions
180177

181178
# License
182179
java-tron is released under the [LGPLv3 license](https://github.com/tronprotocol/java-tron/blob/master/LICENSE).
180+
181+
182+
183+
The minimum hardware requirements are `CPU with 8 cores`,`16GB RAM` and `1TB free storage space` to sync the Mainnet, the recommended hardware requirements:
184+
* CPU with 16+ cores(32+ cores for a super representative)
185+
* 32+ GB RAM(64+ GB for a super representative)
186+
* High Performance SSD with at least 1.5TB free space
187+
* 100+ MB/s download Internet service

chainbase/src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ public Map<byte[], byte[]> getNext(byte[] key, long limit) {
352352
}
353353
}
354354

355+
@Override
355356
public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
356357
resetDbLock.readLock().lock();
357358
try (DBIterator iterator = getDBIterator()) {

chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ public Map<byte[], byte[]> getNext(byte[] key, long limit) {
431431
}
432432
}
433433

434+
@Override
434435
public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
435436
if (quitIfNotAlive()) {
436437
return null;

chainbase/src/main/java/org/tron/common/utils/WalletUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,12 @@ public static byte[] getSelector(byte[] data) {
131131
return ret;
132132
}
133133

134+
public static Long isLong(String s) {
135+
try {
136+
return Long.parseLong(s);
137+
} catch (NumberFormatException ignored) {
138+
return null;
139+
}
140+
}
141+
134142
}

chainbase/src/main/java/org/tron/core/db/TronDatabase.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,7 @@ public T getUnchecked(byte[] key) {
110110
}
111111

112112
public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
113-
Map<WrappedByteArray, byte[]> result = new HashMap<>();
114-
if (dbSource.getClass() == LevelDbDataSourceImpl.class) {
115-
result = ((LevelDbDataSourceImpl) dbSource).prefixQuery(key);
116-
} else if (dbSource.getClass() == RocksDbDataSourceImpl.class) {
117-
result = ((RocksDbDataSourceImpl) dbSource).prefixQuery(key);
118-
}
119-
return result;
113+
return dbSource.prefixQuery(key);
120114
}
121115

122116
public abstract boolean has(byte[] key);

chainbase/src/main/java/org/tron/core/db/common/DbSourceInter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ public interface DbSourceInter<V> extends BatchSourceInter<byte[], V>,
4646

4747
void stat();
4848

49+
Map<WrappedByteArray, byte[]> prefixQuery(byte[] key);
50+
4951
}

chainbase/src/main/java/org/tron/core/db2/core/Chainbase.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import java.util.Set;
1313
import java.util.stream.Collectors;
1414

15-
import com.google.common.primitives.Bytes;
1615
import org.tron.common.utils.ByteUtil;
16+
import org.tron.common.utils.Pair;
1717
import org.tron.core.capsule.utils.MarketUtils;
1818
import org.tron.core.db2.common.IRevokingDB;
1919
import org.tron.core.db2.common.LevelDB;
@@ -350,13 +350,14 @@ private Map<byte[], byte[]> getNext(Snapshot head, byte[] key, long limit) {
350350
}
351351

352352
public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
353-
Map<WrappedByteArray, byte[]> resultSnapshot = prefixQuerySnapshot(key);
354-
Map<WrappedByteArray, byte[]> resultDB = prefixQueryDB(key);
355-
resultDB.putAll(resultSnapshot);
356-
return resultDB;
353+
Map<WrappedByteArray, byte[]> result = prefixQueryRoot(key);
354+
Map<WrappedByteArray, byte[]> snapshot = prefixQuerySnapshot(key);
355+
result.putAll(snapshot);
356+
result.entrySet().removeIf(e -> e.getValue() == null);
357+
return result;
357358
}
358359

359-
private Map<WrappedByteArray, byte[]> prefixQueryDB(byte[] key) {
360+
private Map<WrappedByteArray, byte[]> prefixQueryRoot(byte[] key) {
360361
Map<WrappedByteArray, byte[]> result = new HashMap<>();
361362
if (((SnapshotRoot) head.getRoot()).db.getClass() == LevelDB.class) {
362363
result = ((LevelDB) ((SnapshotRoot) head.getRoot()).db).getDb().prefixQuery(key);
@@ -369,16 +370,10 @@ private Map<WrappedByteArray, byte[]> prefixQueryDB(byte[] key) {
369370
private Map<WrappedByteArray, byte[]> prefixQuerySnapshot(byte[] key) {
370371
Map<WrappedByteArray, byte[]> result = new HashMap<>();
371372
Snapshot snapshot = head();
372-
while (!snapshot.equals(head.getRoot())) {
373-
Iterator<Map.Entry<byte[], byte[]>> iterator = snapshot.iterator();
374-
while (iterator.hasNext()) {
375-
Map.Entry<byte[], byte[]> entry = iterator.next();
376-
WrappedByteArray ks = WrappedByteArray.of(entry.getKey());
377-
if (Bytes.indexOf(entry.getKey(), key) == 0 && !result.containsKey(ks)) {
378-
result.put(ks, entry.getValue());
379-
}
380-
}
381-
snapshot = snapshot.getPrevious();
373+
if (!snapshot.equals(head.getRoot())) {
374+
Map<WrappedByteArray, WrappedByteArray> all = new HashMap<>();
375+
((SnapshotImpl) snapshot).collect(all, key);
376+
all.forEach((k, v) -> result.put(k, v.getBytes()));
382377
}
383378
return result;
384379
}

chainbase/src/main/java/org/tron/core/db2/core/SnapshotImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import com.google.common.collect.Iterators;
55
import com.google.common.collect.Maps;
66
import com.google.common.collect.Streams;
7+
import com.google.common.primitives.Bytes;
78
import java.util.HashMap;
89
import java.util.HashSet;
910
import java.util.Iterator;
1011
import java.util.Map;
12+
import java.util.Objects;
1113
import java.util.Set;
1214
import lombok.Getter;
1315
import org.tron.core.db2.common.HashDB;
@@ -129,6 +131,17 @@ synchronized void collect(Map<WrappedByteArray, WrappedByteArray> all) {
129131
}
130132
}
131133

134+
synchronized void collect(Map<WrappedByteArray, WrappedByteArray> all, byte[] prefix) {
135+
Snapshot next = getRoot().getNext();
136+
while (next != null) {
137+
Streams.stream(((SnapshotImpl) next).db).filter(e -> Bytes.indexOf(
138+
Objects.requireNonNull(e.getKey().getBytes()), prefix) == 0)
139+
.forEach(e -> all.put(WrappedByteArray.of(e.getKey().getBytes()),
140+
WrappedByteArray.of(e.getValue().getBytes())));
141+
next = next.getNext();
142+
}
143+
}
144+
132145
/**
133146
* Note: old --> new
134147
* In the snapshot, there may be same keys.

framework/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id "org.sonarqube" version "2.6"
3+
id "com.gorylenko.gradle-git-properties" version "2.4.1"
34
}
45

56
apply plugin: 'application'

framework/src/main/java/org/tron/common/overlay/server/Channel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class Channel {
6161
private InetSocketAddress inetSocketAddress;
6262
private Node node;
6363
private long startTime;
64+
@Getter
6465
private TronState tronState = TronState.INIT;
6566
private boolean isActive;
6667
@Getter

0 commit comments

Comments
 (0)