Skip to content

Commit 754764b

Browse files
committed
[Net] AcceptBlock, first prev block loaded from disk.
1 parent 2c76194 commit 754764b

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

src/main.cpp

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4693,49 +4693,52 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
46934693
// Start at the block we're adding on to
46944694
CBlockIndex *prev = pindexPrev;
46954695

4696+
CBlock bl;
4697+
if (!ReadBlockFromDisk(bl, prev))
4698+
return error("%s: previous block %s not on disk", __func__, prev->GetBlockHash().GetHex());
4699+
46964700
vector<CBigNum> vBlockSerials;
4697-
if (!chainActive.Contains(prev)) {
4698-
int readBlock = 0;
4699-
CBlock bl;
4700-
// Go backwards on the forked chain up to the split
4701-
do {
4702-
// Check if the forked chain is longer than the max reorg limit
4703-
if (readBlock == Params().MaxReorganizationDepth()) {
4704-
// TODO: Remove this chain from disk.
4705-
return error("%s: forked chain longer than maximum reorg limit", __func__);
4706-
}
4701+
int readBlock = 0;
4702+
// Go backwards on the forked chain up to the split
4703+
while (!chainActive.Contains(prev)) {
4704+
4705+
// Increase amount of read blocks
4706+
readBlock++;
4707+
// Check if the forked chain is longer than the max reorg limit
4708+
if (readBlock == Params().MaxReorganizationDepth()) {
4709+
// TODO: Remove this chain from disk.
4710+
return error("%s: forked chain longer than maximum reorg limit", __func__);
4711+
}
47074712

4708-
if (!ReadBlockFromDisk(bl, prev))
4709-
// Previous block not on disk
4710-
return error("%s: previous block %s not on disk", __func__, prev->GetBlockHash().GetHex());
4711-
// Increase amount of read blocks
4712-
readBlock++;
4713-
// Loop through every input from said block
4714-
for (const CTransaction &t : bl.vtx) {
4715-
for (const CTxIn &in: t.vin) {
4716-
// Loop through every input of the staking tx
4717-
for (const CTxIn &stakeIn : pivInputs) {
4718-
// if it's already spent
4719-
4720-
// First regular staking check
4721-
if (hasPIVInputs) {
4722-
if (stakeIn.prevout == in.prevout) {
4723-
return state.DoS(100, error("%s: input already spent on a previous block",
4724-
__func__));
4725-
}
4726-
4727-
// Second, if there is zPoS staking then store the serials for later check
4728-
if (in.scriptSig.IsZerocoinSpend()) {
4729-
vBlockSerials.push_back(TxInToZerocoinSpend(in).getCoinSerialNumber());
4730-
}
4713+
// Loop through every input from said block
4714+
for (const CTransaction &t : bl.vtx) {
4715+
for (const CTxIn &in: t.vin) {
4716+
// Loop through every input of the staking tx
4717+
for (const CTxIn &stakeIn : pivInputs) {
4718+
// if it's already spent
4719+
4720+
// First regular staking check
4721+
if (hasPIVInputs) {
4722+
if (stakeIn.prevout == in.prevout) {
4723+
return state.DoS(100, error("%s: input already spent on a previous block",
4724+
__func__));
4725+
}
4726+
4727+
// Second, if there is zPoS staking then store the serials for later check
4728+
if (in.scriptSig.IsZerocoinSpend()) {
4729+
vBlockSerials.push_back(TxInToZerocoinSpend(in).getCoinSerialNumber());
47314730
}
47324731
}
47334732
}
47344733
}
4734+
}
47354735

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

4738-
} while (!chainActive.Contains(prev));
47394742
}
47404743

47414744
// Split height

0 commit comments

Comments
 (0)