Skip to content
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

TIP-592: Supplement Disconnect Reasons in Java-tron #592

Closed
317787106 opened this issue Sep 13, 2023 · 1 comment · Fixed by tronprotocol/java-tron#5392
Closed

TIP-592: Supplement Disconnect Reasons in Java-tron #592

317787106 opened this issue Sep 13, 2023 · 1 comment · Fixed by tronprotocol/java-tron#5392

Comments

@317787106
Copy link
Contributor

317787106 commented Sep 13, 2023

TIP: 592
Title: Supplement Disconnect Reasons in Java-tron
Author: [email protected]
Status: Draft
Type: Standards Track
Category: Networking
Created: 2023-09-13

Simple Summary

This TIP describes why and how we supplement disconnect reasons in java-tron.

Abstract

We supplement two disconnect reasons in java-tron, including NOT_WITNESS used inRelayService and NO_SUCH_MESSAGE in P2pEventHandlerImpl, so other peers can acquire the reason why we disconnect with it better.

Motivation

Java-tron nodes send DisconnectMessage to peers before stopping the connection. When stopping, the nodes use relatedReasonCode if it exists as DisconnectMessage, otherwise, no message would be sent. Most java-tron logs record the ReasonCode of peer disconnection, but some do not. For example, the reason for disconnection with non-witness nodes in RelayService is not given.

Specification

Unused ReasonCode

We summarize the use of ReasonCode, many of which have been abandoned and some are moved to libp2p, they may get deleted in the future:

    enum ReasonCode {
      REQUESTED = 0x00;             //Not used
      BAD_PROTOCOL = 0x02;         
      TOO_MANY_PEERS = 0x04;        //Not used
      DUPLICATE_PEER = 0x05;       
      INCOMPATIBLE_PROTOCOL = 0x06; //Not used
      RANDOM_ELIMINATION = 0x07;    //Not used
      PEER_QUITING = 0x08;          
      UNEXPECTED_IDENTITY = 0x09;   
      LOCAL_IDENTITY = 0x0A;        //Not used
      PING_TIMEOUT = 0x0B;          //Not used
      USER_REASON = 0x10;           //Not used
      RESET = 0x11;                 //Not used
      SYNC_FAIL = 0x12;
      FETCH_FAIL = 0x13;
      BAD_TX = 0x14;
      BAD_BLOCK = 0x15;
      FORKED = 0x16;
      UNLINKABLE = 0x17;
      INCOMPATIBLE_VERSION = 0x18;
      INCOMPATIBLE_CHAIN = 0x19;
      TIME_OUT = 0x20;
      CONNECT_FAIL = 0x21;                //Not used
      TOO_MANY_PEERS_WITH_SAME_IP = 0x22; //Not used
      LIGHT_NODE_SYNC_FAIL = 0x23;   
      BELOW_THAN_ME = 0X24;
      UNKNOWN = 0xFF;
    }

    message DisconnectMessage {
      ReasonCode reason = 1;
    }

Add new types to Java-tron ReasonCode

Add the following enumeration type to protos/core/Tron.proto

enum ReasonCode {
  REQUESTED = 0x00;         
  ...
  NOT_WITNESS = 0x25; //Added
  NO_SUCH_MESSAGE = 0x26; //Added
  ...
  UNKNOWN = 0xFF;
}

So, we can use this ReasonCode here, such as in RelayService.java :
image

Send ReasonCode to peer before node quits

Any node should notify peers of the reason when it quits, so others can understand the network better:

public static void close() {
  ...
    for (PeerConnection p : new ArrayList<>(peers)) {
      if (!p.isDisconnect()) {
        p.disconnect(ReasonCode.PEER_QUITING); //added
        p.getChannel().close();
      }
    }
  ...
}

Compatibility

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

@317787106 317787106 changed the title Supplement Disconnect Reasons in Java-tron TIP-592: Supplement Disconnect Reasons in Java-tron Sep 13, 2023
@317787106
Copy link
Contributor Author

Already discussed in tronprotocol/java-tron#5372.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant