Skip to content

Commit

Permalink
Add block height check when processing PBFT messages (#5548)
Browse files Browse the repository at this point in the history
* fix(pbft): Add block height check when processing PBFT messages
  • Loading branch information
jwrct authored Oct 25, 2023
1 parent d1f0ff3 commit 5bafc0c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ public class CommonParameter {
public int pBFTHttpPort;
@Getter
@Setter
public long pBFTExpireNum;
@Getter
@Setter
public long oldSolidityBlockNum = -1;

@Getter/**/
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 5 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 @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,12 @@ public Object getForkLock() {
return dbManager.getForkLock();
}

public long getNextMaintenanceTime() {
return chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
}

public long getMaintenanceTimeInterval() {
return chainBaseManager.getDynamicPropertiesStore().getMaintenanceTimeInterval();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 5bafc0c

Please sign in to comment.