Skip to content

Commit ab6a65e

Browse files
committed
feat(net): optimize p2p exception type description
1 parent 9a825ec commit ab6a65e

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

common/src/main/java/org/tron/core/exception/P2pException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public enum TypeEnum {
5050
TRX_EXE_FAILED(12, "trx exe failed"),
5151
DB_ITEM_NOT_FOUND(13, "DB item not found"),
5252
PROTOBUF_ERROR(14, "protobuf inconsistent"),
53-
SIGN_ERROR(15, "sign error"),
54-
CALC_MERKLE_ROOT_FAILED(16, "calc merkle root failed"),
53+
BLOCK_SIGN_ERROR(15, "block sign error"),
54+
BLOCK_MERKLE_ERROR(16, "block merkle error"),
5555

5656
DEFAULT(100, "default exception");
5757

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public void processBlock(BlockCapsule block, boolean isSync) throws P2pException
285285
logger.error("Process block failed, {}, reason: {}", blockId.getString(), e.getMessage());
286286
if (e instanceof BadBlockException
287287
&& ((BadBlockException) e).getType().equals(CALC_MERKLE_ROOT_FAILED)) {
288-
throw new P2pException(TypeEnum.CALC_MERKLE_ROOT_FAILED, e);
288+
throw new P2pException(TypeEnum.BLOCK_MERKLE_ERROR, e);
289289
} else {
290290
throw new P2pException(TypeEnum.BAD_BLOCK, e);
291291
}
@@ -318,10 +318,10 @@ public void validSignature(BlockCapsule block) throws P2pException {
318318
try {
319319
if (!block.validateSignature(dbManager.getDynamicPropertiesStore(),
320320
dbManager.getAccountStore())) {
321-
throw new P2pException(TypeEnum.SIGN_ERROR, "valid signature failed.");
321+
throw new P2pException(TypeEnum.BLOCK_SIGN_ERROR, "valid signature failed.");
322322
}
323323
} catch (ValidateSignatureException e) {
324-
throw new P2pException(TypeEnum.SIGN_ERROR, e);
324+
throw new P2pException(TypeEnum.BLOCK_SIGN_ERROR, e);
325325
}
326326
}
327327

framework/src/main/java/org/tron/core/net/service/sync/SyncService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.tron.core.net.service.sync;
22

33
import static org.tron.core.config.Parameter.NetConstants.MAX_BLOCK_FETCH_PER_PEER;
4-
import static org.tron.core.exception.P2pException.TypeEnum.CALC_MERKLE_ROOT_FAILED;
5-
import static org.tron.core.exception.P2pException.TypeEnum.SIGN_ERROR;
64

75
import com.google.common.cache.Cache;
86
import com.google.common.cache.CacheBuilder;
@@ -289,8 +287,8 @@ private void processSyncBlock(BlockCapsule block, PeerConnection peerConnection)
289287
} catch (P2pException p2pException) {
290288
logger.error("Process sync block {} failed, type: {}",
291289
blockId.getString(), p2pException.getType());
292-
attackFlag = p2pException.getType().equals(SIGN_ERROR)
293-
|| p2pException.getType().equals(CALC_MERKLE_ROOT_FAILED);
290+
attackFlag = p2pException.getType().equals(TypeEnum.BLOCK_SIGN_ERROR)
291+
|| p2pException.getType().equals(TypeEnum.BLOCK_MERKLE_ERROR);
294292
flag = false;
295293
} catch (Exception e) {
296294
logger.error("Process sync block {} failed", blockId.getString(), e);

0 commit comments

Comments
 (0)