Skip to content

Commit

Permalink
Move IS block filtering into ConnectBlock (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock authored and UdjinM6 committed Mar 12, 2019
1 parent fbcb614 commit 548a489
Showing 1 changed file with 28 additions and 30 deletions.
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

0 comments on commit 548a489

Please sign in to comment.