Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created December 14, 2020 02:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightybyte/f1567c2bec0380539c638225fb8c1cf4 to your computer and use it in GitHub Desktop.
Save mightybyte/f1567c2bec0380539c638225fb8c1cf4 to your computer and use it in GitHub Desktop.
Kadena Stratum Protocol

Kadena stratum protocol

mining.subscribe

params: ["agent", null]
result: [null, "nonce1", "nonce2 size"]

nonce_1 is first part of the block header nonce in hex.

request:

{
  "id": 1,
  "method": "mining.subscribe",
  "params": ["kdaminer-v1.0.0", null]
}

response:

{
  "id": 1,
  "result": [null, "012345", 5],
  "error": null
}

mining.authorize

params: ["username", "password"]
result: true

request:

{
  "id": 2,
  "method": "mining.authorize",
  "params": ["900703b6dd2493696068af72957a94129e54e85f269becc665672bf4730fc6a3", "x"]
}

response:

{
  "id": 2,
  "result": true,
  "error": null
}

mining.set_target

params: ["32 bytes target in big endian hex"]

{
  "id": null,
  "method": "mining.set_target",
  "params": ["0001000000000000000000000000000000000000000000000000000000000000"]
}

mining.notify

params: ["jobId", "header", cleanJob]

{
  "id": null,
  "method": "mining.notify",
  "params": [
    "1234",
    "286 bytes header in hex",
    true
  ]
}

https://github.com/kadena-io/chainweb-node/wiki/Block-Header-Binary-Encoding

Size    Bytes    Value
8       0-7      nonce
8       8-15     time
32      16-47    parent
110     48-157   adjacents
32      158-189  target
32      190-221  payload
4       222-225  chain
32      226-257  weight
8       258-265  height
4       266-269  version
8       270-277  epoch start
8       278-285  flags

mining.submit

old version

params: ["username.worker", "jobId", "nonce2"]
result: true / false

request:

{
  "id": 102,
  "method": "mining.submit",
  "params": [
    "900703b6dd2493696068af72957a94129e54e85f269becc665672bf4730fc6a3.worker1",
    "1234",
    "6789abcdef"
  ]
}
===========================
GPU Mining Speedup Announcement
===========================

tl;dr New GPU miners are now available that mine 5x faster than before.

Hi Everyone,

We would like to announce a new development that is of likely interest to the Kadena mining community. A new version of NoncerPro is now available [1] that can mine more than five times faster than the previous version. A similar improvement is available for the bigolchungus miner as well [2].

For those wondering about what made this speedup possible, the last 64 bits of the block header had been reserved for future protocol changes. It was discovered that miners could use these bits as the nonce. Since these bits are at the end of the block header this makes it possible to mine significantly more efficiently. We’re announcing this to make the information available as broadly as possible to encourage a fair and decentralized mining ecosystem. We expect that other mining software, pools, etc will also come out with improvements to take advantage of this development.

If you are interested in getting more detailed information about this please reach out to us and we’ll be happy to assist.

[1] https://github.com/NoncerPro/Kadena/releases/tag/2.1.1
[2] https://github.com/kadena-community/bigolchungus/pull/20

new version

# new mining submit
params: ["username.worker", "jobId", "nonce2", "extraNonce(hex encoded `flags` field in the header)"]
result: true / false

for example:
{
  "id": 102,
  "method": "mining.submit",
  "params": [
    "900703b6dd2493696068af72957a94129e54e85f269becc665672bf4730fc6a3.worker1",
    "1234",
    "6789abcdef",
    "0123456789abcdef"
  ]
}
response:

accepted share response:

{
  "id": 102,
  "result": true,
  "error": null
}


rejected share response:

{
  "id": 102,
  "result": false,
  "error": [21, "low difficulty", null]
}


in this example:

nonce = nonce1 + nonce2 = 0123456789abcdef (hex in big endian)

we should do `reverse_bytes(hex_decode(nonce))` before writing this to the 286 header
@larskuhtz
Copy link

blake2s_256(block header) not equal block hash ,why ?

@5dao blake2s_256 is used to compute the PoW hash which is different from the block hash. The PoW hash isn't stored in the block header but recomputed on the fly and compared with the target (which is stored in the blog header) during validation.

The block hash is the root of a Merkle tree that includes all fields of the block header. The hash function that is used in the computation of the header Merkle tree is SHA512_256.

@larskuhtz
Copy link

There are now ASICs available that can compute 100-200TH/s. Those devices exhaust 6 bytes of nonce2 in less than 2-3s. (6 bytes of nonce2 corresponds to about 280TH.)

These devices must be provided with a sufficiently large nonce2 space. 7 bytes would be sufficient for almost all blocks. But that leaves only 1 byte for nonce1, which may not be enough for some pool applications. Another solution is to provide the mining device with new work before it has used up all nonces.

A stream of different work items can be produced from a single work header by increasing the timestamp of the work header according to the rate of the stream. The timestamp uses microsecond resolution. Therefore the stream could provide a device with the full nonce2 range for each microsecond. For a nonce2 of size 6, this would be about 280TH/microsecond or 280,000PH/s from a single work header. This number is increased further because chainweb-node concurrently provides headers for all available chains.

The timestamp is stored in the work header at offset 8 as a 64bit twoth complement encoded value in little endian byte order. It counts SI microseconds since POSIX epoch (leap seconds are ignored). Details about the work header format are available at this wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment