原始文献 / 论坛帖 / Re: New getwork

Re: New getwork

Bitcointalk · 2010-11-24 17:21:01 UTC

AuthorSatoshi Nakamoto
TitleRe: New getwork
Date2010-11-24 17:21:01 UTC
ForumBitcointalk · 原文

引用自 jgarzik(2010 年 11 月 24 日 04:47:42 AM)(https://bitcointalk.org/index.php?topic=1901.msg24008#msg24008):我怀疑 ByteReverse(或缺了它)有点怪。'data' 和 'nonce' 到底要不要字节反转、怎么反转,很不清楚。
getwork 会做字节反转。midstate、data 和 hash1 已经是大端序,你传回 data 时还是大端序,所以你在大端序下工作,不用做任何字节反转。它们就是传给 ScanHash_ 函数的同一份数据。你可以拿 midstate、data、hash1,放进 16 字节对齐的缓冲,传给 ScanHash_ 函数,比如 ScanHash(pmidstate, pdata + 64, phash1, nHashesDone)。如果找到 nonce,把它打进 data 再调 getwork。

我大概应该把 ScanHash_ 函数改成用 pdata 而不是 pdata + 64,这样才一致。

target 是小端序,它应该和 m0mchil 那版的做法一样。(如果不一样,那就该修)那是唯一需要字节反转的情况。我觉得做法像这样:if ByteReverse((unsigned int*)hash[6]) < (unsigned int*)target[6]。

引用自 DiabloD3(2010 年 11 月 24 日 11:31:11 AM)(https://bitcointalk.org/index.php?topic=1901.msg24050#msg24050):中本聪,请修一下你的 getwork 实现,让它符合 m0mchill 的规范。
这就是新规范。把你的矿机更新到用它应该不难。

改动是:
- 提交可能命中的结果时不返回工作,只有不带参数调用时才返回。
- block 字段拆成了 data 和 hash1。
- state 为保持一致改名为 midstate。
- 不需要 extranonce。

英文原文

Quote from: jgarzik on November 24, 2010, 04:47:42 AM(https://bitcointalk.org/index.php?topic=1901.msg24008#msg24008)I suspect something weird going on with ByteReverse (or lack thereof).  It's quite unclear whether or not 'data' and 'nonce' must be byte-reversed, and in what way.
getwork does the byte-reversing.  midstate, data and hash1 are already big-endian, and you pass data back still big-endian, so you work in big-endian and don't have to do any byte-reversing.  They're the same data that is passed to the ScanHash_ functions.  You can take midstate, data and hash1, put them in 16-byte aligned buffers and pass them to a ScanHash_ function, like ScanHash(pmidstate, pdata + 64, phash1, nHashesDone).  If a nonce is found, patch it into data and call getwork.

I should probably change the ScanHash_ functions to use pdata instead of pdata + 64 so they're consistent.

target is little endian, it's supposed to be the same as how m0mchil's did it.  (if it's not, then it should be fixed)  That's the only case where you would use byte reverse.  I think you do it like: if ByteReverse((unsigned int*)hash[6]) < (unsigned int*)target[6].

Quote from: DiabloD3 on November 24, 2010, 11:31:11 AM(https://bitcointalk.org/index.php?topic=1901.msg24050#msg24050)Satoshi, please fix your implementation of getwork so it complies with m0mchill's specification
This is the new spec.  It shouldn't be hard to update your miner to use it.

The changes are:
- It does not return work when you submit a possible hit, only when called without parameter.
- The block field has been split into data and hash1.
- state renamed to midstate for consistency.
- extranonce not needed.