blockchain - What if two blocks complete their POW at same time
问题描述
Let's consider a scenario: suppose 2 miners pick up 2 different unconfirmed transactions and they complete the proof of work. If miner A adds the block first to blockChain then the block produced by miner B be will be wrong/useless because the last_Hash he used is now wrong and he has to use the last_hash of miner A that is added right a second before he was going to add his block. e.g.
<b>current chian: block1--block2--block3</b>
<table>
<tr>
<td>Miner A </td>
<td>Miner B</td>
</tr>
<tr>
<td>LastHast=block3-hash<br>
currentHast=SHA(block3's_hash,timestemp,data,nonce) <br>
proof of work <br>
add---- Successfully add block4 <br>
</td>
<td>LastHast=block3-hash<br>
currentHast=SHA(block3's_hash,timestemp,data,nonce) <br>
proof of work <br>
add---- Fail because the last hash is now block4's not block3's So currentHash is wrong so the proof of work<br>
</td>
</tr>
</table>
**
解决方案
有效交易总是在最长的链上,最长的,我的意思是块数更大。
如果矿工 A和矿工 B 同时完成 PoW,则进行分叉
目前,minerA和minerB的交易都存储在 fullnode 上,fullnode 正在等待下一个区块的产生。
在下一个出块时间内,minerA先完成 PoW,然后minerA上的分叉(数据链)被认为更长,因此minerA成为最长的链并被认为是有效的,minerB上的块被认为是无效的,并被丢弃。
推荐阅读
- python - 使用 Electron 应用程序时如何从 Angular 组件与 Python 后端通信?
- android - 在 RxJava 中订阅 Observable 一次并多次使用它的值
- java - 事件监听器 - 实体列级监听器
- dart - 我可以在 Dart 的 switch case 中使用“is”运算符吗?
- java - Android okhttp3 握手失败,码头后端使用 https
- ruby-on-rails - Rspec询问公共方法是否在rails上调用私有的红宝石
- python - 如何找出数据框中的一行是否已存在于单独的数据框中?
- sql-server - 更新和替换查询
- php - Laravel Eloquent 查询仅从数据库表中返回一行
- android - 无法滚动浏览活动