Skip to content

Commit

Permalink
Merge pull request #1934 from cyrossignol/contract-reorg
Browse files Browse the repository at this point in the history
contract: Fix ability to reorganize contracts
  • Loading branch information
jamescowens authored Oct 17, 2020
2 parents beb6c1e + 046af6b commit 263035a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2302,8 +2302,16 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
}

// Validate any contracts published in the transaction:
if (!tx.GetContracts().empty() && !tx.CheckContracts(mapInputs)) {
return false;
if (!tx.GetContracts().empty()) {
if (!tx.CheckContracts(mapInputs)) {
return false;
}

if (nVersion >= 11 && !GRC::ValidateContracts(tx)) {
return tx.DoS(25, error("%s: invalid contract in tx %s",
__func__,
tx.GetHash().ToString()));
}
}

if (!tx.ConnectInputs(txdb, mapInputs, mapQueuedChanges, posThisTx, pindex, true, false))
Expand Down Expand Up @@ -3038,15 +3046,6 @@ bool CBlock::AcceptBlock(bool generated_by_me)
// Check that all transactions are finalized
if (!IsFinalTx(tx, nHeight, GetBlockTime()))
return DoS(10, error("AcceptBlock() : contains a non-final transaction"));

if (nVersion >= 9) {
// Perform contextual validation for any contracts:
if (!tx.GetContracts().empty() && !GRC::ValidateContracts(tx)) {
return tx.DoS(25, error("%s: invalid contract in tx %s",
__func__,
tx.GetHash().ToString()));
}
}
}

// Check that the block chain matches the known block chain up to a checkpoint
Expand Down

0 comments on commit 263035a

Please sign in to comment.