diff --git a/common/src/main/java/org/tron/common/parameter/CommonParameter.java b/common/src/main/java/org/tron/common/parameter/CommonParameter.java index 8c4cd23f09a..f8f6e6c5edb 100644 --- a/common/src/main/java/org/tron/common/parameter/CommonParameter.java +++ b/common/src/main/java/org/tron/common/parameter/CommonParameter.java @@ -518,6 +518,9 @@ public class CommonParameter { public int pBFTHttpPort; @Getter @Setter + public long pBFTExpireNum; + @Getter + @Setter public long oldSolidityBlockNum = -1; @Getter/**/ diff --git a/common/src/main/java/org/tron/core/Constant.java b/common/src/main/java/org/tron/core/Constant.java index 54ff30d9e65..ba867793b41 100644 --- a/common/src/main/java/org/tron/core/Constant.java +++ b/common/src/main/java/org/tron/core/Constant.java @@ -303,6 +303,7 @@ public class Constant { public static final String SEED_NODE_IP_LIST = "seed.node.ip.list"; public static final String NODE_METRICS_ENABLE = "node.metricsEnable"; public static final String COMMITTEE_ALLOW_PBFT = "committee.allowPBFT"; + public static final String COMMITTEE_PBFT_EXPIRE_NUM = "committee.pBFTExpireNum"; public static final String NODE_AGREE_NODE_COUNT = "node.agreeNodeCount"; public static final String COMMITTEE_ALLOW_TRANSACTION_FEE_POOL = "committee.allowTransactionFeePool"; diff --git a/framework/src/main/java/org/tron/core/config/args/Args.java b/framework/src/main/java/org/tron/core/config/args/Args.java index 5c2d76afbb1..75140dd5f54 100644 --- a/framework/src/main/java/org/tron/core/config/args/Args.java +++ b/framework/src/main/java/org/tron/core/config/args/Args.java @@ -149,6 +149,7 @@ public static void clearParam() { PARAMETER.fullNodeHttpPort = 0; PARAMETER.solidityHttpPort = 0; PARAMETER.pBFTHttpPort = 0; + PARAMETER.pBFTExpireNum = 20; PARAMETER.jsonRpcHttpFullNodePort = 0; PARAMETER.jsonRpcHttpSolidityPort = 0; PARAMETER.jsonRpcHttpPBFTPort = 0; @@ -974,6 +975,10 @@ public static void setParam(final String[] args, final String confFileName) { config.hasPath(Constant.COMMITTEE_ALLOW_PBFT) ? config .getLong(Constant.COMMITTEE_ALLOW_PBFT) : 0; + PARAMETER.pBFTExpireNum = + config.hasPath(Constant.COMMITTEE_PBFT_EXPIRE_NUM) ? config + .getLong(Constant.COMMITTEE_PBFT_EXPIRE_NUM) : 20; + PARAMETER.agreeNodeCount = config.hasPath(Constant.NODE_AGREE_NODE_COUNT) ? config .getInt(Constant.NODE_AGREE_NODE_COUNT) : MAX_ACTIVE_WITNESS_NUM * 2 / 3 + 1; PARAMETER.agreeNodeCount = PARAMETER.agreeNodeCount > MAX_ACTIVE_WITNESS_NUM diff --git a/framework/src/main/java/org/tron/core/net/TronNetDelegate.java b/framework/src/main/java/org/tron/core/net/TronNetDelegate.java index 4d22f98d680..5d09e67908d 100644 --- a/framework/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/framework/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -357,4 +357,12 @@ public Object getForkLock() { return dbManager.getForkLock(); } + public long getNextMaintenanceTime() { + return chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime(); + } + + public long getMaintenanceTimeInterval() { + return chainBaseManager.getDynamicPropertiesStore().getMaintenanceTimeInterval(); + } + } diff --git a/framework/src/main/java/org/tron/core/net/messagehandler/PbftMsgHandler.java b/framework/src/main/java/org/tron/core/net/messagehandler/PbftMsgHandler.java index 44eed8d1c2f..4e4cc858898 100644 --- a/framework/src/main/java/org/tron/core/net/messagehandler/PbftMsgHandler.java +++ b/framework/src/main/java/org/tron/core/net/messagehandler/PbftMsgHandler.java @@ -11,9 +11,12 @@ import org.tron.consensus.pbft.PbftManager; import org.tron.consensus.pbft.message.PbftBaseMessage; import org.tron.consensus.pbft.message.PbftMessage; +import org.tron.core.config.args.Args; import org.tron.core.exception.P2pException; +import org.tron.core.net.TronNetDelegate; import org.tron.core.net.TronNetService; import org.tron.core.net.peer.PeerConnection; +import org.tron.protos.Protocol.PBFTMessage.DataType; @Component public class PbftMsgHandler { @@ -26,10 +29,24 @@ public class PbftMsgHandler { @Autowired private PbftManager pbftManager; + @Autowired + private TronNetDelegate tronNetDelegate; + public void processMessage(PeerConnection peer, PbftMessage msg) throws Exception { if (Param.getInstance().getPbftInterface().isSyncing()) { return; } + if (msg.getDataType().equals(DataType.BLOCK) + && tronNetDelegate.getHeadBlockId().getNum() - msg.getNumber() + > Args.getInstance().getPBFTExpireNum()) { + return; + } + long currentEpoch = tronNetDelegate.getNextMaintenanceTime(); + long expireEpoch = 2 * tronNetDelegate.getMaintenanceTimeInterval(); + if (msg.getDataType().equals(DataType.SRL) + && currentEpoch - msg.getEpoch() > expireEpoch) { + return; + } msg.analyzeSignature(); String key = buildKey(msg); Lock lock = striped.get(key);