<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Wyager</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Wyager"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Wyager"/>
	<updated>2026-04-10T01:34:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Controlled_supply&amp;diff=44708</id>
		<title>Controlled supply</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Controlled_supply&amp;diff=44708"/>
		<updated>2014-03-03T05:55:42Z</updated>

		<summary type="html">&lt;p&gt;Wyager: Added possible justifications for the 21 million Bitcoin cap&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In a centralized economy, currency is issued by a central bank at a rate that is supposed to match the growth of the amount of goods that are exchanged so that these goods can be traded with stable prices. The &lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Monetary_base monetary base]&amp;lt;/span&amp;gt; is controlled by a central bank. In the United States, the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Federal_Reserve_System Fed]&amp;lt;/span&amp;gt; increases the monetary base by issuing currency, increasing the amount banks have on reserve, and more recently, printing money electronically in a process called &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Quantitative_easing Quantitative Easing]&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In a fully decentralized monetary system, there is no central authority that regulates the monetary base. Instead, currency is created by the nodes of a peer-to-peer network. The Bitcoin generation algorithm defines, in advance, how currency will be created and at what rate. Any currency that is generated by a malicious user that does not follow the rules will be rejected by the network and thus is worthless.&lt;br /&gt;
&lt;br /&gt;
==Currency with Finite Supply==&lt;br /&gt;
&lt;br /&gt;
Bitcoins are created each time a user discovers a new [[block]]. &lt;br /&gt;
The rate of block creation is approximately constant over time: 6 per hour. The &lt;br /&gt;
number of Bitcoins generated per block is set to decrease geometrically, with a 50% reduction every 4 years. The result is that the number of Bitcoins in existence will &lt;br /&gt;
never exceed 21 million&amp;lt;ref&amp;gt;[http://www.bitcointalk.org/index.php?topic=3366.msg47522#msg47522 21 million cap]&amp;lt;/ref&amp;gt;. This algorithm was chosen because it approximates the rate at which commodities like gold are mined. Possible justifications for the value 21 million are that it matches a 4-year reward halving schedule or that 2.1*10^15 (the maximum number of Satoshis) is close to the maximum exact capacity of a 64-bit floating point number. Users who use their computers to perform calculations to try and discover a block are thus called [[Mining|&#039;&#039;Miners&#039;&#039;]].&lt;br /&gt;
&lt;br /&gt;
==Projected Bitcoins Short Term ==&lt;br /&gt;
This chart shows the number of bitcoins that will exist in the near future. The &#039;&#039;Year&#039;&#039; is a forecast and may be slightly off.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!    Block!!Reward Era!!   BTC/block!!    Year!!         Start BTC!!         BTC Added!!           End BTC!!    BTC Increase|| End BTC % of Limit&lt;br /&gt;
|-&lt;br /&gt;
|0||1||50.00||2009||0||2625000||2625000||infinite||12.500%&lt;br /&gt;
|-&lt;br /&gt;
|52500||1||50.00||2010||2625000||2625000||5250000||100.00%||25.000%&lt;br /&gt;
|-&lt;br /&gt;
|105000||1||50.00||2011||5250000||2625000||7875000||50.00%||37.500%&lt;br /&gt;
|-&lt;br /&gt;
|157500||1||50.00||2012||7875000||2625000||10500000||33.33%||50.000%&lt;br /&gt;
|-&lt;br /&gt;
|210000||2||25.00||2013||10500000||1312500||11812500||12.50%||56.250%&lt;br /&gt;
|-&lt;br /&gt;
|262500||2||25.00||2014||11812500||1312500||13125000||11.11%||62.500%&lt;br /&gt;
|-&lt;br /&gt;
|315000||2||25.00||2015||13125000||1312500||14437500||10.00%||68.750%&lt;br /&gt;
|-&lt;br /&gt;
|367500||2||25.00||2016||14437500||1312500||15750000||9.09%||75.000%&lt;br /&gt;
|-&lt;br /&gt;
|420000||3||12.50||2017||15750000||656250||16406250||4.17%||78.125%&lt;br /&gt;
|-&lt;br /&gt;
|472500||3||12.50||2018||16406250||656250||17062500||4.00%||81.250%&lt;br /&gt;
|-&lt;br /&gt;
|525000||3||12.50||2019||17062500||656250||17718750||3.85%||84.375%&lt;br /&gt;
|-&lt;br /&gt;
|577500||3||12.50||2020||17718750||656250||18375000||3.70%||87.500%&lt;br /&gt;
|-&lt;br /&gt;
|630000||4||6.25||2021||18375000||328125||18703125||1.79%||89.063%&lt;br /&gt;
|-&lt;br /&gt;
|682500||4||6.25||2022||18703125||328125||19031250||1.75%||90.625%&lt;br /&gt;
|-&lt;br /&gt;
|735000||4||6.25||2023||19031250||328125||19359375||1.72%||92.188%&lt;br /&gt;
|-&lt;br /&gt;
|787500||4||6.25||2024||19359375||328125||19687500||1.69%||93.750%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Projected Bitcoins Long Term ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!    Block!!Reward Era!!   BTC/block!!    Year!!         Start BTC!!         BTC Added!!           End BTC!!    BTC Increase||  End BTC % of Limit&lt;br /&gt;
|-&lt;br /&gt;
|        0||  1|| 50.00000000||2009.007||        0.00000000|| 10500000.00000000|| 10500000.00000000||        infinite||       50.00000006%&lt;br /&gt;
|-&lt;br /&gt;
|   210000||  2|| 25.00000000||2013.000|| 10500000.00000000||  5250000.00000000|| 15750000.00000000||    50.00000000%||       75.00000008%&lt;br /&gt;
|-&lt;br /&gt;
|   420000||  3|| 12.50000000||2016.993|| 15750000.00000000||  2625000.00000000|| 18375000.00000000||    16.66666667%||       87.50000010%&lt;br /&gt;
|-&lt;br /&gt;
|   630000||  4||  6.25000000||2020.986|| 18375000.00000000||  1312500.00000000|| 19687500.00000000||     7.14285714%||       93.75000010%&lt;br /&gt;
|-&lt;br /&gt;
|   840000||  5||  3.12500000||2024.978|| 19687500.00000000||   656250.00000000|| 20343750.00000000||     3.33333333%||       96.87500011%&lt;br /&gt;
|-&lt;br /&gt;
|  1050000||  6||  1.56250000||2028.971|| 20343750.00000000||   328125.00000000|| 20671875.00000000||     1.61290323%||       98.43750011%&lt;br /&gt;
|-&lt;br /&gt;
|  1260000||  7||  0.78125000||2032.964|| 20671875.00000000||   164062.50000000|| 20835937.50000000||     0.79365079%||       99.21875011%&lt;br /&gt;
|-&lt;br /&gt;
|  1470000||  8||  0.39062500||2036.956|| 20835937.50000000||    82031.25000000|| 20917968.75000000||     0.39370079%||       99.60937511%&lt;br /&gt;
|-&lt;br /&gt;
|  1680000||  9||  0.19531250||2040.949|| 20917968.75000000||    41015.62500000|| 20958984.37500000||     0.19607843%||       99.80468761%&lt;br /&gt;
|-&lt;br /&gt;
|  1890000|| 10||  0.09765625||2044.942|| 20958984.37500000||    20507.81250000|| 20979492.18750000||     0.09784736%||       99.90234386%&lt;br /&gt;
|-&lt;br /&gt;
|  2100000|| 11||  0.04882812||2048.934|| 20979492.18750000||    10253.90520000|| 20989746.09270000||     0.04887585%||       99.95117198%&lt;br /&gt;
|-&lt;br /&gt;
|  2310000|| 12||  0.02441406||2052.927|| 20989746.09270000||     5126.95260000|| 20994873.04530000||     0.02442599%||       99.97558604%&lt;br /&gt;
|-&lt;br /&gt;
|  2520000|| 13||  0.01220703||2056.920|| 20994873.04530000||     2563.47630000|| 20997436.52160000||     0.01221001%||       99.98779307%&lt;br /&gt;
|-&lt;br /&gt;
|  2730000|| 14||  0.00610351||2060.913|| 20997436.52160000||     1281.73710000|| 20998718.25870000||     0.00610426%||       99.99389658%&lt;br /&gt;
|-&lt;br /&gt;
|  2940000|| 15||  0.00305175||2064.905|| 20998718.25870000||      640.86750000|| 20999359.12620000||     0.00305194%||       99.99694833%&lt;br /&gt;
|-&lt;br /&gt;
|  3150000|| 16||  0.00152587||2068.898|| 20999359.12620000||      320.43270000|| 20999679.55890000||     0.00152592%||       99.99847420%&lt;br /&gt;
|-&lt;br /&gt;
|  3360000|| 17||  0.00076293||2072.891|| 20999679.55890000||      160.21530000|| 20999839.77420000||     0.00076294%||       99.99923713%&lt;br /&gt;
|-&lt;br /&gt;
|  3570000|| 18||  0.00038146||2076.883|| 20999839.77420000||       80.10660000|| 20999919.88080001||     0.00038146%||       99.99961859%&lt;br /&gt;
|-&lt;br /&gt;
|  3780000|| 19||  0.00019073||2080.876|| 20999919.88080001||       40.05330000|| 20999959.93410001||     0.00019073%||       99.99980932%&lt;br /&gt;
|-&lt;br /&gt;
|  3990000|| 20||  0.00009536||2084.869|| 20999959.93410001||       20.02560000|| 20999979.95970001||     0.00009536%||       99.99990468%&lt;br /&gt;
|-&lt;br /&gt;
|  4200000|| 21||  0.00004768||2088.861|| 20999979.95970001||       10.01280000|| 20999989.97250001||     0.00004768%||       99.99995236%&lt;br /&gt;
|-&lt;br /&gt;
|  4410000|| 22||  0.00002384||2092.854|| 20999989.97250001||        5.00640000|| 20999994.97890001||     0.00002384%||       99.99997620%&lt;br /&gt;
|-&lt;br /&gt;
|  4620000|| 23||  0.00001192||2096.847|| 20999994.97890001||        2.50320000|| 20999997.48210001||     0.00001192%||       99.99998812%&lt;br /&gt;
|-&lt;br /&gt;
|  4830000|| 24||  0.00000596||2100.840|| 20999997.48210001||        1.25160000|| 20999998.73370001||     0.00000596%||       99.99999408%&lt;br /&gt;
|-&lt;br /&gt;
|  5040000|| 25||  0.00000298||2104.832|| 20999998.73370001||        0.62580000|| 20999999.35950001||     0.00000298%||       99.99999706%&lt;br /&gt;
|-&lt;br /&gt;
|  5250000|| 26||  0.00000149||2108.825|| 20999999.35950001||        0.31290000|| 20999999.67240001||     0.00000149%||       99.99999855%&lt;br /&gt;
|-&lt;br /&gt;
|  5460000|| 27||  0.00000074||2112.818|| 20999999.67240001||        0.15540000|| 20999999.82780001||     0.00000074%||       99.99999929%&lt;br /&gt;
|-&lt;br /&gt;
|  5670000|| 28||  0.00000037||2116.810|| 20999999.82780001||        0.07770000|| 20999999.90550001||     0.00000037%||       99.99999966%&lt;br /&gt;
|-&lt;br /&gt;
|  5880000|| 29||  0.00000018||2120.803|| 20999999.90550001||        0.03780000|| 20999999.94330001||     0.00000018%||       99.99999984%&lt;br /&gt;
|-&lt;br /&gt;
|  6090000|| 30||  0.00000009||2124.796|| 20999999.94330001||        0.01890000|| 20999999.96220000||     0.00000009%||       99.99999993%&lt;br /&gt;
|-&lt;br /&gt;
|  6300000|| 31||  0.00000004||2128.788|| 20999999.96220000||        0.00840000|| 20999999.97060001||     0.00000004%||       99.99999997%&lt;br /&gt;
|-&lt;br /&gt;
|  6510000|| 32||  0.00000002||2132.781|| 20999999.97060001||        0.00420000|| 20999999.97480001||     0.00000002%||       99.99999999%&lt;br /&gt;
|-&lt;br /&gt;
|  6720000|| 33||  0.00000001||2136.774|| 20999999.97480001||        0.00210000|| 20999999.97690000||     0.00000001%||      100.00000000%&lt;br /&gt;
|-&lt;br /&gt;
|  6930000|| 34||  0.00000000||2140.767|| 20999999.97690000||        0.00000000|| 20999999.97690000||     0.00000000%||      100.00000000%&lt;br /&gt;
|}&lt;br /&gt;
==Money Supply==&lt;br /&gt;
&lt;br /&gt;
While the number of bitcoins in existence will never exceed 21 million, the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Money_supply money supply]&amp;lt;/span&amp;gt; of bitcoins can exceed 21 million due to &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Fractional-reserve_banking Fractional-reserve Banking]. &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Deflation==&lt;br /&gt;
&lt;br /&gt;
Because the monetary base of bitcoins cannot be expanded, the currency would be subject to severe deflation if it becomes widely used. &lt;br /&gt;
Keynesian economists argue that [[Deflationary spiral|deflation]] is bad for an economy because it incentivises individuals and businesses to save money rather than invest in businesses and create jobs. The &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Austrian_School Austrian school]&amp;lt;/span&amp;gt; of thought counters this criticism, claiming that as deflation occurs in all stages of production, entrepreneurs who invest benefit from it. As a result, profit ratios tend to stay the same and only their magnitudes change. In other words, in a deflationary environment, goods and services decrease in price, but at the same time the cost for the production of these goods and services tend to decrease proportionally, effectively not affecting profits. Price deflation encourages an increase in hoarding &amp;amp;mdash; hence savings &amp;amp;mdash; which in turn tends to lower interest rates and increase the incentive for entrepreneurs to invest in projects of longer term.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://www.econlib.org/library/Columns/y2006/Friedmantranscript.html Milton Friedman interview], where he proposed to replace the central bank with a computer, and to fix the money supply growth at 4% annually&lt;br /&gt;
* [[Deflationary spiral]]&lt;br /&gt;
* [http://blockchain.info/charts/total-bitcoins Chart of total bitcoins in circulation]&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Economics]]&lt;/div&gt;</summary>
		<author><name>Wyager</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=39074</id>
		<title>Satoshi Client Node Discovery</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=39074"/>
		<updated>2013-07-04T00:03:00Z</updated>

		<summary type="html">&lt;p&gt;Wyager: /* Address Relay */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
The Satoshi client discovers the IP address and port of nodes in several different ways.&lt;br /&gt;
&lt;br /&gt;
# Nodes discover their own external address by various methods.&lt;br /&gt;
# Nodes receive the callback address of remote nodes that connect to them.&lt;br /&gt;
# Nodes makes DNS request to receive IP addresses.&lt;br /&gt;
# Nodes can use addresses hard coded into the software.&lt;br /&gt;
# Nodes exchange addresses with other nodes.&lt;br /&gt;
# Nodes store addresses in a database and read that database on startup.&lt;br /&gt;
# Nodes can be provided addresses as command line arguments&lt;br /&gt;
# Nodes read addresses from a user provided text file on startup&lt;br /&gt;
&lt;br /&gt;
A timestamp is kept for each address to keep track of when the node&lt;br /&gt;
address was last seen. The AddressCurrentlyConnected in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp] handles&lt;br /&gt;
updating the timestamp whenever a message is received from a node.&lt;br /&gt;
Timestamps are only updated on an address and saved to the database&lt;br /&gt;
when the timestamp is over 20 minutes old.&lt;br /&gt;
&lt;br /&gt;
See the Node Connectivity article for information on which type of&lt;br /&gt;
addresses take precedence when actually connecting to nodes.&lt;br /&gt;
&lt;br /&gt;
In the first section we will cover how a node handles a request for&lt;br /&gt;
addresses via the &amp;quot;getaddr&amp;quot; message. By understanding the role of&lt;br /&gt;
timestamps, it will become more clear why timestamps are kept the way&lt;br /&gt;
they are for each of the different ways an address is discovered.&lt;br /&gt;
&lt;br /&gt;
==Handling Message &amp;quot;getaddr&amp;quot;==&lt;br /&gt;
&lt;br /&gt;
When a node receives a &amp;quot;getaddr&amp;quot; request, it first figures out how many&lt;br /&gt;
addresses it has that have a timestamp in the last 3 hours.&lt;br /&gt;
Then it sends those addresses, but if there are more than 2500 addresses&lt;br /&gt;
seen in the last 3 hours, it selects around 2500 out of the available&lt;br /&gt;
recent addresses by using random selection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now lets look at the ways a node finds out about node addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Discovery Methods==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Local Client&#039;s External Address===&lt;br /&gt;
The client uses public web services which return the information to determine its own external, routable IP address.&lt;br /&gt;
&lt;br /&gt;
The client runs a thread called ThreadGetMyExternalIP (in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp])&lt;br /&gt;
which attempts to determine the client&#039;s IP address as seen from the outside&lt;br /&gt;
world.&lt;br /&gt;
&lt;br /&gt;
First, it attempts to connect to 91.198.22.70 port 80, which should be&lt;br /&gt;
the checkip.dyndns.org server. If connection fails, a DNS request is made&lt;br /&gt;
for checkip.dyndns.org and a connection is attempted to that address.&lt;br /&gt;
Next, it attempts to connect to 74.208.43.192 port 80, which should be&lt;br /&gt;
the www.showmyip.com server. If connection fails, a DNS request is made&lt;br /&gt;
for www.showmyip.com and a connection is attempted to that address.&lt;br /&gt;
&lt;br /&gt;
For each address attempted above, the client attempts to connect,&lt;br /&gt;
send a HTTP request, read the appropriate response line, and parse the&lt;br /&gt;
IP address from it.&lt;br /&gt;
If this succeeds, the IP address is returned, it is advertised to any connected&lt;br /&gt;
nodes, and then the thread finishes (without proceeding to the next&lt;br /&gt;
address).&lt;br /&gt;
&lt;br /&gt;
===Connect Callback Address===&lt;br /&gt;
When a node receives an initial &amp;quot;version&amp;quot; message, and that node initiated the connection, then the node advertises its address to the remote so that it can connect back to the local node if it wants to.&lt;br /&gt;
&lt;br /&gt;
After sending its own address, it sends a &amp;quot;getaddr&amp;quot; request message to the remote node to learn about more addresses, if the remote node version is recent or if the local node does not yet have 1000 addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===IRC Addresses===&lt;br /&gt;
&lt;br /&gt;
As of version 0.6.x the Bitcoin client no longer uses IRC bootstrapping by default, and as of version 0.8.2 support for IRC bootstrapping has been removed completely.  This documentation below is accurate for most prior versions.&lt;br /&gt;
&lt;br /&gt;
In addition to learning and sharing its own address, the node learned about other node addresses via an IRC channel. See [https://github.com/bitcoin/bitcoin/blob/847593228de8634bf6ef5933a474c7e63be59146/src/irc.cpp irc.cpp].&lt;br /&gt;
&lt;br /&gt;
After learning its own address, a node encoded its own address into a string to be used as a nickname. Then, it randomly joined an IRC channel named between #bitcoin00 and #bitcoin99. Then it issued a WHO command. The thread read the lines as they appeared in the channel and decoded the IP addresses of other nodes in the channel. It did this in a loop, forever, until the node was shutdown.&lt;br /&gt;
&lt;br /&gt;
When the client discovered an address from IRC, it set the timestamp on the address to the current time, but it used a &amp;quot;penalty&amp;quot; of 51 minutes, which means it looked like it was actually seen almost an hour earlier.&lt;br /&gt;
&lt;br /&gt;
===DNS Addresses===&lt;br /&gt;
Upon startup, if peer node discovery is needed, the client then issues DNS requests to learn about the addresses of other peer nodes.  The client includes a list of host names for DNS services that are seeded.  As-of May 17, 2012 the list (from chainparams.cpp&amp;lt;ref&amp;gt;[https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L139 bitcoin/src/chainparams.cpp at master]&amp;lt;/ref&amp;gt;) includes:&lt;br /&gt;
&lt;br /&gt;
* bitseed.xf2.org&lt;br /&gt;
* dnsseed.bluematt.me&lt;br /&gt;
* seed.bitcoin.sipa.be&lt;br /&gt;
* dnsseed.bitcoin.dashjr.org&lt;br /&gt;
&lt;br /&gt;
A DNS reply can contain multiple IP addresses for a requested name.&lt;br /&gt;
&lt;br /&gt;
Addresses discovered via DNS are initially given a zero timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
===Hard Coded &amp;quot;Seed&amp;quot; Addresses===&lt;br /&gt;
The client contains hard coded IP addresses that represent bitcoin nodes.&lt;br /&gt;
&lt;br /&gt;
These addresses are only used as a last resort, if no other method has produced any addresses at all. When the loop in the connection handling thread ThreadOpenConnections2() sees an empty address map, it uses the &amp;quot;seed&amp;quot; IP addresses as backup.&lt;br /&gt;
&lt;br /&gt;
There is code is move away from seed nodes when possible. The presumption is that this is to avoid overloading those nodes. Once the local node has enough addresses (presumably learned from the seed nodes), the connection thread will close seed node connections.&lt;br /&gt;
&lt;br /&gt;
Seed Addresses are initially given a zero timestamp,&lt;br /&gt;
therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
===Ongoing &amp;quot;addr&amp;quot; advertisements===&lt;br /&gt;
Nodes may receive addresses in an &amp;quot;addr&amp;quot; message after having sent a &amp;quot;getaddr&amp;quot; request, or &amp;quot;addr&amp;quot; messages may arrive  unsolicited, because nodes advertise addresses gratuitously when they relay addresses (see below), when they advertise their own address periodically, and when a connection is made.&lt;br /&gt;
&lt;br /&gt;
If the address is from a really old version, it is ignored; if from a not-so-old version, it is ignored if we have 1000 addresses already.&lt;br /&gt;
&lt;br /&gt;
If the sender sent over 1000 addresses, they are all ignored.&lt;br /&gt;
&lt;br /&gt;
Addresses received from an &amp;quot;addr&amp;quot; message have a timestamp, but the timestamp is not necessarily honored directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every address in the message:&lt;br /&gt;
# If the timestamp is too low or too high, it is set to 5 days ago.&lt;br /&gt;
# We subtract 2 hours from the timestamp and add the address.&lt;br /&gt;
&lt;br /&gt;
Note that when any address is added, for any reason, the code that calls AddAddress() does not check to see if it already exists. The AddAddresss() function in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp] will do that, and if the address already exists, further processing is done to update the address record. If the advertised services of the address have changed, that is updated and stored.&lt;br /&gt;
&lt;br /&gt;
If the address has been seen in the last 24 hours and the timestamp is currently over 60 minutes old, then it is updated to 60 minutes ago.&lt;br /&gt;
&lt;br /&gt;
If the address has NOT been seen in the last 24 hours, and the timestamp is currently over 24 hours old, then it is updated to 24 hours ago.&lt;br /&gt;
&lt;br /&gt;
====Address Relay====&lt;br /&gt;
&lt;br /&gt;
Once addresses are added from an &amp;quot;addr&amp;quot; message (see above), they then may be relayed to the other nodes. First, the following criteria must be set [9]:&lt;br /&gt;
&lt;br /&gt;
#The address timestamp, after processing, is within 60 minutes of the current time&lt;br /&gt;
#The &amp;quot;addr&amp;quot; message contains 10 addresses or less&lt;br /&gt;
#And fGetAddr is not set on the node. fGetAddr starts false, is set to true when we request addresses from a node, and it is cleared when we receive less than 1000 addresses from a node.&lt;br /&gt;
#The address must be routable.&lt;br /&gt;
&lt;br /&gt;
For every address that meets the above criteria, the node hash the address, the current day (in the form of an integer), and a random 256 bit value (generated at client startup). The node takes the two addresses with the lowest hash values and relays &amp;quot;addr&amp;quot; messages to them. This ensures that each node only relays &amp;quot;addr&amp;quot; messages to two other clients at any given time, that the two other clients are randomly selected, and that the random selection starts over at least once every 24 hours.&lt;br /&gt;
&lt;br /&gt;
====Self broadcast====&lt;br /&gt;
&lt;br /&gt;
Every 24 hours, the node advertises its own address to all connected nodes.&lt;br /&gt;
&lt;br /&gt;
It also clears the list of the addresses we think the remote node has, which will trigger a refresh of sends to nodes. This code is in SendMessages() in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp].&lt;br /&gt;
&lt;br /&gt;
====Old Address Cleanup====&lt;br /&gt;
&lt;br /&gt;
In SendMessages() in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp], there is code to remove old addresses.&lt;br /&gt;
&lt;br /&gt;
This is done every ten minutes, as long as there are 3 active connections.&lt;br /&gt;
&lt;br /&gt;
The node erases messages that have not been used in 14 days as long as there are at least 1000 addresses in the map, and as long as the erasing process has not taken more than 20 seconds.&lt;br /&gt;
&lt;br /&gt;
===Addresses stored in the Database===&lt;br /&gt;
Addresses are stored in the database when AddAddress() is called.&lt;br /&gt;
&lt;br /&gt;
Addresses are read on startup when AppInit2() calls LoadAddresses(), which is located in [https://github.com/bitcoin/bitcoin/blob/master/src/db.cpp db.cpp].&lt;br /&gt;
&lt;br /&gt;
Currently, it appears all addresses are stored all at once whenever any address is stored or updated&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=26436.0 Lots of disk activity on Bitcoin startup: easy fix?]&amp;lt;/ref&amp;gt;. Indeed, AddAddress is seen to take over .01 seconds in various testing and is typically called tens of thousands of times in the initial 12 hours of running the client.&lt;br /&gt;
&lt;br /&gt;
===Command Line Provided Addresses===&lt;br /&gt;
&lt;br /&gt;
The user can specify nodes to connect to with the&lt;br /&gt;
 -addnode &amp;lt;ip&amp;gt; &lt;br /&gt;
command line argument. Multiple nodes may be specified.&lt;br /&gt;
&lt;br /&gt;
Addresses provided on the command line are initially given a zero timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
The user can also specify an address to connect to with the -connect &amp;lt;ip&amp;gt;&lt;br /&gt;
command line argument. Multiple nodes may be specified.&lt;br /&gt;
&lt;br /&gt;
The -connect argument differs from -addnode in that -connect addresses are not added to the address database and when -connect is specified, only those addresses are used.&lt;br /&gt;
&lt;br /&gt;
===Text File Provided Addresses===&lt;br /&gt;
&lt;br /&gt;
The client will automatically read a file named &amp;quot;addr.txt&amp;quot; in the bitcoin data directory and will add any addresses it finds in there as node addresses. These nodes are given no special preference over other addresses. They are just added to the pool.&lt;br /&gt;
&lt;br /&gt;
Addresses loaded from the text file are initially given a zero timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network#Bootstrapping|Network - Boostrapping]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wyager</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=39073</id>
		<title>Satoshi Client Node Discovery</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Satoshi_Client_Node_Discovery&amp;diff=39073"/>
		<updated>2013-07-04T00:02:16Z</updated>

		<summary type="html">&lt;p&gt;Wyager: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
The Satoshi client discovers the IP address and port of nodes in several different ways.&lt;br /&gt;
&lt;br /&gt;
# Nodes discover their own external address by various methods.&lt;br /&gt;
# Nodes receive the callback address of remote nodes that connect to them.&lt;br /&gt;
# Nodes makes DNS request to receive IP addresses.&lt;br /&gt;
# Nodes can use addresses hard coded into the software.&lt;br /&gt;
# Nodes exchange addresses with other nodes.&lt;br /&gt;
# Nodes store addresses in a database and read that database on startup.&lt;br /&gt;
# Nodes can be provided addresses as command line arguments&lt;br /&gt;
# Nodes read addresses from a user provided text file on startup&lt;br /&gt;
&lt;br /&gt;
A timestamp is kept for each address to keep track of when the node&lt;br /&gt;
address was last seen. The AddressCurrentlyConnected in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp] handles&lt;br /&gt;
updating the timestamp whenever a message is received from a node.&lt;br /&gt;
Timestamps are only updated on an address and saved to the database&lt;br /&gt;
when the timestamp is over 20 minutes old.&lt;br /&gt;
&lt;br /&gt;
See the Node Connectivity article for information on which type of&lt;br /&gt;
addresses take precedence when actually connecting to nodes.&lt;br /&gt;
&lt;br /&gt;
In the first section we will cover how a node handles a request for&lt;br /&gt;
addresses via the &amp;quot;getaddr&amp;quot; message. By understanding the role of&lt;br /&gt;
timestamps, it will become more clear why timestamps are kept the way&lt;br /&gt;
they are for each of the different ways an address is discovered.&lt;br /&gt;
&lt;br /&gt;
==Handling Message &amp;quot;getaddr&amp;quot;==&lt;br /&gt;
&lt;br /&gt;
When a node receives a &amp;quot;getaddr&amp;quot; request, it first figures out how many&lt;br /&gt;
addresses it has that have a timestamp in the last 3 hours.&lt;br /&gt;
Then it sends those addresses, but if there are more than 2500 addresses&lt;br /&gt;
seen in the last 3 hours, it selects around 2500 out of the available&lt;br /&gt;
recent addresses by using random selection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now lets look at the ways a node finds out about node addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Discovery Methods==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Local Client&#039;s External Address===&lt;br /&gt;
The client uses public web services which return the information to determine its own external, routable IP address.&lt;br /&gt;
&lt;br /&gt;
The client runs a thread called ThreadGetMyExternalIP (in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp])&lt;br /&gt;
which attempts to determine the client&#039;s IP address as seen from the outside&lt;br /&gt;
world.&lt;br /&gt;
&lt;br /&gt;
First, it attempts to connect to 91.198.22.70 port 80, which should be&lt;br /&gt;
the checkip.dyndns.org server. If connection fails, a DNS request is made&lt;br /&gt;
for checkip.dyndns.org and a connection is attempted to that address.&lt;br /&gt;
Next, it attempts to connect to 74.208.43.192 port 80, which should be&lt;br /&gt;
the www.showmyip.com server. If connection fails, a DNS request is made&lt;br /&gt;
for www.showmyip.com and a connection is attempted to that address.&lt;br /&gt;
&lt;br /&gt;
For each address attempted above, the client attempts to connect,&lt;br /&gt;
send a HTTP request, read the appropriate response line, and parse the&lt;br /&gt;
IP address from it.&lt;br /&gt;
If this succeeds, the IP address is returned, it is advertised to any connected&lt;br /&gt;
nodes, and then the thread finishes (without proceeding to the next&lt;br /&gt;
address).&lt;br /&gt;
&lt;br /&gt;
===Connect Callback Address===&lt;br /&gt;
When a node receives an initial &amp;quot;version&amp;quot; message, and that node initiated the connection, then the node advertises its address to the remote so that it can connect back to the local node if it wants to.&lt;br /&gt;
&lt;br /&gt;
After sending its own address, it sends a &amp;quot;getaddr&amp;quot; request message to the remote node to learn about more addresses, if the remote node version is recent or if the local node does not yet have 1000 addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===IRC Addresses===&lt;br /&gt;
&lt;br /&gt;
As of version 0.6.x the Bitcoin client no longer uses IRC bootstrapping by default, and as of version 0.8.2 support for IRC bootstrapping has been removed completely.  This documentation below is accurate for most prior versions.&lt;br /&gt;
&lt;br /&gt;
In addition to learning and sharing its own address, the node learned about other node addresses via an IRC channel. See [https://github.com/bitcoin/bitcoin/blob/847593228de8634bf6ef5933a474c7e63be59146/src/irc.cpp irc.cpp].&lt;br /&gt;
&lt;br /&gt;
After learning its own address, a node encoded its own address into a string to be used as a nickname. Then, it randomly joined an IRC channel named between #bitcoin00 and #bitcoin99. Then it issued a WHO command. The thread read the lines as they appeared in the channel and decoded the IP addresses of other nodes in the channel. It did this in a loop, forever, until the node was shutdown.&lt;br /&gt;
&lt;br /&gt;
When the client discovered an address from IRC, it set the timestamp on the address to the current time, but it used a &amp;quot;penalty&amp;quot; of 51 minutes, which means it looked like it was actually seen almost an hour earlier.&lt;br /&gt;
&lt;br /&gt;
===DNS Addresses===&lt;br /&gt;
Upon startup, if peer node discovery is needed, the client then issues DNS requests to learn about the addresses of other peer nodes.  The client includes a list of host names for DNS services that are seeded.  As-of May 17, 2012 the list (from chainparams.cpp&amp;lt;ref&amp;gt;[https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L139 bitcoin/src/chainparams.cpp at master]&amp;lt;/ref&amp;gt;) includes:&lt;br /&gt;
&lt;br /&gt;
* bitseed.xf2.org&lt;br /&gt;
* dnsseed.bluematt.me&lt;br /&gt;
* seed.bitcoin.sipa.be&lt;br /&gt;
* dnsseed.bitcoin.dashjr.org&lt;br /&gt;
&lt;br /&gt;
A DNS reply can contain multiple IP addresses for a requested name.&lt;br /&gt;
&lt;br /&gt;
Addresses discovered via DNS are initially given a zero timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
===Hard Coded &amp;quot;Seed&amp;quot; Addresses===&lt;br /&gt;
The client contains hard coded IP addresses that represent bitcoin nodes.&lt;br /&gt;
&lt;br /&gt;
These addresses are only used as a last resort, if no other method has produced any addresses at all. When the loop in the connection handling thread ThreadOpenConnections2() sees an empty address map, it uses the &amp;quot;seed&amp;quot; IP addresses as backup.&lt;br /&gt;
&lt;br /&gt;
There is code is move away from seed nodes when possible. The presumption is that this is to avoid overloading those nodes. Once the local node has enough addresses (presumably learned from the seed nodes), the connection thread will close seed node connections.&lt;br /&gt;
&lt;br /&gt;
Seed Addresses are initially given a zero timestamp,&lt;br /&gt;
therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
===Ongoing &amp;quot;addr&amp;quot; advertisements===&lt;br /&gt;
Nodes may receive addresses in an &amp;quot;addr&amp;quot; message after having sent a &amp;quot;getaddr&amp;quot; request, or &amp;quot;addr&amp;quot; messages may arrive  unsolicited, because nodes advertise addresses gratuitously when they relay addresses (see below), when they advertise their own address periodically, and when a connection is made.&lt;br /&gt;
&lt;br /&gt;
If the address is from a really old version, it is ignored; if from a not-so-old version, it is ignored if we have 1000 addresses already.&lt;br /&gt;
&lt;br /&gt;
If the sender sent over 1000 addresses, they are all ignored.&lt;br /&gt;
&lt;br /&gt;
Addresses received from an &amp;quot;addr&amp;quot; message have a timestamp, but the timestamp is not necessarily honored directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every address in the message:&lt;br /&gt;
# If the timestamp is too low or too high, it is set to 5 days ago.&lt;br /&gt;
# We subtract 2 hours from the timestamp and add the address.&lt;br /&gt;
&lt;br /&gt;
Note that when any address is added, for any reason, the code that calls AddAddress() does not check to see if it already exists. The AddAddresss() function in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp] will do that, and if the address already exists, further processing is done to update the address record. If the advertised services of the address have changed, that is updated and stored.&lt;br /&gt;
&lt;br /&gt;
If the address has been seen in the last 24 hours and the timestamp is currently over 60 minutes old, then it is updated to 60 minutes ago.&lt;br /&gt;
&lt;br /&gt;
If the address has NOT been seen in the last 24 hours, and the timestamp is currently over 24 hours old, then it is updated to 24 hours ago.&lt;br /&gt;
&lt;br /&gt;
====Address Relay====&lt;br /&gt;
&lt;br /&gt;
Once addresses are added from an &amp;quot;addr&amp;quot; message (see above), they then may be relayed to the other nodes. First, the following criteria must be set [9]:&lt;br /&gt;
&lt;br /&gt;
#The address timestamp, after processing, is within 60 minutes of the current time&lt;br /&gt;
#The &amp;quot;addr&amp;quot; message contains 10 addresses or less&lt;br /&gt;
#And fGetAddr is not set on the node. fGetAddr starts false, is set to true when we request addresses from a node, and it is cleared when we receive less than 1000 addresses from a node.&lt;br /&gt;
#The address must be routable.&lt;br /&gt;
&lt;br /&gt;
For every address that meets the above criteria, the node hash the address, the current day (in the form of an integer), and a random 256 bit value (generated at client startup). The node takes the two addresses with the lowest hash values and relays &amp;quot;addr&amp;quot; messages to them. This ensures that each node only relays &amp;quot;addr&amp;quot; messages to two other clients, that the two other clients are randomly selected, and that the random selection starts over at least once every 24 hours.&lt;br /&gt;
&lt;br /&gt;
====Self broadcast====&lt;br /&gt;
&lt;br /&gt;
Every 24 hours, the node advertises its own address to all connected nodes.&lt;br /&gt;
&lt;br /&gt;
It also clears the list of the addresses we think the remote node has, which will trigger a refresh of sends to nodes. This code is in SendMessages() in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp].&lt;br /&gt;
&lt;br /&gt;
====Old Address Cleanup====&lt;br /&gt;
&lt;br /&gt;
In SendMessages() in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp], there is code to remove old addresses.&lt;br /&gt;
&lt;br /&gt;
This is done every ten minutes, as long as there are 3 active connections.&lt;br /&gt;
&lt;br /&gt;
The node erases messages that have not been used in 14 days as long as there are at least 1000 addresses in the map, and as long as the erasing process has not taken more than 20 seconds.&lt;br /&gt;
&lt;br /&gt;
===Addresses stored in the Database===&lt;br /&gt;
Addresses are stored in the database when AddAddress() is called.&lt;br /&gt;
&lt;br /&gt;
Addresses are read on startup when AppInit2() calls LoadAddresses(), which is located in [https://github.com/bitcoin/bitcoin/blob/master/src/db.cpp db.cpp].&lt;br /&gt;
&lt;br /&gt;
Currently, it appears all addresses are stored all at once whenever any address is stored or updated&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=26436.0 Lots of disk activity on Bitcoin startup: easy fix?]&amp;lt;/ref&amp;gt;. Indeed, AddAddress is seen to take over .01 seconds in various testing and is typically called tens of thousands of times in the initial 12 hours of running the client.&lt;br /&gt;
&lt;br /&gt;
===Command Line Provided Addresses===&lt;br /&gt;
&lt;br /&gt;
The user can specify nodes to connect to with the&lt;br /&gt;
 -addnode &amp;lt;ip&amp;gt; &lt;br /&gt;
command line argument. Multiple nodes may be specified.&lt;br /&gt;
&lt;br /&gt;
Addresses provided on the command line are initially given a zero timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
The user can also specify an address to connect to with the -connect &amp;lt;ip&amp;gt;&lt;br /&gt;
command line argument. Multiple nodes may be specified.&lt;br /&gt;
&lt;br /&gt;
The -connect argument differs from -addnode in that -connect addresses are not added to the address database and when -connect is specified, only those addresses are used.&lt;br /&gt;
&lt;br /&gt;
===Text File Provided Addresses===&lt;br /&gt;
&lt;br /&gt;
The client will automatically read a file named &amp;quot;addr.txt&amp;quot; in the bitcoin data directory and will add any addresses it finds in there as node addresses. These nodes are given no special preference over other addresses. They are just added to the pool.&lt;br /&gt;
&lt;br /&gt;
Addresses loaded from the text file are initially given a zero timestamp, therefore they are not advertised in response to a &amp;quot;getaddr&amp;quot; request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network#Bootstrapping|Network - Boostrapping]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Wyager</name></author>
	</entry>
</feed>