Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge master to develop #6031

Merged
merged 67 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ff69595
test(CI): add test-retry plugin for test
halibobo1205 Jul 1, 2024
ee7765f
Merge pull request #5916 from halibobo1205/release/4.7.6_add_retry
lvs007 Jul 18, 2024
496d64d
feat(version): update version to 4.7.6
halibobo1205 Jul 18, 2024
f092d0e
Merge pull request #5919 from halibobo1205/version/update_version
lvs007 Jul 18, 2024
0dc7a3f
feat(net) : optimize the isIdle method
zeusoo001 Jun 24, 2024
ddbe8f1
feat(net): add isSyncIdle method
zeusoo001 Jul 1, 2024
0779c00
feat(net): optimize fetch inventory message check logic
zeusoo001 Jun 25, 2024
fdbfa17
feat(net) : optimizing the sortPeers method
zeusoo001 Jun 21, 2024
ea14933
feat(net): use comparingLong method for sortPeers
zeusoo001 Jul 1, 2024
3b3b668
initial commit of test isolated
317787106 Jul 18, 2024
6466458
init commit of set_block_both_have2
317787106 Jul 18, 2024
6a08ac6
test(MerkleTree): ignore testConcurrent
halibobo1205 Jul 1, 2024
f5961f4
add testcase testProcessBlock for BlockMsgHandler
317787106 Jul 19, 2024
6706d83
add testcase testProcessBlock for BlockMsgHandler
317787106 Jul 19, 2024
4211348
Merge pull request #5927 from halibobo1205/test/remove_unstable_test
lvs007 Jul 19, 2024
90a6e8f
fix(http/metric): change endpoint variable from member to local
tomatoishealthy May 14, 2024
27cd42f
Merge pull request #5920 from halibobo1205/fix/endpoint-concurrent-ac…
lvs007 Jul 22, 2024
e670386
set lastactivetime in P2pEventHandlerImpl
317787106 Jul 22, 2024
4791cdf
Merge branch 'release_v4.7.6' into feature/test_isolated3
317787106 Jul 22, 2024
ecd43b7
Merge pull request #5923 from zeusoo001/f-sortpeers-method-opt
lvs007 Jul 22, 2024
afc3979
Merge pull request #5921 from zeusoo001/f-isidle-method-opt
lvs007 Jul 23, 2024
729a99b
Merge pull request #5922 from zeusoo001/f-sync-fetch-block-opt
lvs007 Jul 23, 2024
735bccb
add updateLastActiveTime
317787106 Jul 23, 2024
cae19ea
Merge branch 'release_v4.7.6' into feature/test_isolated3
317787106 Jul 23, 2024
343c5f6
optimize log method of PeerConnection
317787106 Jul 23, 2024
34eb577
Merge branch 'release_v4.7.6' into hotfix/set_block_both_have2
317787106 Jul 23, 2024
d6bbbe4
Merge pull request #5925 from 317787106/hotfix/set_block_both_have2
lvs007 Jul 25, 2024
a718006
catch exception of sort peers
317787106 Jul 25, 2024
4f234be
Merge branch 'release_v4.7.6' into feature/test_isolated3
317787106 Jul 25, 2024
14fda8f
catch exception min of peers
317787106 Jul 25, 2024
54b0395
Merge pull request #5924 from 317787106/feature/test_isolated3
lvs007 Jul 29, 2024
d6faee8
feat(monitor): add tcp out traffic and udp in traffic statistics
zeusoo001 Jul 31, 2024
21f0cb5
Merge pull request #5942 from zeusoo001/net_traffic_monitor3
lvs007 Aug 6, 2024
81bb50b
add some log for isolated2 disconnection
317787106 Aug 7, 2024
0d21388
add log of candidate disconnect size when node is isolated
317787106 Aug 7, 2024
0acc84b
set blockNotChangeThreshold from 90 to 60 seconds
317787106 Aug 9, 2024
0fc9acb
remove the condition of peer.isDisconnect
317787106 Aug 9, 2024
0f7c7f4
don't disconnect with syncing node when random disconnect
317787106 Aug 13, 2024
7bdae32
add DisConnectCause
317787106 Aug 13, 2024
ffbb69e
add DisConnectCause
317787106 Aug 13, 2024
abf8c42
change the condition of isLanNode
317787106 Aug 13, 2024
40cb055
don't disconnect with syncing peer if i am lan node
317787106 Aug 13, 2024
14a0750
modify testcase of ResilienceServiceTest
317787106 Aug 14, 2024
424a3dd
Merge pull request #5944 from 317787106/feature/test_isolated3
lvs007 Aug 14, 2024
471b522
use the condition: active size >= min active size in isolate2
317787106 Aug 15, 2024
553fbb4
change varible name from lastActiveTime to lastInteractiveTime
317787106 Aug 16, 2024
1a7abf3
fix the testcase of testUpdateLastInteractiveTime
317787106 Aug 16, 2024
ea7ef8e
Merge pull request #5956 from 317787106/feature/test_isolated3
lvs007 Aug 16, 2024
31b5d46
Add transaction expiration time check before execution (#1)
fyyhtx Aug 19, 2024
8d496f8
prefer to disconnect from broadcast nodes when isOpenFullTcpDisconnec…
317787106 Sep 2, 2024
f99d216
adjust ResilienceServiceTest
317787106 Sep 3, 2024
e242ae1
add testcase PeerStatusCheckTest
317787106 Sep 3, 2024
6c3a526
use WeightedRandom to choose broadcast peer
317787106 Sep 4, 2024
59e92c8
don't disconnect from high peer if its number <=1
317787106 Sep 4, 2024
1996f7b
Merge pull request #5984 from 317787106/feature/test_isolated3
lvs007 Sep 5, 2024
7bdf75e
Merge remote-tracking branch 'origin/release_v4.7.6' into release_v4.7.6
jwrct Sep 5, 2024
6c73ede
feat(net): delete useless test code
jwrct Sep 12, 2024
cdbbb0a
Merge pull request #5999 from fyyhtx/release_v4.7.6
lvs007 Sep 12, 2024
ddccce4
print trx size from pending and repush after generating block
317787106 Sep 27, 2024
450763b
add some test case
317787106 Sep 27, 2024
9b58a57
Merge pull request #6017 from 317787106/feature/print_sr_queue_size
lvs007 Sep 27, 2024
98a37b1
feat(dependencies): update dependencies for protobuf-java
halibobo1205 Sep 22, 2024
0f39d7a
Merge pull request #6025 from halibobo1205/feat/update_libp2p
lvs007 Oct 4, 2024
4103dfe
Merge pull request #6010 from tronprotocol/release_v4.7.6
lvs007 Oct 4, 2024
8947617
update a new version. version name:GreatVoyage-v4.7.5-64-g4103dfeb63,…
halibobo1205 Oct 4, 2024
4d0ad61
Merge pull request #6026 from halibobo1205/version/GreatVoyage-v4.7.5…
lvs007 Oct 4, 2024
310c533
Merge remote-tracking branch 'upstream/master' into master_merge_to_d…
halibobo1205 Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ subprojects {
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre'
implementation "com.google.code.findbugs:jsr305:3.0.0"
implementation group: 'org.springframework', name: 'spring-context', version: '5.3.18'
implementation group: 'org.springframework', name: 'spring-tx', version: '5.3.18'
Expand Down Expand Up @@ -68,12 +67,6 @@ subprojects {
reproducibleFileOrder = true
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
}

configurations.all {
resolutionStrategy {
force group: 'com.google.guava', name: 'guava', version: '30.1-jre'
}
}
}

task copyToParent(type: Copy) {
Expand Down
5 changes: 5 additions & 0 deletions chainbase/src/main/java/org/tron/core/ChainBaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ public class ChainBaseManager {
@Setter
private long lowestBlockNum = -1; // except num = 0.

@Getter
@Setter
private long latestSaveBlockTime;

// for test only
public List<ByteString> getWitnesses() {
return witnessScheduleStore.getActiveWitnesses();
Expand Down Expand Up @@ -381,6 +385,7 @@ private void init() {
this.lowestBlockNum = this.blockIndexStore.getLimitNumber(1, 1).stream()
.map(BlockId::getNum).findFirst().orElse(0L);
this.nodeType = getLowestBlockNum() > 1 ? NodeType.LITE : NodeType.FULL;
this.latestSaveBlockTime = System.currentTimeMillis();
}

public void shutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.tron.core.exception.P2pException;
import org.tron.core.exception.PermissionException;
import org.tron.core.exception.SignatureFormatException;
import org.tron.core.exception.TransactionExpirationException;
import org.tron.core.exception.ValidateSignatureException;
import org.tron.core.store.AccountStore;
import org.tron.core.store.DynamicPropertiesStore;
Expand Down Expand Up @@ -869,4 +870,12 @@ public void removeRedundantRet() {
this.transaction = transactionBuilder.build();
}
}

public void checkExpiration(long nextSlotTime) throws TransactionExpirationException {
if (getExpiration() < nextSlotTime) {
throw new TransactionExpirationException(String.format(
"Transaction expiration time is %d, but next slot time is %d",
getExpiration(), nextSlotTime));
}
}
}
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
api 'org.aspectj:aspectjrt:1.8.13'
api 'org.aspectj:aspectjweaver:1.8.13'
api 'org.aspectj:aspectjtools:1.8.13'
api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.1',{
api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.4',{
exclude group: 'io.grpc', module: 'grpc-context'
exclude group: 'io.grpc', module: 'grpc-core'
exclude group: 'io.grpc', module: 'grpc-netty'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ public class CommonParameter {
public boolean isOpenFullTcpDisconnect;
@Getter
@Setter
public int inactiveThreshold;
@Getter
@Setter
public boolean nodeDetectEnable;
@Getter
@Setter
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public class Constant {

public static final String NODE_IS_OPEN_FULL_TCP_DISCONNECT = "node.isOpenFullTcpDisconnect";

public static final String NODE_INACTIVE_THRESHOLD = "node.inactiveThreshold";

public static final String NODE_DETECT_ENABLE = "node.nodeDetectEnable";

public static final String NODE_MAX_TRANSACTION_PENDING_SIZE = "node.maxTransactionPendingSize";
Expand Down
1 change: 1 addition & 0 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ public GrpcAPI.Return broadcastTransaction(Transaction signedTransaction) {
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
}
TransactionMessage message = new TransactionMessage(trx.getInstance().toByteArray());
trx.checkExpiration(tronNetDelegate.getNextBlockSlotTime());
dbManager.pushTransaction(trx);
int num = tronNetService.fastBroadcastTransaction(message);
if (num == 0 && minEffectiveConnection != 0) {
Expand Down
7 changes: 7 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public static void clearParam() {
PARAMETER.receiveTcpMinDataLength = 2048;
PARAMETER.isOpenFullTcpDisconnect = false;
PARAMETER.nodeDetectEnable = false;
PARAMETER.inactiveThreshold = 600;
PARAMETER.supportConstant = false;
PARAMETER.debug = false;
PARAMETER.minTimeRatio = 0.0;
Expand Down Expand Up @@ -845,6 +846,12 @@ public static void setParam(final String[] args, final String confFileName) {
PARAMETER.nodeDetectEnable = config.hasPath(Constant.NODE_DETECT_ENABLE)
&& config.getBoolean(Constant.NODE_DETECT_ENABLE);

PARAMETER.inactiveThreshold = config.hasPath(Constant.NODE_INACTIVE_THRESHOLD)
? config.getInt(Constant.NODE_INACTIVE_THRESHOLD) : 600;
if (PARAMETER.inactiveThreshold < 1) {
PARAMETER.inactiveThreshold = 1;
}

PARAMETER.maxTransactionPendingSize = config.hasPath(Constant.NODE_MAX_TRANSACTION_PENDING_SIZE)
? config.getInt(Constant.NODE_MAX_TRANSACTION_PENDING_SIZE) : 2000;

Expand Down
20 changes: 15 additions & 5 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ public void updateDynamicProperties(BlockCapsule block) {
(chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber()
- chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum()
+ 1));
chainBaseManager.setLatestSaveBlockTime(System.currentTimeMillis());
Metrics.gaugeSet(MetricKeys.Gauge.HEADER_HEIGHT, block.getNum());
Metrics.gaugeSet(MetricKeys.Gauge.HEADER_TIME, block.getTimeStamp());
}
Expand Down Expand Up @@ -1575,6 +1576,7 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
List<TransactionCapsule> toBePacked = new ArrayList<>();
long currentSize = blockCapsule.getInstance().getSerializedSize();
boolean isSort = Args.getInstance().isOpenTransactionSort();
int[] logSize = new int[] {pendingTransactions.size(), rePushTransactions.size(), 0, 0};
while (pendingTransactions.size() > 0 || rePushTransactions.size() > 0) {
boolean fromPending = false;
TransactionCapsule trx;
Expand Down Expand Up @@ -1650,6 +1652,11 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
tmpSession.merge();
toBePacked.add(trx);
currentSize += trxPackSize;
if (fromPending) {
logSize[2] += 1;
} else {
logSize[3] += 1;
}
} catch (Exception e) {
logger.warn("Process trx {} failed when generating block {}, {}.", trx.getTransactionId(),
blockCapsule.getNum(), e.getMessage());
Expand All @@ -1666,11 +1673,14 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
BlockCapsule capsule = new BlockCapsule(blockCapsule.getInstance());
capsule.generatedByMyself = true;
Metrics.histogramObserve(timer);
logger.info("Generate block {} success, trxs:{}, pendingCount: {}, rePushCount: {},"
+ " postponedCount: {}, blockSize: {} B",
capsule.getNum(), capsule.getTransactions().size(),
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount,
capsule.getSerializedSize());
logger.info("Generate block {} success, trxs:{}, before pendingCount: {}, rePushCount: {}, "
+ "from pending: {}, rePush: {}, after pendingCount: {}, rePushCount: {}, "
+ "postponedCount: {}, blockSize: {} B",
capsule.getNum(), capsule.getTransactions().size(),
logSize[0], logSize[1], logSize[2], logSize[3],
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount,
capsule.getSerializedSize());

return capsule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.tron.core.net.message.PbftMessageFactory;
import org.tron.core.net.message.TronMessage;
import org.tron.core.net.message.TronMessageFactory;
import org.tron.core.net.message.adv.FetchInvDataMessage;
import org.tron.core.net.message.adv.InventoryMessage;
import org.tron.core.net.message.base.DisconnectMessage;
import org.tron.core.net.message.handshake.HelloMessage;
Expand All @@ -38,7 +39,7 @@
import org.tron.p2p.P2pEventHandler;
import org.tron.p2p.connection.Channel;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.ReasonCode;
import org.tron.protos.Protocol.Inventory.InventoryType;

@Slf4j(topic = "net")
@Component
Expand Down Expand Up @@ -205,6 +206,7 @@ private void processMessage(PeerConnection peer, byte[] data) {
default:
throw new P2pException(P2pException.TypeEnum.NO_SUCH_MESSAGE, msg.getType().toString());
}
updateLastInteractiveTime(peer, msg);
} catch (Exception e) {
processException(peer, msg, e);
} finally {
Expand All @@ -220,6 +222,27 @@ private void processMessage(PeerConnection peer, byte[] data) {
}
}

private void updateLastInteractiveTime(PeerConnection peer, TronMessage msg) {
MessageTypes type = msg.getType();

boolean flag = false;
switch (type) {
case SYNC_BLOCK_CHAIN:
case BLOCK_CHAIN_INVENTORY:
case BLOCK:
flag = true;
break;
case FETCH_INV_DATA:
flag = ((FetchInvDataMessage) msg).getInventoryType().equals(InventoryType.BLOCK);
break;
default:
break;
}
if (flag) {
peer.setLastInteractiveTime(System.currentTimeMillis());
}
}

private void processException(PeerConnection peer, TronMessage msg, Exception ex) {
Protocol.ReasonCode code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,12 @@ public boolean isBlockUnsolidified() {
return headNum - solidNum >= maxUnsolidifiedBlocks;
}

public long getNextBlockSlotTime() {
long slotCount = 1;
if (chainBaseManager.getDynamicPropertiesStore().getStateFlag() == 1) {
slotCount += chainBaseManager.getDynamicPropertiesStore().getMaintenanceSkipSlots();
}
return chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp()
+ slotCount * BLOCK_PRODUCED_INTERVAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.tron.core.net.peer.PeerStatusCheck;
import org.tron.core.net.service.adv.AdvService;
import org.tron.core.net.service.effective.EffectiveCheckService;
import org.tron.core.net.service.effective.ResilienceService;
import org.tron.core.net.service.fetchblock.FetchBlockService;
import org.tron.core.net.service.nodepersist.NodePersistService;
import org.tron.core.net.service.relay.RelayService;
Expand Down Expand Up @@ -50,6 +51,9 @@ public class TronNetService {
@Autowired
private PeerStatusCheck peerStatusCheck;

@Autowired
private ResilienceService resilienceService;

@Autowired
private TransactionsMsgHandler transactionsMsgHandler;

Expand Down Expand Up @@ -88,6 +92,7 @@ public void start() {
advService.init();
syncService.init();
peerStatusCheck.init();
resilienceService.init();
transactionsMsgHandler.init();
fetchBlockService.init();
nodePersistService.init();
Expand All @@ -110,6 +115,7 @@ public void close() {
nodePersistService.close();
advService.close();
syncService.close();
resilienceService.close();
peerStatusCheck.close();
transactionsMsgHandler.close();
fetchBlockService.close();
Expand Down Expand Up @@ -177,7 +183,7 @@ private P2pConfig updateConfig(P2pConfig config) {
config.setMaxConnectionsWithSameIp(parameter.getMaxConnectionsWithSameIp());
config.setPort(parameter.getNodeListenPort());
config.setNetworkId(parameter.getNodeP2pVersion());
config.setDisconnectionPolicyEnable(parameter.isOpenFullTcpDisconnect());
config.setDisconnectionPolicyEnable(false);
config.setNodeDetectEnable(parameter.isNodeDetectEnable());
config.setDiscoverEnable(parameter.isNodeDiscoveryEnable());
if (StringUtils.isEmpty(config.getIp()) && hasIpv4Stack(NetUtil.getAllLocalAddress())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc
try {
tronNetDelegate.processBlock(block, false);
witnessProductBlockService.validWitnessProductTwoBlock(block);

Item item = new Item(blockId, InventoryType.BLOCK);
tronNetDelegate.getActivePeer().forEach(p -> {
if (p.getAdvInvReceive().getIfPresent(item) != null) {
p.setBlockBothHave(blockId);
}
});
} catch (Exception e) {
logger.warn("Process adv block {} from peer {} failed. reason: {}",
blockId, peer.getInetAddress(), e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ private void check(PeerConnection peer, FetchInvDataMessage fetchInvDataMsg) thr
throw new P2pException(TypeEnum.BAD_MESSAGE,
"minBlockNum: " + minBlockNum + ", blockNum: " + blockNum);
}
if (blockNum > peer.getLastSyncBlockId().getNum()) {
throw new P2pException(TypeEnum.BAD_MESSAGE,
"maxBlockNum: " + peer.getLastSyncBlockId().getNum() + ", blockNum: " + blockNum);
}
if (peer.getSyncBlockIdCache().getIfPresent(hash) != null) {
throw new P2pException(TypeEnum.BAD_MESSAGE,
new BlockId(hash).getString() + " is exist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void processMessage(PeerConnection peer, TronMessage msg) {
Item item = new Item(id, type);
peer.getAdvInvReceive().put(item, System.currentTimeMillis());
advService.addInv(item);
if (type.equals(InventoryType.BLOCK) && peer.getAdvInvSpread().getIfPresent(item) == null) {
peer.setLastInteractiveTime(System.currentTimeMillis());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep
peer.disconnect(Protocol.ReasonCode.BAD_PROTOCOL);
return;
}

long remainNum = 0;

List<BlockId> summaryChainIds = syncBlockChainMessage.getBlockIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.tron.core.config.args.Args;
import org.tron.core.exception.P2pException;
import org.tron.core.exception.P2pException.TypeEnum;
import org.tron.core.exception.TransactionExpirationException;
import org.tron.core.net.TronNetDelegate;
import org.tron.core.net.message.TronMessage;
import org.tron.core.net.message.adv.TransactionMessage;
Expand Down Expand Up @@ -128,6 +129,7 @@ private void handleTransaction(PeerConnection peer, TransactionMessage trx) {
}

try {
trx.getTransactionCapsule().checkExpiration(tronNetDelegate.getNextBlockSlotTime());
tronNetDelegate.pushTransaction(trx.getTransactionCapsule());
advService.broadcast(trx);
} catch (P2pException e) {
Expand All @@ -137,6 +139,9 @@ private void handleTransaction(PeerConnection peer, TransactionMessage trx) {
peer.setBadPeer(true);
peer.disconnect(ReasonCode.BAD_TX);
}
} catch (TransactionExpirationException e) {
logger.warn("{}. trx: {}, peer: {}",
e.getMessage(), trx.getMessageId(), peer.getInetAddress());
} catch (Exception e) {
logger.error("Trx {} from peer {} process failed", trx.getMessageId(), peer.getInetAddress(),
e);
Expand Down
16 changes: 14 additions & 2 deletions framework/src/main/java/org/tron/core/net/peer/PeerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class PeerConnection {
@Setter
private ByteString address;

@Getter
@Setter
private volatile long lastInteractiveTime;

@Getter
@Setter
private TronState tronState = TronState.INIT;
Expand Down Expand Up @@ -159,6 +163,7 @@ public void setChannel(Channel channel) {
this.isRelayPeer = true;
}
this.nodeStatistics = TronStatsManager.getNodeStatistics(channel.getInetAddress());
lastInteractiveTime = System.currentTimeMillis();
}

public void setBlockBothHave(BlockId blockId) {
Expand All @@ -167,7 +172,11 @@ public void setBlockBothHave(BlockId blockId) {
}

public boolean isIdle() {
return advInvRequest.isEmpty() && syncBlockRequested.isEmpty() && syncChainRequested == null;
return advInvRequest.isEmpty() && isSyncIdle();
}

public boolean isSyncIdle() {
return syncBlockRequested.isEmpty() && syncChainRequested == null;
}

public void sendMessage(Message message) {
Expand Down Expand Up @@ -221,11 +230,13 @@ public String log() {
+ "syncBlockRequestedSize:%d\n"
+ "remainNum:%d\n"
+ "syncChainRequested:%d\n"
+ "inactiveSeconds:%d\n"
+ "blockInProcess:%d\n",
channel.getInetSocketAddress(),
(now - channel.getStartTime()) / Constant.ONE_THOUSAND,
channel.getAvgLatency(),
fastForwardBlock != null ? fastForwardBlock.getNum() : blockBothHave.getNum(),
fastForwardBlock != null ? fastForwardBlock.getNum() : String.format("%d [%ds]",
blockBothHave.getNum(), (now - blockBothHaveUpdateTime) / Constant.ONE_THOUSAND),
isNeedSyncFromPeer(),
isNeedSyncFromUs(),
syncBlockToFetch.size(),
Expand All @@ -234,6 +245,7 @@ public String log() {
remainNum,
requested == null ? 0 : (now - requested.getValue())
/ Constant.ONE_THOUSAND,
(now - lastInteractiveTime) / Constant.ONE_THOUSAND,
syncBlockInProcess.size());
}

Expand Down
Loading
Loading