Peercoin chain trust

From Peercoin Wiki
Jump to: navigation, search

Description

Excerpts from the Peercoin whitepaper

« The hash target that stake kernel must meet is a target per unit coin age (coin-day) consumed in the kernel (in contrast to Bitcoin's proof-of-work target which is a fixed target value applying to every node). Thus the more coin age consumed in the kernel, the easier meeting the hash target protocol. »

« The protocol for determining which competing block chain wins as main chain has been switched over to use consumed coin age. Here every transaction in a block contributes its consumed coin age to the score of the block. The block chain with highest total consumed coin age is chosen as main chain. »

Source

Block "target"

Block "target" is defined here: https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L3673

pblock->nBits = GetNextTargetRequired(pindexPrev, pblock->IsProofOfStake());

The GetNextTargetRequired function is described here. The new target value is based on last block target and time elapsed between the last block and the previous one.

This nBits value will be verified by receiving peers here: https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L1930

// Check proof-of-work or proof-of-stake
if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake()))
    return DoS(100, error("AcceptBlock() : incorrect proof-of-work/proof-of-stake"));

This ensures that PoS blocks are generated every 10 minutes (on average) and that the associated difficulty/target can't be faked.

Block "block trust"

Block "block trust" is calculated here: https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.h#L1269

CBigNum CBlockIndex::GetBlockTrust() const
{
    CBigNum bnTarget;
    bnTarget.SetCompact(nBits);
    if (bnTarget <= 0) return 0;
    return (IsProofOfStake()? (CBigNum(1)<<256) / (bnTarget+1) : 1);
}

Block "chain trust"

Block "chain trust" is defined by adding new block "block trust" to prev block "chain trust": https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L1769

// ppcoin: compute chain trust score
pindexNew->bnChainTrust = (pindexNew->pprev ? pindexNew->pprev->bnChainTrust : 0) + pindexNew->GetBlockTrust();

Best chain selection

Peercoin chooses the chain with the best "chain trust": https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L1808

// New best
if (pindexNew->bnChainTrust > bnBestChainTrust)
    if (!SetBestChain(txdb, pindexNew))
        return false;

FAQ

How is pblock->nBits securised as it is not included in the hashed stake kernel since v0.3 and neither in the stake modifier?
This nBits value can't be faked as it will be verified by receiving peers: https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.cpp#L1930
If I have a bad Internet connection, will I be disadvantaged for minting?
The more people are minting, the more competing blocks we will have. So network propagation time might have it's importance to avoid your block being orphaned. To be confirmed. ppcman answered a similar question on peercointalk here.


Feel free to add your own questions in this FAQ

Links