Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created December 14, 2020 02:47
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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

larskuhtz commented Jan 7, 2021

Miners and pools should not make any assumptions about the semantics of the work item bytes beyond what is documented here:

Size Bytes Value
8 0-7 reserved
8 8-15 time
298 16-277 reserved
8 278-285 nonce

total: 286 bytes

Only time and nonce may be modified. Modifying of time is optional. The initial value is valid. time must be strictly larger than the time of the parent header. Nodes must ignore headers with time stamps that are in the future.

Further details can be found on this wiki page.

@wittwitt
Copy link

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

block header:
0000000000000000d9f38a3a1bc20500d4e8b94b1f2e26539408152a0c09a136c2f9b4cb0c8dacbab7413b480bab83fa0300070000007e0bb745c379e348540e1c2548cb912d2188a82c1a23aa77090182a701feaafc0c00000044795fba6dd40b1f336b68a37b0114d3d3eb62f7feb74dcfb3c479f93bd323a911000000ad8356d747f19699f2260a50f84d7f7853b88796dc2138e330e506cccf72a752ffac3c9444c7277f6cbc8e57dcfabc2784fdbbb82acd7ed7510037f07acf7903d9a3081f255e23048e1822d8598a2effab0dc63a19e53ac9afa05d6457dbe20f02000000f70bcf5800000000000000000000000000000000000000000000000000000000fe0200000000000001000000a0fc18a20bc20500010085d0e51c0000

blake2s_256(block header)==8991b95fc0ea0192527669b0e75a4ae8bcbc4ff819e888624d73654700000000

but block hash is b1a285013898dc40e130ce20d66859645485693d827418de798f2b098a97f0cf

@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