{"id":9861,"date":"2020-05-09T13:20:34","date_gmt":"2020-05-09T07:50:34","guid":{"rendered":"https:\/\/bitcoinik.com\/?st-import=7d4acef3fd217d9200603e2336ed9f2f"},"modified":"2020-05-09T13:20:34","modified_gmt":"2020-05-09T07:50:34","slug":"bitcoin-halving-code-explained","status":"publish","type":"post","link":"https:\/\/bitcoinik.com\/?p=9861","title":{"rendered":"Bitcoin Halving Code explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">in this article, we will explain the Bitcoin Halving Code where you will know about how Bitcoin Halving actually happened into the code.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_91 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bitcoinik.com\/?p=9861\/#What_is_Bitcoin_Halving\" >What is Bitcoin Halving?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bitcoinik.com\/?p=9861\/#Bitcoin_Halving_Code_explained\" >Bitcoin Halving Code explained!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bitcoinik.com\/?p=9861\/#What_happened_at_3rd_Bitcoin_Halving\" >What happened at 3rd Bitcoin Halving?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bitcoinik.com\/?p=9861\/#Also_read-_What_is_Bitcoin_Halving_How_Bitcoin_Halving_Affects_Bitcoin_Price\" >Also read- What is Bitcoin Halving? How Bitcoin Halving Affects Bitcoin Price?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Bitcoin_Halving\"><\/span>What is Bitcoin Halving?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bitcoin Halving is an event that occurred after every 210,000 blocks on the bitcoin blockchain and it is the event that responsible for fixed issuance of Bitcoins which is capped to maximum of 21 millions Bitcoins that can ever be generated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bitcoin Halving is responsible for the continuous reduction in the issuance of bitcoins in every four years means it makes bitcoin disinflationary by which the rate of newly bitcoins creation goes down to half after every 4 years due to bitcoin halving event.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, Bitcoin Halving is not measured by years as normally people say that Bitcoin Halving will occur after 4 years. The Bitcoin Halving is counted in blocks where it actually occurred after every 210,000 blocks and every block generated in 10 minutes at average that means 210,000 blocks generated approximately in 4 years of time. That&#8217;s why we saw Bitcoin Halving to be occurred in approximately in 4 years. The 3rd Bitcoin Halving will be occurred at 630,000 block where Bitcoin block reward will reduce from 12.5 Bitcoins to 6.25 Bitcoins.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Bitcoin_Halving_Code_explained\"><\/span>Bitcoin Halving Code explained!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/bitcoinik.com\/wp-content\/uploads\/2020\/05\/IMG_20200509_104014-1024x484.jpg\" alt=\"\" class=\"wp-image-9866\"\/><figcaption>Bitcoin Halving Code<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For every block generated by miners need to put the block subsidy (block reward) for that block in coibase transaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So this block subsidy is calculated for any block generated through a function defined in 1238 line of validation.cpp file in bitcoin source code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">file link-  https<a href=\"https:\/\/github.com\/bitcoin\/bitcoin\/blob\/master\/src\/validation.cpp\" class=\"rank-math-link\">:\/\/github.com\/bitcoin\/bitcoin\/blob\/master\/src\/validation.cpp<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This function named <strong>GetBlosckSubsity<\/strong>() is returned the block subsidy value (block reward) for the recently mined block.<\/p>\n\n\n\n<p class=\"has-background has-very-light-gray-background-color wp-block-paragraph\"><strong>int halvings = nHeight \/ consensusParams.nSubsidyHalvingInterval;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> In this function, it first count the number of halvings already occurred until that recently mined block by dividing the total number of blocks (<strong>nHeight<\/strong>) by 210,000 blocks <strong>(consensusParams.nSubsidyHalvingInterval<\/strong>\ud83d\ude09 that returned only integer value. For example if the recently mined block is 230,000 then it will return 1 (integer value) to the number of halvings counter variable (<strong>halvings<\/strong>) that determines it as only 1 halving occurred at that block.<\/p>\n\n\n\n<p class=\"has-background has-very-light-gray-background-color wp-block-paragraph\"><strong>if (halvings &gt;= 64) return 0;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After counting the <strong>halvings<\/strong>, it checks for <strong>halvings<\/strong> value upto 64 where it returns block subsidy value (block reward) zero if <strong>halvings<\/strong> value more than or equal to 64.<\/p>\n\n\n\n<p class=\"has-background has-very-light-gray-background-color wp-block-paragraph\"><strong>CAmount nSubsidy = 50 * COIN;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, <strong>nSubsidy<\/strong> object is created by initialising it with a value of 5,000,000,000 (in satoshis) where COIN is equal to 100,000,000 (number of Satoshis in one Bitcoin), <strong>nSubsidy<\/strong> referred to the block subsidy value (block reward) for first time when no halving occurred means block reward is 5 billions satoshis from genesis block to 209,999 block.<\/p>\n\n\n\n<p class=\"has-background has-very-light-gray-background-color wp-block-paragraph\"><strong>nSubsidy &gt;&gt;= halvings; return nSubsidy;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, <strong>nSubsidy<\/strong> or block subsidy value get bitwise shifts by <strong>halvings<\/strong> value that means nSubsidy get divided by 2 in every bitwise shifts. For example when halvings value is zero then it doesn&#8217;t do any bitwise shifts and nSubsidy value remain 5 billions satoshis as block reward for miners. If halvings value is 1 then nSubsidy value get bitwise shifts once by dividing it by 2 one time that changes nSubsidy value to 2.5 billions satoshis as block reward for miners.  Similarly, if halvings value is 2 then nSubsidy value get bitwise shifts twice by dividing nSubsidy value by 2 two times that changes nSubsidy value to 1.25 billions satoshis as block reward for miners and so on.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After bitwise shifts, it returns the <strong>nSubsidy<\/strong> value to the function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_happened_at_3rd_Bitcoin_Halving\"><\/span>What happened at 3rd Bitcoin Halving?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The<a href=\"http:\/\/bitcoinik.com\/3rd-bitcoin-halving-is-just-99-days-away-is-the-bull-began-his-run\/\" class=\"rank-math-link\"> 3rd Bitcoin Halving <\/a>is going to occur at 630,000 block that seems to be generated on 12 May 2020.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, the 629,999 block will be the last block that will generate the 12.5 Bitcoins as miners block reward and after it, when the next block 630,000 mined then the block subsidy or block reward will be reduced to 6.25 bitcoins where every block generated after 629,999 must contain no more than 6.25 bitcoins as block subsidy or block reward as per the consensus rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">check bitcoin halving counter &#8211; <a href=\"http:\/\/bitcoinik.com\/bitcoin-halving\/\" class=\"rank-math-link\">click here<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Also_read-_What_is_Bitcoin_Halving_How_Bitcoin_Halving_Affects_Bitcoin_Price\"><\/span>Also read-<strong> <a href=\"http:\/\/bitcoinik.com\/what-is-bitcoin-halving\/\" class=\"rank-math-link\">What is Bitcoin Halving? How Bitcoin Halving Affects Bitcoin Price?<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>in this article, we will explain the Bitcoin Halving Code where you will know about how Bitcoin Halving actually happened into the code. What is Bitcoin Halving? Bitcoin Halving is an event that occurred after every 210,000 blocks on the bitcoin blockchain and it is the event that responsible for fixed issuance of Bitcoins which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3298,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17,19,35],"tags":[],"class_list":["post-9861","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blockchain","category-crypto-education","category-bitcoin"],"acf":[],"jetpack_featured_media_url":"https:\/\/bitcoinik.com\/wp-content\/uploads\/2019\/05\/bitcoin-halving-1.jpg","_links":{"self":[{"href":"https:\/\/bitcoinik.com\/index.php?rest_route=\/wp\/v2\/posts\/9861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcoinik.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcoinik.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcoinik.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcoinik.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9861"}],"version-history":[{"count":0,"href":"https:\/\/bitcoinik.com\/index.php?rest_route=\/wp\/v2\/posts\/9861\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitcoinik.com\/index.php?rest_route=\/wp\/v2\/media\/3298"}],"wp:attachment":[{"href":"https:\/\/bitcoinik.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcoinik.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcoinik.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}