-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Rationale
Java-tron nodes send DisconnectMessage to peers before closing the connection. The nodes use relatedReasonCode if it exists as DisconnectMessage, otherwise, no message would be sent. Most of the java-tron logs record the ReasonCode of peer disconnection, but some do not.
Missing scene
- The reason for disconnection with non-witness nodes in RelayService is not given.
- When node shutdowns, it doesn't tell other peers the reason.
We summarize the use of ReasonCode, many of which have been abandoned:
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; //Not used
UNEXPECTED_IDENTITY = 0x09; //Empty Block Hash
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;
}
Implementation
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
...
UNKNOWN = 0xFF;
}
Give ReasonCode before disconnect
Use ReasonCode NOT_WITNESS in RelayService.java :

Use ReasonCode NOT_WITNESS in PeerManager.java :

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