Bitcoin Forum
December 11, 2017, 11:45:49 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: New alt - nSubsidy issue - FIXED  (Read 359 times)
l8nit3
Hero Member
*****
Offline Offline

Activity: 938

www.L8nit3-miners.com


View Profile WWW
October 20, 2016, 07:37:02 PM
 #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

GirlsToken2.0 - NEW DEV BCT ANN
BTC: 1G2PTf59cYsWKoZjj3i3Cv1Bb8NuNaeho2
L8nit3-Miners YIIMP & ZNOMP #GetMining
[/color]
1512992749
Hero Member
*
Offline Offline

Posts: 1512992749

View Profile Personal Message (Offline)

Ignore
1512992749
Reply with quote  #2

1512992749
Report to moderator
1512992749
Hero Member
*
Offline Offline

Posts: 1512992749

View Profile Personal Message (Offline)

Ignore
1512992749
Reply with quote  #2

1512992749
Report to moderator
1512992749
Hero Member
*
Offline Offline

Posts: 1512992749

View Profile Personal Message (Offline)

Ignore
1512992749
Reply with quote  #2

1512992749
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
iGotSpots
Legendary
*
Offline Offline

Activity: 1498



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

██████████████
██████████████████████
████████████████████████████
████████████████████████████████
████████████████████████████████████
██████████████████████████████████████
██████████████████████████████████████████
████████████████████████████████████████████
█████████████████████████████████████████
██████████████████████████████████████
███████████████████████████████████████████████
███████████████████████████████████████████
███████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████
███████████████████████████████████████████████
████████████████████████████████████████████
██████████████████████████████████████████████
████████████████████████████████████████████
████████████████████████████████████████████
████████████████████████████████████████████
████████████████████████████████████████████
██████████████████████████████████████████
█████████████████████████████████████
████████████████████████████████████
████████████████████████████████
████████████████████████████
██████████████████████
██████████████
   .HealthyWormCoin.   |     Twitter
Explorer
   |       YouTube
Worm Shop
The worms need your help to grow!
l8nit3
Hero Member
*****
Offline Offline

Activity: 938

www.L8nit3-miners.com


View Profile WWW
October 21, 2016, 01:04:13 AM
 #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

GirlsToken2.0 - NEW DEV BCT ANN
BTC: 1G2PTf59cYsWKoZjj3i3Cv1Bb8NuNaeho2
L8nit3-Miners YIIMP & ZNOMP #GetMining
[/color]
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!