Bitcoin Forum
May 24, 2022, 07:22:07 PM
 News: Latest Bitcoin Core release: 23.0 [Torrent]
 Home Help Search Login Register More
 Pages: [1]
 Author Topic: Where is the block reward function?  (Read 3387 times)
misterbigg
Legendary

Offline

Activity: 1064
Merit: 1001

 December 13, 2012, 02:47:31 PM

Can someone please point me to the block reward function in the source code? There is some debate whether the reward ceases to exist on 2040, or 2140 (the Wikipedia entry lists 2140).

Thanks
1653420127
Hero Member

Offline

Posts: 1653420127

Ignore
 1653420127

1653420127
 Report to moderator
1653420127
Hero Member

Offline

Posts: 1653420127

Ignore
 1653420127

1653420127
 Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1653420127
Hero Member

Offline

Posts: 1653420127

Ignore
 1653420127

1653420127
 Report to moderator
DannyHamilton
Legendary

Offline

Activity: 2800
Merit: 3096

 December 13, 2012, 03:04:15 PMLast edit: December 13, 2012, 03:31:25 PM by DannyHamilton

I'm not sure exactly where in the code it is handled, but the protocol and math are pretty clear and simple:

Start with a subsidy of 50 BTC (represented in the output as an integer of 5000000000)
Every 210,000 blocks cut the subsidy in half (handled by performing a bitwise right shift on the integer value of the initial block reward)

This bitwise right shift puts the block subsidy at 0 in block 6,930,000

There are an average of approximately 6 blocks per hour.

6 blocks per hour multiplied by 24 hours per day multiplied by 365.25 days per year gives us approximately 52,596 blocks per year.

block number 6930000 divided by 52596 blocks per year tells us the block subsidy will cease to exist approximately 131 years after block 0 was created.

Block 0 was created in 2009

2009 + 131 = 2140

Looks like Wikipedia is right.

Why did you think it would be 2040?
DannyHamilton
Legendary

Offline

Activity: 2800
Merit: 3096

 December 13, 2012, 03:22:37 PM

Looks like you can see the code here:

https://github.com/bitcoin/bitcoin/blob/v0.7.1/src/main.cpp

Quote
int64 static GetBlockValue(int nHeight, int64 nFees)
{
int64 nSubsidy = 50 * COIN;

// Subsidy is cut in half every 210000 blocks, which will occur approximately every 4 years
nSubsidy >>= (nHeight / 210000);

return nSubsidy + nFees;
}
zebedee
Donator
Hero Member

Offline

Activity: 668
Merit: 500

 December 14, 2012, 12:56:33 PM

Looks like you can see the code here:

https://github.com/bitcoin/bitcoin/blob/v0.7.1/src/main.cpp

Quote
int64 static GetBlockValue(int nHeight, int64 nFees)
{
int64 nSubsidy = 50 * COIN;

// Subsidy is cut in half every 210000 blocks, which will occur approximately every 4 years
nSubsidy >>= (nHeight / 210000);

return nSubsidy + nFees;
}
As I've pointed out before, this is shoddy code.  Once nHeight is about 13.23 million (admittedly some way off) this code has undefined right-shift behaviour.  It needs a conditional such as

if (nHeight / 210k >= 63)
nSubsidy = 0;
else
nSubsidy >>= (nHeight / 210k);

Why code is written with nFees, nHeight and nSubsidy as signed integers, given they can only ever be non-negative, is also weak and a source of bugs IMO.
dree12
Legendary

Offline

Activity: 1246
Merit: 1058

 December 14, 2012, 01:01:24 PM

Looks like you can see the code here:

https://github.com/bitcoin/bitcoin/blob/v0.7.1/src/main.cpp

Quote
int64 static GetBlockValue(int nHeight, int64 nFees)
{
int64 nSubsidy = 50 * COIN;

// Subsidy is cut in half every 210000 blocks, which will occur approximately every 4 years
nSubsidy >>= (nHeight / 210000);

return nSubsidy + nFees;
}
As I've pointed out before, this is shoddy code.  Once nHeight is about 13.23 million (admittedly some way off) this code has undefined right-shift behaviour.  It needs a conditional such as

if (nHeight / 210k >= 63)
nSubsidy = 0;
else
nSubsidy >>= (nHeight / 210k);

Why code is written with nFees, nHeight and nSubsidy as signed integers, given they can only ever be non-negative, is also weak and a source of bugs IMO.
I'm sure you've seen this problem with using unsigned integers.
grau
Hero Member

Offline

Activity: 836
Merit: 1000

bits of proof

 December 14, 2012, 01:45:08 PM

lets fix this within the next 127 years, otherwise we will have 50 BTC blocks again.
gmaxwell
Moderator
Legendary

Offline

Activity: 3668
Merit: 6171

 December 14, 2012, 02:26:23 PM

lets fix this within the next 127 years, otherwise we will have 50 BTC blocks again.
You mean 246 years, right?
grau
Hero Member

Offline

Activity: 836
Merit: 1000

bits of proof

 December 14, 2012, 05:55:30 PM

lets fix this within the next 127 years, otherwise we will have 50 BTC blocks again.
You mean 246 years, right?
Block reward will be 0 in years:
Code:
N[Ceiling[Log2[25*100000000]]*210000*10/60/24/365]
127.854
It will be 50 BTC again as nHeight overflows in about 40853 years.
Code:
N[(2^31 - 1 - 212190)*10/60/24/365]
40853.7
Shift with negative numbers will thereafter exponentially increase block reward and destroy the economy in a hyperinflation.

Let us do something against it in this century!
grau
Hero Member

Offline

Activity: 836
Merit: 1000

bits of proof

 December 14, 2012, 06:28:58 PM

BTW the expected date of the first 0 reward block is 5th September 2140

Code:
DatePlus[{2012, 12,
14}, (2*210000 - 212196 +
Ceiling[Log2[12.5 * 100000000]]*210000)*10/60/24]
{2140, 9, 5, 10}
DannyHamilton
Legendary

Offline

Activity: 2800
Merit: 3096

 December 14, 2012, 07:13:01 PM

. . . Once nHeight is about 13.23 million . . . this code has undefined right-shift behaviour . . .

Before we start worrying about improvements to code that won't be a problem for over 130 years, can we first deal with the more pressing problem of storing the block time stamp as UNIX epoch time in a 4 byte unsigned integer?  Unless I'm mistaken this time stamp will roll over in only 93 years on 2106-02-07!

gmaxwell
Moderator
Legendary

Offline

Activity: 3668
Merit: 6171

 December 15, 2012, 01:01:18 AM

lets fix this within the next 127 years, otherwise we will have 50 BTC blocks again.
You mean 246 years, right?

It's still 246 years before the shift becomes undefined (I'm mostly asking to confirm that you are not expecting to use int32 or uint32 to hold bitcoin values…).
grau
Hero Member

Offline

Activity: 836
Merit: 1000

bits of proof

 December 15, 2012, 07:03:33 AM

lets fix this within the next 127 years, otherwise we will have 50 BTC blocks again.
You mean 246 years, right?

It's still 246 years before the shift becomes undefined (I'm mostly asking to confirm that you are not expecting to use int32 or uint32 to hold bitcoin values…).
Would you explain the 246 ?

Since there never will be more than 2099999997690000 satoshis, therefore 51 bits would be sufficient to hold them, even if they would choose to gather at the same place.

I offer a couple more at their places, so they can fit loosely and feel that I threat them with respect.
gmaxwell
Moderator
Legendary

Offline

Activity: 3668
Merit: 6171

 December 15, 2012, 05:54:42 PM

Would you explain the 246 ?
Because that is roughly when (well, a couple years before) the shift would go from 63 to 64 and become undefined. (See the standard, "The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand."). Until then its just outputting zero which is the reasonable and expected behavior, after then the compiler is permitted to end the universe (but more likely it will return 0 on some systems and 50 BTC on others).
grau
Hero Member

Offline

Activity: 836
Merit: 1000

bits of proof

 December 15, 2012, 07:40:19 PM

Would you explain the 246 ?
Because that is roughly when (well, a couple years before) the shift would go from 63 to 64 and become undefined. (See the standard, "The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand."). Until then its just outputting zero which is the reasonable and expected behavior, after then the compiler is permitted to end the universe (but more likely it will return 0 on some systems and 50 BTC on others).

Sounds exciting, let us leave it as it is, I want to see it happening then.
dree12
Legendary

Offline

Activity: 1246
Merit: 1058

 December 15, 2012, 09:40:14 PM

Would you explain the 246 ?
Because that is roughly when (well, a couple years before) the shift would go from 63 to 64 and become undefined. (See the standard, "The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand."). Until then its just outputting zero which is the reasonable and expected behavior, after then the compiler is permitted to end the universe (but more likely it will return 0 on some systems and 50 BTC on others).

Sounds exciting, let us leave it as it is, I want to see it happening then.
I doubt Bitcoin will be around then. I doubt computers will be around then. Heck, I doubt humans as we know them will be around them. With power comes responsibility, and with the nigh-infinite power mankind is achieving I doubt we're responsible enough.
 Pages: [1]