Skip to content

Commit 55152cb

Browse files
UdjinM6codablock
authored andcommitted
Move IS block filtering into ConnectBlock
1 parent 2299ee2 commit 55152cb

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

src/validation.cpp

+37-39
Original file line numberDiff line numberDiff line change
@@ -2209,13 +2209,49 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
22092209
LogPrint("bench", " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n", nInputs - 1, 0.001 * (nTime4 - nTime2), nInputs <= 1 ? 0 : 0.001 * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * 0.000001);
22102210

22112211

2212-
// DASH : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS
2212+
// DASH
22132213

22142214
// It's possible that we simply don't have enough data and this could fail
22152215
// (i.e. block itself could be a correct one and we need to store it),
22162216
// that's why this is in ConnectBlock. Could be the other way around however -
22172217
// the peer who sent us this block is missing some data and wasn't able
22182218
// to recognize that block is actually invalid.
2219+
2220+
// DASH : CHECK TRANSACTIONS FOR INSTANTSEND
2221+
2222+
if (sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) {
2223+
// Require other nodes to comply, send them some data in case they are missing it.
2224+
for (const auto& tx : block.vtx) {
2225+
// skip txes that have no inputs
2226+
if (tx->vin.empty()) continue;
2227+
// LOOK FOR TRANSACTION LOCK IN OUR MAP OF OUTPOINTS
2228+
for (const auto& txin : tx->vin) {
2229+
uint256 hashLocked;
2230+
if (instantsend.GetLockedOutPointTxHash(txin.prevout, hashLocked) && hashLocked != tx->GetHash()) {
2231+
// The node which relayed this should switch to correct chain.
2232+
// TODO: relay instantsend data/proof.
2233+
LOCK(cs_main);
2234+
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
2235+
return state.DoS(10, error("ConnectBlock(DASH): transaction %s conflicts with transaction lock %s", tx->GetHash().ToString(), hashLocked.ToString()),
2236+
REJECT_INVALID, "conflict-tx-lock");
2237+
}
2238+
}
2239+
uint256 txConflict;
2240+
if (llmq::quorumInstantSendManager->GetConflictingTx(*tx, txConflict)) {
2241+
// The node which relayed this should switch to correct chain.
2242+
// TODO: relay instantsend data/proof.
2243+
LOCK(cs_main);
2244+
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
2245+
return state.DoS(10, error("ConnectBlock(DASH): transaction %s conflicts with transaction lock %s", tx->GetHash().ToString(), txConflict.ToString()),
2246+
REJECT_INVALID, "conflict-tx-lock");
2247+
}
2248+
}
2249+
} else {
2250+
LogPrintf("ConnectBlock(DASH): spork is off, skipping transaction locking checks\n");
2251+
}
2252+
2253+
// DASH : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS
2254+
22192255
// TODO: resync data (both ways?) and try to reprocess this block later.
22202256
CAmount blockReward = nFees + GetBlockSubsidy(pindex->pprev->nBits, pindex->pprev->nHeight, chainparams.GetConsensus());
22212257
std::string strError = "";
@@ -3269,44 +3305,6 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
32693305
if (block.vtx[i]->IsCoinBase())
32703306
return state.DoS(100, false, REJECT_INVALID, "bad-cb-multiple", false, "more than one coinbase");
32713307

3272-
3273-
// DASH : CHECK TRANSACTIONS FOR INSTANTSEND
3274-
3275-
if(sporkManager.IsSporkActive(SPORK_3_INSTANTSEND_BLOCK_FILTERING)) {
3276-
// We should never accept block which conflicts with completed transaction lock,
3277-
// that's why this is in CheckBlock unlike coinbase payee/amount.
3278-
// Require other nodes to comply, send them some data in case they are missing it.
3279-
for(const auto& tx : block.vtx) {
3280-
// skip coinbase, it has no inputs
3281-
if (tx->IsCoinBase()) continue;
3282-
// LOOK FOR TRANSACTION LOCK IN OUR MAP OF OUTPOINTS
3283-
for (const auto& txin : tx->vin) {
3284-
uint256 hashLocked;
3285-
if(instantsend.GetLockedOutPointTxHash(txin.prevout, hashLocked) && hashLocked != tx->GetHash()) {
3286-
// The node which relayed this will have to switch later,
3287-
// relaying instantsend data won't help it.
3288-
LOCK(cs_main);
3289-
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
3290-
return state.DoS(100, false, REJECT_INVALID, "conflict-tx-lock", false,
3291-
strprintf("transaction %s conflicts with transaction lock %s", tx->GetHash().ToString(), hashLocked.ToString()));
3292-
}
3293-
}
3294-
uint256 txConflict;
3295-
if (llmq::quorumInstantSendManager->GetConflictingTx(*tx, txConflict)) {
3296-
// The node which relayed this will have to switch later,
3297-
// relaying instantsend data won't help it.
3298-
LOCK(cs_main);
3299-
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
3300-
return state.DoS(100, false, REJECT_INVALID, "conflict-tx-lock", false,
3301-
strprintf("transaction %s conflicts with transaction lock %s", tx->GetHash().ToString(), txConflict.ToString()));
3302-
}
3303-
}
3304-
} else {
3305-
LogPrintf("CheckBlock(DASH): spork is off, skipping transaction locking checks\n");
3306-
}
3307-
3308-
// END DASH
3309-
33103308
// Check transactions
33113309
for (const auto& tx : block.vtx)
33123310
if (!CheckTransaction(*tx, state))

0 commit comments

Comments
 (0)