Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.13.x] Backport: Move IS block filtering into ConnectBlock #2766

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2222,13 +2222,40 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
pindex->GetBlockHash().ToString(), FormatStateMessage(state));
}

// DASH : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS
// DASH

// It's possible that we simply don't have enough data and this could fail
// (i.e. block itself could be a correct one and we need to store it),
// that's why this is in ConnectBlock. Could be the other way around however -
// the peer who sent us this block is missing some data and wasn't able
// to recognize that block is actually invalid.

// DASH : CHECK TRANSACTIONS FOR INSTANTSEND

if (sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) {
// Require other nodes to comply, send them some data in case they are missing it.
for (const auto& tx : block.vtx) {
// skip txes that have no inputs
if (tx->vin.empty()) continue;
// LOOK FOR TRANSACTION LOCK IN OUR MAP OF OUTPOINTS
for (const auto& txin : tx->vin) {
uint256 hashLocked;
if (instantsend.GetLockedOutPointTxHash(txin.prevout, hashLocked) && hashLocked != tx->GetHash()) {
// The node which relayed this should switch to correct chain.
// TODO: relay instantsend data/proof.
LOCK(cs_main);
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
return state.DoS(10, error("ConnectBlock(DASH): transaction %s conflicts with transaction lock %s", tx->GetHash().ToString(), hashLocked.ToString()),
REJECT_INVALID, "conflict-tx-lock");
}
}
}
} else {
LogPrintf("ConnectBlock(DASH): spork is off, skipping transaction locking checks\n");
}

// DASH : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS

// TODO: resync data (both ways?) and try to reprocess this block later.
CAmount blockReward = nFees + GetBlockSubsidy(pindex->pprev->nBits, pindex->pprev->nHeight, chainparams.GetConsensus());
std::string strError = "";
Expand Down Expand Up @@ -3271,35 +3298,6 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
if (block.vtx[i]->IsCoinBase())
return state.DoS(100, false, REJECT_INVALID, "bad-cb-multiple", false, "more than one coinbase");


// DASH : CHECK TRANSACTIONS FOR INSTANTSEND

if(sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) {
// We should never accept block which conflicts with completed transaction lock,
// that's why this is in CheckBlock unlike coinbase payee/amount.
// Require other nodes to comply, send them some data in case they are missing it.
for(const auto& tx : block.vtx) {
// skip coinbase, it has no inputs
if (tx->IsCoinBase()) continue;
// LOOK FOR TRANSACTION LOCK IN OUR MAP OF OUTPOINTS
for (const auto& txin : tx->vin) {
uint256 hashLocked;
if(instantsend.GetLockedOutPointTxHash(txin.prevout, hashLocked) && hashLocked != tx->GetHash()) {
// The node which relayed this will have to switch later,
// relaying instantsend data won't help it.
LOCK(cs_main);
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
return state.DoS(100, false, REJECT_INVALID, "conflict-tx-lock", false,
strprintf("transaction %s conflicts with transaction lock %s", tx->GetHash().ToString(), hashLocked.ToString()));
}
}
}
} else {
LogPrintf("CheckBlock(DASH): spork is off, skipping transaction locking checks\n");
}

// END DASH

// Check transactions
for (const auto& tx : block.vtx)
if (!CheckTransaction(*tx, state))
Expand Down