Skip to content

Commit 0e64cd4

Browse files
authored
Merge pull request #833 from tronprotocol/sonarcloud
Sonarcloud
2 parents 4777049 + 5e211ba commit 0e64cd4

File tree

10 files changed

+97
-62
lines changed

10 files changed

+97
-62
lines changed

.travis.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
sudo: required
22
language: java
33
jdk: oraclejdk8
4-
script:
5-
- sh tron.sh
6-
- ./gradlew lint
7-
- ./gradlew test
84
addons:
95
ssh_known_hosts:
106
- 47.93.9.236:22008
7+
sonarcloud:
8+
organization: tron-zhaohong
9+
token:
10+
secure: "KXWEeQ1elAoQ0XfR54TQWfhrIdDP0+2CYPv2X9aWpU/YDl7hqZBAjcCOAUGvlbyM54jtG6YMaWwG48jlrOwwl5l/VjWSnUXF+7ixQy5ki0Ci9s7Y1pTQwV9SpL8TLIK2TYqabN8Mw+FJULASXLjYr9GerbbcUbCPTmcL6mQKw6ivxxpNPmz4eNoKAEuOzruO9fTXGAV3yr8Nn85c+mVxV8EUhkR17zpE9O8fvzOtSnYArWNOSCgDBn0EG45UNNPF2vn44s1c3h3gX1m3WK6PeCXPgy3hPqRn3wTG+xglnbqthGpo2wt1rJ83af+BwdYwvPEcUq84yLgXcE/aMkTKcVAfPWBP/6vblaoI90jxCeFji+MdMimKZAqIXt7oLqDZVmIq65de5YC5s7QTSbzJNY/tsAu3dqzSfbUJY6CRNFDcoenVpvgQkqb37TkDah4mJM8EUjbu2A9Q2HSFbyCVsQJtdasuu9cBOf6azK3U0XgFNBc0y2aziZrTnX30q7bi+5L/mbTnRdXrDqBOqyPeGtT77UZfcajHHmEWU/e6gYWiA/c+K25n13DD53Au6gpnnQ6ALeUl/1gDwz3fPBebJ5bVWrkIcLj7bbysjzfOvQmDS6G13RNz58Hm0/B7bVtZTr1E1q6Z1zEJwbuJYEJASNcezAfK5x/hIfZTGNqT3M8="
11+
cache:
12+
directories:
13+
- '$HOME/.sonar/cache'
14+
script:
15+
- sh tron.sh
16+
- "./gradlew build"
17+
- sonar-scanner
1118
skip_build:
1219
- README.md:
1320
- LICENSE
@@ -17,6 +24,5 @@ deploy:
1724
on:
1825
branch: develop
1926
after_deploy:
20-
- ./gradlew stest
21-
27+
- "./gradlew stest"
2228

build.gradle

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
buildscript {
2+
repositories {
3+
maven { url 'http://mvnrepository.com' }
4+
mavenCentral()
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
9+
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
10+
}
11+
}
12+
plugins {
13+
id "org.sonarqube" version "2.6"
14+
}
15+
116
group 'org.tron'
217
version '1.0.0'
318

@@ -8,7 +23,6 @@ apply plugin: 'checkstyle'
823
apply plugin: 'com.github.johnrengelman.shadow'
924
apply plugin: "jacoco"
1025

11-
1226
sourceCompatibility = 1.8
1327
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
1428
mainClassName = 'org.tron.program.FullNode'
@@ -18,19 +32,6 @@ repositories {
1832
mavenLocal()
1933
mavenCentral()
2034
}
21-
22-
buildscript {
23-
repositories {
24-
maven { url 'http://mvnrepository.com' }
25-
mavenCentral()
26-
jcenter()
27-
}
28-
dependencies {
29-
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
30-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
31-
}
32-
}
33-
3435
def versions = [
3536
checkstyle: '8.7',
3637
]
@@ -143,17 +144,15 @@ checkstyle {
143144
}
144145

145146
checkstyleMain {
146-
source 'src'
147-
include '**/*.java'
148-
exclude '**/gen/**'
147+
source = 'src/main/java'
149148
}
150149

151150
task lint(type: Checkstyle) {
152151
// Cleaning the old log because of the creation of the new ones (not sure if totaly needed)
153152
delete fileTree(dir: "${project.rootDir}/app/build/reports")
154153
source 'src'
155154
include '**/*.java'
156-
exclude '**/gen/**'
155+
exclude 'main/gen/**'
157156
// empty classpath
158157
classpath = files()
159158
//Failing the build
@@ -186,6 +185,7 @@ protobuf {
186185
protoc {
187186
artifact = "com.google.protobuf:protoc:3.5.1-1"
188187
}
188+
189189
plugins {
190190
grpc {
191191
artifact = 'io.grpc:protoc-gen-grpc-java:1.9.0'
@@ -236,9 +236,9 @@ jacocoTestReport {
236236
}
237237
}
238238

239-
task stest(type:Test){
240-
useTestNG{
241-
suites( file('src/test/resources/testng.xml') )
239+
task stest(type: Test) {
240+
useTestNG {
241+
suites(file('src/test/resources/testng.xml'))
242242
}
243243

244244
testLogging {
@@ -247,7 +247,7 @@ task stest(type:Test){
247247
}
248248
}
249249

250-
def binaryRelease(taskName,jarName,mainClass) {
250+
def binaryRelease(taskName, jarName, mainClass) {
251251
return tasks.create("${taskName}", Jar) {
252252
baseName = jarName
253253
version = null
@@ -267,7 +267,8 @@ def binaryRelease(taskName,jarName,mainClass) {
267267
}
268268
}
269269

270+
270271
artifacts {
271-
archives(binaryRelease('buildSolidityNodeJar','SolidityNode','org.tron.program.SolidityNode'),
272-
binaryRelease('buildFullNodeJar','FullNode','org.tron.program.FullNode'))
272+
archives(binaryRelease('buildSolidityNodeJar', 'SolidityNode', 'org.tron.program.SolidityNode'),
273+
binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode'))
273274
}

sonar-project.properties

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sonar.projectKey=java-tron
2+
sonar.projectName=java-tron
3+
sonar.projectVersion=2.1
4+
# =====================================================
5+
# Meta-data for the project
6+
# =====================================================
7+
sonar.links.homepage=https://github.com/tronprotocol/java-tron
8+
sonar.links.ci=https://travis-ci.org/tronprotocol/java-tron
9+
sonar.links.scm=https://github.com/tronprotocol/java-tron
10+
sonar.links.issue=https://github.com/tronprotocol/java-tron/issues
11+
# =====================================================
12+
# Properties that will be shared amongst all modules
13+
# =====================================================
14+
# SQ standard properties
15+
sonar.sources=src/main
16+
sonar.tests=src/test
17+
sonar.java.binaries=build/classes
18+
# =====================================================
19+
# Properties that will be shared amongst all modules

src/main/java/org/tron/core/config/Parameter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ interface ChainConstant {
1414
double SOLIDIFIED_THRESHOLD = 0.7;
1515
int PRIVATE_KEY_LENGTH = 64;
1616
int MAX_ACTIVE_WITNESS_NUM = 27;
17-
int TRXS_SIZE = 2_000_000; // < 2MiB
17+
//int TRXS_SIZE = 2_000_000; // < 2MiB
18+
int BLOCK_SIZE = 2_000_000;
1819
int BLOCK_PRODUCED_INTERVAL = 3000; //ms,produce block period, must be divisible by 60. millisecond
19-
long CLOCK_MAX_DELAY = 3600 * 1000; //ms
20+
long CLOCK_MAX_DELAY = 3600000; // 3600 * 1000 ms
2021
double BLOCK_PRODUCED_TIME_OUT = 0.75;
2122
long BATCH_FETCH_RESPONSE_SIZE = 1000; //for each inventory message from peer, the max count of fetch inv message
2223
long PRECISION = 1000_000;
2324
long ONE_DAY_NET_LIMIT = 57_600_000_000L;
24-
long WINDOW_SIZE_MS = 24 * 3600 * 1000;
25+
long WINDOW_SIZE_MS = 24 * 3600 * 1000L;
2526
long CREATE_NEW_ACCOUNT_COST = 10000;
2627
}
2728

@@ -37,6 +38,7 @@ interface NodeConstant {
3738
}
3839

3940
interface NetConstants {
41+
4042
long GRPC_IDLE_TIME_OUT = 60000L;
4143
long ADV_TIME_OUT = 20000L;
4244
long SYNC_TIME_OUT = 5000L;
@@ -50,6 +52,7 @@ interface NetConstants {
5052
}
5153

5254
interface DatabaseConstants {
55+
5356
int TRANSACTIONS_COUNT_LIMIT_MAX = 1000;
5457
}
5558
}

src/main/java/org/tron/core/db/Manager.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.ArrayList;
1414
import java.util.Arrays;
1515
import java.util.Collections;
16-
import java.util.Formatter;
1716
import java.util.Iterator;
1817
import java.util.LinkedList;
1918
import java.util.List;
@@ -434,19 +433,21 @@ void validateTapos(TransactionCapsule transactionCapsule) throws TaposException
434433
if (Arrays.equals(blockHash, refBlockHash)) {
435434
return;
436435
} else {
437-
String str = new Formatter().format(
436+
String str = String.format(
438437
"Tapos failed, different block hash, %s, %s , recent block %s, solid block %s head block %s",
439438
ByteArray.toLong(refBlockNumBytes), Hex.toHexString(refBlockHash),
440439
Hex.toHexString(blockHash),
441440
getSolidBlockId().getString(), getHeadBlockId().getString()).toString();
441+
logger.info(str);
442442
throw new TaposException(str);
443443

444444
}
445445
} catch (ItemNotFoundException e) {
446-
String str = new Formatter().
446+
String str = String.
447447
format("Tapos failed, block not found, ref block %s, %s , solid block %s head block %s",
448448
ByteArray.toLong(refBlockNumBytes), Hex.toHexString(refBlockHash),
449449
getSolidBlockId().getString(), getHeadBlockId().getString()).toString();
450+
logger.info(str);
450451
throw new TaposException(str);
451452
}
452453
}
@@ -925,25 +926,22 @@ public synchronized BlockCapsule generateBlock(
925926

926927
final BlockCapsule blockCapsule =
927928
new BlockCapsule(number + 1, preHash, when, witnessCapsule.getAddress());
928-
929+
currentTrxSize = blockCapsule.getInstance().getSerializedSize();
929930
dialog.reset();
930931
dialog.setValue(revokingStore.buildDialog());
931-
932932
Iterator iterator = pendingTransactions.iterator();
933933
while (iterator.hasNext()) {
934934
TransactionCapsule trx = (TransactionCapsule) iterator.next();
935-
currentTrxSize += trx.getSerializedSize();
936-
// judge block size
937-
if (currentTrxSize > ChainConstant.TRXS_SIZE) {
938-
postponedTrxCount++;
939-
continue;
940-
}
941-
942935
if (DateTime.now().getMillis() - when > ChainConstant.BLOCK_PRODUCED_INTERVAL * 0.5) {
943936
logger.debug("Processing transaction time exceeds the 50% producing time。");
944937
break;
945938
}
946-
939+
currentTrxSize += trx.getSerializedSize();
940+
// check the block size
941+
if (currentTrxSize + 2 > ChainConstant.BLOCK_SIZE) {
942+
postponedTrxCount++;
943+
continue;
944+
}
947945
// apply transaction
948946
try (Dialog tmpDialog = revokingStore.buildDialog()) {
949947
processTransaction(trx);

src/main/java/org/tron/core/db/TransactionStore.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public long getTotalTransactions() {
5050

5151
private static TransactionStore instance;
5252

53-
public static void destory() {
54-
instance = null;
55-
}
56-
5753
public static void destroy() {
5854
instance = null;
5955
}

src/main/java/org/tron/core/net/message/BlockMessage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.tron.core.net.message;
22

3+
import com.google.protobuf.InvalidProtocolBufferException;
34
import org.tron.common.utils.Sha256Hash;
45
import org.tron.core.capsule.BlockCapsule;
56
import org.tron.core.capsule.BlockCapsule.BlockId;
@@ -10,7 +11,7 @@ public class BlockMessage extends TronMessage {
1011

1112
private Block block;
1213

13-
public BlockMessage(byte[] data) throws Exception {
14+
public BlockMessage(byte[] data) throws InvalidProtocolBufferException {
1415
this.type = MessageTypes.BLOCK.asByte();
1516
this.data = data;
1617
this.block = Protocol.Block.parseFrom(data);
@@ -22,7 +23,7 @@ public BlockMessage(Block block) {
2223
this.data = block.toByteArray();
2324
}
2425

25-
public BlockMessage(BlockCapsule block) throws Exception {
26+
public BlockMessage(BlockCapsule block) {
2627
data = block.getData();
2728
this.type = MessageTypes.BLOCK.asByte();
2829
this.block = block.getInstance();

src/main/java/org/tron/core/net/node/NodeDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public interface NodeDelegate {
1919

2020
LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boolean syncMode)
21-
throws BadBlockException, UnLinkedBlockException;
21+
throws BadBlockException, UnLinkedBlockException, InterruptedException;
2222

2323
void handleTransaction(TransactionCapsule trx) throws BadTransactionException;
2424

src/main/java/org/tron/core/net/node/NodeDelegateImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tron.core.net.node;
22

33
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
4+
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_SIZE;
45

56
import com.google.common.primitives.Longs;
67
import java.util.ArrayList;
@@ -48,7 +49,12 @@ public NodeDelegateImpl(Manager dbManager) {
4849

4950
@Override
5051
public synchronized LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boolean syncMode)
51-
throws BadBlockException, UnLinkedBlockException {
52+
throws BadBlockException, UnLinkedBlockException, InterruptedException {
53+
54+
if (block.getInstance().getSerializedSize() > BLOCK_SIZE + 100) {
55+
throw new BadBlockException("block size over limit");
56+
}
57+
5258
// TODO timestamp shouble be consistent.
5359
long gap = block.getTimeStamp() - System.currentTimeMillis();
5460
if (gap >= BLOCK_PRODUCED_INTERVAL) {
@@ -77,8 +83,6 @@ public synchronized LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boole
7783
throw new BadBlockException("ContractValidate exception," + e.getMessage());
7884
} catch (ContractExeException e) {
7985
throw new BadBlockException("Contract Exectute exception," + e.getMessage());
80-
} catch (InterruptedException e) {
81-
throw new BadBlockException("pre validate signature exception," + e.getMessage());
8286
} catch (TaposException e) {
8387
throw new BadBlockException("tapos exception," + e.getMessage());
8488
} catch (DupTransactionException e) {

src/main/java/org/tron/core/net/node/NodeImpl.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
764764
//TODO: lack the complete flow.
765765
if (!freshBlockId.contains(block.getBlockId())) {
766766
try {
767-
LinkedList<Sha256Hash> trxIds = del.handleBlock(block, false);
768-
767+
LinkedList<Sha256Hash> trxIds = null;
768+
trxIds = del.handleBlock(block, false);
769769
freshBlockId.offer(block.getBlockId());
770770

771771
trxIds.forEach(trxId -> advObjToFetch.remove(trxId));
@@ -786,18 +786,25 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
786786
block.getBlockId().getString(), peer.getNode().getHost(),
787787
del.getHeadBlockId().getString());
788788
startSyncWithPeer(peer);
789-
} catch (Exception e) {
790-
logger.error("Fail to process adv block {} from {}", block.getBlockId().getString(),
791-
peer.getNode().getHost(), e);
789+
} catch (InterruptedException e) {
790+
Thread.currentThread().interrupt();
792791
}
792+
793+
// logger.error("Fail to process adv block {} from {}", block.getBlockId().getString(),
794+
// peer.getNode().getHost(), e);
795+
793796
}
794797
}
795798

796799
private boolean processSyncBlock(BlockCapsule block) {
797800
boolean isAccept = false;
798801
ReasonCode reason = null;
799802
try {
800-
del.handleBlock(block, true);
803+
try {
804+
del.handleBlock(block, true);
805+
} catch (InterruptedException e) {
806+
Thread.currentThread().interrupt();
807+
}
801808
freshBlockId.offer(block.getBlockId());
802809
logger.info("Success handle block {}", block.getBlockId().getString());
803810
isAccept = true;

0 commit comments

Comments
 (0)