Bitcoin Forum
October 18, 2017, 09:03:23 PM
 News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 Home Help Search Donate Login Register
 Pages: [1]
 Author Topic: New alt - nSubsidy issue - FIXED  (Read 329 times)
l8nit3
Hero Member

Offline

Activity: 896

www.L8nit3-miners.com

 October 20, 2016, 07:37:02 PM

Hello
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 I will continue updating with any common errors and fixes I encounter for future coin-builders

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

Offline

Posts: 1508360603

Ignore
 1508360603

1508360603
 Report to moderator
1508360603
Hero Member

Offline

Posts: 1508360603

Ignore
 1508360603

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

Offline

Posts: 1508360603

Ignore
 1508360603

1508360603
 Report to moderator
1508360603
Hero Member

Offline

Posts: 1508360603

Ignore
 1508360603

1508360603
 Report to moderator
iGotSpots
Legendary

Offline

Activity: 1442

 October 20, 2016, 08:40:51 PM

Hello
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 I will continue updating with any common errors and fixes I encounter for future coin-builders

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. | TwitterExplorer | YouTubeWorm Shop
The worms need your help to grow!
l8nit3
Hero Member

Offline

Activity: 896

www.L8nit3-miners.com

 October 21, 2016, 01:04:13 AM

Thank you for taking the time out to give advice on this issue
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

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 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

STILL NO RELEASE PLANS - Learning for future projects

GirlsToken2.0 - NEW DEV BCT ANN
BTC: 1G2PTf59cYsWKoZjj3i3Cv1Bb8NuNaeho2
L8nit3-Miners YIIMP & ZNOMP #GetMining
[/color]
 Pages: [1]
 « previous topic next topic »