Skip to content

Commit

Permalink
Merge #885: [Backport] 3.2.2 backports
Browse files Browse the repository at this point in the history
85ee5f2 Fix incorrect last checkpoint timestamp (Fuzzbawls)
bd4f505 [Net] Add additional checkpoints (Fuzzbawls)
a5c4b62 [Net] AcceptBlock, first prev block loaded from disk. (furszy)
a36360b [Net] Valid blocks from forks badly rejected due an invalid view of the available utxo set for forked chains + split height going one block further than what should be. (furszy)

Tree-SHA512: cd71b22893c01ae80faee9dbd737095718a4ffbedf6d94f984c0878e5e48513acf4822626dbc10ed624f5f2a5fd627dca7435d1cafc53cb639f71ab33f301fef
  • Loading branch information
Mrs-X committed May 8, 2019
2 parents 3c3266d + 85ee5f2 commit 68d6622
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
8 changes: 5 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
(908000, uint256("202708f8c289b676fceb832a079ff6b308a28608339acbf7584de533619d014d"))
(1142400, uint256("98aff9d605bf123247f98b1e3a02567eb5799d208d78ec30fb89737b1c1f79c5"))
(1679090, uint256("f747ce055ba1b12e1f2e842bd480bc647210799359cb2e553ab292065e3419d6")) //!< First block with a "wrapped" serial spend
(1686229, uint256("bb42bf1e886a7c23474634c90893dd3d68a6ccbfea4ac92a98da5cad0c6a6cb7")); //!< Last block in the "wrapped" serial attack range
(1686229, uint256("bb42bf1e886a7c23474634c90893dd3d68a6ccbfea4ac92a98da5cad0c6a6cb7")) //!< Last block in the "wrapped" serial attack range
(1778954, uint256("0d3241268264a2908d6babf00d9cd1ffb83d93d7bb4e428820127fe227c2029c")) //!< Network split here
(1788528, uint256("ea9243ff8fc079fdd7a04f11fac415de4d98e1bb0dc38db6f79f8f8bbfdbe496")); //!< Network split here
static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1551924791, // * UNIX timestamp of last checkpoint block
4036872, // * total number of transactions between genesis and last checkpoint
1556924938, // * UNIX timestamp of last checkpoint block
4271692, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
2000 // * estimated number of transactions per day after checkpoint
};
Expand Down
42 changes: 23 additions & 19 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4693,47 +4693,53 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
// Start at the block we're adding on to
CBlockIndex *prev = pindexPrev;

int readBlock = 0;
vector<CBigNum> vBlockSerials;
CBlock bl;
if (!ReadBlockFromDisk(bl, prev))
return error("%s: previous block %s not on disk", __func__, prev->GetBlockHash().GetHex());

vector<CBigNum> vBlockSerials;
int readBlock = 0;
// Go backwards on the forked chain up to the split
do {
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()){
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) {
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) {
for (const CTxIn &stakeIn : pivInputs) {
// if it's already spent

// First regular staking check
if(hasPIVInputs) {
if (hasPIVInputs) {
if (stakeIn.prevout == in.prevout) {
return state.DoS(100, error("%s: input already spent on a previous block", __func__));
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()){
if (in.scriptSig.IsZerocoinSpend()) {
vBlockSerials.push_back(TxInToZerocoinSpend(in).getCoinSerialNumber());
}
}
}
}
}

// 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
splitHeight = prev->nHeight;
Expand Down Expand Up @@ -4795,9 +4801,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
return error("%s: coin stake inputs not available on main chain, received height %d vs current %d", __func__, nHeight, chainActive.Height());
}
if(coin && !coin->IsAvailable(in.prevout.n)){
// If this is not available get the height of the spent and validate it with the forked height
// Check if this occurred before the chain split
if(!(isBlockFromFork && coin->nHeight > splitHeight)){
if(!isBlockFromFork){
// Coins not available
return error("%s: coin stake inputs already spent in main chain", __func__);
}
Expand Down

0 comments on commit 68d6622

Please sign in to comment.