Gram 백서

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

ploys (once the local IP address and the TCP port of the proxy are entered into the browser's conguration), and forwards these queries through the TON Network to the abstract address of the service. Then the user would have a browsing experience similar to that of the World Wide Web (WWW). In the I 2P ecosystem, such eep-services are called eep-sites. One can easily create ton-sites in the TON ecosystem as well. This is facilitated somewhat by the existence of services such as the TON DNS, which exploit the TON Blockchain and the TON DHT to translate (TON) domain names into abstract addresses. 4.1.6. Mixed services: partly o-chain, partly on-chain. Some ser- vices might use a mixed approach: do most of the processing o-chain, but also have some on-chain part (for example, to register their obligations to- wards their users, and vice versa). In this way, part of the state would still be kept in the TON Blockchain (i.e., an immutable public ledger), and any misbehavior of the service or of its users could be punished by smart con- tracts. 4.1.7. Example: keeping les o-chain; TON Storage. An example of such a service is given by TON Storage . In its simplest form, it allows users to store les o-chain, by keeping on-chain only a hash of the le to be stored, and possibly a smart contract where some other parties agree to keep the le in question for a given period of time for a pre-negotiated fee. In fact, the le may be subdivided into chunks of some small size (e.g., 1 kilobyte), augmented by an erasure code such as a ReedSolomon or a fountain code, a 100 4.1. TON Ser vice Implementation Strategies Merkle tree hash may be constructed for the augmented sequence of chunks, and this Merkle tree hash might be published in the smart contract instead of or along with the usual hash of the le. This is somewhat reminiscent of the way les are stored in a torrent. An even simpler form of storing les is completely o-chain: one might es- sentially create a torrent for a new le, and use TON DHT as a distributed torrent tracker for this torrent (cf. 3.2.10 ). This might actually work pretty well for popular les. However, one does not get any availability guarantees. For example, a hypothetical blockchain Facebook (cf. 2.9.13 ), which would opt to keep the prole photographs of its users completely o-chain in such torrents, might risk losing photographs of ordinary (not especially popular) users, or at least risk being unable to present these photographs for prolonged periods. The TON Storage technology, which is mostly o-chain, but uses an on-chain smart contract to enforce availability of the stored les, might be a better match for this task. 4.1.8. Decentralized mixed services, or fog services. So far, we have discussed centralized mixed services and applications. While their on-chain component is processed in a decentralized and distributed fashion, being located in the blockchain, their o-chain component relies on some servers controlled by the service provider in the usual centralized fashion. Instead of using some dedicated servers, computing power might be rented from a cloud computing service oered by one of the large companies. However, this would not lead to decentralization of the o-chain component of the service. A decentralized approach to implementing the o-chain component of a service consists in creating a market , where anybody possessing the required hardware and willing to rent their computing power or disk space would oer their services to those needing them. For example, there might exist a registry (which might also be called a market or an exchange) where all nodes interested in keeping les of other users publish their contact information, along with their available storage capacity, availability policy, and prices. Those needing these services might look them up there, and, if the other party agrees, create smart contracts in the blockchain and upload les for o-chain storage. In this way a service like TON Storage becomes truly decentralized, because it does not need to rely on any centralized cluster of servers for storing les. 4.1.9. Example: fog computing platforms as decentralized mixed services. Another example of such a decentralized mixed application arises 101 4.2. Connecting Users and Ser vice Providers when one wants to perform some specic computations (e.g., 3D rendering or training neural networks), often requiring specic and expensive hardware. Then those having such equipment might oer their services through a similar exchange, and those needing such services would rent them, with the obli- gations of the sides registered by means of smart contracts. This is similar to what fog computing platforms, such as Golem ( https://golem.network/ ) or SONM ( https://sonm.io/ ), promise to deliver. 4.1.10. Example: TON Proxy is a fog service. TON Proxy provides yet another example of a fog service, where nodes wishing to oer their services (with or without compensation) as tunnels for ADNL network trac might register, and those needing them might choose one of these nodes depending on the price, latency and bandwidth oered. Afterwards, one might use payment channels provided by TON Payments for processing micropayments for the services of those proxies, with payments collected, for instance, for every 128 KiB transferred. 4.1.11. Example: TON Payments is a fog service. The TON Payments platform (cf. 5 ) is also an example of such a decentralized mixed application. 4.2 Connecting Users and Service Providers We have seen in 4.1.8 that fog services (i.e., mixed decentralized services) will usually need some markets , exchanges or registries , where those needing specic services might meet those providing them. Such markets are likely to be implemented as on-chain, o-chain or mixed services themselves, centralized or distributed. 4.2.1. Example: connecting to TON Payments. For example, if one wants to use TON Payments (cf. 5 ), the rst step would be to nd at least some existing transit nodes of the lightning network (cf. 5.2 ), and establish payment channels with them, if they are willing. Some nodes can be found with the aid of the encompassing overlay network, which is supposed to contain all transit lightning network nodes (cf. 3.3.17 ). However, it is not clear whether these nodes will be willing to create new payment channels. Therefore, a registry is needed where nodes ready to create new links can publish their contact information (e.g., their abstract addresses). 4.2.2. Example: uploading a le into TON Storage. Similarly, if one wants to upload a le into the TON Storage, she must locate some nodes 102 4.3. Accessing TON Ser vices willing to sign a smart contract binding them to keep a copy of that le (or of any le below a certain size limit, for that matter). Therefore, a registry of nodes oering their services for storing les is needed. 4.2.3. On-chain, mixed and o-chain registries. Such a registry of service providers might be implemented completely on-chain, with the aid of a smart contract which would keep the registry in its permanent storage. However, this would be quite slow and expensive. A mixed approach is more ecient, where the relatively small and rarely changed on-chain registry is used only to point out some nodes (by their abstract addresses, or by their public keys, which can be used to locate actual abstract addresses as described in 3.2.12 ), which provide o-chain (centralized) registry services. Finally, a decentralized, purely o-chain approach might consist of a public overlay network (cf. 3.3 ), where those willing to oer their services, or those looking to buy somebody's services, simply broadcast their oers, signed by their private keys. If the service to be provided is very simple, even broadcasting the oers might be not necessary: the approximate membership of the overlay network itself might be used as a registry of those willing to provide a particular service. Then a client requiring this service might lo- cate (cf. 3.3.7 ) and query some nodes of this overlay network, and then query their neighbors, if the nodes already known are not ready to satisfy its needs. 4.2.4. Registry or exchange in a side-chain. Another approach to im- plementing decentralized mixed registries consists in creating an indepen- dent specialized blockchain (side-chain), maintained by its own set of self- proclaimed validators, who publish their identities in an on-chain smart con- tract and provide network access to all interested parties to this specialized blockchain, collecting transaction candidates and broadcasting block updates through dedicated overlay networks (cf. 3.3 ). Then any full node for this sidechain can maintain its own copy of the shared registry (essentially equal to the global state of this side-chain), and process arbitrary queries related to this registry. 4.2.5. Registry or exchange in a workchain. Another option is to create a dedicated workchain inside the TON Blockchain, specialized for creating registries, markets and exchanges. This might be more ecient and less expensive than using smart contracts residing in the basic workchain (cf. 2.1.11 ). However, this would still be more expensive than maintaining registries in side-chains (cf. 4.2.4 ). 103 4.3. Accessing TON Ser vices 4.3 Accessing TON Services We have discussed in 4.1 the dierent approaches one might employ for creating new services and applications residing in the TON ecosystem. Now we discuss how these services might be accessed, and some of the helper services that will be provided by TON, including TON DNS and TON Storage . 4.3.1. TON DNS: a mostly on-chain hierarchical domain name ser- vice. The TON DNS is a predened service, which uses a collection of smart contracts to keep a map from human-readable domain names to (256-bit) ad- dresses of ADNL network nodes and TON Blockchain accounts and smart contracts. While anybody might in principle implement such a service using the TON Blockchain, it is useful to have such a predened service with a well- known interface, to be used by default whenever an application or a service wants to translate human-readable identiers into addresses. 4.3.2. TON DNS use cases. For example, a user looking to transfer some cryptocurrency to another user or to a merchant may prefer to remember a TON DNS domain name of the account of that user or merchant, instead of keeping their 256-bit account identiers at hand and copy-pasting them into the recipient eld in their light wallet client. Similarly, TON DNS may be used to locate account identiers of smart contracts or entry points of ton-services and ton-sites (cf. 4.1.5 ), enabling a specialized client (ton-browser), or a usual internet browser combined with a specialized ton-proxy extension or stand-alone application, to deliver a WWW-like browsing experience to the user. 4.3.3. TON DNS smart contracts. The TON DNS is implemented by means of a tree of special (DNS) smart contracts. Each DNS smart contract is responsible for registering subdomains of some xed domain. The root DNS smart contract, where level one domains of the TON DNS system will be kept, is located in the masterchain. Its account identier must be hardcoded into all software that wishes to access the TON DNS database directly. Any DNS smart contract contains a hashmap, mapping variable-length null-terminated UTF-8 strings into their values. This hashmap is imple- mented as a binary Patricia tree, similar to that described in 2.3.7 but supporting variable-length bitstrings as keys. 104 4.3. Accessing TON Ser vices 4.3.4. Values of the DNS hashmap, or TON DNS records. As to the values, they are TON DNS records described by a TL-scheme (cf. 2.2.5 ). They consist of a magic number, selecting one of the options supported, and then either an account identier, or a smart-contract identier, or an abstract network address (cf. 3.1 ), or a public key used to locate abstract addresses of a service (cf. 3.2.12 ), or a description of an overlay network, and so on. An important case is that of another DNS smart contract: in such a case, that smart contract is used to resolve subdomains of its domain. In this way, one can create separate registries for dierent domains, controlled by the owners of those domains. These records may also contain an expiration time, a caching time (usu- ally very large, because updating values in a blockchain too often is expen- sive), and in most cases a reference to the owner of the subdomain in question. The owner has the right to change this record (in particular, the owner eld, thus transferring the domain to somebody else's control), and to prolong it. 4.3.5. Registering new subdomains of existing domains. In order to register a new subdomain of an existing domain, one simply sends a message to the smart contract, which is the registrar of that domain, containing the subdomain (i.e., the key) to be registered, the value in one of several prede- ned formats, an identity of the owner, an expiration date, and some amount of cryptocurrency as determined by the domain's owner. Subdomains are registered on a rst-come, rst-served basis. 4.3.6. Retrieving data from a DNS smart contract. In principle, any full node for the masterchain or shardchain containing a DNS smart contract might be able to look up any subdomain in the database of that smart contract, if the structure and the location of the hashmap inside the persistent storage of the smart contract are known. However, this approach would work only for certain DNS smart contracts. It would fail miserably if a non-standard DNS smart contract were used. Instead, an approach based on general smart contract interfaces and get methods (cf. 4.3.11 ) is used. Any DNS smart contract must dene a get method with a known signature, which is invoked to look up a key. Since this approach makes sense for other smart contracts as well, especially those providing on-chain and mixed services, we explain it in some detail in 4.3.11 . 4.3.7. Translating a TON DNS domain. Once any full node, acting by itself or on behalf of some light client, can look up entries in the database 105 4.3. Accessing TON Ser vices of any DNS smart contract, arbitrary TON DNS domain names can be re- cursively translated, starting from the well-known and xed root DNS smart contract (account) identier. For example, if one wants to translate A.B.C , one looks up keys .C , .B.C , and A.B.C in the root domain database. If the rst of them is not found, but the second is, and its value is a reference to another DNS smart contract, then A is looked up in the database of that smart contract and the nal value is retrieved. 4.3.8. Translating TON DNS domains for light nodes. In this way, a full node for the masterchainand also for all shardchains involved in the domain look-up processmight translate any domain name into its current value without external help. A light node might request a full node to do this on its behalf and return the value, along with a Merkle proof (cf. 2.5.11 ). This Merkle proof would enable the light node to verify that the answer is correct, so such TON DNS responses cannot be spoofed by a malicious interceptor, in contrast to the usual DNS protocol. Because no node can be expected to be a full node with respect to all shardchains, actual TON DNS domain translation would involve a combina- tion of these two strategies. 4.3.9. Dedicated TON DNS servers. One might provide a simple TON DNS server, which would receive RPC DNS queries (e.g., via the ADNL or RLDP protocols described in 3.1 ), requesting that the server trans- late a given domain, process these queries by forwarding some subqueries to other (full) nodes if necessary, and return answers to the original queries, augmented by Merkle proofs if required. Such DNS servers might oer their services (for free or not) to any other nodes and especially light clients, using one of the methods described in 4.2 . Notice that these servers, if considered part of the TON DNS service, would eectively transform it from a distributed on-chain service into a distributed mixed service (i.e., a fog service). This concludes our brief overview of the TON DNS service, a scalable on-chain registry for human-readable domain names of TON Blockchain and TON Network entities. 4.3.10. Accessing data kept in smart contracts. We have already seen that it is sometimes necessary to access data stored in a smart contract without changing its state. 106 4.3. Accessing TON Ser vices If one knows the details of the smart-contract implementation, one can extract all the needed information from the smart contract's persistent stor- age, available to all full nodes of the shardchain the smart contract resides in. However, this is quite an inelegant way of doing things, depending very much on the smart-contract implementation. 4.3.11. Get methods of smart contracts. A better way would be to dene some get methods in the smart contract, that is, some types of inbound messages that do not aect the state of the smart contract when delivered, but generate one or more output messages containing the result of the get method. In this way, one can obtain data from a smart contract, knowing only that it implements a get method with a known signature (i.e., a known format of the inbound message to be sent and outbound messages to be received as a result). This way is much more elegant and in line with object oriented program- ming (OOP). However, it has an obvious defect so far: one must actually commit a transaction into the blockchain (sending the get message to the smart contract), wait until it is committed and processed by the validators, extract the answer from a new block, and pay for gas (i.e., for executing the get method on the validators' hardware). This is a waste of resources: get methods do not change the state of the smart contract anyways, so they need not be executed in the blockchain. 4.3.12. Tentative execution of get methods of smart contracts. We have already remarked (cf. 2.4.6 ) that any full node can tentatively exe- cute any method of any smart contract (i.e., deliver any message to a smart contract), starting from a given state of the smart contract, without actually committing the corresponding transaction. The full node can simply load the code of the smart contract under consideration into the TON VM, initialize its persistent storage from the global state of the shardchain (known to all full nodes of the shardchain), and execute the smart-contract code with the inbound message as its input parameter. The output messages created will yield the result of this computation. In this way, any full node can evaluate arbitrary get methods of arbitrary smart contracts, provided their signature (i.e., the format of inbound and outbound messages) is known. The node may keep track of the cells of the shardchain state accessed during this evaluation, and create a Merkle proof of the validity of the computation performed, for the benet of a light node that might have asked the full node to do so (cf. 2.5.11 ). 107 4.3. Accessing TON Ser vices 4.3.13. Smart-contract interfaces in TL-schemes. Recall that the methods implemented by a smart contract (i.e., the input messages accepted by it) are essentially some TL-serialized objects, which can be described by a TL-scheme (cf. 2.2.5 ). The resulting output messages can be described by the same TL-scheme as well. In this way, the interface provided by a smart contract to other accounts and smart contracts may be formalized by means of a TL-scheme. In particular, (a subset of) get methods supported by a smart contract can be described by such a formalized smart-contract interface. 4.3.14. Public interfaces of a smart contract. Notice that a formalized smart-contract interface, either in form of a TL-scheme (rep
프로젝트로 돌아가기