Digital Currency News >TON > TON DHT service implementation overview

Related Articles

ViewTONAll Articles
0
TON
0
Step 1: Enter the TON/USDT spot trading page
0
Step 2: Enter the order unit and quantity, then click Buy/Sell

TON DHT service implementation overview

2024-08-28 19:33:18

In the decentralized network, the TON (The Open Network) project utilizes a Kademlia-like decentralized hash table (DHT) to implement the core functions of its network. This technology not only helps locate other nodes in the network, but also improves overall reliability and efficiency. This article will take an in-depth look at how TON DHT works, its key features, and its applications.


Basic structure of DHT

TON DHT uses 256-bit integers as keys, which are usually calculated by SHA256 on TL serialized objects. The corresponding value (Value) is a byte string of any length, and its specific meaning is determined by the preimage of the corresponding key. This means that the node that queries the key and the node that stores the key generally know the interpretation of these byte strings.

In the simplest case, the key can represent a node's ADNL address, and the value can be its IP address and port number. Such key-value mapping is stored on the DHT node, allowing nodes in the network to query it easily.


DHT node characteristics

Each DHT node has a 256-bit DHT address. Unlike ADNL addresses, DHT addresses should not change frequently, otherwise other nodes will not be able to locate the required keys. By design, the value of key K should be stored on the K closest Kademlia nodes, and this number is usually represented by a small parameter S, such as S=7. This design is to improve the reliability of DHT, because if the key is only stored on one node, the corresponding value will be lost when the node goes offline.

Kademlia routing table: Any node participating in a DHT typically maintains a Kademlia routing table. This routing table consists of 256 buckets, numbered from 0 to 255. The i-th bucket will contain information about some known nodes whose Kademlia distance is between 2^i and 2^(i+1) − 1. This information includes the DHT address, IP address, UDP port, and some availability information such as the time and latency of the last ping.

When a Kademlia node learns about another Kademlia node through a query, it places that node into the corresponding bucket in the routing table, first as a candidate node. If some of the "best" nodes fail in that bucket (e.g., do not respond to ping queries for a long time), they can be replaced with these candidate nodes. This way, the Kademlia routing table remains active at all times.


Adding and updating key-value pairs

In TON DHT, key-value pairs can be added and updated. Updated rules may vary. In some cases, they only allow replacing an old value with a new value, provided that the new value must be signed by the owner or creator (the signature must be retained as part of the value, so that other nodes can check it after getting the value for that key) . In other cases, the old value affects the new value in some way. For example, the old value can contain a sequence number and will only be overwritten if the new sequence number is greater (to prevent replay attacks).

TON DHT is not only used to store the IP addresses of ADNL nodes, but is also used for many other purposes. This makes DHT an indispensable part of the TON network, supporting its decentralized features and efficient data access.


Application scenarios of TON DHT

TON DHT has a wide range of application scenarios. It can not only be used for communication between nodes, but also for storing user data, status information of smart contracts, and other data required by decentralized applications. Due to its efficient query method and reliable data storage, TON DHT has become the cornerstone of many decentralized applications.

For example, in decentralized finance (DeFi) applications, TON DHT can be used to store transaction records and user asset information to ensure the security and availability of these data. In addition, TON DHT can also be used on decentralized social media platforms to help users store and share content and ensure data privacy.


in conclusion

In short, the implementation of TON DHT service is an important part of the decentralized network. It leverages Kademlia's decentralized hash table technology to provide an efficient and reliable way to store and query data. With the popularity of decentralized applications, TON DHT will play an increasingly important role in the future digital ecosystem. This not only improves the performance of the TON network, but also brings a better experience to users.

In the future, we can look forward to further development of TON DHT services and explore its application potential in more fields.

Disclaimer:

1. The information does not constitute investment advice, and investors should make independent decisions and bear the risks themselves

2. The copyright of this article belongs to the original author, and it only represents the author's own views, not the views or positions of HiBT