|
23 | 23 | import org.tron.core.capsule.BlockCapsule.BlockId; |
24 | 24 | import org.tron.core.config.Parameter.NetConstants; |
25 | 25 | import org.tron.core.config.args.Args; |
| 26 | +import org.tron.core.exception.BadBlockException; |
26 | 27 | import org.tron.core.exception.P2pException; |
27 | 28 | import org.tron.core.exception.P2pException.TypeEnum; |
28 | 29 | import org.tron.core.net.TronNetDelegate; |
@@ -263,33 +264,46 @@ private synchronized void handleSyncBlock() { |
263 | 264 | tronNetDelegate.getActivePeer().stream() |
264 | 265 | .filter(peer -> msg.getBlockId().equals(peer.getSyncBlockToFetch().peek())) |
265 | 266 | .forEach(peer -> { |
266 | | - peer.getSyncBlockToFetch().pop(); |
267 | | - peer.getSyncBlockInProcess().add(msg.getBlockId()); |
268 | 267 | isFound[0] = true; |
269 | 268 | }); |
270 | 269 | if (isFound[0]) { |
271 | 270 | blockWaitToProcess.remove(msg); |
272 | 271 | isProcessed[0] = true; |
273 | | - processSyncBlock(msg.getBlockCapsule()); |
| 272 | + processSyncBlock(msg.getBlockCapsule(), peerConnection); |
274 | 273 | } |
275 | 274 | } |
276 | 275 | }); |
277 | 276 | } |
278 | 277 | } |
279 | 278 |
|
280 | | - private void processSyncBlock(BlockCapsule block) { |
| 279 | + private void processSyncBlock(BlockCapsule block, PeerConnection peerConnection) { |
281 | 280 | boolean flag = true; |
| 281 | + boolean attackFlag = false; |
282 | 282 | BlockId blockId = block.getBlockId(); |
283 | 283 | try { |
284 | 284 | tronNetDelegate.validSignature(block); |
285 | 285 | tronNetDelegate.processBlock(block, true); |
286 | 286 | pbftDataSyncHandler.processPBFTCommitData(block); |
| 287 | + } catch (P2pException p2pException) { |
| 288 | + logger.error("Process sync block {} failed, type: {}", |
| 289 | + blockId.getString(), p2pException.getType()); |
| 290 | + attackFlag = p2pException.getType().equals(TypeEnum.BLOCK_SIGN_ERROR) |
| 291 | + || p2pException.getType().equals(TypeEnum.BLOCK_MERKLE_ERROR); |
| 292 | + flag = false; |
287 | 293 | } catch (Exception e) { |
288 | 294 | logger.error("Process sync block {} failed", blockId.getString(), e); |
289 | 295 | flag = false; |
290 | 296 | } |
| 297 | + |
| 298 | + if (attackFlag) { |
| 299 | + invalid(blockId, peerConnection); |
| 300 | + peerConnection.disconnect(ReasonCode.BAD_BLOCK); |
| 301 | + return; |
| 302 | + } |
| 303 | + |
291 | 304 | for (PeerConnection peer : tronNetDelegate.getActivePeer()) { |
292 | | - if (peer.getSyncBlockInProcess().remove(blockId)) { |
| 305 | + if (blockId.equals(peer.getSyncBlockToFetch().peek())) { |
| 306 | + peer.getSyncBlockToFetch().pop(); |
293 | 307 | if (flag) { |
294 | 308 | peer.setBlockBothHave(blockId); |
295 | 309 | if (peer.getSyncBlockToFetch().isEmpty() && peer.isFetchAble()) { |
|
0 commit comments