diff options
| author | Bitflash <btf01@proton.me> | 2026-07-30 18:22:45 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-30 18:22:45 -0300 |
| commit | 50eeb9c9d620895c0d63664d610ea4cfe7b81a34 (patch) | |
| tree | 398a34af243fc9a5b3d97a71b01a6ba075e6ef87 /src/main.cpp | |
| parent | 10f248876aaa77e840dcb0d9585aba2fde712130 (diff) | |
mine: put the block height in the coinbase, so two can never be identical (#59)
Nothing in a coinbase belonged to the block it was in. The transaction was a
function of three things: the difficulty, a counter, and the payout key.
nBits holds still for long stretches, and bnExtraNonce is a local that
restarts at zero whenever the miner does, so the same combination comes
round again and produces a byte-identical transaction with the same txid.
Two blocks then name the same transaction. The index keeps whichever
arrived last, and the outputs of the first stop being reachable, with
nothing logged and nothing shown.
It has already happened twice on the main chain -- coinbase c9e56f7131 at
heights 841 and 859, e635f4441f at 845 and 860 -- and 100 BTF are gone
because of it. #58 has the full account.
Putting the height first makes two coinbases at different heights unequal
by construction, whatever the counter and the key do afterwards.
Nothing validates coinbase content today, so this changes only what this
node produces: blocks stay acceptable to every node already on the network,
with no coordination and no activation height. Requiring the height, and
enforcing BIP30 on top of it, is the separate coordinated step that this
one has to come before.
Verified by mining with the patch: the coinbase reads 5104ffff0f1f0101 --
OP_1 for height 1, then nBits, then the counter -- and the scriptSig is 8
bytes against the 100-byte ceiling in CheckTransaction.
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index f4e6ce2..c77448d 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -2883,7 +2883,25 @@ bool BitcoinMiner(int nThreadId) | |||
| 2883 | CTransaction txNew; | 2883 | CTransaction txNew; |
| 2884 | txNew.vin.resize(1); | 2884 | txNew.vin.resize(1); |
| 2885 | txNew.vin[0].prevout.SetNull(); | 2885 | txNew.vin[0].prevout.SetNull(); |
| 2886 | txNew.vin[0].scriptSig << nBits << ++bnExtraNonce; | 2886 | // The height comes first and is what makes this transaction unique. |
| 2887 | // | ||
| 2888 | // Without it nothing in the coinbase belongs to the block: it is a | ||
| 2889 | // function of the difficulty, a counter, and the payout key. nBits | ||
| 2890 | // holds still for long stretches and bnExtraNonce is a local that | ||
| 2891 | // restarts at zero whenever the miner does, so the same combination | ||
| 2892 | // comes round again and produces a byte-identical transaction with the | ||
| 2893 | // same txid. Two blocks then name the same transaction and the index | ||
| 2894 | // keeps whichever arrived last, which silently destroys the outputs of | ||
| 2895 | // the first. It has already happened twice on this chain, at heights | ||
| 2896 | // 859 and 860 (#58). | ||
| 2897 | // | ||
| 2898 | // Two coinbases at different heights can now never be identical, no | ||
| 2899 | // matter what the counter or the key do. | ||
| 2900 | // | ||
| 2901 | // Nothing validates coinbase content, so this changes only what we | ||
| 2902 | // produce -- nodes that do not upgrade accept these blocks unchanged. | ||
| 2903 | // Requiring the height is a separate, coordinated step. | ||
| 2904 | txNew.vin[0].scriptSig << (pindexPrev ? pindexPrev->nHeight + 1 : 0) << nBits << ++bnExtraNonce; | ||
| 2887 | txNew.vout.resize(1); | 2905 | txNew.vout.resize(1); |
| 2888 | // Always pay coinbase to own wallet key. In operator mode, the pool | 2906 | // Always pay coinbase to own wallet key. In operator mode, the pool |
| 2889 | // server distributes shares to miners via SendMoney() after each block. | 2907 | // server distributes shares to miners via SendMoney() after each block. |