chaincoin-legacy / chaincoin

Chaincoin crypto currency
http://www.chaincoin.org/
Other
60 stars 22 forks source link

is CMasternode::CalculateScore fair? #25

Closed ponnanganni closed 7 years ago

ponnanganni commented 7 years ago

I'm looking at masternode reward system, it is supposedly random but we can see in the code this:

//
// Deterministically calculate a given "score" for a Masternode depending on how close it's hash is to
// the proof of work for that block. The further away they are the better, the furthest will win the election
// and get paid this block
//
uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight)
{
    if(chainActive.Tip() == NULL) return 0;

    uint256 hash = 0;
    uint256 aux = vin.prevout.hash + vin.prevout.n;

    if(!GetBlockHash(hash, nBlockHeight)) return 0;

    uint256 hash2 = Hash(BEGIN(hash), END(hash));
    uint256 hash3 = Hash(BEGIN(hash), END(hash), BEGIN(aux), END(aux));

    uint256 r = (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);

    return r;
}

Can someone give some information about what is vin.prevout? it looks like a fixed value, probably attributed on masternode start.

I'd like we try to consider another way to compute a weight, based on uptime (anytime we fail to reach a seed server, uptime gets reset) and time since last reward, this would result in a more fair reward distribution system.

brakmic commented 7 years ago

prevout is previous transaction's output. As you may know in a blockchain input transactions are "output transactions" of the previous block.

I don't see much difference between our CalculateScore with the one from Dash.

Do you have any concrete ideas on how it should look like? Just saying that something could be made more fair is not helping when developing software. A code snipped would surely help.

Also please take into account that GitHub's "Issues" are for, well, issues with the software. This is not a slack channel or discord.

Thanks.

chaincoin-legacy commented 7 years ago

It is basically a deterministic random number generator. It uses information from the block and transaction to calculate a hash which is used as random number/score. Every node needs to agree about what "uptime" for a node is (this could be difficult), otherwise the score is not deterministic.