Skip to content

Commit fe3a38d

Browse files
committed
merge develop
2 parents 5bf5501 + fcd6fec commit fe3a38d

205 files changed

Lines changed: 8714 additions & 3388 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ src/main/resources/META-INF/
5252
output*
5353
nodeId.properties
5454
Wallet
55+
56+
# vm_trace
57+
/vm_trace/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ TRON Protocol and the Tron Virtual Machine (TVM) allow anyone to develop decentr
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
* Open **UDP** ports for connection to the network
66-
* **MINIMUM** 2 CPU Cores
66+
* **MINIMUM** 2 ENERGY Cores
6767

6868
## Build and Deploy automatically using scripts
6969

build.gradle

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ repositories {
4949
maven { url 'http://mvnrepository.com' }
5050
mavenLocal()
5151
mavenCentral()
52+
maven { url 'http://repo.spring.io/plugins-release' }
5253
}
5354
def versions = [
5455
checkstyle: '8.7',
@@ -68,6 +69,24 @@ configurations.getByName('checkstyleConfig') {
6869
transitive = false
6970
}
7071

72+
static def isWindows() {
73+
return org.gradle.internal.os.OperatingSystem.current().isWindows()
74+
}
75+
76+
if (isWindows()) {
77+
ext {
78+
leveldbGroup = "org.ethereum"
79+
leveldbName = "leveldbjni-all"
80+
leveldbVersion = "1.18.3"
81+
}
82+
} else {
83+
ext {
84+
leveldbGroup = "org.fusesource.leveldbjni"
85+
leveldbName = "leveldbjni-all"
86+
leveldbVersion = "1.8"
87+
}
88+
}
89+
7190
dependencies {
7291
//local libraries
7392
compile fileTree(dir: 'libs', include: '*.jar')
@@ -95,8 +114,7 @@ dependencies {
95114

96115
compile "org.iq80.leveldb:leveldb:0.7"
97116

98-
compile group: 'org.fusesource.leveldbjni', name: 'leveldbjni-all',
99-
version: '1.8'
117+
compile group: leveldbGroup, name: leveldbName, version: leveldbVersion
100118

101119
compile "org.apache.commons:commons-collections4:4.0"
102120

src/main/java/org/tron/common/application/Application.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ public interface Application {
4343
void addService(Service service);
4444

4545
Manager getDbManager();
46+
4647
}

src/main/java/org/tron/common/application/ApplicationImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.tron.core.config.args.Args;
77
import org.tron.core.db.BlockStore;
88
import org.tron.core.db.Manager;
9-
import org.tron.core.db.RevokingStore;
109
import org.tron.core.net.node.Node;
1110
import org.tron.core.net.node.NodeDelegate;
1211
import org.tron.core.net.node.NodeDelegateImpl;
@@ -25,7 +24,7 @@ public class ApplicationImpl implements Application {
2524

2625
@Autowired
2726
private Manager dbManager;
28-
27+
2928
private boolean isProducer;
3029

3130
private void resetP2PNode() {
@@ -76,6 +75,7 @@ public void shutdown() {
7675
closeAllStore();
7776
}
7877
closeConnection();
78+
dbManager.stopRepushThread();
7979
System.err.println("******** end to shutdown ********");
8080
}
8181

src/main/java/org/tron/common/application/CliApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ public void addService(Service service) {
7575
public Manager getDbManager() {
7676
return null;
7777
}
78+
7879
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.tron.common.application;
2+
3+
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
4+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5+
import org.tron.core.db.Manager;
6+
7+
public class TronApplicationContext extends AnnotationConfigApplicationContext {
8+
9+
public TronApplicationContext() {
10+
}
11+
12+
public TronApplicationContext(DefaultListableBeanFactory beanFactory) {
13+
super(beanFactory);
14+
}
15+
16+
public TronApplicationContext(Class<?>... annotatedClasses) {
17+
super(annotatedClasses);
18+
}
19+
20+
public TronApplicationContext(String... basePackages) {
21+
super(basePackages);
22+
}
23+
24+
@Override
25+
public void destroy() {
26+
27+
Manager dbManager = getBean(Manager.class);
28+
dbManager.stopRepushThread();
29+
30+
super.destroy();
31+
}
32+
}

src/main/java/org/tron/common/overlay/discover/node/NodeManager.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public class NodeManager implements EventHandler {
6060

6161
private static final org.slf4j.Logger logger = LoggerFactory.getLogger("NodeManager");
6262

63-
private Cache<InetSocketAddress, NodeHandler> badNodes = CacheBuilder.newBuilder().maximumSize(10000)
64-
.expireAfterWrite(1, TimeUnit.HOURS).recordStats().build();
65-
6663
private Args args = Args.getInstance();
6764

6865
private Manager dbManager;
@@ -241,11 +238,6 @@ public void handleEvent(UdpEvent udpEvent) {
241238

242239
NodeHandler nodeHandler = getNodeHandler(n);
243240
nodeHandler.getNodeStatistics().messageStatistics.addUdpInMessage(m.getType());
244-
calculateMsgCount(nodeHandler);
245-
if (badNodes.getIfPresent(nodeHandler.getInetSocketAddress()) != null){
246-
logger.warn("Receive packet from bad node {}.", sender.getAddress());
247-
return;
248-
}
249241

250242
switch (m.getType()) {
251243
case DISCOVER_PING:
@@ -384,21 +376,4 @@ void checkAll() {
384376
}
385377
}
386378

387-
private void calculateMsgCount(NodeHandler nodeHandler){
388-
int interval = 10;
389-
int maxCount = 10;
390-
MessageStatistics statistics = nodeHandler.getNodeStatistics().messageStatistics;
391-
int pingCount = statistics.discoverInPing.getCount(interval);
392-
int pongCount = statistics.discoverInPong.getCount(interval);
393-
int findNodeCount = statistics.discoverInFindNode.getCount(interval);
394-
int neighboursCount = statistics.discoverInNeighbours.getCount(interval);
395-
int count = pingCount + pongCount + findNodeCount + neighboursCount;
396-
if (count > maxCount){
397-
logger.warn("UDP attack found: {} with total count({}), ping({}), pong({}), findNode({}), neighbours({})",
398-
nodeHandler, count, pingCount, pongCount, findNodeCount, neighboursCount);
399-
badNodes.put(nodeHandler.getInetSocketAddress(), nodeHandler);
400-
table.dropNode(nodeHandler.getNode());
401-
}
402-
}
403-
404379
}

src/main/java/org/tron/common/overlay/discover/node/statistics/MessageCount.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public void add() {
3434
totalCount++;
3535
}
3636

37-
public void add(int length) {
37+
public void add(int count) {
3838
update();
39-
szCount[index]++;
40-
totalCount += length;
39+
szCount[index] += count;
40+
totalCount += count;
4141
}
4242

4343
public int getCount(int interval) {

src/main/java/org/tron/common/overlay/discover/node/statistics/MessageStatistics.java

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.tron.common.net.udp.message.UdpMessageTypeEnum;
5+
import org.tron.common.overlay.message.Message;
6+
import org.tron.core.net.message.FetchInvDataMessage;
7+
import org.tron.core.net.message.InventoryMessage;
58
import org.tron.core.net.message.MessageTypes;
9+
import org.tron.core.net.message.TransactionsMessage;
610

711
@Slf4j
812
public class MessageStatistics {
@@ -31,6 +35,39 @@ public class MessageStatistics {
3135
public final MessageCount tronInMessage = new MessageCount();
3236
public final MessageCount tronOutMessage = new MessageCount();
3337

38+
public final MessageCount tronInSyncBlockChain = new MessageCount();
39+
public final MessageCount tronOutSyncBlockChain = new MessageCount();
40+
public final MessageCount tronInBlockChainInventory = new MessageCount();
41+
public final MessageCount tronOutBlockChainInventory = new MessageCount();
42+
43+
public final MessageCount tronInTrxInventory = new MessageCount();
44+
public final MessageCount tronOutTrxInventory = new MessageCount();
45+
public final MessageCount tronInTrxInventoryElement = new MessageCount();
46+
public final MessageCount tronOutTrxInventoryElement = new MessageCount();
47+
48+
public final MessageCount tronInBlockInventory = new MessageCount();
49+
public final MessageCount tronOutBlockInventory = new MessageCount();
50+
public final MessageCount tronInBlockInventoryElement = new MessageCount();
51+
public final MessageCount tronOutBlockInventoryElement = new MessageCount();
52+
53+
public final MessageCount tronInTrxFetchInvData = new MessageCount();
54+
public final MessageCount tronOutTrxFetchInvData = new MessageCount();
55+
public final MessageCount tronInTrxFetchInvDataElement = new MessageCount();
56+
public final MessageCount tronOutTrxFetchInvDataElement = new MessageCount();
57+
58+
public final MessageCount tronInBlockFetchInvData = new MessageCount();
59+
public final MessageCount tronOutBlockFetchInvData = new MessageCount();
60+
public final MessageCount tronInBlockFetchInvDataElement = new MessageCount();
61+
public final MessageCount tronOutBlockFetchInvDataElement = new MessageCount();
62+
63+
64+
public final MessageCount tronInTrx = new MessageCount();
65+
public final MessageCount tronOutTrx = new MessageCount();
66+
public final MessageCount tronInTrxs = new MessageCount();
67+
public final MessageCount tronOutTrxs = new MessageCount();
68+
public final MessageCount tronInBlock = new MessageCount();
69+
public final MessageCount tronOutBlock = new MessageCount();
70+
public final MessageCount tronOutAdvBlock = new MessageCount();
3471

3572
public void addUdpInMessage(UdpMessageTypeEnum type){
3673
addUdpMessage(type, true);
@@ -40,12 +77,12 @@ public void addUdpOutMessage(UdpMessageTypeEnum type){
4077
addUdpMessage(type, false);
4178
}
4279

43-
public void addTcpInMessage(MessageTypes type){
44-
addTcpMessage(type, true);
80+
public void addTcpInMessage(Message msg){
81+
addTcpMessage(msg, true);
4582
}
4683

47-
public void addTcpOutMessage(MessageTypes type){
48-
addTcpMessage(type, false);
84+
public void addTcpOutMessage(Message msg){
85+
addTcpMessage(msg, false);
4986
}
5087

5188
private void addUdpMessage(UdpMessageTypeEnum type, boolean flag){
@@ -67,8 +104,15 @@ private void addUdpMessage(UdpMessageTypeEnum type, boolean flag){
67104
}
68105
}
69106

70-
private void addTcpMessage(MessageTypes type, boolean flag){
71-
switch (type){
107+
private void addTcpMessage(Message msg, boolean flag){
108+
109+
if (flag) {
110+
tronInMessage.add();
111+
} else {
112+
tronOutMessage.add();
113+
}
114+
115+
switch (msg.getType()){
72116
case P2P_HELLO:
73117
if (flag) p2pInHello.add(); else p2pOutHello.add();
74118
break;
@@ -82,14 +126,69 @@ private void addTcpMessage(MessageTypes type, boolean flag){
82126
if (flag) p2pInDisconnect.add(); else p2pOutDisconnect.add();
83127
break;
84128
case SYNC_BLOCK_CHAIN:
129+
if (flag) tronInSyncBlockChain.add(); else tronOutSyncBlockChain.add();
130+
break;
85131
case BLOCK_CHAIN_INVENTORY:
132+
if (flag) tronInBlockChainInventory.add(); else tronOutBlockChainInventory.add();
133+
break;
86134
case INVENTORY:
135+
InventoryMessage inventoryMessage = (InventoryMessage) msg;
136+
int inventorySize = inventoryMessage.getInventory().getIdsCount();
137+
if (flag) {
138+
if (inventoryMessage.getInvMessageType() == MessageTypes.TRX){
139+
tronInTrxInventory.add();
140+
tronInTrxInventoryElement.add(inventorySize);
141+
}else {
142+
tronInBlockInventory.add();
143+
tronInBlockInventoryElement.add(inventorySize);
144+
}
145+
} else {
146+
if (inventoryMessage.getInvMessageType() == MessageTypes.TRX){
147+
tronOutTrxInventory.add();
148+
tronOutTrxInventoryElement.add(inventorySize);
149+
}else {
150+
tronOutBlockInventory.add();
151+
tronOutBlockInventoryElement.add(inventorySize);
152+
}
153+
}
154+
break;
87155
case FETCH_INV_DATA:
88-
case BLOCK:
156+
FetchInvDataMessage fetchInvDataMessage = (FetchInvDataMessage) msg;
157+
int fetchSize = fetchInvDataMessage.getInventory().getIdsCount();
158+
if (flag) {
159+
if (fetchInvDataMessage.getInvMessageType() == MessageTypes.TRX){
160+
tronInTrxFetchInvData.add();
161+
tronInTrxFetchInvDataElement.add(fetchSize);
162+
}else {
163+
tronInBlockFetchInvData.add();
164+
tronInBlockFetchInvDataElement.add(fetchSize);
165+
}
166+
} else {
167+
if (fetchInvDataMessage.getInvMessageType() == MessageTypes.TRX){
168+
tronOutTrxFetchInvData.add();
169+
tronOutTrxFetchInvDataElement.add(fetchSize);
170+
}else {
171+
tronOutBlockFetchInvData.add();
172+
tronOutBlockFetchInvDataElement.add(fetchSize);
173+
}
174+
}
175+
break;
89176
case TRXS:
177+
TransactionsMessage transactionsMessage = (TransactionsMessage)msg;
178+
if (flag) {
179+
tronInTrxs.add();
180+
tronInTrx.add(transactionsMessage.getTransactions().getTransactionsCount());
181+
} else {
182+
tronOutTrxs.add();
183+
tronOutTrx.add(transactionsMessage.getTransactions().getTransactionsCount());
184+
}
185+
break;
90186
case TRX:
91187
if (flag) tronInMessage.add(); else tronOutMessage.add();
92188
break;
189+
case BLOCK:
190+
if (flag) tronInBlock.add(); tronOutBlock.add();
191+
break;
93192
default:
94193
break;
95194
}

0 commit comments

Comments
 (0)