Skip to content

Commit

Permalink
[Net] AcceptBlock, first prev block loaded from disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed May 7, 2019
1 parent 2c76194 commit 754764b
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4693,49 +4693,52 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
// Start at the block we're adding on to
CBlockIndex *prev = pindexPrev;

CBlock bl;
if (!ReadBlockFromDisk(bl, prev))
return error("%s: previous block %s not on disk", __func__, prev->GetBlockHash().GetHex());

vector<CBigNum> vBlockSerials;
if (!chainActive.Contains(prev)) {
int readBlock = 0;
CBlock bl;
// Go backwards on the forked chain up to the split
do {
// Check if the forked chain is longer than the max reorg limit
if (readBlock == Params().MaxReorganizationDepth()) {
// TODO: Remove this chain from disk.
return error("%s: forked chain longer than maximum reorg limit", __func__);
}
int readBlock = 0;
// Go backwards on the forked chain up to the split
while (!chainActive.Contains(prev)) {

// Increase amount of read blocks
readBlock++;
// Check if the forked chain is longer than the max reorg limit
if (readBlock == Params().MaxReorganizationDepth()) {
// TODO: Remove this chain from disk.
return error("%s: forked chain longer than maximum reorg limit", __func__);
}

if (!ReadBlockFromDisk(bl, prev))
// Previous block not on disk
return error("%s: previous block %s not on disk", __func__, prev->GetBlockHash().GetHex());
// Increase amount of read blocks
readBlock++;
// Loop through every input from said block
for (const CTransaction &t : bl.vtx) {
for (const CTxIn &in: t.vin) {
// Loop through every input of the staking tx
for (const CTxIn &stakeIn : pivInputs) {
// if it's already spent

// First regular staking check
if (hasPIVInputs) {
if (stakeIn.prevout == in.prevout) {
return state.DoS(100, error("%s: input already spent on a previous block",
__func__));
}

// Second, if there is zPoS staking then store the serials for later check
if (in.scriptSig.IsZerocoinSpend()) {
vBlockSerials.push_back(TxInToZerocoinSpend(in).getCoinSerialNumber());
}
// Loop through every input from said block
for (const CTransaction &t : bl.vtx) {
for (const CTxIn &in: t.vin) {
// Loop through every input of the staking tx
for (const CTxIn &stakeIn : pivInputs) {
// if it's already spent

// First regular staking check
if (hasPIVInputs) {
if (stakeIn.prevout == in.prevout) {
return state.DoS(100, error("%s: input already spent on a previous block",
__func__));
}

// Second, if there is zPoS staking then store the serials for later check
if (in.scriptSig.IsZerocoinSpend()) {
vBlockSerials.push_back(TxInToZerocoinSpend(in).getCoinSerialNumber());
}
}
}
}
}

prev = prev->pprev;
// Prev block
prev = prev->pprev;
if (!ReadBlockFromDisk(bl, prev))
// Previous block not on disk
return error("%s: previous block %s not on disk", __func__, prev->GetBlockHash().GetHex());

} while (!chainActive.Contains(prev));
}

// Split height
Expand Down

0 comments on commit 754764b

Please sign in to comment.