Giter VIP home page Giter VIP logo

altmarketscoin's People

Contributors

altmarkets avatar jonn4y avatar teamswipp avatar theholyroger avatar ultra-pool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

altmarketscoin's Issues

GetPoWMHashPS

I'm not sure where the root of this code comes from; searching github reveals 4700+ repositories with it in it.

double GetPoWMHashPS(const CBlockIndex* blockindex)
{
    int nPoWInterval = 72;
    int64_t nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30;

    const CBlockIndex* pindex = chainActive.Genesis();
    const CBlockIndex* pindexPrevWork = chainActive.Genesis();

    while (pindex)
    {
        if (pindex->IsProofOfWork())
        {
            int64_t nActualSpacingWork = pindex->GetBlockTime() - pindexPrevWork->GetBlockTime();
            nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1);
            nTargetSpacingWork = std::max(nTargetSpacingWork, nTargetSpacingWorkMin);
            pindexPrevWork = pindex;
        }

        pindex = chainActive.Next(pindex);
    }

    return GetDifficulty() * 4294.967296 / nTargetSpacingWork;
}

This code, appears to either be ridiculously inefficient, or just not functioning as it was intended to.

First; it takes an argument "blockindex", which isn't used anywhere. The prototype defines it to be NULL if a caller doesn't include it; which the caller doesn't. So it comes in as null. Not that it matters, since it's not used.

The code starts at the genesis block, and while (pindex), walks through the whole chain from genesis to tip. When it comes across a a block that is Proof of Work, it gets the time difference between the current block and the previous proof of work block; creates nTargetSpacingWork from that information, and then checks if it's bigger then the minimum...

... and then continues to the next block. When it finds another Proof of Work block, it overwrites nTargetSpacingWork with the new information.

In other words; it walks down the whole entire chain, doing calculations at every proof of work block it finds, only to return the nTargetSpacingWork for the last Proof of Work block it found.

If that is really what was intended; then it would make much more sense to start at chainActive.Tip(), and walk backwards through the chain until you find a proof of work block (setting pindexNextWork to be that block), and continuing until the next earlier PoW block is found, calculate the spacing if pIndexNextWork != NULL, and breaking out of the while loop when done.

e.g.

pindex = chainActive.Tip();
pindexNextWork = NULL;
while (pindex) {
    if (pindex->isProofOfWork) {
        if (pindexNextWork == NULL) {
            pindexNextWork = pindex;
            continue;   // found the last, find the next to last.
        } else {
            int64_t nActualSpacingWork = pindexNextWork->GetBlockTime() - pindex->GetBlockTime();
            nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1);
            nTargetSpacingWork = std::max(nTargetSpacingWork, nTargetSpacingWorkMin);
            break;  // found both, got our number; get out.
        }
    }
  pindex = pindex->pprev;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.