Skip to content

Commit db74739

Browse files
authored
Merge pull request #6031 from halibobo1205/master_merge_to_develop
merge master to develop
2 parents 773b374 + 310c533 commit db74739

40 files changed

+1015
-44
lines changed

build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ subprojects {
3737
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
3838
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
3939
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
40-
implementation group: 'com.google.guava', name: 'guava', version: '30.1-jre'
4140
implementation "com.google.code.findbugs:jsr305:3.0.0"
4241
implementation group: 'org.springframework', name: 'spring-context', version: '5.3.18'
4342
implementation group: 'org.springframework', name: 'spring-tx', version: '5.3.18'
@@ -68,12 +67,6 @@ subprojects {
6867
reproducibleFileOrder = true
6968
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
7069
}
71-
72-
configurations.all {
73-
resolutionStrategy {
74-
force group: 'com.google.guava', name: 'guava', version: '30.1-jre'
75-
}
76-
}
7770
}
7871

7972
task copyToParent(type: Copy) {

chainbase/src/main/java/org/tron/core/ChainBaseManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ public class ChainBaseManager {
244244
@Setter
245245
private long lowestBlockNum = -1; // except num = 0.
246246

247+
@Getter
248+
@Setter
249+
private long latestSaveBlockTime;
250+
247251
// for test only
248252
public List<ByteString> getWitnesses() {
249253
return witnessScheduleStore.getActiveWitnesses();
@@ -381,6 +385,7 @@ private void init() {
381385
this.lowestBlockNum = this.blockIndexStore.getLimitNumber(1, 1).stream()
382386
.map(BlockId::getNum).findFirst().orElse(0L);
383387
this.nodeType = getLowestBlockNum() > 1 ? NodeType.LITE : NodeType.FULL;
388+
this.latestSaveBlockTime = System.currentTimeMillis();
384389
}
385390

386391
public void shutdown() {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.tron.core.exception.P2pException;
6060
import org.tron.core.exception.PermissionException;
6161
import org.tron.core.exception.SignatureFormatException;
62+
import org.tron.core.exception.TransactionExpirationException;
6263
import org.tron.core.exception.ValidateSignatureException;
6364
import org.tron.core.store.AccountStore;
6465
import org.tron.core.store.DynamicPropertiesStore;
@@ -869,4 +870,12 @@ public void removeRedundantRet() {
869870
this.transaction = transactionBuilder.build();
870871
}
871872
}
873+
874+
public void checkExpiration(long nextSlotTime) throws TransactionExpirationException {
875+
if (getExpiration() < nextSlotTime) {
876+
throw new TransactionExpirationException(String.format(
877+
"Transaction expiration time is %d, but next slot time is %d",
878+
getExpiration(), nextSlotTime));
879+
}
880+
}
872881
}

common/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646
api 'org.aspectj:aspectjrt:1.8.13'
4747
api 'org.aspectj:aspectjweaver:1.8.13'
4848
api 'org.aspectj:aspectjtools:1.8.13'
49-
api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.1',{
49+
api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.4',{
5050
exclude group: 'io.grpc', module: 'grpc-context'
5151
exclude group: 'io.grpc', module: 'grpc-core'
5252
exclude group: 'io.grpc', module: 'grpc-netty'

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ public class CommonParameter {
333333
public boolean isOpenFullTcpDisconnect;
334334
@Getter
335335
@Setter
336+
public int inactiveThreshold;
337+
@Getter
338+
@Setter
336339
public boolean nodeDetectEnable;
337340
@Getter
338341
@Setter

common/src/main/java/org/tron/core/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public class Constant {
198198

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

201+
public static final String NODE_INACTIVE_THRESHOLD = "node.inactiveThreshold";
202+
201203
public static final String NODE_DETECT_ENABLE = "node.nodeDetectEnable";
202204

203205
public static final String NODE_MAX_TRANSACTION_PENDING_SIZE = "node.maxTransactionPendingSize";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ public GrpcAPI.Return broadcastTransaction(Transaction signedTransaction) {
549549
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
550550
}
551551
TransactionMessage message = new TransactionMessage(trx.getInstance().toByteArray());
552+
trx.checkExpiration(tronNetDelegate.getNextBlockSlotTime());
552553
dbManager.pushTransaction(trx);
553554
int num = tronNetService.fastBroadcastTransaction(message);
554555
if (num == 0 && minEffectiveConnection != 0) {

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public static void clearParam() {
173173
PARAMETER.receiveTcpMinDataLength = 2048;
174174
PARAMETER.isOpenFullTcpDisconnect = false;
175175
PARAMETER.nodeDetectEnable = false;
176+
PARAMETER.inactiveThreshold = 600;
176177
PARAMETER.supportConstant = false;
177178
PARAMETER.debug = false;
178179
PARAMETER.minTimeRatio = 0.0;
@@ -845,6 +846,12 @@ public static void setParam(final String[] args, final String confFileName) {
845846
PARAMETER.nodeDetectEnable = config.hasPath(Constant.NODE_DETECT_ENABLE)
846847
&& config.getBoolean(Constant.NODE_DETECT_ENABLE);
847848

849+
PARAMETER.inactiveThreshold = config.hasPath(Constant.NODE_INACTIVE_THRESHOLD)
850+
? config.getInt(Constant.NODE_INACTIVE_THRESHOLD) : 600;
851+
if (PARAMETER.inactiveThreshold < 1) {
852+
PARAMETER.inactiveThreshold = 1;
853+
}
854+
848855
PARAMETER.maxTransactionPendingSize = config.hasPath(Constant.NODE_MAX_TRANSACTION_PENDING_SIZE)
849856
? config.getInt(Constant.NODE_MAX_TRANSACTION_PENDING_SIZE) : 2000;
850857

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ public void updateDynamicProperties(BlockCapsule block) {
13911391
(chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber()
13921392
- chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum()
13931393
+ 1));
1394+
chainBaseManager.setLatestSaveBlockTime(System.currentTimeMillis());
13941395
Metrics.gaugeSet(MetricKeys.Gauge.HEADER_HEIGHT, block.getNum());
13951396
Metrics.gaugeSet(MetricKeys.Gauge.HEADER_TIME, block.getTimeStamp());
13961397
}
@@ -1575,6 +1576,7 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
15751576
List<TransactionCapsule> toBePacked = new ArrayList<>();
15761577
long currentSize = blockCapsule.getInstance().getSerializedSize();
15771578
boolean isSort = Args.getInstance().isOpenTransactionSort();
1579+
int[] logSize = new int[] {pendingTransactions.size(), rePushTransactions.size(), 0, 0};
15781580
while (pendingTransactions.size() > 0 || rePushTransactions.size() > 0) {
15791581
boolean fromPending = false;
15801582
TransactionCapsule trx;
@@ -1650,6 +1652,11 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
16501652
tmpSession.merge();
16511653
toBePacked.add(trx);
16521654
currentSize += trxPackSize;
1655+
if (fromPending) {
1656+
logSize[2] += 1;
1657+
} else {
1658+
logSize[3] += 1;
1659+
}
16531660
} catch (Exception e) {
16541661
logger.warn("Process trx {} failed when generating block {}, {}.", trx.getTransactionId(),
16551662
blockCapsule.getNum(), e.getMessage());
@@ -1666,11 +1673,14 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
16661673
BlockCapsule capsule = new BlockCapsule(blockCapsule.getInstance());
16671674
capsule.generatedByMyself = true;
16681675
Metrics.histogramObserve(timer);
1669-
logger.info("Generate block {} success, trxs:{}, pendingCount: {}, rePushCount: {},"
1670-
+ " postponedCount: {}, blockSize: {} B",
1671-
capsule.getNum(), capsule.getTransactions().size(),
1672-
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount,
1673-
capsule.getSerializedSize());
1676+
logger.info("Generate block {} success, trxs:{}, before pendingCount: {}, rePushCount: {}, "
1677+
+ "from pending: {}, rePush: {}, after pendingCount: {}, rePushCount: {}, "
1678+
+ "postponedCount: {}, blockSize: {} B",
1679+
capsule.getNum(), capsule.getTransactions().size(),
1680+
logSize[0], logSize[1], logSize[2], logSize[3],
1681+
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount,
1682+
capsule.getSerializedSize());
1683+
16741684
return capsule;
16751685
}
16761686

framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.tron.core.net.message.PbftMessageFactory;
2020
import org.tron.core.net.message.TronMessage;
2121
import org.tron.core.net.message.TronMessageFactory;
22+
import org.tron.core.net.message.adv.FetchInvDataMessage;
2223
import org.tron.core.net.message.adv.InventoryMessage;
2324
import org.tron.core.net.message.base.DisconnectMessage;
2425
import org.tron.core.net.message.handshake.HelloMessage;
@@ -38,7 +39,7 @@
3839
import org.tron.p2p.P2pEventHandler;
3940
import org.tron.p2p.connection.Channel;
4041
import org.tron.protos.Protocol;
41-
import org.tron.protos.Protocol.ReasonCode;
42+
import org.tron.protos.Protocol.Inventory.InventoryType;
4243

4344
@Slf4j(topic = "net")
4445
@Component
@@ -205,6 +206,7 @@ private void processMessage(PeerConnection peer, byte[] data) {
205206
default:
206207
throw new P2pException(P2pException.TypeEnum.NO_SUCH_MESSAGE, msg.getType().toString());
207208
}
209+
updateLastInteractiveTime(peer, msg);
208210
} catch (Exception e) {
209211
processException(peer, msg, e);
210212
} finally {
@@ -220,6 +222,27 @@ private void processMessage(PeerConnection peer, byte[] data) {
220222
}
221223
}
222224

225+
private void updateLastInteractiveTime(PeerConnection peer, TronMessage msg) {
226+
MessageTypes type = msg.getType();
227+
228+
boolean flag = false;
229+
switch (type) {
230+
case SYNC_BLOCK_CHAIN:
231+
case BLOCK_CHAIN_INVENTORY:
232+
case BLOCK:
233+
flag = true;
234+
break;
235+
case FETCH_INV_DATA:
236+
flag = ((FetchInvDataMessage) msg).getInventoryType().equals(InventoryType.BLOCK);
237+
break;
238+
default:
239+
break;
240+
}
241+
if (flag) {
242+
peer.setLastInteractiveTime(System.currentTimeMillis());
243+
}
244+
}
245+
223246
private void processException(PeerConnection peer, TronMessage msg, Exception ex) {
224247
Protocol.ReasonCode code;
225248

0 commit comments

Comments
 (0)