0
0
Blockchain / Solidityprogramming~10 mins

Distributed ledger concept in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Distributed ledger concept
Transaction Created
Transaction Broadcast
Nodes Receive Transaction
Nodes Validate Transaction
Transaction Added to Ledger
Ledger Updated Across Nodes
Consensus Achieved
End
This flow shows how a transaction is created, shared, validated, added to the ledger, and synchronized across all nodes to keep the ledger consistent.
Execution Sample
Blockchain / Solidity
transaction = {'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}
network.broadcast(transaction)
for node in network.nodes:
    if node.validate(transaction):
        node.ledger.append(transaction)
network.sync_ledgers()
This code simulates creating a transaction, broadcasting it to nodes, validating it, adding it to each node's ledger, and syncing ledgers.
Execution Table
StepActionTransaction StateNode Ledger StateNetwork State
1Create transaction{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}[]Transaction ready to broadcast
2Broadcast transaction{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}[]Transaction sent to all nodes
3Node 1 validatesValid[]Waiting to add transaction
4Node 1 adds to ledgerValid[{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]Partial ledger updated
5Node 2 validatesValid[]Waiting to add transaction
6Node 2 adds to ledgerValid[{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]Partial ledger updated
7Sync ledgersValid[{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]All ledgers synchronized
8Consensus achievedValid[{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]Ledger consistent across network
💡 All nodes have validated and added the transaction; ledgers are synchronized and consensus is reached.
Variable Tracker
VariableStartAfter Step 4After Step 6Final
transactionNone{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}
Node 1 ledger[][{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}][{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}][{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]
Node 2 ledger[][][{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}][{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]
Network stateIdleTransaction sent to all nodesPartial ledger updatedLedger consistent across network
Key Moments - 3 Insights
Why do all nodes need to validate the transaction before adding it to their ledger?
Each node must check the transaction to ensure it is valid and not fraudulent. This prevents bad data from entering the ledger, as shown in steps 3 and 5 where nodes validate before adding.
What happens if one node's ledger is different from others after adding a transaction?
The network syncs ledgers to keep them consistent, as seen in step 7. This synchronization ensures all nodes have the same ledger state, preventing conflicts.
Why is consensus important in a distributed ledger?
Consensus means all nodes agree on the ledger's content, ensuring trust and preventing fraud. Step 8 shows consensus achieved after synchronization.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of Node 1's ledger after step 4?
ATransaction not added yet
B[]
C[{'sender': 'Alice', 'receiver': 'Bob', 'amount': 10}]
DLedger empty
💡 Hint
Check the 'Node Ledger State' column at step 4 in the execution_table.
At which step does the network synchronize all ledgers?
AStep 7
BStep 5
CStep 3
DStep 2
💡 Hint
Look for the action 'Sync ledgers' in the execution_table.
If Node 2 did not validate the transaction, what would happen to its ledger after step 6?
AIt would include the transaction anyway
BIt would remain empty
CIt would crash
DIt would sync automatically
💡 Hint
Refer to the 'Node Ledger State' and validation steps in the execution_table and variable_tracker.
Concept Snapshot
Distributed Ledger Concept:
- Transactions are created and broadcast to all nodes.
- Each node validates transactions independently.
- Valid transactions are added to each node's ledger.
- Ledgers are synchronized to keep data consistent.
- Consensus ensures all nodes agree on the ledger state.
Full Transcript
This visual execution shows how a distributed ledger works in a blockchain network. First, a transaction is created by a user. Then, it is broadcast to all nodes in the network. Each node receives the transaction and validates it to check if it is correct and not fraudulent. If valid, the node adds the transaction to its own ledger. After all nodes add the transaction, the network synchronizes the ledgers to make sure they all have the same data. Finally, consensus is reached when all nodes agree on the ledger's content, ensuring trust and consistency across the network.