Skip to content

coinbaser: Build coinb1/coinb2 hex in a per-call buffer and keep each job's coinbase as one binary transaction - #28

Open
iohzrd wants to merge 1 commit into
CONVOYMining:masterfrom
iohzrd:coinbase-binary-parts
Open

iohzrd wants to merge 1 commit into
CONVOYMining:masterfrom
iohzrd:coinbase-binary-parts

Conversation

@iohzrd

@iohzrd iohzrd commented Oct 6, 2026 •

Copy link
Copy Markdown

Based on #24, whose two commits come first here. Review the last commit.

T_DATUM_STRATUM_COINBASE held each coinbase twice: in ascii hex (coinb1, coinb2) and in binary (coinb1_bin, coinb2_bin). Only the coinbaser reads the hex, which it builds and then converts. Every share, notify and DATUM submission reads the binary parts, and two of those readers rebuilt the full transaction (coinb1, 12 zero extranonce bytes, coinb2) on the stack each time. BLAKE2b work sends the miner a 39-byte coinb1 computed from the commitment, so the coinb1/coinb2 split is now only needed for the share's coinbase section. Each job holds seven coinbases (MAX_COINBASE_TYPES plus the subsidy-only one), and update_stratum_job zeroes the whole job, so every job slot's buffers become resident.

  • T_DATUM_STRATUM_COINBASE is now txn[MAX_COINBASE_TXN_SIZE_BYTES], the coinbase transaction (coinb1, 12 zero extranonce bytes, coinb2), plus coinb1_len and coinb2_len.
  • T_DATUM_COINBASE_HEX (datum_coinbaser.h) holds one coinbase's coinb1 and coinb2 in hex. generate_base_coinbase_txns_for_stratum_job and generate_coinbase_txns_for_stratum_job calloc one per coinbase they build and free them on return. generate_coinbase_txns_for_stratum_job_subtypebysize takes the array. datum_coinbase_hex_to_bin writes txn and replaces the four copies of the hex-to-binary loop.
  • client_mining_submit copies txn with one memcpy. The share's coinbase section sends txn[0, coinb1_len) and the coinb2 after the extranonce bytes, so the wire format is unchanged.
  • datum_stratum_job_blake2b_commitment, which runs for each notify, hashes txn in place with the PoT byte substituted, through double_sha256_with_byte (libsodium's incremental SHA-256). It used to copy the coinbase to the stack first. Its frame drops from 17056 bytes to 128 (gcc 16.2, x86_64, default CMake build).
  • BSS goes from 150.0 MB to 89.5 MB.
  • Tests: the coinbases built for an empty job are checked in txn. Class 0 has the right version, input count, zero extranonce bytes, sequence, outputs and lock time; the other classes equal class 0; the subsidy-only coinbase pays the block reward. The existing commitment test compares the in-place hash with hashing a copy that has the PoT byte written.

Every commit builds with -Wall -Werror and passes --test.

@luke-jr

luke-jr commented Oct 8, 2026

Copy link
Copy Markdown

Why not just combine them into a single transaction?

@iohzrd
iohzrd force-pushed the coinbase-binary-parts branch from 0a54867 to fd8631d Compare October 9, 2026 01:18
@iohzrd iohzrd changed the title coinbaser: Build coinb1/coinb2 hex in a per-call buffer and keep only the binary parts in each job coinbaser: Build coinb1/coinb2 hex in a per-call buffer and keep each job's coinbase as one binary transaction Oct 9, 2026
@iohzrd

iohzrd commented Oct 9, 2026 •

Copy link
Copy Markdown
Author

Done in fd8631d. T_DATUM_STRATUM_COINBASE is now one txn (coinb1, 12 zero extranonce bytes, coinb2) plus the two lengths. The share's coinbase section sends the two parts out of it, client_mining_submit copies it with one memcpy, and the notify commitment hashes it in place with the PoT byte substituted, so its 17 KB stack copy is gone. #29 and #30 are rebased onto it. I was on the fence between the two...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants