Sharding

El sharding es una técnica de partición de bases de datos utilizada para mejorar la escalabilidad de las blockchains al dividir la red en partes más pequeñas y manejables llamadas shards.

El sharding aborda el trilema de escalabilidad al permitir que una blockchain procese más transacciones por segundo (TPS). En lugar de que cada nodo valide cada transacción, los nodos se asignan a shards específicos, cada uno responsable de procesar un subconjunto de las transacciones de la red. Este procesamiento paralelo aumenta significativamente el rendimiento. El sharding también reduce la carga computacional en los nodos individuales, lo que facilita que los nuevos participantes se unan a la red y contribuye a la descentralización. Existen diferentes implementaciones de sharding, que varían en la forma en que asignan nodos a shards y en cómo garantizan la comunicación y la seguridad entre shards.

        graph LR
  Center["Sharding"]:::main
  Rel_transaction_sharding["transaction-sharding"]:::related -.-> Center
  click Rel_transaction_sharding "/terms/transaction-sharding"
  Rel_eip_4844["eip-4844"]:::related -.-> Center
  click Rel_eip_4844 "/terms/eip-4844"
  Rel_stablecoin_scalability_solutions["stablecoin-scalability-solutions"]:::related -.-> Center
  click Rel_stablecoin_scalability_solutions "/terms/stablecoin-scalability-solutions"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧠 Prueba de conocimiento

1 / 3

🧒 Explícalo como si tuviera 5 años

🍕 Imagine you have a giant 100-meter pizza and only one person to eat it. It would take weeks! Sharding is like cutting that pizza into 100 pieces and inviting 100 people to eat one piece each at the same time. The whole pizza is finished in minutes. In a computer, this means splitting a massive pile of data into smaller piles so many computers can handle it at once.

🤓 Expert Deep Dive

Sharding fundamentally alters the monolithic blockchain architecture by introducing state and transaction partitioning. Instead of a single global state and all full nodes processing every transaction, the network is divided into N shards, each maintaining its own subset of the total state and processing its own transactions.

State Sharding: The entire blockchain state (account balances, smart contract storage) is divided among shards. Each shard s is responsible for a contiguous or hashed portion of the state space, denoted as S_s. A node assigned to shard s only needs to store and process transactions related to its assigned state subset.

Transaction Sharding: Transactions are routed to the shard responsible for their originating account or the state they interact with. This allows for parallel transaction execution. For instance, if a transaction tx involves accounts A and B, and both A and B reside in shard s, then tx is processed exclusively by nodes within shard s.

Cross-Shard Communication: This is a critical challenge. Transactions or smart contract calls that involve state across multiple shards require a robust communication protocol. Common approaches include:

  1. Asynchronous Message Passing: Shards communicate via receipts or proofs. When shard s1 needs to interact with shard s2, it generates a receipt containing relevant transaction data and proofs. Shard s2 can then process this receipt. This often involves Merkle proofs to verify the integrity of data from other shards.
  2. Receipt Chains: A chain of receipts is maintained, linking cross-shard interactions and ensuring atomicity or eventual consistency.

Consensus Mechanisms: Each shard can employ its own consensus mechanism (e.g., PoS variations, BFT variants) for intra-shard finality. However, a coordinating layer or beacon chain is typically required to aggregate shard block headers, facilitate cross-shard communication verification, and provide overall network security and finality. The beacon chain might run a global consensus protocol that all shards attest to.

Node Assignment & Randomization: Nodes are typically assigned to shards through a randomization process (e.g., using Verifiable Random Functions - VRFs) to prevent single-shard collusion and ensure even distribution of the validator set across shards. This assignment is often dynamic, rotating validators periodically to enhance security.

Security Considerations:
Single-Shard Takeover (1% Attack): If k is the number of shards and V is the total validator set size, a malicious actor might only need to control V/k validators to compromise a single shard. Sharding protocols must implement mechanisms to mitigate this, such as validator randomization, cross-linking, and robust cross-shard verification.
Data Availability: Ensuring that all shard data is available is crucial. Techniques like data availability sampling are employed, where nodes randomly sample shard blocks to verify data availability without downloading the entire block.

Architecturally, sharding transforms a single, computationally bound blockchain into a network of smaller, more manageable blockchains that operate in parallel, significantly increasing the network's capacity and reducing transaction latency.

📚 Fuentes