Skip to content

Commit

Permalink
use ReasonCode.BAD_PROTOCOL; noInvBackTime is recoverable
Browse files Browse the repository at this point in the history
  • Loading branch information
317787106 committed Jul 10, 2024
1 parent 3a85f98 commit eafda50
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) {
if (type.equals(InventoryType.BLOCK) && flag
&& peer.getAdvInvSpread().getIfPresent(item) == null) {
peer.getFeature().setLastRecBlockInvTime(System.currentTimeMillis());
peer.getFeature().resetNoInvBackTime();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ private void processDisconnect(Protocol.ReasonCode reason) {
case BAD_PROTOCOL:
case BAD_BLOCK:
case BAD_TX:
case MALICIOUS_NODE:
channel.close(BAD_PEER_BAN_TIME);
break;
default:
Expand Down Expand Up @@ -410,6 +409,17 @@ public void updateNoInvBackTime() {
}
}

// if i receive valid block inventory from malicious peer with noInvBackTime > 0 before it is
// disconnected, then i reset this peer to normal
public void resetNoInvBackTime() {
if (stopInvEnable && noInvBackTime > 0) {
logger.info("resetNoInvBackTime peer {}", channel.getInetSocketAddress());
noInvBackTime = 0;
stopBlockInvStartTime = 0;
stopBlockInvEndTime = 0;
}
}

public long getEarliestTime() {
List<Long> times = new ArrayList<>();
if (badSyncBlockChainTime > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private boolean findAndDisconnect(boolean excludeActive, DisconnectStrategy stra
private void disconnectMaliciousPeer(PeerConnection p, DisconnectStrategy strategy) {
logger.info("feature {}: {}, strategy: {}", p.getInetSocketAddress(), p.getFeature(),
strategy);
p.disconnect(ReasonCode.MALICIOUS_NODE);
p.disconnect(ReasonCode.BAD_PROTOCOL);
}

public enum DisconnectStrategy {
Expand Down
1 change: 0 additions & 1 deletion protocol/src/main/protos/core/Tron.proto
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ enum ReasonCode {
BELOW_THAN_ME = 0X24;
NOT_WITNESS = 0x25;
NO_SUCH_MESSAGE = 0x26;
MALICIOUS_NODE = 0X27;
UNKNOWN = 0xFF;
}

Expand Down

0 comments on commit eafda50

Please sign in to comment.