Skip to content

Commit 81d7d85

Browse files
committed
Merge branch 'develop' of https://github.com/tronprotocol/java-tron into develop
2 parents 82fdee6 + 8c900c0 commit 81d7d85

Some content is hidden

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

51 files changed

+728
-793
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ deploy:
1818
branch: develop
1919
after_deploy:
2020
- ./gradlew stest
21+
22+

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Then, run `FullNode::main()` again.
271271
### Running multi-nodes
272272
273273
To run TRON on more than one node, you need to specify several seed nodes' IPs in `config.conf` in `seed.node.ip.list`:
274-
For private testnet, the IPs are allocated by yourself.
274+
For private test net, the IPs are allocated by yourself.
275275

276276
## Running a local node and connecting to the public testnet
277277

@@ -292,8 +292,6 @@ cd build/libs
292292
java -jar java-tron.jar
293293
```
294294

295-
It is almost the same as that does in the private testnet, except that the IPs in the `config.conf` are officially declared by TRON.
296-
297295
### Running a Super Node
298296

299297
* Use the executable JAR(Recommend the way)

src/main/java/org/tron/common/overlay/message/PingMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public byte[] getData() {
2424

2525
@Override
2626
public String toString() {
27-
return "[" + getType().name() + "]";
27+
return super.toString();
2828
}
2929

3030
@Override

src/main/java/org/tron/common/overlay/message/PongMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public byte[] getData() {
2323

2424
@Override
2525
public String toString() {
26-
return "[" + this.getType().name() + "]";
26+
return super.toString();
2727
}
2828

2929
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ChannelManager {
4646

4747
private static final Logger logger = LoggerFactory.getLogger("ChannelManager");
4848

49-
private static final int inboundConnectionBanTimeout = 60 * 1000;
49+
private static final int inboundConnectionBanTimeout = 30 * 1000;
5050

5151
private final Map<ByteArrayWrapper, Channel> activePeers = new ConcurrentHashMap<>();
5252

@@ -137,8 +137,8 @@ public synchronized boolean procPeer(Channel peer) {
137137
return false;
138138
}
139139
}
140-
logger.info("Add active peer {}, total active peers: {}", peer, activePeers.size());
141140
activePeers.put(peer.getNodeIdWrapper(), peer);
141+
logger.info("Add active peer {}, total active peers: {}", peer, activePeers.size());
142142
return true;
143143
}
144144

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.context.annotation.Scope;
1616
import org.springframework.stereotype.Component;
1717
import org.tron.common.overlay.message.Message;
18+
import org.tron.common.overlay.message.PingMessage;
1819
import org.tron.common.overlay.message.ReasonCode;
1920

2021
@Component
@@ -25,6 +26,8 @@ public class MessageQueue {
2526

2627
private volatile boolean sendMsgFlag = false;
2728

29+
private volatile long sendTime;
30+
2831
private Thread sendMsgThread;
2932

3033
private Channel channel;
@@ -84,11 +87,20 @@ public void setChannel(Channel channel) {
8487
}
8588

8689
public void sendMessage(Message msg) {
90+
91+
if (msg instanceof PingMessage && sendTime > System.currentTimeMillis() - 10_000){
92+
return;
93+
}
94+
8795
logger.info("Send to {}, {} ", ctx.channel().remoteAddress(), msg);
88-
if (msg.getAnswerMessage() != null)
96+
97+
sendTime = System.currentTimeMillis();
98+
99+
if (msg.getAnswerMessage() != null){
89100
requestQueue.add(new MessageRoundtrip(msg));
90-
else
101+
}else {
91102
msgQueue.offer(msg);
103+
}
92104
}
93105

94106
public void receivedMessage(Message msg){

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import java.util.concurrent.ScheduledExecutorService;
2727
import java.util.concurrent.ScheduledFuture;
2828
import java.util.concurrent.TimeUnit;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3129
import org.springframework.context.annotation.Scope;
3230
import org.springframework.stereotype.Component;
3331
import org.tron.common.overlay.message.DisconnectMessage;
@@ -38,8 +36,6 @@
3836
@Scope("prototype")
3937
public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
4038

41-
private final static Logger logger = LoggerFactory.getLogger("P2pHandler");
42-
4339
private static ScheduledExecutorService pingTimer =
4440
Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "P2pPingTimer"));
4541

@@ -49,9 +45,9 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
4945

5046
private ScheduledFuture<?> pingTask;
5147

52-
private boolean hasPing = false;
48+
private volatile boolean hasPing = false;
5349

54-
private long sendPingTime;
50+
private volatile long sendPingTime;
5551

5652
private ChannelHandlerContext ctx;
5753

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.util.concurrent.ScheduledExecutorService;
2828
import java.util.concurrent.TimeUnit;
2929
import java.util.function.Predicate;
30+
31+
import com.google.common.cache.Cache;
32+
import com.google.common.cache.CacheBuilder;
3033
import org.slf4j.Logger;
3134
import org.slf4j.LoggerFactory;
3235
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +39,9 @@
3639
import org.tron.common.overlay.discover.Node;
3740
import org.tron.common.overlay.discover.NodeHandler;
3841
import org.tron.common.overlay.discover.NodeManager;
42+
import org.tron.common.utils.Sha256Hash;
3943
import org.tron.core.config.args.Args;
44+
import org.tron.core.net.message.TransactionMessage;
4045
import org.tron.core.net.peer.PeerConnection;
4146
import org.tron.core.net.peer.PeerConnectionDelegate;
4247

@@ -49,6 +54,9 @@ public class SyncPool {
4954

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

57+
private Cache<NodeHandler, Long> nodeHandlerCache = CacheBuilder.newBuilder()
58+
.maximumSize(1000).expireAfterWrite(120, TimeUnit.SECONDS).recordStats().build();
59+
5260
@Autowired
5361
private NodeManager nodeManager;
5462

@@ -102,7 +110,10 @@ private void fillUp() {
102110
nodesInUse.add(nodeManager.getPublicHomeNode().getHexId());
103111

104112
List<NodeHandler> newNodes = nodeManager.getNodes(new NodeSelector(nodesInUse), lackSize);
105-
newNodes.forEach(n -> peerClient.connectAsync(n, false));
113+
newNodes.forEach(n -> {
114+
peerClient.connectAsync(n, false);
115+
nodeHandlerCache.put(n, System.currentTimeMillis());
116+
});
106117
}
107118

108119
// for test only
@@ -112,17 +123,17 @@ public void addActivePeers(PeerConnection p) {
112123

113124

114125
synchronized void logActivePeers() {
126+
115127
logger.info("-------- active node {}", nodeManager.dumpActiveNodes().size());
116-
nodeManager.dumpActiveNodes().forEach(handler -> {
128+
nodeManager.dumpActiveNodes().forEach(handler -> {
117129
if (handler.getNode().getPort() == 18888) {
118130
logger.info("address: {}:{}, ID:{} {}",
119-
handler.getNode().getHost(), handler.getNode().getPort(),
120-
handler.getNode().getHexIdShort(), handler.getNodeStatistics().toString());
131+
handler.getNode().getHost(), handler.getNode().getPort(),
132+
handler.getNode().getHexIdShort(), handler.getNodeStatistics().toString());
121133
}
122-
});
134+
});
123135

124-
logger.info("-------- active channel {}, node in user size {}", channelManager.getActivePeers().size(),
125-
channelManager.nodesInUse().size());
136+
logger.info("-------- active channel {}", channelManager.getActivePeers().size());
126137
for (Channel channel: channelManager.getActivePeers()){
127138
logger.info(channel.toString());
128139
}
@@ -203,6 +214,10 @@ public boolean test(NodeHandler handler) {
203214
return false;
204215
}
205216

217+
if (nodeHandlerCache.getIfPresent(handler) != null){
218+
return false;
219+
}
220+
206221
if (handler.getNodeStatistics().getReputation() < 100) {
207222
return false;
208223
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ public boolean validate() throws ContractValidateException {
128128
throw new ContractValidateException("Invalidate description");
129129
}
130130

131+
if (assetIssueContract.getStartTime() == 0) {
132+
throw new ContractValidateException("start time should be not empty");
133+
}
134+
if (assetIssueContract.getEndTime() == 0) {
135+
throw new ContractValidateException("end time should be not empty");
136+
}
137+
if (assetIssueContract.getEndTime() <= assetIssueContract.getStartTime()) {
138+
throw new ContractValidateException("end time should be greater than start time");
139+
}
140+
if (assetIssueContract.getStartTime() < dbManager.getHeadBlockTimeStamp()){
141+
throw new ContractValidateException("start time should be greater than HeadBlockTime");
142+
}
143+
131144
if (this.dbManager.getAssetIssueStore().get(assetIssueContract.getName().toByteArray())
132145
!= null) {
133146
throw new ContractValidateException("Token exists");
@@ -179,12 +192,12 @@ public boolean validate() throws ContractValidateException {
179192
throw new ContractValidateException("Account not exists");
180193
}
181194

182-
if (accountCapsule.getFrozenSupplyCount() != 0) {
183-
throw new ContractValidateException("An account can only issue one asset at a time");
195+
if (!accountCapsule.getAssetIssuedName().isEmpty()) {
196+
throw new ContractValidateException("An account can only issue one asset");
184197
}
185198

186199
if (accountCapsule.getBalance() < calcFee()) {
187-
throw new ContractValidateException("No enough blance for fee!");
200+
throw new ContractValidateException("No enough balance for fee!");
188201
}
189202
} catch (InvalidProtocolBufferException e) {
190203
throw new ContractValidateException(e.getMessage());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ public boolean execute(TransactionResultCapsule ret)
2828
throws ContractExeException {
2929
long fee = calcFee();
3030
try {
31-
3231
AccountCreateContract accountCreateContract = contract.unpack(AccountCreateContract.class);
3332
AccountCapsule accountCapsule = new AccountCapsule(accountCreateContract,
3433
dbManager.getHeadBlockTimeStamp());
3534
dbManager.getAccountStore()
3635
.put(accountCreateContract.getOwnerAddress().toByteArray(), accountCapsule);
3736
ret.setStatus(fee, code.SUCESS);
38-
return true;
3937
} catch (InvalidProtocolBufferException e) {
4038
ret.setStatus(fee, code.FAILED);
4139
logger.debug(e.getMessage(), e);
4240
throw new ContractExeException(e.getMessage());
4341
}
42+
43+
return true;
4444
}
4545

4646
@Override

0 commit comments

Comments
 (0)