# 95-702 Distributed Systems Project 3 ### Author Le-Hao, Hsu (Gavin Hsu) ### Andrew Id: lehaoh ## Task 0 ### Task 0 Execution ``` 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 0 Current size of chain: 1 Difficulty of most recent block: 2 Total difficulty for all blocks: 2 Approximate hashes per second on this machine: 2375296 Expected total hashes required for the whole chain: 256.0 Nonce for the most recent block: 304 Chain hash: 00E1613831F69101BBBAA51BBB285C98CC55BF96B8035406C080344299BDDEE0 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Alice pays Bob 100DSCoin Total execution time was 6 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Bob pays Carol 50DSCoin Total execution time was 4 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Carol pays Donna 10 DSCoin Total execution time was 2 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 3 View the Blockchain {"ds_chain": "["{"index":0,"time stamp ":"2022-10-28 16:47:24.988", "Tx ":"Genesis","PrevHash ":"","nonce":304, "difficulty":2}", "{"index":1,"time stamp ":"2022-10-28 17:03:29.729", "Tx ":"Alice pays Bob 100DSCoin", "PrevHash":"00E1613831F69101BBBAA51BBB285C98CC55BF96B8035406C080344299BDDEE0", "nonce":285,"difficulty":2}", "{"index":2,"time stamp ":"2022-10-28 17:05:39.994", "Tx ":"Bob pays Carol 50DSCoin", "PrevHash":"0067A51584B0CB75BD57E377F58F3FAA4658A6F49F36D1778C7208804AD1D219", "nonce":145,"difficulty":2}", "{"index":3,"time stamp ":"2022-10-28 17:06:51.353", "Tx ":"Carol pays Donna 10 DSCoin", "PrevHash ":"0064F804A776E4C65C7967B31AF744778F0C771E00A8EABFD634640E1C89290A", "nonce":63,"difficulty":2}"]", "chainHash":"000AA45954E697AB25B0EA923300EC87CD052DC6F8A41E2D683C0EAB06C27D1D"} 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 4 corrupt the Blockchain Enter block ID of block to corrupt 1 Enter new data for block 1 Alice pays Bob 76 DScoin Block 1 now holds Alice pays Bob 76 DScoin 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 3 View the Blockchain {"ds_chain": "["{"index":0,"time stamp ":"2022-10-28 16:47:24.988", "Tx ":"Genesis","PrevHash ":"","nonce":304,"difficulty":2}", "{"index":1,"time stamp ":"2022-10-28 17:03:29.729", "Tx ":"Alice pays Bob 76 DScoin", "PrevHash ":"00E1613831F69101BBBAA51BBB285C98CC55BF96B8035406C080344299BDDEE0", "nonce":285,"difficulty":2}", "{"index":2,"time stamp ":"2022-10-28 17:05:39.994", "Tx ":"Bob pays Carol 50DSCoin", "PrevHash ":"0067A51584B0CB75BD57E377F58F3FAA4658A6F49F36D1778C7208804AD1D219", "nonce":145,"difficulty":2}", "{"index":3,"time stamp ":"2022-10-28 17:06:51.353", "Tx ":"Carol pays Donna 10 DSCoin", "PrevHash ":"0064F804A776E4C65C7967B31AF744778F0C771E00A8EABFD634640E1C89290A", "nonce":63,"difficulty":2}"]", "chainHash":"000AA45954E697AB25B0EA923300EC87CD052DC6F8A41E2D683C0EAB06C27D1D"} 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain verification: FALSE Improper hash on node 1 Does not begin with 00 Total execution time to verify the chain was 1 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 5 Total execution time required to repair the chain was 5 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 4 Enter transaction Donna pays Sean 25 DScoin Total execution time was 169 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 0 Current size of chain: 5 Difficulty of most recent block: 4 Total difficulty for all blocks: 12 Approximate hashes per second on this machine: 2375296 Expected total hashes required for the whole chain: 66560.0 Nonce for the most recent block: 39563 Chain hash: 0000FCDFF92976C2167D4192B1C3E960FE566DF5D9B0FD75B03BAA279ECE3CDC 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 6 Process finished with exit code 0 ``` ### Task 0 Block.java ![](https://i.imgur.com/ZKTFWCl.png) ![](https://i.imgur.com/sZBIqeJ.png) ![](https://i.imgur.com/9H7e0Qo.png) ![](https://i.imgur.com/Q2xRFNo.png) ![](https://i.imgur.com/RSK0Woc.png) ### Task 0 BlockChain.java ![](https://i.imgur.com/xHeAA1H.png) ![](https://i.imgur.com/u6reTNG.png) ![](https://i.imgur.com/LtHY4DP.png) ![](https://i.imgur.com/OBTJwjy.png) ![](https://i.imgur.com/3tgdDeh.png) ![](https://i.imgur.com/E2EP2IW.png) ![](https://i.imgur.com/Yl6UCQU.png) ![](https://i.imgur.com/K4mQgph.png) ![](https://i.imgur.com/xx3VeSj.png) ![](https://i.imgur.com/mcqxqBO.png) ### The analysis in the main routine *Comment is in the below of the code* 1. addBlock() ![](https://i.imgur.com/vsNgSSf.png) ``` 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Difficulty equals 2 Total execution time was 1 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 3 Enter transaction Difficulty equals 3 Total execution time was 8 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 4 Enter transaction Difficulty equals 4 Total execution time was 29 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 5 Enter transaction Difficulty equals 5 Total execution time was 816 milliseconds ``` 2. isChainValid() & chainRepair() ![](https://i.imgur.com/9khVr0T.png) ``` 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 4 corrupt the Blockchain Enter block ID of block to corrupt 3 Enter new data for block 3 Corrupt block 3 Block 3 now holds Corrupt block 3 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 5 Total execution time required to repair the chain was 652 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 4 corrupt the Blockchain Enter block ID of block to corrupt 4 Enter new data for block 4 Corrupt block 4 Block 4 now holds Corrupt block 4 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain verification: FALSE Improper hash on node 4 Does not begin with 00000 Total execution time to verify the chain was 2 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 5 Total execution time required to repair the chain was 1848 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds ``` ## Task1 ## Task 1 Client Side Execution ``` The client is running. Please enter server port: 6789 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 0 Current size of chain: 1 Difficulty of most recent block: 2 Total difficulty for all blocks: 2 Approximate hashes per second on this machine: 2475247 Expected total hashes required for the whole chain: 256.0 Nonce for the most recent block: 50 Chain hash: 00B3AF7E0A12DF2FE87007728AA78FFEB1478130CFDEAF0DCE8C1E378A58FDC6 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Alice pays Bob 100DSCoin Total execution time was 6 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Bob pays Carol 50DSCoin Total execution time was 3 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 2 Enter transaction Carol pays Donna 10 DSCoin Total execution time was 1 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 3 View the Blockchain {"ds_chain": "["{"index":0,"time stamp ":"2022-10-31 03:09:53.721", "Tx ":"Genesis","PrevHash ":"","nonce":50,"difficulty":2}", "{"index":1,"time stamp ":"2022-10-31 03:10:09.158", "Tx ":"Alice pays Bob 100DSCoin", "PrevHash ":"00B3AF7E0A12DF2FE87007728AA78FFEB1478130CFDEAF0DCE8C1E378A58FDC6", "nonce":135,"difficulty":2}", "{"index":2,"time stamp ":"2022-10-31 03:10:22.94", "Tx ":"Bob pays Carol 50DSCoin", "PrevHash ":"00E39555ADA83C280660B575BA5D72F2DBE833292D4EF676AC6C94C9D41EEC06", "nonce":67,"difficulty":2}", "{"index":3,"time stamp ":"2022-10-31 03:10:34.685", "Tx ":"Carol pays Donna 10 DSCoin", "PrevHash ":"0090B614E9E3C0BEF7C4F493266CBF337DABFED379F9449650A9B12773F69A91", "nonce":24,"difficulty":2}"]", "chainHash":"00BB3DB92B60CADC4DD84CC80C82846E449411F359399DA99887E4C55911AFA6"} 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 4 corrupt the Blockchain Enter block ID of block to corrupt 1 Enter new data for block 1 Alice pays Bob 76 DScoin Block 1 now holds Alice pays Bob 76 DScoin 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 3 View the Blockchain {"ds_chain": "["{"index":0,"time stamp ":"2022-10-31 03:09:53.721", "Tx ":"Genesis","PrevHash ":"","nonce":50,"difficulty":2}", "{"index":1,"time stamp ":"2022-10-31 03:10:09.158", "Tx ":"Alice pays Bob 76 DScoin", "PrevHash ":"00B3AF7E0A12DF2FE87007728AA78FFEB1478130CFDEAF0DCE8C1E378A58FDC6", "nonce":135,"difficulty":2}", "{"index":2,"time stamp ":"2022-10-31 03:10:22.94", "Tx ":"Bob pays Carol 50DSCoin", "PrevHash ":"00E39555ADA83C280660B575BA5D72F2DBE833292D4EF676AC6C94C9D41EEC06", "nonce":67,"difficulty":2}", "{"index":3,"time stamp ":"2022-10-31 03:10:34.685", "Tx ":"Carol pays Donna 10 DSCoin", "PrevHash ":"0090B614E9E3C0BEF7C4F493266CBF337DABFED379F9449650A9B12773F69A91", "nonce":24,"difficulty":2}"]", "chainHash":"00BB3DB92B60CADC4DD84CC80C82846E449411F359399DA99887E4C55911AFA6"} 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain verification: FALSE Improper hash on node 1 Does not begin with 00 Total execution time to verify the chain was 1 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 5 Total execution time required to repair the chain was 10 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 2 Chain Verification: TRUE Total execution time to verify the chain was 0 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 1 Enter difficulty > 0 4 Enter transaction Donna pays Sean 25 DScoin Total execution time was 204 milliseconds 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 0 Current size of chain: 5 Difficulty of most recent block: 4 Total difficulty for all blocks: 12 Approximate hashes per second on this machine: 2475247 Expected total hashes required for the whole chain: 66560.0 Nonce for the most recent block: 51812 Chain hash: 0000A3A301A9A280EFB5F793C92EABF756E2ED2085B68C12A55F2369AEA78ADF 0. View basic blockchain status. 1. Add a transaction to the blockchain. 2. Verify the blockchain. 3. View the blockchain. 4. Corrupt the chain. 5. Hide the corruption by repairing the chain. 6. Exit 6 Client side quitting. The remote variable server is still running. ``` ### Task 1 Server Side Execution ``` Blockchain server running. We have a visitor Response: {"selection":1,"size":"1", "chainHash":"00B3AF7E0A12DF2FE87007728AA78FFEB1478130CFDEAF0DCE8C1E378A58FDC6", "totalHashes":"256.0","totalDiff":"2","recentNonce":"50","diff":"2", "hps":"2475247"} Adding a block Setting response to Total Execution time to add to this block was 6 milliseconds ...{"selection":1, "response":"Total Execution time to add to this block was 6 milliseconds"} Adding a block Setting response to Total Execution time to add to this block was 3 milliseconds ...{"selection":1, "response":"Total Execution time to add to this block was 3 milliseconds"} Adding a block Setting response to Total Execution time to add to this block was 1 milliseconds ...{"selection":1, "response":"Total Execution time to add to this block was 1 milliseconds"} Verifying entire chain Chain Verification: TRUE Total execution time required to verify the chain was 0 milliseconds Setting response to Total execution time to verify the chain was 0 milliseconds View the Blockchain Setting response to {"ds_chain": "["{"index":0,"time stamp ":"2022-10-31 03:09:53.721","Tx ":"Genesis", "PrevHash ":"","nonce":50,"difficulty":2}", "{"index":1,"time stamp ":"2022-10-31 03:10:09.158", "Tx ":"Alice pays Bob 100DSCoin", "PrevHash ":"00B3AF7E0A12DF2FE87007728AA78FFEB1478130CFDEAF0DCE8C1E378A58FDC6", "nonce":135,"difficulty":2}", "{"index":2,"time stamp ":"2022-10-31 03:10:22.94", "Tx ":"Bob pays Carol 50DSCoin", "PrevHash ":"00E39555ADA83C280660B575BA5D72F2DBE833292D4EF676AC6C94C9D41EEC06", "nonce":67,"difficulty":2}", "{"index":3,"time stamp ":"2022-10-31 03:10:34.685", "Tx ":"Carol pays Donna 10 DSCoin", "PrevHash ":"0090B614E9E3C0BEF7C4F493266CBF337DABFED379F9449650A9B12773F69A91", "nonce":24,"difficulty":2}"]", "chainHash":"00BB3DB92B60CADC4DD84CC80C82846E449411F359399DA99887E4C55911AFA6"} Corrupt the Blockchain Block 1 now holds Alice pays Bob 76 DScoin Setting response to Block 1 now holds Alice pays Bob 76 DScoin View the Blockchain Setting response to {"ds_chain": "["{"index":0,"time stamp ":"2022-10-31 03:09:53.721","Tx ":"Genesis", "PrevHash ":"","nonce":50,"difficulty":2}", "{"index":1,"time stamp ":"2022-10-31 03:10:09.158", "Tx ":"Alice pays Bob 76 DScoin", "PrevHash ":"00B3AF7E0A12DF2FE87007728AA78FFEB1478130CFDEAF0DCE8C1E378A58FDC6", "nonce":135,"difficulty":2}", "{"index":2,"time stamp ":"2022-10-31 03:10:22.94", "Tx ":"Bob pays Carol 50DSCoin", "PrevHash ":"00E39555ADA83C280660B575BA5D72F2DBE833292D4EF676AC6C94C9D41EEC06", "nonce":67,"difficulty":2}", "{"index":3,"time stamp ":"2022-10-31 03:10:34.685", "Tx ":"Carol pays Donna 10 DSCoin", "PrevHash ":"0090B614E9E3C0BEF7C4F493266CBF337DABFED379F9449650A9B12773F69A91", "nonce":24,"difficulty":2}"]", "chainHash":"00BB3DB92B60CADC4DD84CC80C82846E449411F359399DA99887E4C55911AFA6"} Verifying entire chain Chain verification: FALSE Improper hash on node 1 Does not begin with 00 Total execution time required to verify the chain was 1 milliseconds Setting response to Total execution time to verify the chain was 1 milliseconds Repairing the entire chain Setting response to Total execution time required to repair the chain was 10 milliseconds Verifying entire chain Chain Verification: TRUE Total execution time required to verify the chain was 0 milliseconds Setting response to Total execution time to verify the chain was 0 milliseconds Adding a block Setting response to Total Execution time to add to this block was 204 milliseconds ...{"selection":1,"response":"Total Execution time to add to this block was 204 milliseconds"} Response: {"selection":1,"size":"5", "chainHash":"0000A3A301A9A280EFB5F793C92EABF756E2ED2085B68C12A55F2369AEA78ADF", "totalHashes":"66560.0","totalDiff":"12","recentNonce":"51812","diff":"4", "hps":"2475247"} ``` ### Task 1 Client Source Code ![](https://i.imgur.com/HdEyF7X.png) ![](https://i.imgur.com/iE9E35e.png) ### Task 1 Server Source Code ![](https://i.imgur.com/d4YL9fo.png) ![](https://i.imgur.com/ZKM4bEL.png)