Skip to content

Commit 3fee99e

Browse files
committed
resolve conflict
2 parents ba8200f + 3f636c2 commit 3fee99e

File tree

8 files changed

+48
-40
lines changed

8 files changed

+48
-40
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ dependencies {
8989

9090
compile group: 'com.beust', name: 'jcommander', version: '1.72'
9191

92-
compile group: 'junit', name: 'junit', version: '4.8.1'
92+
compile group: 'junit', name: 'junit', version: '4.12'
9393

9494
compile group: 'net.jcip', name: 'jcip-annotations', version: '1.0'
9595

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,28 @@
2020
import static org.tron.common.overlay.message.ReasonCode.DUPLICATE_PEER;
2121
import static org.tron.common.overlay.message.ReasonCode.TOO_MANY_PEERS;
2222

23-
import java.io.IOException;
2423
import java.net.InetAddress;
2524
import java.net.InetSocketAddress;
26-
import java.util.*;
25+
import java.util.ArrayList;
26+
import java.util.Collection;
27+
import java.util.Collections;
28+
import java.util.Comparator;
29+
import java.util.Date;
30+
import java.util.HashSet;
31+
import java.util.List;
32+
import java.util.Map;
33+
import java.util.Set;
2734
import java.util.concurrent.ConcurrentHashMap;
2835
import java.util.concurrent.CopyOnWriteArrayList;
2936
import java.util.concurrent.Executors;
3037
import java.util.concurrent.ScheduledExecutorService;
3138
import java.util.concurrent.TimeUnit;
32-
33-
import io.netty.channel.ChannelHandlerContext;
34-
import io.netty.handler.timeout.ReadTimeoutException;
3539
import org.apache.commons.collections4.map.LRUMap;
3640
import org.slf4j.Logger;
3741
import org.slf4j.LoggerFactory;
3842
import org.springframework.beans.factory.annotation.Autowired;
3943
import org.springframework.stereotype.Component;
4044
import org.tron.common.overlay.client.PeerClient;
41-
import org.tron.common.overlay.message.DisconnectMessage;
4245
import org.tron.common.overlay.message.ReasonCode;
4346
import org.tron.core.config.args.Args;
4447
import org.tron.core.db.ByteArrayWrapper;
@@ -143,6 +146,13 @@ public void notifyDisconnect(Channel channel) {
143146
syncPool.onDisconnect(channel);
144147
activePeers.values().remove(channel);
145148
newPeers.remove(channel);
149+
if (channel == null || channel.getChannelHandlerContext() == null
150+
|| channel.getChannelHandlerContext().channel() == null) {
151+
return;
152+
}
153+
InetSocketAddress socketAddress = (InetSocketAddress) channel.getChannelHandlerContext()
154+
.channel().remoteAddress();
155+
recentlyDisconnected.put(socketAddress.getAddress(), new Date());
146156
}
147157

148158
public boolean isRecentlyDisconnected(InetAddress peerAddr) {

src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ public byte[] getData() {
360360
return this.transaction.toByteArray();
361361
}
362362

363+
public long getSerializedSize() {
364+
return this.transaction.getSerializedSize();
365+
}
366+
363367
@Override
364368
public Transaction getInstance() {
365369
return this.transaction;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ public synchronized BlockCapsule generateBlock(
861861
Iterator iterator = pendingTransactions.iterator();
862862
while (iterator.hasNext()) {
863863
TransactionCapsule trx = (TransactionCapsule) iterator.next();
864-
currentTrxSize += RamUsageEstimator.sizeOf(trx);
864+
currentTrxSize += trx.getSerializedSize();
865865
// judge block size
866866
if (currentTrxSize > ChainConstant.TRXS_SIZE) {
867867
postponedTrxCount++;

src/main/java/org/tron/program/FullNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public static void main(String[] args) throws InterruptedException {
2222
Args.setParam(args, Constant.TESTNET_CONF);
2323
Args cfgArgs = Args.getInstance();
2424

25-
ApplicationContext context = new AnnotationConfigApplicationContext(DefaultConfig.class);
26-
2725
if (cfgArgs.isHelp()) {
2826
logger.info("Here is the help message.");
2927
return;
3028
}
29+
30+
ApplicationContext context = new AnnotationConfigApplicationContext(DefaultConfig.class);
3131
Application appT = ApplicationFactory.create(context);
3232
shutdown(appT);
3333
//appT.init(cfgArgs);

src/test/java/org/tron/core/net/node/BroadTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.concurrent.ScheduledExecutorService;
1212
import lombok.extern.slf4j.Slf4j;
1313
import org.apache.commons.collections4.CollectionUtils;
14-
import org.junit.AfterClass;
14+
import org.junit.After;
1515
import org.junit.Assert;
1616
import org.junit.Before;
1717
import org.junit.Test;
@@ -52,6 +52,7 @@ public class BroadTest {
5252
PeerClient peerClient;
5353
ChannelManager channelManager;
5454
SyncPool pool;
55+
private static final String dbPath = "output-nodeImplTest/broad";
5556

5657
private class Condition {
5758

@@ -166,7 +167,7 @@ public void init() {
166167
@Override
167168
public void run() {
168169
logger.info("Full node running.");
169-
Args.setParam(new String[]{"-d", "output-BroadTest-test"}, "config.conf");
170+
Args.setParam(new String[]{"-d",dbPath}, "config.conf");
170171
Args cfgArgs = Args.getInstance();
171172
cfgArgs.setNodeListenPort(17889);
172173
cfgArgs.setNodeDiscoveryEnable(false);
@@ -215,14 +216,6 @@ public void run() {
215216
}
216217
}
217218

218-
219-
@AfterClass
220-
public static void destroy() {
221-
Args.clearParam();
222-
FileUtil.deleteDir(new File("output-BroadTest-test"));
223-
// context.destroy();
224-
}
225-
226219
private void prepare() {
227220
try {
228221
ExecutorService advertiseLoopThread = ReflectUtils.getFieldValue(node, "broadPool");
@@ -273,4 +266,9 @@ public void run() {
273266
}
274267
}
275268

269+
@After
270+
public void destroy() {
271+
FileUtil.deleteDir(new File("output-nodeImplTest"));
272+
}
273+
276274
}

src/test/java/org/tron/core/net/node/HandleSyncBlockTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.netty.util.internal.ConcurrentSet;
55
import lombok.extern.slf4j.Slf4j;
66
import org.apache.commons.collections4.CollectionUtils;
7-
import org.junit.AfterClass;
7+
import org.junit.After;
88
import org.junit.Assert;
99
import org.junit.Before;
1010
import org.junit.Test;
@@ -49,6 +49,7 @@ public class HandleSyncBlockTest {
4949
PeerClient peerClient;
5050
ChannelManager channelManager;
5151
SyncPool pool;
52+
private static final String dbPath = "output-nodeImplTest/handleSyncBlock";
5253

5354
private class Condition {
5455

@@ -151,7 +152,7 @@ public void init() {
151152
@Override
152153
public void run() {
153154
logger.info("Full node running.");
154-
Args.setParam(new String[]{"-d","output-handleSyncBlock-test"}, "config.conf");
155+
Args.setParam(new String[]{"-d",dbPath}, "config.conf");
155156
Args cfgArgs = Args.getInstance();
156157
cfgArgs.setNodeListenPort(17889);
157158
cfgArgs.setNodeDiscoveryEnable(false);
@@ -200,14 +201,6 @@ public void run() {
200201
}
201202
}
202203

203-
@AfterClass
204-
public static void destroy() {
205-
Args.clearParam();
206-
FileUtil.deleteDir(new File("output-handleSyncBlock-test"));
207-
// context.destroy();
208-
}
209-
210-
211204
private void prepare() {
212205
try {
213206
ExecutorService advertiseLoopThread = ReflectUtils.getFieldValue(node, "broadPool");
@@ -257,4 +250,9 @@ public void run() {
257250
e.printStackTrace();
258251
}
259252
}
253+
254+
@After
255+
public void destroy() {
256+
FileUtil.deleteDir(new File("output-nodeImplTest"));
257+
}
260258
}

src/test/java/org/tron/core/net/node/StartFetchSyncBlockTest.java

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

33
import lombok.extern.slf4j.Slf4j;
44
import org.apache.commons.collections4.CollectionUtils;
5-
import org.junit.AfterClass;
5+
import org.junit.After;
66
import org.junit.Assert;
77
import org.junit.Before;
88
import org.junit.Test;
@@ -44,6 +44,7 @@ public class StartFetchSyncBlockTest {
4444
PeerClient peerClient;
4545
ChannelManager channelManager;
4646
SyncPool pool;
47+
private static final String dbPath = "output-nodeImplTest/startFetchSyncBlockTest";
4748

4849
private class Condition {
4950

@@ -115,7 +116,7 @@ public void init() {
115116
@Override
116117
public void run() {
117118
logger.info("Full node running.");
118-
Args.setParam(new String[]{"-d","output-startFetchSyncBlock-test"}, "config.conf");
119+
Args.setParam(new String[]{"-d",dbPath}, "config.conf");
119120
Args cfgArgs = Args.getInstance();
120121
cfgArgs.setNodeListenPort(17889);
121122
cfgArgs.setNodeDiscoveryEnable(false);
@@ -170,14 +171,6 @@ public void run() {
170171
}
171172
}
172173

173-
@AfterClass
174-
public static void destroy() {
175-
Args.clearParam();
176-
FileUtil.deleteDir(new File("output-startFetchSyncBlock-test"));
177-
// context.destroy();
178-
179-
}
180-
181174
private void prepare() {
182175
try {
183176
ExecutorService advertiseLoopThread = ReflectUtils.getFieldValue(node, "broadPool");
@@ -227,4 +220,9 @@ public void run() {
227220
e.printStackTrace();
228221
}
229222
}
223+
224+
@After
225+
public void destroy() {
226+
FileUtil.deleteDir(new File("output-nodeImplTest"));
227+
}
230228
}

0 commit comments

Comments
 (0)