burstcoin硬盘挖矿原理
Proof-of-Capacity (PoC) consensus algorithm
Block generator: 产生新区块的账号
Generation Signature:基于前一个块的 generation signature 和 block generator,用来产生新块的,长度 32 bytes
Block signature:每个区块都由产生者签名,使用 Sha256 and Curve25519 和私钥签名生成 64byte long hash
平均每4分钟出一个块,一天 360 块,每 10800 块(大约30天),奖励减少 5%,
Base target:从最后 24 块计算出来,用来调整难度,base target 越低,找到低的 deadline 的难度越大。
动态调整用来保证平均 4 分钟一个区块。
plotting
硬盘上预先生成尽可能多的 plotting 文件。用于解决挖矿的公式算法问题。
每产生一个 plotting 文件,就需要生成若干个 nonce 数据,每个 nonce 包括 256Kib 数据,用来计算 deadline 的。
每个 nonce 都有自己独特的数字,范围是 $0-18446744073709551615(2^{64})$,这个数字也会用来做种子,因为每个 nonce 都会有自己一组唯一的数据。
每个 nonce 包括 8192 个 hash 编号从 0 - 8191,每对 hash 作为一个 scoop,总共包括 4096 个 scoop,
例如 hash 0 and 1 构成 scoop 0, hash 2 and 3 构成 hash 1
每个 scoop 包括 64 Bytes 数据也就是 2 个 hash 值。每个 hash 会和 final hash 做异或(final hash 会在生成 nonce 的时候得到)。
在创建 plotting 文件的时候需要绑定一个 burst account,数字 account 会在创建 nonce 的时候使用,这样就算使用相同的 nonce 也会产生不同的 plotting 文件
创建nonce
第一个 hash: 这个作为 nonce 的最后一个 hash 值 #8191
start seed = 8 bytes account id + 8 Bytes nonce number(nr)
#8191 = Shabal256(start seed)
第二个 hash:
#8190 = Shabal256(32 bytes hash #8191 + 8 bytes account id + 8 Bytes nonce nr)
如此循环迭代 128 次后,seed 超过 4096 bytes,后面的计算截取 seed 最后的 4096 个字节。
32bytes result = Shabal256((seed for 129 - 8192)last generated 4096 bytes)
当创建了 8192 个 hash 之后,我们计算 final hash。
32 bytes final hash = Shabal256(hash #0 - #8191 + 16 bytes start seed(262160 bytes))
然后 final hash 和每个 hash 单独做异或。
现在我们可以保存 nonce 到一个 plot 文件中,然后计算下一个 nonce
mining
found a nonce and a deadline
All references to wallet in this text can also be a pool depending on scenario.
All references to miner in this text is a software able to do a mining operation for Burstcoin.
miner 向 wallet 要挖矿信息,包括 a new generation signature + base target + and the next block height.
32bytes Generation hash = Shabal256(32bytes GenSig + 8 bytes Blockheight)
找到 scoop number = GenHash mod 4096 因为只有 4096 个scoops
从所有的 plot 文件中读取所有的 nonce 中的 64bytes 长的 scoop,每个单独处理
从所有的 plot 文件中的所有的 nonce 中,读取所有的 64-byte long scoops,分别处理生成各自的 target
target = Shabal256(64bytes scoop data + 64 bytes GenSig)
开始挖矿,产生一个 scoop 数字比如 38,找到 nonce 1 的 scoop 38 然后使用它的数据计算一个 deadline。
重复上面的步骤,直到把硬盘上存储的所有的 nonce 都计算完毕
选出 deadline 值最小的那个
deadline 表示一个矿工在最后一个区块挖出后,多少时间之后可以挖新区块,单位是秒,如果其他人在这段时间内没有挖出新区块,那么矿工就可以出新区块了。
例如:如果矿工 X 算出最小的 deadline 是 36 秒,如果接下来的 36 秒内没有出新区块,X 将获得出新区块的机会,并获得收益。
为了防止 nonce spamming 类似垃圾邮件的问题,miner 会检查是否 deadline 比近期生成的最小值都小,或者一个很不合理的大数字。