Skip to content

Commit

Permalink
add blocks that have pegins rejected to the reconsider queue
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Nov 6, 2017
1 parent 0b9c5eb commit 6bad4e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/consensus/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const unsigned char REJECT_NONSTANDARD = 0x40;
static const unsigned char REJECT_DUST = 0x41;
static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
static const unsigned char REJECT_CHECKPOINT = 0x43;
static const unsigned char REJECT_PEGIN = 0x44;

/** Capture information about block/transaction validation */
class CValidationState {
Expand Down
23 changes: 21 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
if (tx.vin[i].m_is_pegin) {
// Check existence and validity of pegin witness
if (tx.wit.vtxinwit.size() <= i || !IsValidPeginWitness(tx.wit.vtxinwit[i].m_pegin_witness, prevout)) {
return state.DoS(0, false, REJECT_INVALID, "bad-pegin-witness", true);
return state.DoS(0, false, REJECT_PEGIN, "bad-pegin-witness", true);
}
std::pair<uint256, COutPoint> pegin = std::make_pair(uint256(tx.wit.vtxinwit[i].m_pegin_witness.stack[2]), prevout);
if (inputs.IsWithdrawSpent(pegin)) {
Expand Down Expand Up @@ -3035,7 +3035,26 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
if (!rv) {
if (state.IsInvalid()) {
InvalidBlockFound(pindexNew, state);
}
//Possibly result of RPC to bitcoind failure
//or unseen Bitcoin blocks.
if (state.GetRejectCode() == REJECT_PEGIN) {
//Write queue of invalid blocks that
//must be cleared to continue operation
std::vector<uint256> vinvalidBlocks;
pblocktree->ReadInvalidBlockQueue(vinvalidBlocks);
bool blockAlreadyInvalid = false;
BOOST_FOREACH(uint256& hash, vinvalidBlocks) {
if (hash == pblock->GetHash()) {
blockAlreadyInvalid = true;
break;
}
}
if (!blockAlreadyInvalid) {
vinvalidBlocks.push_back(pblock->GetHash());
pblocktree->WriteInvalidBlockQueue(vinvalidBlocks);
}
}
}

return error("ConnectTip(): ConnectBlock %s failed", pindexNew->GetBlockHash().ToString());
}
Expand Down

0 comments on commit 6bad4e9

Please sign in to comment.