A detailed explanation of the parallel execution of Sei: the key puzzle to innovate the DeFi product experience.

CN
1 year ago

Sei is firmly committed to solving scalability challenges through parallel execution, optimized data storage, and future upgrades.

Author: DAIC

Translation: DeepTechFlow

The decentralized finance (DeFi) revolution has ignited a global wave of financial empowerment and disintermediation. However, immediate peer-to-peer transactions are often hindered by slow blockchains. Imagine the time it takes for transaction confirmation, or the painful delays exposed to drastic price fluctuations. This is the friction point that Sei is committed to eliminating.

Key Points

  • Sei is an L1 blockchain with an architecture optimized for various trading applications, ensuring optimal performance.

  • The built-in native order matching engine is directly integrated into L1, enabling seamless order execution and excellent scalability suitable for trading applications.

  • Sei's Twin Turbo consensus mechanism achieves sub-second finality, providing nearly instant transaction confirmation.

  • Sei adopts a market-based parallelization approach, particularly suitable for high-frequency trading demands.

  • By processing orders in batches, Sei prevents front-running behavior exploited by malicious bots.

  • Sei V2 upgrade—parallel EVM, Optimistic parallelization, and SeiDB.

Sei Overview

The current mainstream blockchains, as the foundation for many crypto projects, face significant obstacles. The Sei Labs team believes that existing infrastructure cannot keep up with the demands of decentralized exchanges (DEX). They often have limitations in throughput (the number of transactions processed per second) and final confirmation time (the time it takes for a transaction to be considered complete and irreversible). This results in slow performance, becoming a major obstacle for high-frequency trading strategies and large-scale trading activities.

Sei aims to break through this barrier by meticulously optimizing every layer of the blockchain stack to specifically meet the trading demands. The team provides a clear value proposition: regardless of the type of trading application—whether it's DeFi, NFT markets, or games—operations on Sei will run smoother and faster than on any other L1 network.

With this innovative solution, Sei positions itself as the ultimate disruptor in the DeFi space, aiming to become the preferred infrastructure provider for exchanges seeking a platform designed specifically for rapid digital asset trading.

Utilizing the interoperable Cosmos SDK framework, Sei has a dedicated L1 blockchain equipped with a set of collaborative features to enhance the trading experience.

Its native order matching engine simplifies trading operations by eliminating external dependencies, while the innovative Twin Turbo consensus mechanism provides sub-second finality, achieving near-instant transaction confirmation. Security and developer experience are always paramount, with features such as front-running prevention and local price Oracle ensuring a robust and user-friendly environment.

Let's delve into the key features positioning it as the "turbo engine" for DeFi trading.

Twin-Turbo Approach

Sei relies on a modified version of the Tendermint consensus mechanism, known as Twin-Turbo consensus, based on the proof-of-stake (PoS) protocol.

Validators play a crucial role in processing transactions and confirming changes in network state. These validators are selected based on their total stake (including self-bonded and delegated SEI tokens). Currently, only the top 39 validators by total stake participate in the consensus process, earning transaction fees and staking rewards.

SEI token holders can choose to delegate their SEI tokens to existing validators, contributing to network security. Delegators receive a portion of the validator's SEI rewards after deducting the commission rate chosen by the validator.

When it comes to consensus, Tendermint provides a solid foundation, ensuring transactions are finally determined and irreversible after being added to the blockchain (single-slot finality). However, its 6-second block time is not suitable for Sei's high-speed trading vision.

Through improvements introduced by the Twin Turbo consensus, Sei Labs has reduced Tendermint's 6-second block time to less than 400 milliseconds, achieving single-slot finality.

This result is achieved through two key optimizations introduced by the Twin Turbo consensus, known as "Smart Block Propagation" and "Optimistic Block Processing." Together, these have led to the remarkable result presented by Sei today—transaction processing during consensus takes only milliseconds.

The Smart Block Propagation mechanism differs from the traditional approach of transmitting complete transaction details within blocks. Instead, block proposers initiate the process by sending proposals containing unique identifiers and hashes for each transaction.

Considering that validators typically have the most recent transactions in their local memory pool, they can reconstruct the complete block, avoiding unnecessary bandwidth consumption and reducing the wait time for retrieving redundant data. This optimization promotes overall network efficiency, ultimately translating into faster transaction processing for users.

Optimistic Block Processing further accelerates transaction processing by bypassing "pre-vote" and "pre-commit" rounds. Its goal is to simplify the process by allowing consensus steps to proceed simultaneously, significantly saving time. This approach results in faster block validation and voting, contrasting sharply with the sequential processing common on other blockchains.

The consensus mechanism advances with remarkable efficiency through the synergy between Optimistic Block Processing and Smart Block Propagation.

Upon receiving the initial block proposal for a given height, the system conducts a validity check and processes it optimistically during the "pre-vote" and "pre-commit" periods. Optimistic Block Processing writes the candidate state to the cache.

This innovative approach enables validators to process transactions optimistically upon receiving a valid block proposal, bypassing the delay of waiting for the "pre-commit" phase to end. This strategy maximizes the utilization of the trend where the first proposed block at a specific height wins the vote in most cases. If the block is accepted, the cached candidate state from Optimistic processing seamlessly integrates into the blockchain. Conversely, if the block is rejected, the cached data is discarded, and subsequent rounds at the same height avoid Optimistic block processing. Validators reset their position, preparing to process the next block proposal. This concept cleverly leverages the predictability of block acceptance to significantly improve transaction processing speed while reducing the risk of block rejection. Compared to traditional solutions, this means a significant increase in throughput.

This provides traders with a smoother user experience, minimizing confirmation time and reducing the risk for market makers, which are the two major pain points in the current DeFi ecosystem.

Parallelization

In chains like Sei running on the Cosmos SDK, validators follow a structured three-step process upon receiving a block: "BeginBlock," "DeliverTx," and "EndBlock." Sei has customized the latter two steps to introduce parallel processing.

Traditionally, transactions in the DeliverTx phase are processed sequentially. However, Sei has modified this approach to allow simultaneous processing, using the concept of a Directed Acyclic Graph (DAG) to manage transaction order and avoid conflicts.

In addition, Sei processes order execution in parallel at the end of each block, especially for independent orders related to its native order matching engine. These orders are treated as independent, and developers can define market dependencies if they involve different markets within the same block.

Sei's native order matching engine allows decentralized exchanges to create their own order books. We will delve into this in more detail below.

Hidden Costs of Tendermint

While Sei leverages a modified version of the Tendermint consensus, renowned for its fast block finality, it comes with a hidden cost: secondary communication complexity. This principle states that the number of messages required for communication between validators grows quadratically with the increasing number of validators in the network.

Imagine a conference call—communication flows smoothly within a small group. But as the number of participants increases, managing the conversation becomes much more complex. Similarly, in a blockchain using Tendermint, the growth of the validator set leads to a surge in message traffic, potentially putting pressure on network bandwidth and validator processing capacity. This could hinder scalability, making it difficult to add many validators without compromising performance.

As the current validator set steadily expands, Sei is committed to addressing this challenge head-on by strengthening decentralized initiatives. The goal is to maintain network performance by cultivating a globally distributed validator network, supplemented by lightweight clients for trustless verification.

Order Matching Engine

Sei has integrated an order matching engine at the chain level, allowing developers to create order book-based exchanges on the Sei blockchain.

This feature supports the development of a Central Limit Order Book (CLOB) system, commonly used in traditional centralized trading platforms. Sei also supports the automated market maker (AMM) systems commonly used in decentralized exchanges (DEX).

How It Works

All transactions involving the matching engine are atomically executed within a block range. These transactions are routed to the DEX module, with each transaction potentially containing multiple orders. Upon submission, the transaction processor adds the orders of each transaction to the internal MemState of the DEX module. During block processing, the EndBlocker hook of the DEX module batch merges the recorded orders in MemState. This merging aggregates orders by market (e.g., all orders for BTC perpetual contracts), forming a single smart contract call.

Transaction Order Packing

Sei introduces multi-layered order packing to enhance user experience and optimize performance:

  • Client Order Packing: Sei allows transactions to include orders from multiple trading markets, including orders across smart contracts (e.g., orders for the BTC/USDC spot pair and BTC perpetual contracts). During block processing, Sei accurately routes orders to their respective smart contracts, helping market makers minimize gas fees associated with position updates.

  • Chain-Level Order Packing: Instead of instantiating a virtual machine (VM) for each transaction instance related to the matching engine, Sei consolidates orders from all transactions (by market) and initiates VM instantiation only once. This significantly reduces the order latency by approximately 1 millisecond, especially during high throughput periods.

Hook Integration

Sei allows contracts to set "hooks" in the network. These registered hooks are triggered once per block, facilitating operations such as flash loan repayments, with transaction settlements occurring within the same block. Contracts can define two types of hooks: one executed at the beginning of a block to prepare for potential transactions, and another executed at the end of a block, allowing contracts to perform any necessary post-transaction logic after order matching and settlement.

Asset Agnosticism

The matching engine does not directly trade tokens but provides a diverse interface, allowing decentralized exchanges to decide how to represent assets. For example, decentralized exchanges can choose to track positions in their smart contract state instead of tokenizing them.

Frequent Batch Auctions

Sei introduces a method called "frequent batch auctions" to address a phenomenon called "MEV" (Maximal Extractable Value) and ensure fair market conditions. MEV arises when validators prioritize processing their own transactions to maximize profits, potentially at the expense of other participants.

To mitigate this issue, Sei consolidates all market orders and executes them at a consistent settlement price. For example, if there are two sell orders (ask prices) at prices P1 and P2, and two buy orders (bid prices), Sei calculates a unified settlement price—simply taking the average of P1 and P2. Subsequently, both buy orders are executed at this unified settlement price.

By avoiding individual transaction sequencing, Sei eliminates the incentive for validators to manipulate transaction order for personal gain, creating a fairer trading environment.

Price Oracle

To facilitate asset pricing, Sei implements a native price Oracle. Validators act as Oracles, ensuring the reliability and accuracy of asset pricing. To maintain the freshness of Oracle pricing, the voting window can be as short as one block, allowing for rapid updates of current asset prices.

During the voting step within the voting window, validators propose exchange rates. At the end of the voting period, all exchange rate votes are aggregated, and a weighted median is calculated based on validator voting weights to determine the accurate exchange rates for each asset. Validators who do not participate or provide inaccurate data will be penalized.

Validators have a misbehavior count, tracking instances where they fail to provide data or provide significantly divergent data from the weighted median. If a validator's misbehavior count exceeds a certain threshold within a specified voting period, they will be subject to reduced penalties for prolonged misconduct.

Sei V2 Upgrade

In November 2023, Sei unveiled the blueprint for Sei V2, marking the network's three transformative enhancements: parallel EVM, Optimistic parallelization, and SeiDB.

By cleverly combining parallel execution and EVM compatibility, Sei V2 addresses performance and availability issues in a single operation, providing users and developers with the ability to break free from Ethereum limitations while retaining the familiar environment of the EVM ecosystem. This breakthrough approach improves transaction processing efficiency, significantly alleviating Ethereum's bottlenecks during periods of high demand, while providing a seamless experience for EVM veterans.

This upgrade is expected to be deployed to the mainnet in the first half of 2024. Meanwhile, Sei opened a public development network in February 2024 as a testing ground for the innovation of Sei V2.

(Image Source)

Sei is making a major leap with Sei V2, its first major upgrade. This upgrade unleashes the powerful capabilities of parallelizing the Ethereum Virtual Machine (EVM), providing developers with a super-optimized execution layer and enhancing state storage efficiency.

Additionally, a new component will be introduced to accommodate EVM smart contracts. These contracts will leverage the advancements in consensus and parallelization while seamlessly interacting with existing Cosmwasm smart contracts.

(Image Source)

This upgrade will enable Sei to have the following features:

  • Backward compatibility for EVM smart contracts

  • Optimistic parallelization

  • SeiDB—improvements to the storage layer

  • Interoperability—composability between EVM and other execution environments

Backward Compatibility

With this update, all existing and audited EVM-compatible smart contracts can be seamlessly deployed on Sei without code changes, leveraging familiar tools such as Foundry, Remix, and Hardhat.

Sei nodes will integrate Geth, the Go implementation of the Ethereum Virtual Machine responsible for processing Ethereum transactions. Any subsequent updates (such as state modifications or non-EVM contract calls) will be handled through a special interface created by Sei specifically for EVM.

(Image Reference)

Optimistic Parallelization

Optimistic parallelization will apply to all transactions running on Sei, including Sei native transactions, Cosmwasm transactions, and EVM transactions.

(Image Reference)

In Sei V2, developers will no longer need to manually define state access. Instead, the chain will employ an optimistic approach to parallel transaction execution.

When conflicts arise—such as transactions affecting the same state—the chain will monitor which storage area each transaction interacts with. Transactions involving different storage areas will be rerun in parallel, while transactions involving the same state will be rerun sequentially.

This process will continue iteratively until all conflicts are resolved. Due to the ordered nature of transactions within a block, this approach ensures determinism while simplifying developers' workflows and retaining parallelization at the chain level. For more technical details, please refer to.

SeiDB

The increased transaction processing leads to the creation of more blockchain states, requiring consideration not only for parallel runtime but also for state management. Sei V2 introduces SeiDB as a major component, fundamentally changing the mechanism of state access, state commitment, and state storage.

(Image Reference)

The current implementation of Sei uses a database layer consisting of the IAVL tree data structure. However, due to its schema and additional metadata, this structure is inefficient in terms of storage and latency, leading to write amplification and slow disk access.

Based on ADR-065 (Architecture Decision Record), the Sei Labs engineering team developed SeiDB. Its primary strategy is to avoid storing all data in a single large database. Instead, the data is separated into two independent layers:

  • State Commitment uses a highly optimized in-memory IAVL tree for fast data commitment, minimizing disk access to help validators reach consensus faster.

  • State Storage facilitates low-latency direct access to raw key-value pairs, enhancing the RPC nodes' ability to efficiently handle queries.

(Illustration of SeiDB distinguishing state commitment and state storage)

The separation of active state and historical data significantly improves the performance of all node operators in the Sei ecosystem. This architectural decision enables the Sei Labs engineering team to represent the current chain state as a memory-mapped IAVL tree using MemIAVL. As a result, validator nodes can track the blockchain state through mmap, reducing state access time from hundreds of microseconds to just hundreds of nanoseconds. This significant improvement greatly enhances state synchronization time and read/write amplification.

Using minimal metadata to store raw key-value pairs in the state storage layer can improve the locality in the LSM tree, while asynchronous pruning can prevent nodes from falling behind. These changes have reduced the state storage requirements by at least 60% and lowered the overall data growth rate by 90%, saving a significant amount of long-term disk space as the nodes continue to operate.

Additionally, Sei has thoroughly benchmarked various leading databases in the industry. As a result, Sei V2 will transition to using PebbleDB instead of GoLevelDB. This transition is expected to significantly improve read/write performance, especially for multi-threaded access.

Key points of SeiDB:

  • Reduced active state size by 60%;

  • Lowered historical data growth rate by ~90%;

  • Reduced state synchronization time by 1200% and block synchronization time by 2x;

  • Shortened block commit time by 287x;

  • Provided faster state access and state commitment, resulting in a 2x increase in overall TPS;

  • Ensured that Sei archival nodes can achieve the same high performance as any full node.

(Image Reference)

The significant upgrade to the network storage layer has addressed data overload issues, optimized performance, and simplified the onboarding process for new nodes. This ensures consistent network scalability and performance.

Interoperability

The upcoming Sei V2 upgrade will bring revolutionary features, especially the advanced high-performance parallel EVM. This advancement will enhance user experience and pave the way for innovative development possibilities.

Sei is committed to promoting seamless composability between EVM and other supported execution environments, driving interoperability within the existing chain.

(Image Reference)

As an integrated blockchain, Sei will allow transactions to seamlessly interact across various Sei components (banking, EVM, Wasm, staking). Despite their different use cases, these transactions share common features such as gas, sender, and transaction subject. Once received, the chain treats these transactions as Sei native transactions and directs them to relevant storage sections (e.g., routing CosmWasm transactions to the Wasm module for execution). This integration facilitates a smooth experience for developers, enabling EVM developers to easily leverage native tokens and other chain functionalities such as staking.

Furthermore, as Sei V2 enhances support for two execution environments (CosmWasm and EVM), all token standards available on the Ethereum blockchain will also be available on Sei. Some users may be concerned that this could introduce too much complexity to the ecosystem and compromise user experience, but Sei has taken this into consideration.

Every token available on Sei, whether it's an NFT (CW-721) or a standard token (CW-20), can be made compatible with EVM wallets and applications through pointer contracts. These contracts establish links for tokens between EVM and CosmWasm, enabling seamless usage without the need to "wrap" assets. This ensures that the same token balance can be controlled on both EVM and CosmWasm.

(Pointer contracts enable wallets from either environment to access all tokens)

Pointer contracts also enable the use of CW-20, CW-721, and native tokens in EVM applications and vice versa. However, they are not convenient for interacting with existing Sei applications using EVM wallets, which requires another feature called "precompiles."

To address this issue, Sei Labs has directly implemented "precompile" smart contracts within the Sei blockchain. These contracts serve as gateways for users and developers to access native Sei functionalities through the EVM RPC interface, ensuring interaction with smart contracts using their preferred wallets.

The precompiled contracts available on Sei include:

Developers seeking to use these precompiled guides can find instructions in the "Example Usage" section.

Once funds are deposited into your EVM address, you can seamlessly use them with your Sei address, and vice versa. This integration merges them into one account, ensuring smooth interaction between the EVM and Sei ecosystems.

User Account Setup on Sei

In Sei, each user "account" is associated with a unique public key. However, after upgrading to Sei V2, this public key will correspond to two types of addresses:

  • EVM address: Starting with 0x, used for Ethereum-related operations.

  • SEI address: Starting with Sei, used for Sei native operations.

(Image Reference)

Although these addresses may appear different on the surface, they are essentially linked to the same underlying account. This means that any operations performed using one token address will inevitably affect the other address.

Sei's Parallel Stack

With the launch of Sei V2, the team is focused on introducing Sei's parallel stack, which will serve as the gateway for layer 2 networks to enter the Sei ecosystem.

(Image Reference)

Derived from the building experience of Sei V2, this open-source powerhouse tool will empower developers to create high-performance layer 2 solutions and aggregations, harnessing the power of parallel processing. The parallel stack addresses the performance bottlenecks faced by layer 2 blockchains in the current Ethereum ecosystem.

The framework provides developers with a robust and secure foundation to build innovative layer 2 solutions. Notably, the parallel stack offers unparalleled customization, allowing developers to tailor their creations according to specific project requirements. Additionally, projects inherently benefit from the strong security features of the Ethereum blockchain or any data availability layer they integrate with. As part of the default configuration options, projects can choose to leverage Sei's validated set of validators. This integration further enhances security while maximizing the benefits of the innovative architecture of the parallel stack.

Decentralized Parallel EVM

Building aggregations from scratch can be a daunting task. Sei's collaboration with Altlayer to democratize parallel EVM further unleashes the potential of developers in the high-performance DeFi space.

Altlayer's "Reaggregation as a Service" (RaaS) product eliminates the complexity of managing node infrastructure, allowing developers to focus on leveraging the capabilities of the parallel stack to develop innovative dApps. This saves developers a significant amount of time and resources.

In addition to simplification, Altlayer's "Re-staking Aggregations" (a set of three vertically integrated active validation services) seamlessly integrates with the parallel stack, adding a layer of robust security to these high-performance aggregations. This translates to faster transaction finality, a more decentralized ordering environment, and continuous validation of aggregation states—key factors in fostering trust and security in DeFi applications.

Developers gain access to a powerful toolkit, allowing them to create lightning-fast and highly secure DeFi applications on the Ethereum ecosystem. This collaboration not only empowers developers but also paves the way for a more scalable and accessible DeFi landscape, ultimately benefiting the entire user community.

Future Developments

Unified NFT: New xERC-721 NFT Standard

The thriving Ethereum ecosystem faces a challenge—fragmentation. With the emergence of various scaling solutions (layer 2 aggregations, high-performance EVM), NFTs are isolated within specific platforms. This isolation divides the community and hinders innovation.

Sei Labs and the Omni Foundation have proposed a solution: the xERC-721 standard. The xERC-721 NFT serves as a streamlined upgrade to ERC-721. It provides greater freedom for NFT creators and holders, no longer confined to a single domain, opening the doors for innovation and experimentation within the Ethereum ecosystem.

Advantages of xERC-721:

  1. xERC721 tokens can securely move across multiple domains without introducing unnecessary risks or relying on any privileged third parties (such as specific interoperability networks), through the lockbox interface functionality described. This ensures that sovereignty remains in the hands of the NFT community.

  2. xERC721 token contracts are extended through the mintBatch and burnBatch function interfaces. This addresses a pain point for developers, leading to the introduction of new standards such as ERC-1155. This issue is further exacerbated when programming across multiple blockchains, as it introduces asynchronicity and requires compensating for the costs of interoperability network validation and transaction delivery.

  3. Existing NFT collections can be easily upgraded to xERC-721 by deploying a new gateway contract, making them accessible throughout the aggregation ecosystem.

This initiative, along with EIP-7281, lays the groundwork for a standardized approach to NFTs in the decentralized Ethereum environment. By leveraging these open standards, developers gain access to powerful tools, paving the way for further innovation in the digital asset space.

Sei Creator Fund: $10 Million Grant Program

The Sei Foundation is committed to fostering the growth of the Sei ecosystem and has launched the Sei Creator Fund—a $10 million grant program aimed at inspiring innovation by supporting new project development and expanding existing projects in the NFT and social experience space.

Whether you are brimming with new infrastructure or tool ideas, looking to turn your creative vision into reality, or hoping to propel existing NFT projects forward, the Sei Creator Fund is here to support you.

Conclusion

Sei is steadfast in addressing scalability challenges through parallel execution, optimized data storage, and future upgrades, paving the way for groundbreaking advancements that enable projects to harness the advantages of diverse platforms to tackle complex financial challenges.

This pioneering approach heralds an era of unprecedented transaction processing throughput, facilitating rapid and low-cost interactions for traders. The resulting enhancement in user experience signifies the potential for wider adoption of DeFi.

As Sei's technology evolves, its impact on the DeFi space could be transformative, leading the way to an era of unprecedented scalability, efficiency, and accessibility. By promoting a more inclusive DeFi future, Sei empowers creators and users to redefine decentralized finance.

免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。

好手气即赢小米 Yu7 Max、LV 限量手提箱
Ad
Share To
APP

X

Telegram

Facebook

Reddit

CopyLink