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

Add block height check when processing PBFT messages (#5548) #5554

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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