Skip to content

feat(net):supplement disconnect reasons #5392

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

Merged
merged 5 commits into from
Sep 5, 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 @@ -38,6 +38,7 @@
import org.tron.p2p.P2pEventHandler;
import org.tron.p2p.connection.Channel;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.ReasonCode;

@Slf4j(topic = "net")
@Component
Expand Down Expand Up @@ -232,7 +233,8 @@ private void processException(PeerConnection peer, TronMessage msg, Exception ex
code = Protocol.ReasonCode.BAD_BLOCK;
break;
case NO_SUCH_MESSAGE:
case MESSAGE_WITH_WRONG_LENGTH:
code = Protocol.ReasonCode.NO_SUCH_MESSAGE;
break;
case BAD_MESSAGE:
code = Protocol.ReasonCode.BAD_PROTOCOL;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public String toString() {
sb.append(", end blockId: ").append(blockIdWeGet.peekLast().getString());
}
}
sb.append(", remain_num: ").append(chainInventory.getRemainNum());
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.tron.common.prometheus.MetricLabels;
import org.tron.common.prometheus.Metrics;
import org.tron.p2p.connection.Channel;
import org.tron.protos.Protocol.ReasonCode;

@Slf4j(topic = "net")
public class PeerManager {
Expand Down Expand Up @@ -48,6 +49,7 @@ public static void close() {
try {
for (PeerConnection p : new ArrayList<>(peers)) {
if (!p.isDisconnect()) {
p.disconnect(ReasonCode.PEER_QUITING);
p.getChannel().close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.tron.core.store.WitnessScheduleStore;
import org.tron.p2p.connection.Channel;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.ReasonCode;

@Slf4j(topic = "net")
@Component
Expand Down Expand Up @@ -184,6 +185,7 @@ private void disconnect() {
TronNetService.getP2pConfig().getActiveNodes().remove(address);
TronNetService.getPeers().forEach(peer -> {
if (peer.getInetAddress().equals(address.getAddress())) {
peer.disconnect(ReasonCode.NOT_WITNESS);
peer.getChannel().close();
}
});
Expand Down
2 changes: 2 additions & 0 deletions protocol/src/main/protos/core/Tron.proto
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ enum ReasonCode {
TOO_MANY_PEERS_WITH_SAME_IP = 0x22;
LIGHT_NODE_SYNC_FAIL = 0x23;
BELOW_THAN_ME = 0X24;
NOT_WITNESS = 0x25;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it compatible with older versions?

Copy link
Contributor Author

@317787106 317787106 Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the newly added unrecognized ReasonCode will be converted to ReasonCode UNKNOWN, and no exception will be thrown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It is recommended to make it more perfect, whether each of these merged cases defines a reason, and there are some unknown scenarios
    case NO_SUCH_MESSAGE:
    case MESSAGE_WITH_WRONG_LENGTH:
    case BAD_MESSAGE:
    code = Protocol.ReasonCode.BAD_PROTOCOL;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wubin01 there is no MESSAGE_WITH_WRONG_LENGTH really. But there is NO_SUCH_MESSAGE. Do you means add NO_SUCH_MESSAGE in Protocol.ReasonCode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added new ReasonCode NO_SUCH_MESSAGE in proto.

NO_SUCH_MESSAGE = 0x26;
UNKNOWN = 0xFF;
}

Expand Down