<p>You should not be tampering with any code that has anything to do with determining block validity if you don't thoroughly understand the security model that proof of work coins use.</p>

<pre><code>i = getrandint(iMin, iMax);
int64 nSubsidy = nBlockRewardStartCoin * i ;
</code></pre>

<p>You can't use any randomness in any code that involves block validation! The entire security model of the blockchain absolutely requires that servers <em>agree</em> on whether blocks are valid or not. Whatever it is you are trying to do, this is <strong>not</strong> how you do it.</p>

CC BY-SA 3.0
2014-03-04T13:08:53.360Z
you mean if I want to use randomness, I only can use in Scrypt algorithm? I was thinking to do a concept like doge coin where rewards is a range of 1-500000 for the first 10000 blocks etc for quark fork.
user1595932
CC BY-SA 3.0
2014-03-04T13:12:06.413Z
If you do not fully understand the security model for proof of work coins, you should not be tampering with the block validity logic. It is absolutely *not* simple. The block reward must be known at the time the coinbase transaction is formed, before hashing begins.
David Schwartz
CC BY-SA 3.0
2014-03-04T13:40:47.427Z
okay . I understood what you meant. If i set nsubsidy base on nHeight and is known to all nodes before the transaction is form, then its suppose be valid ? By taking away randomness and just put a constant int base on nHeight to determine nSubsidy and then reward proof of work
user1595932
CC BY-SA 3.0
2014-03-04T10:37:12.887Z
2014-03-04T10:37:12.887Z
David Schwartz
<p>ERROR: ConnectBlock() : coinbase pays too much (actual=20000000 vs limit=20000000)</p>

<p>I got this error at my debug.log</p>

<p>anyone know how to fix this issue? I am coding a new coin, changing its rewards, which parametter I need change to increase the limit.</p>

<p>on the line:</p>

<pre><code> if (vtx[0].GetValueOut() &gt; GetBlockValue(pindex-&gt;nHeight, nFees, pindex-&gt;nBits))
        return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", vtx[0].GetV$
</code></pre>

<p>I changed my nsubsidy for the code</p>

<pre><code>int getrandint(int min, int max)
{
    int num;
    num=rand();
    num=num%(max-min+1)+min;
    return num;
}



int64 static GetBlockValue(int nHeight, int64 nFees, unsigned int nBits)
{
    if (nHeight == 0)
    {
        return nGenesisBlockRewardCoin;
    }

   unsigned int i, iMax, iMin;


   iMin = 1;
   iMax = 50;

if(nHeight&lt;500)
{
iMax = 3;
}
if(nHeight &gt; 8000)
{
iMax = 30;
}
if(nHeight &gt; 20000)
{
iMax = 20;
}
if(nHeight &gt; 100000)
{
iMax = 10;
}


  i = getrandint(iMin, iMax);
    int64 nSubsidy = nBlockRewardStartCoin * i ;



    // Subsidy is cut in half every 60480 blocks (21 days)
    //nSubsidy &gt;&gt;= (nHeight / 60480);

    // Minimum subsidy
    if (nSubsidy &lt; nBlockRewardMinimumCoin)
    {
        nSubsidy = nBlockRewardMinimumCoin;
    }

    return nSubsidy + nFees;

}
</code></pre>

<p>The code originally was </p>

<pre><code>int64 static GetBlockValue(int nHeight, int64 nFees, unsigned int nBits)
{
    if (nHeight == 0)
    {
        return nGenesisBlockRewardCoin;
    }

    int64 nSubsidy = nBlockRewardStartCoin;

    // Subsidy is cut in half every 60480 blocks (21 days)
    nSubsidy &gt;&gt;= (nHeight / 60480);

    // Minimum subsidy
    if (nSubsidy &lt; nBlockRewardMinimumCoin)
    {
        nSubsidy = nBlockRewardMinimumCoin;
    }

    return nSubsidy + nFees;
}
</code></pre>

<p>Because of what I change, my code give the error coinbase pays too much</p>

<pre><code>root@eatSushi1:~/dogequark/src$ ./dogequarkd
dogequark server starting
root@eatSushi1:~/dogequark/src$ terminate called after throwing an instance of 'std::runtime_error'
  what():  CreateNewBlock() : ConnectBlock failed
</code></pre>

<p>I also got this error when I run the coind at another server after cloning through github.</p>

CC BY-SA 3.0
2014-03-04T06:54:21.807Z
@GregHewgill, what you mention made sense and helps me, but I got a issue is how should I change my code so It can work with my new nSubsidy..
user1595932
CC BY-SA 3.0
2014-03-04T11:02:23.740Z
Your code **can't** work with your `nSubsidy` for the reason JoelKatz explained.
Nik Bougalis
CC BY-SA 3.0
2014-03-05T11:55:32.807Z
This question appears to be off-topic because it is about basic programming.
Stéphane Gimenez
<api><json-rpc><altcoin><quarkcoin>
How to fix CoinBase pay too much error
user1595932
# How to fix CoinBase pay too much error

(Asked by: username_0 on 2014-03-04)

ERROR: ConnectBlock() : coinbase pays too much (actual=20000000 vs limit=20000000)

I got this error at my debug.log

anyone know how to fix this issue? I am coding a new coin, changing its rewards, which parametter I need change to increase the limit.

on the line:

```
 if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees, pindex->nBits))
        return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", vtx[0].GetV$

```

I changed my nsubsidy for the code

```
int getrandint(int min, int max)
{
    int num;
    num=rand();
    num=num%(max-min+1)+min;
    return num;
}

int64 static GetBlockValue(int nHeight, int64 nFees, unsigned int nBits)
{
    if (nHeight == 0)
    {
        return nGenesisBlockRewardCoin;
    }

   unsigned int i, iMax, iMin;

   iMin = 1;
   iMax = 50;

if(nHeight<500)
{
iMax = 3;
}
if(nHeight > 8000)
{
iMax = 30;
}
if(nHeight > 20000)
{
iMax = 20;
}
if(nHeight > 100000)
{
iMax = 10;
}

  i = getrandint(iMin, iMax);
    int64 nSubsidy = nBlockRewardStartCoin * i ;

    // Subsidy is cut in half every 60480 blocks (21 days)
    //nSubsidy >>= (nHeight / 60480);

    // Minimum subsidy
    if (nSubsidy < nBlockRewardMinimumCoin)
    {
        nSubsidy = nBlockRewardMinimumCoin;
    }

    return nSubsidy + nFees;

}

```

The code originally was

```
int64 static GetBlockValue(int nHeight, int64 nFees, unsigned int nBits)
{
    if (nHeight == 0)
    {
        return nGenesisBlockRewardCoin;
    }

    int64 nSubsidy = nBlockRewardStartCoin;

    // Subsidy is cut in half every 60480 blocks (21 days)
    nSubsidy >>= (nHeight / 60480);

    // Minimum subsidy
    if (nSubsidy < nBlockRewardMinimumCoin)
    {
        nSubsidy = nBlockRewardMinimumCoin;
    }

    return nSubsidy + nFees;
}

```

Because of what I change, my code give the error coinbase pays too much

```
root@eatSushi1:~/dogequark/src$ ./dogequarkd
dogequark server starting
root@eatSushi1:~/dogequark/src$ terminate called after throwing an instance of 'std::runtime_error'
  what():  CreateNewBlock() : ConnectBlock failed

```

I also got this error when I run the coind at another server after cloning through github.

**Tags:** api, json-rpc, altcoin, quarkcoin

> **Comments:**
> **username_0**: @GregHewgill, what you mention made sense and helps me, but I got a issue is how should I change my code so It can work with my new nSubsidy..  
> **username_1**: Your code **can't** work with your `nSubsidy` for the reason JoelKatz explained.  
> **username_2**: This question appears to be off-topic because it is about basic programming.  

---

## 1 answers

### Answer by username_3 on 2014-03-04. Score: 4

You should not be tampering with any code that has anything to do with determining block validity if you don't thoroughly understand the security model that proof of work coins use.

```
i = getrandint(iMin, iMax);
int64 nSubsidy = nBlockRewardStartCoin * i ;

```

You can't use any randomness in any code that involves block validation! The entire security model of the blockchain absolutely requires that servers *agree* on whether blocks are valid or not. Whatever it is you are trying to do, this is **not** how you do it.

> **Comments:**
> **username_0**: you mean if I want to use randomness, I only can use in Scrypt algorithm? I was thinking to do a concept like doge coin where rewards is a range of 1-500000 for the first 10000 blocks etc for quark fork.  
> **username_3**: If you do not fully understand the security model for proof of work coins, you should not be tampering with the block validity logic. It is absolutely *not* simple. The block reward must be known at the time the coinbase transaction is formed, before hashing begins.  
> **username_0**: okay . I understood what you meant. If i set nsubsidy base on nHeight and is known to all nodes before the transaction is form, then its suppose be valid ? By taking away randomness and just put a constant int base on nHeight to determine nSubsidy and then reward proof of work  

---

