Bitcoin Forum
April 24, 2024, 10:22:26 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: New alt - nSubsidy issue - FIXED  (Read 436 times)
l8nit3 (OP)
Legendary
*
Offline Offline

Activity: 1007
Merit: 1000


View Profile
October 20, 2016, 07:37:02 PM
Last edit: October 20, 2016, 08:14:41 PM by l8nit3
 #1

Hello Smiley
I am currently in the process of building my own coin. I have been following multiple guides (some for the code modding, some for windows compiling, etc) and have gotten to a point where my code builds properly for both windows (mxe or mingw) and linux ,what a job that was! My original goal was to complete start to finish without asking for forum help... but im stumped.

My Issue:
I have my code set for a block halving every 1mil blocks, with 1440 (one day) blocks at 1 coin for a fair distribution start. Yet no matter what I do to the code, my blocks do not change reward with the coded schedule, similar to the 42coin issue where it never stopped lol

int64_t GetProofOfWorkReward(int64_t nFees)
{

    int64_t nSubsidy;

    if (pindexBest->nHeight+1 >= 0 && pindexBest->nHeight+1 <= 1440)
    {
     nSubsidy = 1 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1440 && pindexBest->nHeight+1 <= 1001440)
    {
     nSubsidy = 230 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1001441 && pindexBest->nHeight+1 <= 2001440)
    {
     nSubsidy = 115 * COIN;
    }

    if (pindexBest->nHeight+1 >= 2001441 && pindexBest->nHeight+1 <= 3001440)
    {
     nSubsidy = 57.5 * COIN;
    }

    if (pindexBest->nHeight+1 >= 3001441 && pindexBest->nHeight+1 <= 4001440)
    {
     nSubsidy = 28.75 * COIN;
    }

    else
    {
     nSubsidy = 0 * COIN;
    }


FIXED
needed to add 'else' before each if.. stupid mistake but good to know Smiley I will continue updating with any common errors and fixes I encounter for future coin-builders Smiley
1713954146
Hero Member
*
Offline Offline

Posts: 1713954146

View Profile Personal Message (Offline)

Ignore
1713954146
Reply with quote  #2

1713954146
Report to moderator
The block chain is the main innovation of Bitcoin. It is the first distributed timestamping system.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
iGotSpots
Legendary
*
Offline Offline

Activity: 2548
Merit: 1054


CPU Web Mining 🕸️ on webmining.io


View Profile WWW
October 20, 2016, 08:40:51 PM
 #2

Hello Smiley
I am currently in the process of building my own coin. I have been following multiple guides (some for the code modding, some for windows compiling, etc) and have gotten to a point where my code builds properly for both windows (mxe or mingw) and linux ,what a job that was! My original goal was to complete start to finish without asking for forum help... but im stumped.

My Issue:
I have my code set for a block halving every 1mil blocks, with 1440 (one day) blocks at 1 coin for a fair distribution start. Yet no matter what I do to the code, my blocks do not change reward with the coded schedule, similar to the 42coin issue where it never stopped lol

int64_t GetProofOfWorkReward(int64_t nFees)
{

    int64_t nSubsidy = 0;

    if (pindexBest->nHeight+1 >= 0 && pindexBest->nHeight+1 <= 1440)
    {
     nSubsidy = 1 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1440 && pindexBest->nHeight+1 <= 1001440)
    {
     nSubsidy = 230 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1001441 && pindexBest->nHeight+1 <= 2001440)
    {
     nSubsidy = 115 * COIN;
    }

    if (pindexBest->nHeight+1 >= 2001441 && pindexBest->nHeight+1 <= 3001440)
    {
     nSubsidy = 57.5 * COIN;
    }

    if (pindexBest->nHeight+1 >= 3001441 && pindexBest->nHeight+1 <= 4001440)
    {
     nSubsidy = 28.75 * COIN;
    }

 return nSubsidy;



FIXED
needed to add 'else' before each if.. stupid mistake but good to know Smiley I will continue updating with any common errors and fixes I encounter for future coin-builders Smiley

You don't need all the elses. There a lot more efficient ways to do this, though

Every condition that is true will change the reward so it will go through all checks anyway. Get rid of all the &&s, bring nHeight into the function, and do it properly

I changed one thing to get you started, but you do not need to write the word else in this function at all

l8nit3 (OP)
Legendary
*
Offline Offline

Activity: 1007
Merit: 1000


View Profile
October 21, 2016, 01:04:13 AM
Last edit: October 21, 2016, 02:59:45 AM by l8nit3
 #3

Thank you for taking the time out to give advice on this issue Smiley
Strangely, adding the else statements allowed it to finally work for me, however as its simply testing I will 100% give your advice a try Smiley

I am currently looking at some other coin sources to see more elegant ways of applying the halving schedule. However to fully 'clean' the code the way I want to its going to take me quite awhile, I have very little experience in c++, but am learning along the way and will be taking pointers from the source of some coins I really like on how things SHOULD be applied.

Is this closer to what you mean?

  if(nHeight > 1440)
    {
        nSubsidy = 230 * COIN;
     }


*EDIT*
Thank you again for your advice Smiley I have trimmed down the code removing all of my && statements and the else's as per your suggestion. You were absolutely right that I had simply bloated the code with extras that didnt need to be there. Basically, in trying to 'cover all angles' I ended up overthinking and overcoding.

I still plan on tidying the code up even more and hopefully manage to work it into 1 or 2 if statements (one for the first 1440, and one for the rest), aswell as many other things I'd love to learn to implement from other coins. Just basic features for now (irc, BE in-wallet, cpu miner in-wallet, and eventually an algo change) but all leading up to hopefully bigger better things Smiley

STILL NO RELEASE PLANS - Learning for future projects
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!