Ethereum networks (mainnet, testnet) in Blockchain / Solidity - Time & Space Complexity
When working with Ethereum networks like mainnet and testnet, it's important to understand how the time to process transactions grows as more data is involved.
We want to know how the execution time changes when the number of transactions or blocks increases.
Analyze the time complexity of the following simplified code snippet that processes blocks on an Ethereum network.
function processBlocks(blocks) {
for (let i = 0; i < blocks.length; i++) {
processTransactions(blocks[i].transactions);
}
}
function processTransactions(transactions) {
for (let j = 0; j < transactions.length; j++) {
verifyTransaction(transactions[j]);
}
}
This code goes through each block and then through each transaction inside that block to verify it.
Look at the loops that repeat work:
- Primary operation: Looping through all blocks and then all transactions inside each block.
- How many times: The outer loop runs once per block, and the inner loop runs once per transaction in that block.
As the number of blocks and transactions grows, the total work grows too.
| Input Size (blocks * avg transactions) | Approx. Operations |
|---|---|
| 10 blocks * 10 tx | 100 operations |
| 100 blocks * 10 tx | 1,000 operations |
| 100 blocks * 100 tx | 10,000 operations |
Pattern observation: The total work grows roughly with the total number of transactions processed across all blocks.
Time Complexity: O(b * t)
This means the time grows in proportion to the number of blocks times the average number of transactions per block.
[X] Wrong: "Processing blocks is always constant time regardless of transactions inside."
[OK] Correct: Each block can have many transactions, so the time depends on both blocks and transactions, not just blocks alone.
Understanding how processing time grows with blocks and transactions helps you explain blockchain performance clearly and confidently in real-world discussions.
"What if we only processed every 10th block? How would the time complexity change?"
Practice
Solution
Step 1: Understand the purpose of testnets
Testnets are designed for testing and development without real value at risk.Step 2: Compare with mainnet
Mainnet is the live network where real transactions and value exist, so testing there risks real money.Final Answer:
Testnet -> Option CQuick Check:
Testnet = Safe testing network [OK]
- Confusing mainnet with testnet
- Thinking private network is the default test environment
- Assuming production network is safe for testing
Solution
Step 1: Recall Ethereum network IDs
Mainnet uses network ID 1, testnets have other IDs like 3 (Ropsten), 4 (Rinkeby), 42 (Kovan).Step 2: Match the ID to mainnet
Network ID 1 corresponds to the Ethereum mainnet.Final Answer:
"networkId": 1 -> Option AQuick Check:
Mainnet networkId = 1 [OK]
- Using testnet IDs for mainnet
- Confusing networkId with chainId
- Assuming networkId 0 is valid
const provider = new ethers.providers.JsonRpcProvider("https://rinkeby.infura.io/v3/YOUR_PROJECT_ID");
const network = await provider.getNetwork();
console.log(network.name);Solution
Step 1: Identify the RPC URL
The URL contains "rinkeby.infura.io", indicating the Rinkeby testnet.Step 2: Understand provider.getNetwork()
This method returns the network info based on the RPC URL, so it will return "rinkeby".Final Answer:
"rinkeby" -> Option BQuick Check:
RPC URL domain = rinkeby [OK]
- Assuming default is mainnet
- Confusing testnet names
- Ignoring the URL and guessing
const provider = new ethers.providers.JsonRpcProvider("https://mainnet.infura.io/v3/YOUR_PROJECT_ID");
const signer = provider.getSigner();
// deploy contract code here
What is the main issue?Solution
Step 1: Examine the signer line
JsonRpcProvider.getSigner() fails because public RPC providers like Infura do not expose signing accounts or private keys.Step 2: Correct approach for deployment
Create a wallet signer: const wallet = new ethers.Wallet('0x-your-private-key', provider); const signer = wallet.connect(provider);Final Answer:
Missing private key for signer -> Option DQuick Check:
Use Wallet(privateKey, provider) for signing [OK]
- Using provider.getSigner() without wallet
- Assuming getSigner() works without wallet
- Overlooking private key requirement
Solution
Step 1: Understand deployment best practices
Testnets like Goerli are used to test contracts safely before mainnet deployment.Step 2: Apply conditional deployment logic
Deploy on Goerli, run tests, and only deploy on mainnet if tests succeed to avoid costly errors.Final Answer:
Deploy on Goerli testnet, run tests, then deploy on mainnet if tests pass -> Option AQuick Check:
Test on testnet before mainnet deployment [OK]
- Deploying on mainnet before testing
- Skipping testnets entirely
- Deploying on both networks at once
Ready to prove it?
Pass the test and this pattern moves unknown
