Skip to content

Commit 5e211ba

Browse files
committed
fix thread interupt.
1 parent b1c7072 commit 5e211ba

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/main/java/org/tron/core/net/message/BlockMessage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.tron.core.net.message;
22

3+
import com.google.protobuf.InvalidProtocolBufferException;
34
import org.tron.common.utils.Sha256Hash;
45
import org.tron.core.capsule.BlockCapsule;
56
import org.tron.core.capsule.BlockCapsule.BlockId;
@@ -10,7 +11,7 @@ public class BlockMessage extends TronMessage {
1011

1112
private Block block;
1213

13-
public BlockMessage(byte[] data) throws Exception {
14+
public BlockMessage(byte[] data) throws InvalidProtocolBufferException {
1415
this.type = MessageTypes.BLOCK.asByte();
1516
this.data = data;
1617
this.block = Protocol.Block.parseFrom(data);
@@ -22,7 +23,7 @@ public BlockMessage(Block block) {
2223
this.data = block.toByteArray();
2324
}
2425

25-
public BlockMessage(BlockCapsule block) throws Exception {
26+
public BlockMessage(BlockCapsule block) {
2627
data = block.getData();
2728
this.type = MessageTypes.BLOCK.asByte();
2829
this.block = block.getInstance();

src/main/java/org/tron/core/net/node/NodeDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public interface NodeDelegate {
1919

2020
LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boolean syncMode)
21-
throws BadBlockException, UnLinkedBlockException;
21+
throws BadBlockException, UnLinkedBlockException, InterruptedException;
2222

2323
void handleTransaction(TransactionCapsule trx) throws BadTransactionException;
2424

src/main/java/org/tron/core/net/node/NodeDelegateImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public NodeDelegateImpl(Manager dbManager) {
4949

5050
@Override
5151
public synchronized LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boolean syncMode)
52-
throws BadBlockException, UnLinkedBlockException {
52+
throws BadBlockException, UnLinkedBlockException, InterruptedException {
5353

5454
if (block.getInstance().getSerializedSize() > BLOCK_SIZE + 100) {
5555
throw new BadBlockException("block size over limit");
@@ -83,8 +83,6 @@ public synchronized LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boole
8383
throw new BadBlockException("ContractValidate exception," + e.getMessage());
8484
} catch (ContractExeException e) {
8585
throw new BadBlockException("Contract Exectute exception," + e.getMessage());
86-
} catch (InterruptedException e) {
87-
throw new BadBlockException("pre validate signature exception," + e.getMessage());
8886
} catch (TaposException e) {
8987
throw new BadBlockException("tapos exception," + e.getMessage());
9088
} catch (DupTransactionException e) {

src/main/java/org/tron/core/net/node/NodeImpl.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
764764
//TODO: lack the complete flow.
765765
if (!freshBlockId.contains(block.getBlockId())) {
766766
try {
767-
LinkedList<Sha256Hash> trxIds = del.handleBlock(block, false);
768-
767+
LinkedList<Sha256Hash> trxIds = null;
768+
trxIds = del.handleBlock(block, false);
769769
freshBlockId.offer(block.getBlockId());
770770

771771
trxIds.forEach(trxId -> advObjToFetch.remove(trxId));
@@ -786,18 +786,25 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
786786
block.getBlockId().getString(), peer.getNode().getHost(),
787787
del.getHeadBlockId().getString());
788788
startSyncWithPeer(peer);
789-
} catch (Exception e) {
790-
logger.error("Fail to process adv block {} from {}", block.getBlockId().getString(),
791-
peer.getNode().getHost(), e);
789+
} catch (InterruptedException e) {
790+
Thread.currentThread().interrupt();
792791
}
792+
793+
// logger.error("Fail to process adv block {} from {}", block.getBlockId().getString(),
794+
// peer.getNode().getHost(), e);
795+
793796
}
794797
}
795798

796799
private boolean processSyncBlock(BlockCapsule block) {
797800
boolean isAccept = false;
798801
ReasonCode reason = null;
799802
try {
800-
del.handleBlock(block, true);
803+
try {
804+
del.handleBlock(block, true);
805+
} catch (InterruptedException e) {
806+
Thread.currentThread().interrupt();
807+
}
801808
freshBlockId.offer(block.getBlockId());
802809
logger.info("Success handle block {}", block.getBlockId().getString());
803810
isAccept = true;

0 commit comments

Comments
 (0)