Gram 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 16쪽 중 11쪽

t recipient on the path). In this way, some support for tunneling and proxyingsomewhat sim- ilar to that provided by the TOR or I 2P projectscan be added on the level of the TON Abstract Datagram Network Layer, without aecting the func- tionality of all higher-level TON network protocols, which would be agnostic of such an addition. This opportunity is exploited by the TON Proxy service (cf. 4.1.10 ). 3.1.7. Zero channel and the bootstrap problem. Normally, a TON ADNL node will have some neighbor table, containing information about other known nodes, such as their abstract addresses and their preimages (i.e., public keys) and their IP addresses and UDP ports. Then it will gradually extend this table by using information learned from these known nodes as answers to special queries, and sometimes prune obsolete records. However, when a TON ADNL node just starts up, it may happen that it does not know any other node, and can learn only the IP address and UDP port of a node, but not its abstract address. This happens, for example, if a light client is not able to access any of the previously cached nodes and any nodes hardcoded into the software, and must ask the user to enter an IP address or a DNS domain of a node, to be resolved through DNS. In this case, the node will send packets to a special zero channel of the node in question. This does not require knowledge of the recipient's public key (but the message should still contain the sender's identity and signature), so the message is transferred without encryption. It should be normally used only to obtain an identity (maybe a one-time identity created especially for this purpose) of the receiver, and then to start communicating in a safer way. Once at least one node is known, it is easy to populate the neighbor table and routing table by more entries, learning them from answers to 31 https://geti2p.net/en/docs/how/garlic-routing 83 3.2. TON DHT: Kademlia-like Distributed Hash Table special queries sent to the already known nodes. Not all nodes are required to process datagrams sent to the zero channel, but those used to bootstrap light clients should support this feature. 3.1.8. TCP-like stream protocol over ADNL. The ADNL, being an un- reliable (small-size) datagram protocol based on 256-bit abstract addresses, can be used as a base for more sophisticated network protocols. One can build, for example, a TCP-like stream protocol, using ADNL as an abstract replacement for IP. However, most components of the TON Project do not need such a stream protocol. 3.1.9. RLDP, or Reliable Large Datagram Protocol over ADNL. A reliable arbitrary-size datagram protocol built upon the ADNL, called RLDP, is used instead of a TCP-like protocol. This reliable datagram protocol can be employed, for instance, to send RPC queries to remote hosts and receive answers from them (cf. 4.1.5 ). 3.2 TON DHT: Kademlia-like Distributed Hash Table The TON Distributed Hash Table (DHT) plays a crucial role in the net- working part of the TON Project, being used to locate other nodes in the network. For example, a client wanting to commit a transaction into a shard- chain might want to nd a validator or a collator of that shardchain, or at least some node that might relay the client's transaction to a collator. This can be done by looking up a special key in the TON DHT. Another impor- tant application of the TON DHT is that it can be used to quickly populate a new node's neighbor table (cf. 3.1.7 ), simply by looking up a random key, or the new node's address. If a node uses proxying and tunneling for its in- bound datagrams, it publishes the tunnel identier and its entry point (e.g., IP address and UDP port) in the TON DHT; then all nodes wishing to send datagrams to that node will obtain this contact information from the DHT rst. The TON DHT is a member of the family of Kademlia-like distributed hash tables [10]. 3.2.1. Keys of the TON DHT. The keys of the TON DHT are simply 256- bit integers. In most cases, they are computed as sha256 of a TL-serialized object (cf. 2.2.5 ), called preimage of the key, or key description . In some cases, the abstract addresses of the TON Network nodes (cf. 3.1.1 ) can also 84 3.2. TON DHT: Kademlia-like Distributed Hash Table be used as keys of the TON DHT, because they are also 256-bit, and they are also hashes of TL-serialized objects. For example, if a node is not afraid of publishing its IP address, it can be found by anybody who knows its abstract address by simply looking up that address as a key in the DHT. 3.2.2. Values of the DHT. The values assigned to these 256-bit keys are essentially arbitrary byte strings of limited length. The interpretation of such byte strings is determined by the preimage of the corresponding key; it is usually known both by the node that looks up the key, and by the node that stores the key. 3.2.3. Nodes of the DHT. Semi-permanent network identities. The key-value mapping of the TON DHT is kept on the nodes of the DHT essentially, all members of the TON Network. To this end, any node of the TON Network (perhaps with the exception of some very light nodes), apart from any number of ephemeral and permanent abstract addresses described in 3.1.1 , has at least one semi-permanent address, which identies it as a member of the TON DHT. This semi-permanent or DHT address should not to be changed too often, otherwise other nodes would be unable to locate the keys they are looking for. If a node does not want to reveal its true identity, it generates a separate abstract address to be used only for the purpose of participating in the DHT. However, this abstract address must be public, because it will be associated with the node's IP address and port. 3.2.4. Kademlia distance. Now we have both 256-bit keys and 256-bit (semi-permanent) node addresses. We introduce the so-called XOR distance or Kademlia distance dK on the set of 256-bit sequences, given by dK(x,y ) := (x⊕y) interpreted as an unsigned 256-bit integer (25) Here x⊕y denotes the bitwise eXclusive OR (XOR) of two bit sequences of the same length. The Kademlia distance introduces a metric on the set 2256 of all 256-bit sequences. In particular, we have dK(x,y ) = 0 if and only if x =y, dK(x,y ) = dK(y,x ), and dK(x,z )≤dK(x,y ) +dK(y,z ). Another important property is that there is only one point at any given distance from x: dK(x,y ) =dK(x,y′) implies y =y′. 3.2.5. Kademlia-like DHTs and the TON DHT. We say that a dis- tributed hash table (DHT) with 256-bit keys and 256-bit node addresses is a 85 3.2. TON DHT: Kademlia-like Distributed Hash Table Kademlia-like DHT if it is expected to keep the value of key K on s Kademlia- nearest nodes to K (i.e., the s nodes with smallest Kademlia distance from their addresses to K.) Here s is a small parameter, say, s = 7, needed to improve reliability of the DHT (if we would keep the key only on one node, the nearest one to K, the value of that key would be lost if that only node goes oine). The TON DHT is a Kademlia-like DHT, according to this denition. It is implemented over the ADNL protocol described in 3.1 . 3.2.6. Kademlia routing table. Any node participating in a Kademlia- like DHT usually maintains a Kademlia routing table . In the case of TON DHT, it consists of n = 256 buckets, numbered from 0 to n− 1. The i-th bucket will contain information about some known nodes (a xed number t of best nodes, and maybe some extra candidates) that lie at a Kademlia distance from 2i to 2i+1− 1 from the node's address a. 32 This information includes their (semi-permanent) addresses, IP addresses and UDP ports, and some availability information such as the time and the delay of the last ping. When a Kademlia node learns about any other Kademlia node as a result of some query, it includes it into a suitable bucket of its routing table, rst as a candidate. Then, if some of the best nodes in that bucket fail (e.g., do not respond to ping queries for a long time), they can be replaced by some of the candidates. In this way the Kademlia routing table stays populated. New nodes from the Kademlia routing table are also included in the ADNL neighbor table described in 3.1.7 . If a best node from a bucket of the Kademlia routing table is used often, a channel in the sense described in 3.1.5 can be established to facilitate the encryption of datagrams. A special feature of the TON DHT is that it tries to select nodes with the smallest round-trip delays as the best nodes for the buckets of the Kademlia routing table. 3.2.7. (Kademlia network queries.) A Kademlia node usually supports the following network queries: ˆ Ping  Checks node availability. 32 If there are suciently many nodes in a bucket, it can be subdivided further into, say, eight sub-buckets depending on the top four bits of the Kademlia distance. This would speed up DHT lookups. 86 3.2. TON DHT: Kademlia-like Distributed Hash Table ˆ Store (key,value )  Asks the node to keep value as a value for key key. For TON DHT, the Store queries are slightly more complicated (cf. 3.2.9 ). ˆ Find_Node (key,l )  Asks the node to return l Kademlia-nearest known nodes (from its Kademlia routing table) to key. ˆ Find_V alue (key,l )  The same as above, but if the node knows the value corresponding to key key, it just returns that value. When any node wants to look up the value of a key K, it rst creates a set S of s′ nodes (for some small value of s′, say, s′ = 5 ), nearest to K with respect to the Kademlia distance among all known nodes (i.e., they are taken from the Kademlia routing table). Then a Find_V alue query is sent to each of them, and nodes mentioned in their answers are included in S. Then the s′ nodes from S, nearest to K, are also sent a Find_V alue query if this hasn't been done before, and the process continues until the value is found or the set S stops growing. This is a sort of beam search of the node nearest to K with respect to Kademlia distance. If the value of some key K is to be set, the same procedure is run for s′≥s, with Find_Node queries instead of Find_V alue , to nd s nearest nodes to K. Afterwards, Store queries are sent to all of them. There are some less important details in the implementation of a Kademlia- like DHT (for example, any node should look up s nearest nodes to itself, say, once every hour, and re-publish all stored keys to them by means of Store queries). We will ignore them for the time being. 3.2.8. Booting a Kademlia node. When a Kademlia node goes online, it rst populates its Kademlia routing table by looking up its own address. During this process, it identies the s nearest nodes to itself. It can download from them all (key,value ) pairs known to them to populate its part of the DHT. 3.2.9. Storing values in TON DHT. Storing values in TON DHT is slightly dierent from a general Kademlia-like DHT. When someone wishes to store a value, she must provide not only the key K itself to the Store query, but also its preimage i.e., a TL-serialized string (with one of several predened TL-constructors at the beginning) containing a description of the key. This key description is later kept by the node, along with the key and the value. 87 3.2. TON DHT: Kademlia-like Distributed Hash Table The key description describes the type of the object being stored, its owner, and its update rules in case of future updates. The owner is usually identied by a public key included in the key description. If it is included, normally only updates signed by the corresponding private key will be accepted. The type of the stored object is normally just a byte string. However, in some cases it can be more sophisticatedfor example, an input tunnel description (cf. 3.1.6 ), or a collection of node addresses. The update rules can also be dierent. In some cases, they simply permit replacing the old value with the new value, provided the new value is signed by the owner (the signature must be kept as part of the value, to be checked later by any other nodes after they obtain the value of this key). In other cases, the old value somehow aects the new value. For example, it can contain a sequence number, and the old value is overwritten only if the new sequence number is larger (to prevent replay attacks). 3.2.10. Distributed torrent trackers and network interest groups in TON DHT. Yet another interesting case is when the value contains a list of nodesperhaps with their IP addresses and ports, or just with their abstract addressesand the update rule consists in including the requester in this list, provided she can conrm her identity. This mechanism might be used to create a distributed torrent tracker, where all nodes interested in a certain torrent (i.e., a certain le) can nd other nodes that are interested in the same torrent, or already have a copy. TON Storage (cf. 4.1.7 ) uses this technology to nd the nodes that have a copy of a required le (e.g., a snapshot of the state of a shardchain, or an old block). However, its more important use is to create overlay multicast subnetworks and network interest groups (cf. 3.3 ). The idea is that only some nodes are interested in the updates of a specic shardchain. If the number of shardchains becomes very large, nding even one node interested in the same shard may become complicated. This distributed torrent tracker provides a convenient way to nd some of these nodes. Another option would be to request them from a validator, but this would not be a scalable approach, and validators might choose not to respond to such queries coming from arbitrary unknown nodes. 3.2.11. Fall-back keys. Most of the key types described so far have an extra 32-bit integer eld in their TL description, normally equal to zero. However, if the key obtained by hashing that description cannot be retrieved from or updated in the TON DHT, the value in this eld is increased, and 88 3.2. TON DHT: Kademlia-like Distributed Hash Table a new attempt is made. In this way, one cannot capture and censor a key (i.e., perform a key retention attack) by creating a lot of abstract addresses lying near the key under attack and controlling the corresponding DHT nodes. 3.2.12. Locating services. Some services, located in the TON Network and available through the (higher-level protocols built upon the) TON ADNL described in 3.1 , may want to publish their abstract addresses somewhere, so that their clients would know where to nd them. However, publishing the service's abstract address in the TON Blockchain may not be the best approach, because the abstract address might need to be changed quite often, and because it could make sense to provide several addresses, for reliability or load balancing purposes. An alternative is to publish a public key into the TON Blockchain, and use a special DHT key indicating that public key as its owner in the TL description string (cf. 2.2.5 ) to publish an up-to-date list of the service's abstract addresses. This is one of the approaches exploited by TON Services. 3.2.13. Locating owners of TON blockchain accounts. In most cases, owners of TON blockchain accounts would not like to be associated with abstract network addresses, and especially IP addresses, because this can violate their privacy. In some cases, however, the owner of a TON blockchain account may want to publish one or several abstract addresses where she could be contacted. A typical case is that of a node in the TON Payments lightning network (cf. 5.2 ), the platform for instant cryptocurrency transfers. A public TON Payments node may want not only to establish payment channels with other peers, but also to publish an abstract network address that could be used to contact it at a later time for transferring payments along the already- established channels. One option would be to include an abstract network address in the smart contract creating the payment channel. A more exible option is to include a public key in the smart contract, and then use DHT as explained in 3.2.12 . The most natural way would be to use the same private key that con- trols the account in the TON Blockchain to sign and publish updates in the TON DHT about the abstract addresses associated with that account. This is done almost in the same way as described in 3.2.12 ; however, the DHT key employed would require a special key description, containing only the 89 3.3. Overlay Networks and Multicasting Messages account_id itself, equal to sha256 of the account description, which con- tains the public key of the account. The signature, included in the value of this DHT key, would contain the account description as well. In this way, a mechanism for locating abstract network addresses of some owners of the TON Blockchain accounts becomes available. 3.2.14. Locating abstract addresses. Notice that the TON DHT, while being implemented over TON ADNL, is itself used by the TON ADNL for several purposes. The most important of them is to locate a node or its contact data starting from its 256-bit abstract address. This is necessary because the TON ADNL should be able to send datagrams to arbitrary 256-bit abstract addresses, even if no additional information is provided. To this end, the 256-bit abstract address is simply looked up as a key in the DHT. Either a node with this address (i.e., using this address as a public semi-persistent DHT address) is found, in which case its IP address and port can be learned; or, an input tunnel description may be retrieved as the value of the key in question, signed by the correct private key, in which case this tunnel description would be used to send ADNL datagrams to the intended recipient. Notice that in order to make an abstract address public (reachable from any nodes in the network), its owner must either use it as a semi-permanent DHT address, or publish (in the DHT key equal to the abstract address under consideration) an input tunnel description with another of its public abstract addresses (e.g., the semi-permanent address) as the tunnel's entry point. Another option would be to simply publish its IP address and UDP port. 3.3 Overlay Networks and Multicasting Messages In a multi-blockchain system like the TON Blockchain, even full nodes would normally be interested in obtaining updates (i.e., new blocks) only about some shardchains. To this end, a special overlay (sub)network must be built inside the TON Network, on top of the ADNL protocol discussed in 3.1 , one for each shardchain. Therefore, the need to build arbitrary overlay subnetworks, open to any nodes willing to participate, arises. Special gossip protocols, built upon ADNL, will be run in these overlay networks. In particular, these gossip 90 3.3. Overlay Networks and Multicasting Messages protocols may be used to propagate (broadcast) arbitrary data inside such a subnetwork. 3.3.1. Overlay networks. An overlay (sub)network is simply a (virtual) network implemented inside some larger network. Usually only some nodes of the larger network participate in the overlay subnetwork, and only some links between these nodes, physical or virtual, are part of the overlay sub- network. In this way, if the encompassing network is represented as a graph (per- haps a full graph in the case of a datagram network such as ADNL, where any node can easily communicate to any other), the overlay subnetwork is a subgraph of this graph. In most cases, the overlay network is implemented using some protocol built upon the network protocol of the larger network. It may use the same addresses as the larger network, or use custom addresses. 3.3.2. Overlay networks in TON. Overlay networks in TON are built upon the ADNL protocol discussed in 3.1 ; they use 256-bit ADNL abstract addresses as addresses in the overlay networks as well. Each node usually selects one of its abstract addresses to double as its address in the overlay network. In contras
프로젝트로 돌아가기