Skip to content

Commit aed6daf

Browse files
authored
Merge pull request #682 from tronprotocol/develop
merge develop
2 parents 8a4dd22 + 62536c6 commit aed6daf

File tree

72 files changed

+2284
-767
lines changed

Some content is hidden

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

72 files changed

+2284
-767
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ Then observe whether block synchronization success,If synchronization successf
463463
464464
# Quick Start
465465
466-
Read the [Quick Start](http://wiki.tron.network/en/latest/quick_start.html).
466+
Read the [Quick Start](http://wiki.tron.network/en/latest/Quick_Start.html).
467467
468468
# Community
469469

build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,29 @@ task stest(type:Test){
226226
exceptionFormat = 'full'
227227
showStackTraces = "true"
228228
}
229+
}
230+
231+
def binaryRelease(taskName,jarName,mainClass) {
232+
return tasks.create("${taskName}", Jar) {
233+
baseName = jarName
234+
version = null
235+
from(sourceSets.main.output) {
236+
include "/**"
237+
}
238+
239+
from {
240+
configurations.compile.collect {
241+
it.isDirectory() ? it : zipTree(it)
242+
}
243+
}
244+
245+
manifest {
246+
attributes "Main-Class": "${mainClass}"
247+
}
248+
}
249+
}
250+
251+
artifacts {
252+
archives(binaryRelease('buildSolidityNodeJar','SolidityNode','org.tron.program.SolidityNode'),
253+
binaryRelease('buildFullNodeJar','FullNode','org.tron.program.FullNode'))
229254
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.net.InetAddress;
2121
import java.net.InetSocketAddress;
2222
import java.util.ArrayList;
23+
import java.util.Comparator;
2324
import java.util.HashSet;
2425
import java.util.IdentityHashMap;
2526
import java.util.List;
@@ -205,7 +206,7 @@ private void trimTable() {
205206
if (nodeHandlerMap.size() > NODES_TRIM_THRESHOLD) {
206207
List<NodeHandler> sorted = new ArrayList<>(nodeHandlerMap.values());
207208
// reverse sort by reputation
208-
sorted.sort((o1, o2) -> o1.getNodeStatistics().getReputation() - o2.getNodeStatistics().getReputation());
209+
sorted.sort(Comparator.comparingInt(o -> o.getNodeStatistics().getReputation()));
209210
for (NodeHandler handler : sorted) {
210211
nodeHandlerMap.remove(getKey(handler.getNode()));
211212
if (nodeHandlerMap.size() <= MAX_NODES) {
@@ -287,8 +288,7 @@ public List<NodeHandler> getNodes(Predicate<NodeHandler> predicate, int limit) {
287288
filtered.size());
288289

289290
//TODO: here can use head num sort.
290-
filtered.sort((o1, o2) -> o2.getNodeStatistics().getReputation() - o1.getNodeStatistics()
291-
.getReputation());
291+
filtered.sort(Comparator.comparingInt((NodeHandler o) -> o.getNodeStatistics().getReputation()).reversed());
292292

293293
return CollectionUtils.truncate(filtered, limit);
294294
}
@@ -322,8 +322,7 @@ public synchronized void addDiscoverListener(DiscoverListener listener,
322322

323323
public synchronized String dumpAllStatistics() {
324324
List<NodeHandler> l = new ArrayList<>(nodeHandlerMap.values());
325-
l.sort((o1, o2) -> -(o1.getNodeStatistics().getReputation() - o2.getNodeStatistics()
326-
.getReputation()));
325+
l.sort(Comparator.comparingInt((NodeHandler o) -> o.getNodeStatistics().getReputation()).reversed());
327326

328327
StringBuilder sb = new StringBuilder();
329328
int zeroReputCount = 0;

src/main/java/org/tron/common/overlay/discover/UDPListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public UDPListener(final NodeManager nodeManager) {
7272
}
7373

7474
public void start() throws Exception {
75-
NioEventLoopGroup group = new NioEventLoopGroup(1);
75+
NioEventLoopGroup group = new NioEventLoopGroup(args.getUdpNettyWorkThreadNum());
7676
try {
7777
discoveryExecutor = new DiscoveryExecutor(nodeManager);
7878
discoveryExecutor.start();

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,18 @@ public void disconnect(ReasonCode reason) {
153153
}
154154

155155
public void processException(Throwable throwable){
156+
Throwable baseThrowable = throwable;
157+
while (baseThrowable.getCause() != null){
158+
baseThrowable = baseThrowable.getCause();
159+
}
156160
String errMsg = throwable.getMessage();
157161
SocketAddress address = ctx.channel().remoteAddress();
158162
if (throwable instanceof ReadTimeoutException){
159163
logger.error("Read timeout, {}", address);
164+
}else if(baseThrowable instanceof P2pException){
165+
logger.error("type: {}, info: {}, {}", ((P2pException) throwable).getType(), errMsg, address);
160166
}else if (errMsg != null && errMsg.contains("Connection reset by peer")){
161167
logger.error("{}, {}", errMsg, address);
162-
}else if(throwable instanceof P2pException){
163-
logger.error("type: {}, info: {}, {}", ((P2pException) throwable).getType(), errMsg, address);
164168
}else {
165169
logger.error("exception caught, {}", address, throwable);
166170
}

src/main/java/org/tron/common/overlay/server/PeerServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public PeerServer(final Args args, final ApplicationContext ctx) {
6161
public void start(int port) {
6262

6363
bossGroup = new NioEventLoopGroup(1);
64-
workerGroup = new NioEventLoopGroup();
64+
workerGroup = new NioEventLoopGroup(args.getTcpNettyWorkThreadNum());
6565
tronChannelInitializer = ctx.getBean(TronChannelInitializer.class, "");
6666

6767
tronChannelInitializer.setNodeImpl(p2pNode);

src/main/java/org/tron/common/overlay/server/SyncPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class SyncPool {
4545

4646
public static final Logger logger = LoggerFactory.getLogger("SyncPool");
4747

48-
private static final long WORKER_TIMEOUT = 15;
48+
private static final long WORKER_TIMEOUT = 16;
4949

5050
private final List<PeerConnection> activePeers = Collections.synchronizedList(new ArrayList<PeerConnection>());
5151

src/main/java/org/tron/common/utils/Sha256Hash.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class Sha256Hash implements Serializable, Comparable<Sha256Hash> {
4545

4646
private final byte[] bytes;
4747

48+
private long blockNum;
49+
4850

4951
private byte[] generateBlockId(long blockNum, Sha256Hash blockHash) {
5052
byte[] numBytes = Longs.toByteArray(blockNum);
@@ -60,16 +62,22 @@ private byte[] generateBlockId(long blockNum, byte[] blockHash) {
6062
return hash;
6163
}
6264

65+
public long getBlockNum(){
66+
return blockNum;
67+
}
68+
6369
public Sha256Hash(long num, byte[] hash) {
6470
byte[] rawHashBytes = this.generateBlockId(num, hash);
6571
checkArgument(rawHashBytes.length == LENGTH);
6672
this.bytes = rawHashBytes;
73+
this.blockNum = num;
6774
}
6875

6976
public Sha256Hash(long num, Sha256Hash hash) {
7077
byte[] rawHashBytes = this.generateBlockId(num, hash);
7178
checkArgument(rawHashBytes.length == LENGTH);
7279
this.bytes = rawHashBytes;
80+
this.blockNum = num;
7381
}
7482

7583
/**

src/main/java/org/tron/core/Wallet.java

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@
2626
import org.apache.commons.lang3.StringUtils;
2727
import org.springframework.beans.factory.annotation.Autowired;
2828
import org.springframework.stereotype.Component;
29+
import org.tron.api.GrpcAPI;
2930
import org.tron.api.GrpcAPI.AccountList;
3031
import org.tron.api.GrpcAPI.AssetIssueList;
3132
import org.tron.api.GrpcAPI.BlockList;
3233
import org.tron.api.GrpcAPI.NumberMessage;
34+
import org.tron.api.GrpcAPI.Return.response_code;
3335
import org.tron.api.GrpcAPI.WitnessList;
3436
import org.tron.common.crypto.ECKey;
3537
import org.tron.common.crypto.Hash;
3638
import org.tron.common.overlay.message.Message;
3739
import org.tron.common.utils.Base58;
3840
import org.tron.common.utils.ByteArray;
41+
import org.tron.common.utils.ByteUtil;
3942
import org.tron.common.utils.Utils;
4043
import org.tron.core.capsule.AccountCapsule;
4144
import org.tron.core.capsule.AssetIssueCapsule;
@@ -53,14 +56,8 @@
5356
import org.tron.core.exception.ValidateSignatureException;
5457
import org.tron.core.net.message.TransactionMessage;
5558
import org.tron.core.net.node.NodeImpl;
56-
import org.tron.protos.Contract.AccountCreateContract;
5759
import org.tron.protos.Contract.AssetIssueContract;
58-
import org.tron.protos.Contract.ParticipateAssetIssueContract;
59-
import org.tron.protos.Contract.TransferAssetContract;
6060
import org.tron.protos.Contract.TransferContract;
61-
import org.tron.protos.Contract.VoteWitnessContract;
62-
import org.tron.protos.Contract.WitnessCreateContract;
63-
import org.tron.protos.Contract.WitnessUpdateContract;
6461
import org.tron.protos.Protocol.Account;
6562
import org.tron.protos.Protocol.Block;
6663
import org.tron.protos.Protocol.Transaction;
@@ -115,7 +112,7 @@ public static void setAddressPreFixByte(byte addressPreFixByte) {
115112
}
116113

117114
public static boolean addressValid(byte[] address) {
118-
if (address == null || address.length == 0) {
115+
if (ByteUtil.isNullOrZeroArray(address)) {
119116
logger.warn("Warning: Address is empty !!");
120117
return false;
121118
}
@@ -207,60 +204,61 @@ public Transaction createTransaction(TransferContract contract) {
207204
/**
208205
* Broadcast a transaction.
209206
*/
210-
public boolean broadcastTransaction(Transaction signaturedTransaction) {
207+
public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
208+
GrpcAPI.Return.Builder builder = GrpcAPI.Return.newBuilder();
211209
TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
212210
try {
213211
Message message = new TransactionMessage(signaturedTransaction);
214212
if (message.getData().length > Constant.TRANSACTION_MAX_BYTE_SIZE) {
215-
throw new TooBigTransactionException("too big transaction, the size is " + message.getData().length + " bytes");
213+
throw new TooBigTransactionException(
214+
"too big transaction, the size is " + message.getData().length + " bytes");
216215
}
217216
dbManager.pushTransactions(trx);
218217
p2pNode.broadcast(message);
219-
return true;
218+
return builder.setResult(true).setCode(response_code.SUCCESS).build();
220219
} catch (ValidateSignatureException e) {
221220
logger.error(e.getMessage(), e);
221+
return builder.setResult(false).setCode(response_code.SIGERROR)
222+
.setMessage(ByteString.copyFromUtf8("validate signature error"))
223+
.build();
222224
} catch (ContractValidateException e) {
223225
logger.error(e.getMessage(), e);
226+
return builder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
227+
.setMessage(ByteString.copyFromUtf8("contract validate error"))
228+
.build();
224229
} catch (ContractExeException e) {
225230
logger.error(e.getMessage(), e);
231+
return builder.setResult(false).setCode(response_code.CONTRACT_EXE_ERROR)
232+
.setMessage(ByteString.copyFromUtf8("contract execute error"))
233+
.build();
226234
} catch (ValidateBandwidthException e) {
227235
logger.error("high freq", e);
236+
return builder.setResult(false).setCode(response_code.BANDWITH_ERROR)
237+
.setMessage(ByteString.copyFromUtf8("high freq error"))
238+
.build();
228239
} catch (DupTransactionException e) {
229240
logger.error("dup trans", e);
241+
return builder.setResult(false).setCode(response_code.DUP_TRANSACTION_ERROR)
242+
.setMessage(ByteString.copyFromUtf8("dup transaction"))
243+
.build();
230244
} catch (TaposException e) {
231245
logger.debug("tapos error", e);
246+
return builder.setResult(false).setCode(response_code.TAPOS_ERROR)
247+
.setMessage(ByteString.copyFromUtf8("Tapos check error"))
248+
.build();
232249
} catch (TooBigTransactionException e) {
233250
logger.debug("transaction error", e);
234-
} catch (Exception e){
251+
return builder.setResult(false).setCode(response_code.TOO_BIG_TRANSACTION_ERROR)
252+
.setMessage(ByteString.copyFromUtf8("TooBigTransactionException"))
253+
.build();
254+
} catch (Exception e) {
235255
logger.error("exception caught", e);
256+
return builder.setResult(false).setCode(response_code.OTHER_ERROR)
257+
.setMessage(ByteString.copyFromUtf8("other error"))
258+
.build();
236259
}
237-
return false;
238260
}
239261

240-
@Deprecated
241-
public Transaction createAccount(AccountCreateContract contract) {
242-
AccountStore accountStore = dbManager.getAccountStore();
243-
return new TransactionCapsule(contract, accountStore).getInstance();
244-
}
245-
246-
@Deprecated
247-
public Transaction createTransaction(VoteWitnessContract voteWitnessContract) {
248-
return new TransactionCapsule(voteWitnessContract).getInstance();
249-
}
250-
251-
@Deprecated
252-
public Transaction createTransaction(AssetIssueContract assetIssueContract) {
253-
return new TransactionCapsule(assetIssueContract).getInstance();
254-
}
255-
@Deprecated
256-
public Transaction createTransaction(WitnessCreateContract witnessCreateContract) {
257-
return new TransactionCapsule(witnessCreateContract).getInstance();
258-
}
259-
260-
@Deprecated
261-
public Transaction createTransaction(WitnessUpdateContract witnessUpdateContract) {
262-
return new TransactionCapsule(witnessUpdateContract).getInstance();
263-
}
264262

265263
public Block getNowBlock() {
266264
try {
@@ -295,15 +293,6 @@ public WitnessList getWitnessList() {
295293
.forEach(witnessCapsule -> builder.addWitnesses(witnessCapsule.getInstance()));
296294
return builder.build();
297295
}
298-
@Deprecated
299-
public Transaction createTransaction(TransferAssetContract transferAssetContract) {
300-
return new TransactionCapsule(transferAssetContract).getInstance();
301-
}
302-
@Deprecated
303-
public Transaction createTransaction(
304-
ParticipateAssetIssueContract participateAssetIssueContract) {
305-
return new TransactionCapsule(participateAssetIssueContract).getInstance();
306-
}
307296

308297
public AssetIssueList getAssetIssueList() {
309298
AssetIssueList.Builder builder = AssetIssueList.newBuilder();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public static List<Actuator> createActuator(TransactionCapsule transactionCapsul
4141

4242
private static Actuator getActuatorByContract(Contract contract, Manager manager) {
4343
switch (contract.getType()) {
44-
case AccountCreateContract:
45-
return new CreateAccountActuator(contract.getParameter(), manager);
44+
case AccountUpdateContract:
45+
return new UpdateAccountActuator(contract.getParameter(), manager);
4646
case TransferContract:
4747
return new TransferActuator(contract.getParameter(), manager);
4848
case TransferAssetContract:

0 commit comments

Comments
 (0)