Skip to content

Commit d18597f

Browse files
authored
Merge pull request #5554 from tronprotocol/release_v4.7.3.1
Add block height check when processing PBFT messages (#5548)
2 parents d1f0ff3 + 5bafc0c commit d18597f

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ public class CommonParameter {
518518
public int pBFTHttpPort;
519519
@Getter
520520
@Setter
521+
public long pBFTExpireNum;
522+
@Getter
523+
@Setter
521524
public long oldSolidityBlockNum = -1;
522525

523526
@Getter/**/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public class Constant {
303303
public static final String SEED_NODE_IP_LIST = "seed.node.ip.list";
304304
public static final String NODE_METRICS_ENABLE = "node.metricsEnable";
305305
public static final String COMMITTEE_ALLOW_PBFT = "committee.allowPBFT";
306+
public static final String COMMITTEE_PBFT_EXPIRE_NUM = "committee.pBFTExpireNum";
306307
public static final String NODE_AGREE_NODE_COUNT = "node.agreeNodeCount";
307308

308309
public static final String COMMITTEE_ALLOW_TRANSACTION_FEE_POOL = "committee.allowTransactionFeePool";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public static void clearParam() {
149149
PARAMETER.fullNodeHttpPort = 0;
150150
PARAMETER.solidityHttpPort = 0;
151151
PARAMETER.pBFTHttpPort = 0;
152+
PARAMETER.pBFTExpireNum = 20;
152153
PARAMETER.jsonRpcHttpFullNodePort = 0;
153154
PARAMETER.jsonRpcHttpSolidityPort = 0;
154155
PARAMETER.jsonRpcHttpPBFTPort = 0;
@@ -974,6 +975,10 @@ public static void setParam(final String[] args, final String confFileName) {
974975
config.hasPath(Constant.COMMITTEE_ALLOW_PBFT) ? config
975976
.getLong(Constant.COMMITTEE_ALLOW_PBFT) : 0;
976977

978+
PARAMETER.pBFTExpireNum =
979+
config.hasPath(Constant.COMMITTEE_PBFT_EXPIRE_NUM) ? config
980+
.getLong(Constant.COMMITTEE_PBFT_EXPIRE_NUM) : 20;
981+
977982
PARAMETER.agreeNodeCount = config.hasPath(Constant.NODE_AGREE_NODE_COUNT) ? config
978983
.getInt(Constant.NODE_AGREE_NODE_COUNT) : MAX_ACTIVE_WITNESS_NUM * 2 / 3 + 1;
979984
PARAMETER.agreeNodeCount = PARAMETER.agreeNodeCount > MAX_ACTIVE_WITNESS_NUM

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,12 @@ public Object getForkLock() {
357357
return dbManager.getForkLock();
358358
}
359359

360+
public long getNextMaintenanceTime() {
361+
return chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
362+
}
363+
364+
public long getMaintenanceTimeInterval() {
365+
return chainBaseManager.getDynamicPropertiesStore().getMaintenanceTimeInterval();
366+
}
367+
360368
}

framework/src/main/java/org/tron/core/net/messagehandler/PbftMsgHandler.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
import org.tron.consensus.pbft.PbftManager;
1212
import org.tron.consensus.pbft.message.PbftBaseMessage;
1313
import org.tron.consensus.pbft.message.PbftMessage;
14+
import org.tron.core.config.args.Args;
1415
import org.tron.core.exception.P2pException;
16+
import org.tron.core.net.TronNetDelegate;
1517
import org.tron.core.net.TronNetService;
1618
import org.tron.core.net.peer.PeerConnection;
19+
import org.tron.protos.Protocol.PBFTMessage.DataType;
1720

1821
@Component
1922
public class PbftMsgHandler {
@@ -26,10 +29,24 @@ public class PbftMsgHandler {
2629
@Autowired
2730
private PbftManager pbftManager;
2831

32+
@Autowired
33+
private TronNetDelegate tronNetDelegate;
34+
2935
public void processMessage(PeerConnection peer, PbftMessage msg) throws Exception {
3036
if (Param.getInstance().getPbftInterface().isSyncing()) {
3137
return;
3238
}
39+
if (msg.getDataType().equals(DataType.BLOCK)
40+
&& tronNetDelegate.getHeadBlockId().getNum() - msg.getNumber()
41+
> Args.getInstance().getPBFTExpireNum()) {
42+
return;
43+
}
44+
long currentEpoch = tronNetDelegate.getNextMaintenanceTime();
45+
long expireEpoch = 2 * tronNetDelegate.getMaintenanceTimeInterval();
46+
if (msg.getDataType().equals(DataType.SRL)
47+
&& currentEpoch - msg.getEpoch() > expireEpoch) {
48+
return;
49+
}
3350
msg.analyzeSignature();
3451
String key = buildKey(msg);
3552
Lock lock = striped.get(key);

0 commit comments

Comments
 (0)