THORChain 백서

THORChain

원문

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

zed witness transaction format that THORChain can process, regardless of the source chain's architecture. ![Bifrost Protocol Architecture](https://3337783180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfvaTNxU33ciP7UstKtwU%2Fuploads%2Fgit-blob-a68a042b46158086bee30830741768b57e19f458%2Fimage%20\(6\).png?alt=media) {% hint style="info" %} For complete technical specifications including transaction structures, chain clients, and integration details, see the [Bifrost Developer Documentation](https://dev.thorchain.org/bifrost/how-bifrost-works.html). {% endhint %} ## Vault System Architecture THORChain uses a sophisticated two-layer vault system designed for security and scalability: ### Two-Layer Vault Design 1. Logical Vaults - Represent a bonded set of validator nodes 2. Physical Vaults - Sharded instances of logical vaults for operational efficiency All vaults use Threshold Signature Scheme (TSS) for distributed control, requiring a supermajority of nodes to sign transactions. This eliminates single points of failure while maintaining operational efficiency. ### Vault Sharding To support network scaling, THORChain automatically shards vaults based on the `asgardsize` parameter (default: 20 nodes per shard). With 120 active nodes, the system will operate 6 physical vault shards, each controlled by a subset of validators. ### Vault Selection The protocol dynamically selects which vault receives inbound transactions based on the highest bond-to-asset ratio, ensuring funds are always directed to the most secure vault. This selection rotates automatically as vault compositions change. ![THORChain State Machine](https://3337783180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfvaTNxU33ciP7UstKtwU%2Fuploads%2Fgit-blob-dd5dc4fe320e714dd62852bbdf88b488302298e1%2Fimage%20\(7\).png?alt=media) {% hint style="info" %} For detailed vault behaviors, sharding logic, and security mechanisms, see the [Vault Behaviors Documentation](https://dev.thorchain.org/bifrost/vault-behaviors.html). {% endhint %} ## Vault Lifecycle Vaults progress through a defined lifecycle: 1. InitVault - Newly created vault, not yet active 2. Active - Processing inbound and outbound transactions 3. Retiring - Migrating funds to new vaults, no new inbound transactions 4. Inactive - Empty vault, eventually pruned from state ## Migration Process Vault migration ensures continuous operation during validator set changes: * Occurs automatically during churn cycles when validator sets change * Prioritizes non-gas assets for migration efficiency * Executes across multiple rounds to prevent congestion * Maintains service availability throughout the process ### Security During Migration When vaults retire, the newest vault immediately becomes active for receiving funds. The retiring vault continues to be monitored until migration completes, after which it becomes inactive. {% hint style="danger" %} Never send funds to a retired vault address. Once migration completes and the vault becomes inactive, any funds sent to that address are permanently lost and cannot be recovered. {% endhint %} ## Threshold Signature Scheme (TSS) TSS enables distributed control of vault assets without any single party having complete access: * No Single Point of Failure - No complete private keys exist * Threshold Security - Requires supermajority participation * Chain Agnostic - Works across all supported blockchains * Efficient Operations - Enables fast transaction signing ![TSS Signing Process](https://3337783180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfvaTNxU33ciP7UstKtwU%2Fuploads%2Fgit-blob-81076f1c6554b39afadc865520a95d80739ca669%2Fimage%20\(10\).png?alt=media) # Midgard What is Midgard in the THORChain tech stack Midgard is a layer 2 REST API that provides front-end consumers with semi real-time rolled up data and analytics of the THORChain network. Most requests to the network will come through Midgard. This daemon is here to keep the chain itself from fielding large quantities of requests. You can think of it as a “read-only slave” to the chain. This keeps the resources of the network focused on processing transactions. Midgard is heavily used in dashboards and transaction scanners like [Thorchain.net](https://thorchain.net/), [Thorchain.network](https://thorchain.network/) and [Runescan.io](https://runescan.io/). You find a full overview of the REST API endpoints on: * <https://gateway.liquify.com/chain/thorchain_api/thorchain/doc> * <https://gateway.liquify.com/chain/thorchain_midgard/v2/doc> For more information see [Gitlab repo](https://gitlab.com/thorchain/midgard). ## Developer Integration For comprehensive integration guides including: * Complete REST API documentation * WebSocket subscription endpoints * Query optimization strategies * Rate limiting and best practices * Running your own Midgard instance See the [THORChain Developer Documentation](https://dev.thorchain.org/) # Cosmos SDK How THORChain has configured the CosmWasm module The [Cosmos SDK](https://github.com/cosmos/cosmos-sdk) is an open-source toolkit for building multi-asset public Proof-of-Stake (PoS) blockchains, like the Cosmos Hub, as well as permissioned Proof-of-Authority (PoA) blockchains. Blockchains built with the Cosmos SDK are generally referred to as application-specific blockchains, like THORChain. There are multiple benefits from building an application-specific blockchain using the Cosmos SDK: * Flexibility * Performance * Security * Sovereignty ### Flexibility THORChain offers developers maximum flexibility: * Programming Language Choice: Developers can use the programming language they prefer for building the state-machine, thanks to the ABCI (Application Blockchain Interface). * Framework Selection: Various frameworks are available, such as the Cosmos SDK (in Golang) or Lotion (in JavaScript), allowing developers to choose based on their preferred language. * Customizable Consensus Engines: Developers can swap or tweak the consensus engine to better suit their needs. Currently, CometBFT is production-ready, but more options will emerge in the future. * Tradeoff Exploration: Developers can adjust parameters like the number of validators vs. transaction throughput, or choose different storage models like DB or IAVL tree. * Automated Logic Execution: The Cosmos SDK enables automatic execution of code at the beginning and end of each block, providing further customization. * Cryptographic Flexibility: Developers are free to choose their cryptographic libraries, avoiding constraints imposed by underlying environments in virtual-machine blockchains. This flexibility allows developers to create optimized, tailored solutions for THORChain, enhancing overall performance and adaptability. ### Performance THORChain, being an application-specific blockchain, provides several performance advantages: * Efficient Consensus: Using a consensus engine like CometBFT BFT offers higher throughput compared to Proof-of-Work blockchains. * Focused Resources: THORChain operates a single application, eliminating competition for computation and storage resources seen in non-sharded virtual-machine blockchains. * Reduced Complexity: Avoiding the need for a virtual-machine to interpret transactions significantly lowers computational complexity and boosts performance. ### Security Application-specific blockchains like THORChain enhance security in several ways: * Proven Languages: Developers can use established programming languages like Go, which are more mature than many smart contract languages. * Custom Cryptography: Developers can implement well-audited crypto libraries, rather than relying on the limited functions available in virtual-machines. * Simplified Security: By eliminating the complexities of a virtual-machine, developers can more easily ensure the security of their application. ### Sovereignty One of the major benefits of THORChain as an application-specific blockchain is sovereignty: * Full Control: Stakeholders have complete control over the chain, ensuring that governance and application requirements are aligned. * Responsive Upgrades: If bugs are found or new features are needed, the community can quickly act without waiting for the broader blockchain’s consensus. * Community Alignment: The community governing THORChain is directly aligned with the application’s stakeholders, providing a streamlined and responsive governance process. You can find more information about CosmWasm in their official [docs](https://docs.cosmos.network/). # CosmWasm CosmWasm smart contracts on THORChain (App Layer overview) THORChain now supports **CosmWasm smart contracts** directly on the base chain. This is called the **App Layer** and was introduced with SDK V50 (V3.0). Contracts are written in WebAssembly (Wasm), most commonly using [Rust](https://www.rust-lang.org/). ## How it works * CosmWasm runs inside THORNode through the `x/wasm` module. * Contracts are **permissioned**: only approved code and deployers can be whitelisted for mainnet. * All contracts are tested on **stagenet** before release. * Nodes can pause contracts or the entire app layer if needed (via Mimir). ## Supported assets * **Native RUNE and L1 assets** (BTC, ETH, ATOM, etc.) can be used. * **Secured Assets** (e.g. `btc-btc`) are wrapped forms of L1s managed in THORChain’s state. * **TokenFactory assets** (“X assets”) can be created by contracts. > Trade assets (deposit slips) are not supported as contract-moved tokens. ## Security model The App Layer is **sandboxed** from the base layer: * Contracts have no special privileges beyond a normal THOR address. * They can send, swap, or call other contracts, but cannot touch vault logic. * If an app fails, the base chain remains secure. ## Why it matters * Developers can build DeFi apps directly on THORChain (orderbooks, perps, stablecoins, lending, etc.). * Apps can share fees with THORNodes to pay for the security they use. * Users interact with apps natively from L1 wallets — no wrapping or bridges. ## Learn more * [THORChain Developer Documentation](https://dev.thorchain.org/) * [CosmWasm Documentation](https://docs.cosmwasm.com/docs/) * [ADR-020: App Layer](https://dev.thorchain.org/architecture/adr-020-app-layer.html) # THORChain & Cosmos This FAQ clarifies how THORChain has implemented the Cosmos tech stack and solved some of the most common problems faced by developers building on Cosmos chains ## Multiple asset representations With many Cosmos chains running on various bridged assets, Cosmos teams often end up with multiple representations of the same asset, e.g. Axelar bridged BTC, Nomic bridged BTC, and wBTC bridged from multiple different layer 2s. This splits liquidity and causes significant user confusion. THORChain will only have one bridged asset for per asset. E.g. `ETH.ETH` on L1 will be represented as a bridged asset with `ETH-ETH`. ## Buggy RPC/gRPC node software With multiple node providers validating blocks around the world, the risk of node crashes that disrupts work flow, testing and live implementations can happen. Some teams resort to spending significant amount of time adding fairly complex fallback and retry logic in our backend Cosmos library to deal with the situation, but it still occasionally causes alerts to go crazy. THORChain alleviates this problem by having anonymous nodes that [churn in and out](https://docs.thorchain.org/thornodes/overview/node-operations) validating blocks. The constant churn process keeps node operators on their toes and keeps the network running at optimal levels. ## Derivation path/wallet address incompatibility Most chains in the Cosmos ecosystem use the same public key hash method and derivation path, making their addresses convertible (works for Osmosis, Neutron, Juno, and Sei v1). Other chains attempt to keep Ethereum compatibility (Injective and Sei v2). The result is that addresses cannot be converted between these chains, which makes things like cross-chain incentivization difficult. THORChain will have have addresses compatible with at least one other Cosmos chain as the "canonical chain". There is all work being done to try and link different wallet addresses together so that matching accounts can be found across many chains. ## CosmWasm contract size limit Many CosmWasm contracts quickly move beyond the default 800kb limit for a contract. The CosmWasm team has previously discussed bumping this limit. THORChain will push on bumping up the contract limit to 1.5mb or more. ## Differing transaction size limits across nodes Having different settings between nodes for transaction size limits causes P2P sharing of mempool entries to sometimes get stuck. This can cause a node to be “starved” and none of the transactions broadcast to it to be picked up by the network. Levana’s workaround for this is quite involved: * They run a backend server, the querier, which provides a transaction broadcast endpoint * Their backend library has added support for an “all nodes broadcast,” where any broadcasts are sent to both the primary node and any fallbacks we’ve configured * Their frontends do not rely on the standard RPC interface leveraged by cosmjs, but instead have custom code to talk to the querier THORChain has defined [Node Operations](/technical-documentation/understanding-thorchain/roles/node-operators) that all nodes adhere to, and hence the problem of mempool entries getting stuck is solved. ## Congestion attacks/lack of MEV Some Cosmos chains have had periods of high traffic, either due to roll-up syncs, large NFT mints, or direct attacks on the chain. Most Cosmos chains have no concept of MEV or fee markets. Osmosis has implemented a basic fee market system, but it was at least initially buggy, and only gate-keeps entrance to the memory pool. It does not prioritize transactions within the pool. On THORChain, congestion attacks will be less impactful because of the use of chain-native oracles. More on how THORChain addresses MEV in the [FAQ](https://docs.thorchain.org/frequently-asked-questions#how-does-thorchain-prevent-mev). ## Poor wallet compatibility/frontend library support The Cosmos ecosystem generally uses CosmosKit for wallet integration. It’s a workable library, but has historically suffered from integration bugs, and the documentation has been poor. Furthermore, slight differences in behavior of different wallets has made broad wallet support difficult to achieve. THORChain is actively working with wallets like XDEFI/Ctrl, Keplr and Leap to alleviate compatibility issues, yet its an iterative process where there will be back and forth. ## Mishandling of multiple gas coins Many Cosmos chains allow for multiple coins to pay for network/gas fees rather than just one. Having this option is suboptimal. As a recent example from Levana on Osmosis: * Governance contract lives on Osmosis * Governance token, LVN, is a native coin on Osmosis, and it can be used for gas fees * An option in the Levana governance UI allows users to stake the entirety of their LVN holdings * Keplr has on occasion selected LVN as the gas token to be used in such transactions, even when a user has another gas coin available * All simulations and checks within the Levana dapp will indicate that this transaction will succeed, since selection of gas coin occurs after our app initiates the signing process * Keplr provides no useful warning about the fact that more LVN will be used than are available in the wallet THORChain addresses this by only allowing for [RUNE](/technical-documentation/understanding-thorchain/rune) to be used to pay network/gas fees # THORNode Overview Overview of THORNodes ## Overview THORNodes service the THORChain network. Each THORNode is comprised of several independent servers in a cluster. All THORNodes communicate and operate in cooperation to create a cross-chain swapping network. Running a node is a serious undertaking. While Node Operators are well [compensated](/thornodes/overview/risks-costs-and-rewards#compensation) for running a node, there are also [risks](/thornodes/overview/risks-costs-and-rewards), [skills required](#skillsets) and [costs](/thornodes/overview/risks-costs-and-rewards#costs). See the [Node Operator 101 Video](https://youtu.be/XXYXNAolPEU) to learn more before running a node. {% embed url="<https://youtu.be/XXYXNAolPEU>" %} To understand more about running a THORNode, see the below links: {% content-ref url="/pages/aU3za5gCtrmKi5YlXZAq" %} [Risks, Costs and Rewards](/thornodes/overview/risks-costs-and-rewards) {% endcontent-ref %} {% content-ref url="/pages/IRWx6jeWmJEDbnFltsuh" %} [THORNode Stack](/thornodes/overview/thornode-stack) {% endcontent-ref %} {% content-ref url="/pages/L4KiOVBHdgKtPMLYDBmk" %} [Node Operations](/thornodes/overview/node-operations) {% endcontent-ref %} ## THORNode Dashboards THORNode information can be viewed at the following dashboards: 1. [THORNode API (Liquify)](https://gateway.liquify.com/chain/thorchain_api/thorchain/nodes) - Live THORNode data 2. [thorchain.net](https://thorchain.net/nodes) - THORNode information and network statistics 3. [runescan.io](https://runescan.io/nodes) - THORNode information within the block explorer 4. [thorcharts.org](https://thorcharts.org/thorchain_earnings_distribution) - Earning distribution and other historical data ## Skillsets Running a THORNode is no simple task. As an operator, you will need to run/maintain multiple linux servers with extremely high uptime. It is encouraged that only professional systems engineers run nodes to maintain the highest quality reliability and security of the network. The simple question to know if you have the skillsets to run a THORNode is: > *Have you used pagerduty before?* If the answer is no, it’s probably best that you do not run a node and participate in the network in other ways, such as a [RUNEPool participant](/technical-documentation/thorchain-finance/runepool)or a [bond provider.](/thornodes/pooled-thornodes) The following skill sets are required to be an effective node operator. * Advanced knowledge of Linux server administration and security * Advanced knowledge of Kubernetes * Advanced experience running a host of nodes on a hosted platform such as AWS, Google Cloud, Digital Ocean, etc * Knowledge of running full nodes for other chains such as Bitcoin and Ethereum. * Willingness to be “on call” at all times to respond to issues when/if your node becomes unavailable ## Creating a Node To set up a node, you have two choices: 1. Set up manually (not recommended unless you are an expert) 2. Set up via Kubernetes (recommended) You can create a bare metal node with your own hardware or use the cluster launcher section for step by step guides using a host provider: {% embed url="<https://medium.com/@Runetard/bare-metal-node-n00b-guide-a29c5c067b4a>" %} {% content-ref url="/pages/KOVyvL9C028BNKA5rxlw" %} [Cluster Launcher](/thornodes/kubernetes) {% endcontent-ref %} Once created, follow the [Deploying](/thornodes/deploying), [Joining](/thornodes/joining) and [Managing](/thornodes/managing) pages. ## Node Voting THORNodes have the ability to vote on [Mimir](https://gateway.liquify.com/chain/thorchain_api/thorchain/mimir) settings. This is important when voting for [ADRs](https://dev.thorchain.org/architecture/index.html) and for [network governance](/technical-documentation/technical-deep-dive/governance#mimir-network-settings). Mimir settings have specific [abilities](https://dev.thorchain.org/mimir.html). Mimir keys and values are listed in the [Mimir endpoint](https://gateway.liquify.com/chain/thorchain_api/thorchain/mimir). The process for voting from a node is: ```cmd Make mimir => Enter THORNode Mimir key: <key> => Enter THORNode Mimir value: <value> ``` 1. Only an active node can vote, and each active no
프로젝트로 돌아가기