Skip to content

Commit 727fd17

Browse files
author
renchengchang
committed
fix conflicts in wallet
2 parents 458d063 + 33f7add commit 727fd17

File tree

17 files changed

+128
-93
lines changed

17 files changed

+128
-93
lines changed

src/main/java/org/tron/common/overlay/client/PeerClient.java

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/*
2-
* Copyright (c) [2016] [ <ether.camp> ]
3-
* This file is part of the ethereumJ library.
4-
*
5-
* The ethereumJ library is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Lesser General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* The ethereumJ library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public License
16-
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
17-
*/
181
package org.tron.common.overlay.client;
192

203
import io.netty.bootstrap.Bootstrap;
@@ -38,16 +21,10 @@
3821
import java.util.concurrent.ThreadFactory;
3922
import java.util.concurrent.atomic.AtomicInteger;
4023

41-
42-
/**
43-
* This class creates the connection to an remote address using the Netty framework
44-
*
45-
* @see <a href="http://netty.io">http://netty.io</a>
46-
*/
4724
@Component
4825
public class PeerClient {
4926

50-
private static final Logger logger = LoggerFactory.getLogger("net");
27+
private static final Logger logger = LoggerFactory.getLogger("PeerClient");
5128

5229
@Autowired
5330
private ApplicationContext ctx;
@@ -69,34 +46,11 @@ public Thread newThread(Runnable r) {
6946
}
7047

7148
public void connect(String host, int port, String remoteId) {
72-
connect(host, port, remoteId, false);
73-
}
74-
75-
/**
76-
* Connects to the node and returns only upon connection close
77-
*/
78-
public void connect(String host, int port, String remoteId, boolean discoveryMode) {
7949
try {
80-
ChannelFuture f = connectAsync(host, port, remoteId, discoveryMode);
81-
82-
f.sync();
83-
84-
// Wait until the connection is closed.
85-
f.channel().closeFuture().sync();
86-
87-
logger.debug("Connection is closed");
88-
50+
ChannelFuture f = connectAsync(host, port, remoteId, false);
51+
f.sync().channel().closeFuture().sync();
8952
} catch (Exception e) {
90-
if (discoveryMode) {
91-
logger.trace("Exception:", e);
92-
} else {
93-
if (e instanceof IOException) {
94-
logger.info("PeerClient: Can't connect to " + host + ":" + port + " (" + e.getMessage() + ")");
95-
logger.debug("PeerClient.connect(" + host + ":" + port + ") exception:", e);
96-
} else {
97-
logger.error("Exception:", e);
98-
}
99-
}
53+
logger.info("PeerClient: Can't connect to " + host + ":" + port + " (" + e.getMessage() + ")");
10054
}
10155
}
10256

@@ -114,8 +68,7 @@ public ChannelFuture connectAsync(String host, int port, String remoteId, boolea
11468

11569
b.option(ChannelOption.SO_KEEPALIVE, true);
11670
b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
117-
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
118-
Args.getInstance().getNodeConnectionTimeout());
71+
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Args.getInstance().getNodeConnectionTimeout());
11972
b.remoteAddress(host, port);
12073

12174
b.handler(tronChannelInitializer);
@@ -125,7 +78,6 @@ public ChannelFuture connectAsync(String host, int port, String remoteId, boolea
12578
}
12679

12780
public void close() {
128-
logger.info("Shutdown peerClient");
12981
workerGroup.shutdownGracefully();
13082
workerGroup.terminationFuture().syncUninterruptibly();
13183
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818
package org.tron.common.overlay.discover;
1919

20+
import com.sun.org.apache.xpath.internal.Arg;
2021
import org.slf4j.LoggerFactory;
2122
import org.spongycastle.util.encoders.Hex;
2223
import org.tron.common.overlay.discover.message.*;
24+
import org.tron.core.config.args.Args;
2325

2426
import java.net.InetSocketAddress;
2527
import java.util.List;
@@ -184,8 +186,12 @@ void handlePong(PongMessage msg) {
184186
getNodeStatistics().discoverInPong.add();
185187
getNodeStatistics().discoverMessageLatency.add(System.currentTimeMillis() - pingSent);
186188
getNodeStatistics().lastPongReplyTime.set(System.currentTimeMillis());
187-
changeState(State.Alive);
188189
node.setId(msg.getNodeId());
190+
if (msg.getVersion() != Args.getInstance().getNodeP2pVersion()){
191+
changeState(State.NonActive);
192+
}else {
193+
changeState(State.Alive);
194+
}
189195
}
190196
}
191197

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public Node getFrom(){
4545
return node;
4646
}
4747

48+
public int getVersion(){
49+
return this.pongMessage.getEcho();
50+
}
51+
4852
@Override
4953
public byte[] getNodeId() {
5054
return this.pongMessage.getFrom().getNodeId().toByteArray();

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.slf4j.LoggerFactory;
3838
import org.springframework.beans.factory.annotation.Autowired;
3939
import org.springframework.stereotype.Component;
40+
import org.tron.common.overlay.client.PeerClient;
4041
import org.tron.common.overlay.message.DisconnectMessage;
4142
import org.tron.common.overlay.message.ReasonCode;
4243
import org.tron.core.config.args.Args;
@@ -65,12 +66,15 @@ public class ChannelManager {
6566

6667
private PeerServer peerServer;
6768

69+
private PeerClient peerClient;
70+
6871
@Autowired
6972
private SyncPool syncPool;
7073

7174
@Autowired
72-
private ChannelManager(final PeerServer peerServer) {
75+
private ChannelManager(final PeerServer peerServer, final PeerClient peerClient) {
7376
this.peerServer = peerServer;
77+
this.peerClient = peerClient;
7478

7579
mainWorker.scheduleWithFixedDelay(() -> {
7680
try {
@@ -115,7 +119,7 @@ private void processNewPeers() {
115119
}else if (activePeers.containsKey(peer.getNodeIdWrapper())) {
116120
Channel channel = activePeers.get(peer.getNodeIdWrapper());
117121
if (channel.getStartTime() > peer.getStartTime()) {
118-
logger.info("disconnect connection established later, {}", channel.getNode());
122+
logger.info("Disconnect connection established later, {}", channel.getNode());
119123
disconnect(channel, DUPLICATE_PEER);
120124
} else {
121125
disconnect(peer, DUPLICATE_PEER);
@@ -160,8 +164,6 @@ public Collection<Channel> getActivePeers() {
160164
return new ArrayList<>(activePeers.values());
161165
}
162166

163-
164-
165167
public void close() {
166168
try {
167169
mainWorker.shutdownNow();
@@ -170,6 +172,7 @@ public void close() {
170172
logger.warn("Problems shutting down", e);
171173
}
172174
peerServer.close();
175+
peerClient.close();
173176

174177
ArrayList<Channel> allPeers = new ArrayList<>(activePeers.values());
175178
allPeers.addAll(newPeers);

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,12 @@ private void send() {
122122

123123
Message msg = messageRoundtrip.getMsg();
124124

125-
ctx.writeAndFlush(msg.getSendData())
126-
.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
125+
ctx.writeAndFlush(msg.getSendData());
127126

128127
logger.info("send {} to {}", msg.getType(), ctx.channel().remoteAddress());
129128

130-
if (msg.getAnswerMessage() != null) {
131-
messageRoundtrip.incRetryTimes();
132-
messageRoundtrip.saveTime();
133-
}
129+
messageRoundtrip.incRetryTimes();
130+
messageRoundtrip.saveTime();
134131
}
135132

136133
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,21 @@ public boolean broadcastTransaction(Transaction signaturedTransaction) {
210210
p2pNode.broadcast(message);
211211
return true;
212212
} catch (ValidateSignatureException e) {
213-
logger.debug(e.getMessage(), e);
213+
logger.error(e.getMessage(), e);
214214
} catch (ContractValidateException e) {
215-
logger.debug(e.getMessage(), e);
215+
logger.error(e.getMessage(), e);
216216
} catch (ContractExeException e) {
217-
logger.debug(e.getMessage(), e);
217+
logger.error(e.getMessage(), e);
218218
} catch (ValidateBandwidthException e) {
219-
logger.debug("high freq", e);
219+
logger.error("high freq", e);
220220
} catch (DupTransactionException e) {
221-
logger.debug("dup trans", e);
221+
logger.error("dup trans", e);
222222
} catch (TaposException e) {
223223
logger.debug("tapos error", e);
224224
} catch (TooBigTransactionException e) {
225225
logger.debug("transaction error", e);
226+
} catch (Exception e){
227+
logger.error("exception caught", e);
226228
}
227229
return false;
228230
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
6060

6161
private long calculateBandwidth(FreezeBalanceContract freezeBalanceContract) {
6262

63-
return freezeBalanceContract.getFrozenBalance() / 1_000_000L
63+
return freezeBalanceContract.getFrozenBalance()
6464
* freezeBalanceContract.getFrozenDuration()
6565
* dbManager.getDynamicPropertiesStore().getBandwidthPerCoinday();
6666
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ private DynamicPropertiesStore(@Qualifier("properties") String dbName) {
151151
try {
152152
this.getBandwidthPerTransaction();
153153
} catch (IllegalArgumentException e) {
154-
this.saveBandwidthPerTransaction(1);
154+
this.saveBandwidthPerTransaction(100_000);
155155
}
156156

157157
try {
158158
this.getBandwidthPerCoinday();
159159
} catch (IllegalArgumentException e) {
160-
this.saveBandwidthPerCoinday(10);
160+
this.saveBandwidthPerCoinday(1);
161161
}
162162

163163
try {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import lombok.Setter;
2222
import lombok.extern.slf4j.Slf4j;
2323
import org.apache.commons.collections4.CollectionUtils;
24+
import org.joda.time.DateTime;
2425
import org.springframework.beans.factory.annotation.Autowired;
2526
import org.springframework.stereotype.Component;
2627
import org.tron.common.crypto.ECKey;
@@ -423,9 +424,8 @@ public synchronized boolean pushTransactions(final TransactionCapsule trx)
423424
if (!trx.validateSignature()) {
424425
throw new ValidateSignatureException("trans sig validate failed");
425426
}
426-
consumeBandwidth(trx);
427427

428-
//validateTapos(trx);
428+
validateTapos(trx);
429429

430430
//validateFreq(trx);
431431

@@ -434,6 +434,7 @@ public synchronized boolean pushTransactions(final TransactionCapsule trx)
434434
}
435435

436436
try (RevokingStore.Dialog tmpDialog = revokingStore.buildDialog()) {
437+
consumeBandwidth(trx);
437438
processTransaction(trx);
438439
pendingTransactions.add(trx);
439440
tmpDialog.merge();
@@ -456,7 +457,10 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
456457
long bandwidth = accountCapsule.getBandwidth();
457458
long now = Time.getCurrentMillis();
458459
long latestOperationTime = accountCapsule.getLatestOperationTime();
459-
if (now - latestOperationTime >= 5 * 60 * 1000) {
460+
//5 * 60 * 1000
461+
if (now - latestOperationTime >= 300_000L) {
462+
accountCapsule.setLatestOperationTime(now);
463+
this.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
460464
return;
461465
}
462466
long bandwidthPerTransaction = getDynamicPropertiesStore().getBandwidthPerTransaction();
@@ -860,6 +864,12 @@ public synchronized BlockCapsule generateBlock(
860864
postponedTrxCount++;
861865
continue;
862866
}
867+
868+
if (DateTime.now().getMillis() - when > ChainConstant.BLOCK_PRODUCED_INTERVAL * 0.5) {
869+
logger.debug("Processing transaction time exceeds the 50% producing time。");
870+
break;
871+
}
872+
863873
// apply transaction
864874
try (Dialog tmpDialog = revokingStore.buildDialog()) {
865875
processTransaction(trx);
@@ -946,6 +956,7 @@ public void processBlock(BlockCapsule block)
946956
}
947957
updateMaintenanceState(needMaint);
948958
//witnessController.updateWitnessSchedule();
959+
updateRecentBlock(block);
949960
}
950961

951962
public void updateRecentBlock(BlockCapsule block) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public void close() {
3333
try {
3434
dbManager.pushTransactions(trx);
3535
} catch (ValidateSignatureException e) {
36-
logger.debug(e.getMessage(), e);
36+
logger.error(e.getMessage(), e);
3737
} catch (ContractValidateException e) {
38-
logger.debug(e.getMessage(), e);
38+
logger.error(e.getMessage(), e);
3939
} catch (ContractExeException e) {
40-
logger.debug(e.getMessage(), e);
40+
logger.error(e.getMessage(), e);
4141
} catch (ValidateBandwidthException e) {
42-
logger.debug(e.getMessage(), e);
42+
logger.error(e.getMessage(), e);
4343
} catch (DupTransactionException e) {
44-
logger.debug("pending manager: dup trans", e);
44+
logger.error("pending manager: dup trans", e);
4545
} catch (TaposException e) {
46-
logger.debug("pending manager: tapos exception", e);
46+
logger.error("pending manager: tapos exception", e);
4747
}
4848
});
4949
dbManager.getPoppedTransactions().stream()

0 commit comments

Comments
 (0)