Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

1 Communication

1.1 Introduction

Commmunication module exposes three main abstraction:

  1. Transport Layer - implemented using gRPC
  2. Node discovery - implemented using specic version of Kademlia.
  3. RChain protocol - implemented in Connect.scala

1.2 Ideal world

In ideal world: Transport Layer has zero dependecies. It provides abstracton to send any (serializable) messages between two nodes.

Node Discovery is depended on Transport Layer. It will use Transport Layer to send messages, providing constant discovery of nodes in P2P network. It will expose two functionalities: addMe (to add given node to the network) and listPeers (to list peers [neighbours] that Node Discovery knows at the given moment). This abstraction does not know anything about RChain yet. It just gives an abstraction of a P2P network - allowing external entities (like for example RChain protocol) learn about neighbouring nodes.

RChain Protocol depends on both Transport Layer and Node Discovery. It uses NodeDiscovery.listPeers in order to learn about neighbouring nodes. It uses Transport Layer to send messages to those nodes.  It exposes concept of a "connection" (exchange of ProtocolHandshake-ProtocolHandshake response) and ability to send messages of type Packet between nodes. RChain Protocol allows to send Packet messages only to nodes who previously went through the protocol handshake.

Diagram below shows dependency usage between all three abstractions in the ideal world


+-------------------------+
|                         |
|  RChain Protocol        |
|                         |
+-------------------------+
       |           | uses
       |uses       v
       |
       |     +-----------+
       |     |           |
       |     | Node      |
       |     | Discovery |
       |     |           |
       |     +-----------+
       |            |
       v            v  uses

   +--------------------+
   |  Transport Layer   |
   +--------------------+


That's the dream. Reality is...

1.3 Reality

Reality is that Transport Layer, Node Discovery and RChain Protocol have circular dependencies. Some of those dependencies we could live with for now (just add overall complexity to the design), some are potential cause of weird bugs and security issues (and should be considered as high priority issues).

Diagram below illustrates those dependencies


              uses messages     +-----------+
         +----------------------+ Transport | <---------------+
         |                      | Layer     |                 |
         |                      +-----------+                 | use to send
         |     +----------------------^                       | messages
         |     |    uses to send messages                     |
         v     |                                              |
               |                                              |
+-----------------+          uses findPeers                   |
|                 | <----------------------------------------------------+
| Node Discovery  |                                       |   Rchain     |
|                 |                                       |   Protocol   |
+-----------------+                                       +--------------+
             +------------------------------------------------^
                            peers only added by rchan protocol


Cycle: Node Discovery ← → Transport Layer

This cycle has lower priority. It is not crucial to fix it right away. Details in CORE-836 and CORE-839.

Cycle: Node Discovery ← → RChain protocol

This cycle has high priority and should be addressed ASAP. Details in CORE-770.


1.4 Detailed description of abstractions

Below detailed description of how the abstractions are currently implemented and what are the issues that have to be addressed.


1.4.1 Transport Layer

Transport Layer abstracts the communication pipeline, allowing two nodes sending messages between each other. Transport Layer is neither aware of Node Discovery nor RChain protocol. Current implementation TcpTransportLayer is missing integration tests, minimum set of missing tests are defined under CORE-607.

Transport Layer exposes following functions:

trait TransportLayer[F[_]] {
  def local: F[PeerNode]
  def roundTrip(peer: PeerNode, msg: Protocol, timeout: FiniteDuration): F[CommErr[Protocol]]
  def send(peer: PeerNode, msg: Protocol): F[Unit]
  def broadcast(peers: Seq[PeerNode], msg: Protocol): F[Unit]
  def receive(dispatch: Protocol => F[CommunicationResponse]): F[Unit]
  def disconnect(peer: PeerNode): F[Unit]
  def shutdown(msg: Protocol): F[Unit]
}
  1. local

    Method local returns PeerNode representing given running node. This method should be removed and PeerNode information should be provided via `ApplicativeAsk` abstraction (see CORE-738 and CORE739 for detail).

  2. disconnect

    Method disconnect should never be part of TransportLayer abstraction. It is TcpTransportLayer implementation detail. It will be removed from the abstraction (see CORE-835 for details).

  3. shutdown

    Shutdown method gracefully shuts down the Transport Layer. After being called, no message can be send (via roundTrip, send, broadcast) nor received.

  4. roundTrip, send, broadcast

    Methods roundTrip and send allow sending and receiving messages of type Protocol - object defined in routing.proto. Protocol message can be one of the following:

    message Protocol {
        Header header                           = 1;
    
        oneof message {
            google.protobuf.Any upstream        = 2;
    
            Ping                ping            = 3;
            Pong                pong            = 4;
            Lookup              lookup          = 5;
            LookupResponse      lookup_response = 6;
            Disconnect          disconnect      = 7;
        }
    }
    
    1. Ping, Pong, Loookup, LookupResponse

      Ping+Pong and Lookup+LookupResponse are part of the Node Discovery abstraction, so there is clear coupeling between those two abstraction. More details in CORE-836.

    2. Disconnect

      Disconnect is currently send by TcpTransportLayer when it shuts down (Disconnect is being broadcast). This method is NOT needed as nodes should realize that other peers disconnect regardlessly if they managed to shut down gracefully or not. This message will be removed from the Protocol object (see CORE-838 for details).

    3. Any upstream

      This is a placeholder for ANY possible message that is build on top Protocol. Effectively this is where messages from RChain protocol will be placed. Originally was designed to decouple TransportLayer, NodeDiscovery and RChain protocol (not successfully). This coupeling should be removed, see CORE-839 for details.


1.4.2 Node Discovery


Below we describe how Node Discovery works currently

  1. Relation to Transport Layer

    Node discovery is using Tranport Layer to fullfil its work. It uses

    +----------------+
    |                |
    | NODE DISCOVERY |
    |                |
    +----------------+
            |
            v uses
    
    +----------------+
    |   TRANSPORT    |
    |   LAYER        |
    +----------------+
    

    This is almost true, as mentioned in previous section, TransportLayer sends messages of type Protocol (routing.proto) that are very Kademlia specific. See CORE-838 and CORE-839 to see the issue how to remove that cyclic dependency between Node Discovery and Transport Layer.


    2. How current Kademlia implementation is different from the original paper

TBD


    3. Kademlia in etherum

       Etherum also uses its own Kademlia-like protocol. Description under https://github.com/ethereum/wiki/wiki/Kademlia-Peer-Selection

1.4.3 RChain protocol

 RChain protocol messages are defined in p2p.proto and are the following:

message Protocol {
    oneof message {
        Disconnect                  diconnect                     = 1;
        Hello                       hello                         = 2;
        ProtocolHandshake           protocol_handshake            = 3;
        ProtocolHandshakeResponse   protocol_handshake_response   = 4;
        Packet                      packet                        = 5;
    }
}

Messages Hello and Disconnect are not used in the RChain protocol (even though defined) and will be removed from it (see CORE-840 for details).

RChain Protocol exposes few functionalities:

  1. Connect to bootstrap - feature that allows given node to connect to given bootstrap
  2. findAndConnect - feature that constantly triggers NodeDiscovery to look for new nodes and runs for them connection protocol
  3. Ability to send messegae of type Packet to nodes that exchanged the protocol handshake (went through the connection) 


List of issues mentioned in this document


key summary type created updated due assignee reporter priority status resolution
Loading...
Refresh

  • No labels