Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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 @@ -45,6 +46,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 @@ -182,6 +183,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
1 change: 1 addition & 0 deletions protocol/src/main/protos/core/Tron.proto
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ 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.

UNKNOWN = 0xFF;
}

Expand Down