Module 2: Core Concepts in Blockchain


    2.1 Blocks, Hashes, and Chains

    1. What is a Block?

    A block is a container of data in a blockchain. It stores a list of transactions and some metadata.

    Main Components of a Block:

    • Block Number: Unique ID for the block
    • Timestamp: When the block was created
    • Transactions: List of operations (send, receive, etc.)
    • Previous Hash: Hash of the previous block
    • Current Hash: Unique hash of this block

    2. What is a Hash?

    A hash is a digital fingerprint of data. It is generated by a mathematical function (like SHA-256) and is always the same length, no matter the size of input.

    Properties of a Hash:

    • Fixed-length output (e.g., 64 characters for SHA-256)
    • One-way: You can't reverse a hash to get original data
    • Small change in input = completely different hash

    Example:
    SHA-256("hello") =
    2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

    3. What is a Chain?

    A chain is formed when blocks are connected using hashes. Each block contains the hash of the previous block, which links them together in order.

    This makes blockchain:

    • Immutable: If one block is changed, all the next blocks become invalid
    • Secure: Tampering is easily detected

    Illustration:

        Block #1
    
        | Transactions | Hash: A1 | Prev Hash: 0000 |
    
        Block #2
    
        | Transactions | Hash: B2 | Prev Hash: A1 |
    
        Block #3
    
        | Transactions | Hash: C3 | Prev Hash: B2 |
    
      

    Summary

    • Blocks hold transaction data
    • Hashes give each block a unique identity
    • Chains connect blocks in a secure and unbreakable sequence


    2.2 Consensus Mechanisms in Blockchain

    A consensus mechanism is a method used by blockchain networks to agree on the validity of transactions and maintain security. It ensures all participants in a decentralized network agree on the state of the ledger.

    1. Proof of Work (PoW)

    Used by: Bitcoin, Ethereum (before ETH 2.0)

    How it works: Miners compete to solve complex mathematical problems. The first to solve adds the block and gets a reward.

    Pros:

    • Very secure
    • Proven and tested

    Cons:

    • High energy consumption
    • Slower transactions

    2. Proof of Stake (PoS)

    Used by: Ethereum 2.0, Cardano, Solana

    How it works: Validators are chosen based on how much crypto they "stake" (lock up). The more you stake, the higher your chances of validating a block.

    Pros:

    • Energy-efficient
    • Faster than PoW

    Cons:

    • Wealthier users may have more influence

    3. Delegated Proof of Stake (DPoS)

    Used by: EOS, TRON

    How it works: Token holders vote for a small number of delegates (block producers) who validate transactions and maintain the network.

    Pros:

    • Faster transactions
    • More scalable

    Cons:

    • Less decentralized (only a few block producers)

    4. Proof of Authority (PoA)

    Used by: VeChain, some private/enterprise blockchains

    How it works: Only approved nodes (validators) are allowed to validate transactions. These validators are usually known and trusted entities.

    Pros:

    • Very fast and efficient
    • Great for private blockchains

    Cons:

    • Centralized (requires trust in validators)

    Comparison Table:

    Mechanism Speed Energy Usage Decentralization
    PoW Slow High High
    PoS Fast Low Moderate
    DPoS Very Fast Low Low
    PoA Very Fast Very Low Low

    Conclusion:

    Consensus mechanisms are the backbone of blockchain security and integrity. Different blockchains choose different models depending on their use case, balancing speed, decentralization, and energy efficiency.



    2.3 P2P Networking & Node Types in Blockchain

    What is Peer-to-Peer (P2P) Networking?

    P2P networking forms the foundation of blockchain. In this system, each participant (node) connects directly with others, eliminating the need for a central server.

    • Decentralized: No central authority; every node is equal.
    • Distributed Data: Each node holds a full or partial copy of the blockchain.
    • Direct Communication: Nodes talk directly to exchange and verify data.

    Structure of a P2P Blockchain Network

    Blockchain networks rely on P2P topology to ensure resilience, decentralization, and censorship resistance.

    • Mesh Network: Nodes are interconnected, allowing data to flow in multiple directions.
    • Gossip Protocol: Information (like new blocks/transactions) spreads from node to node, quickly updating the network.
    • Resilience: Even if several nodes fail, the network continues functioning.

    Types of Blockchain Nodes

    Different nodes serve different purposes in a blockchain network:

    • Full Node: Stores the entire blockchain ledger and validates transactions/blocks independently.
    • Light Node (SPV): Doesn’t store full data, but uses headers to verify transactions. Lightweight and faster.
    • Mining Node: Special full node that participates in block creation (mining/validation).
    • Archive Node: Stores historical states of the blockchain (e.g., for Ethereum dApps).
    • Validator Node (PoS): Proposes and verifies new blocks in Proof-of-Stake blockchains.

    Key Takeaway

    P2P networking empowers blockchains to be open, decentralized, and fault-tolerant. Understanding node types helps grasp how blockchain infrastructure operates globally.



    2.4 Forks in Blockchain: Soft vs Hard

    What is a Fork?

    A fork occurs when a blockchain diverges into two potential paths forward. It can happen due to changes in the protocol or disagreements among the network participants.

    • Protocol Update: Forks are often the result of software updates.
    • Consensus Split: Forks may arise when nodes disagree on the rules to follow.

    Soft Fork

    A soft fork is a backward-compatible update, meaning old nodes still recognize new blocks as valid.

    • Backward-Compatible: Old software works with new rules.
    • Stricter Rules: Often introduces tighter constraints (e.g., block size reduction).
    • Single Chain: Usually results in one continuous chain if most nodes upgrade.
    • Example: Bitcoin’s SegWit (Segregated Witness) upgrade in 2017.

    Hard Fork

    A hard fork is a non-backward-compatible change, creating a permanent split in the blockchain if not all nodes upgrade.

    • Not Compatible: Older nodes can't validate new blocks.
    • New Chain: Leads to a new, separate blockchain if consensus isn’t reached.
    • Coin Split: Both chains may have their own coins (e.g., ETH & ETC).
    • Example: Bitcoin Cash forked from Bitcoin in 2017 due to block size debate.

    Key Takeaway

    Forks are essential for blockchain evolution but can also create disagreements and competition. Understanding soft vs hard forks helps you grasp how communities handle upgrades and conflicts.



    2.5 Gas Fees & Transaction Lifecycle

    What are Gas Fees?

    Gas fees are payments made by users to compensate for the computing energy required to process and validate transactions on a blockchain like Ethereum.

    • Measured in: Gwei (a small denomination of Ether).
    • Paid to: Miners (Proof of Work) or Validators (Proof of Stake).
    • Variable: Gas price fluctuates based on network demand.
    • Smart Contracts: More complex operations → higher gas usage.

    Why Do Gas Fees Exist?

    • Prevent spam and misuse of the network.
    • Prioritize transactions based on willingness to pay.
    • Incentivize miners/validators to include your transaction in the block.

    Transaction Lifecycle

    Here's what happens from the moment you initiate a transaction to when it’s finalized:

    1. Initiation: You submit a transaction via wallet or DApp.
    2. Pending: The transaction waits in the mempool for miners/validators to pick it.
    3. Block Inclusion: A miner/validator selects your transaction and includes it in a block.
    4. Validation: The block is validated, and consensus is achieved.
    5. Confirmation: After multiple blocks are added on top, the transaction is considered final.

    Failed Transactions

    If a smart contract runs out of gas during execution, the transaction fails but still costs gas fees.

    Pro Tips

    • Use gas estimators to avoid underpaying or overpaying.
    • During peak hours, gas fees spike – time your transactions wisely.
    • Layer-2 solutions (e.g., Arbitrum, Optimism) offer cheaper gas.

    No comments:

    Post a Comment