Skip to content

Commit

Permalink
CheckTransaction add nHeight and blockReward
Browse files Browse the repository at this point in the history
  • Loading branch information
alamshafil committed Jul 14, 2022
1 parent 4b2d43f commit 119222c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
return nSigOps;
}

bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs, bool fMempoolCheck, bool fBlockCheck)
bool CheckTransaction(const CTransaction& tx, CValidationState &state, int nHeight, CAmount blockReward, bool fCheckDuplicateInputs, bool fMempoolCheck, bool fBlockCheck)
{
// Basic checks that don't depend on any context
if (tx.vin.empty())
Expand Down Expand Up @@ -395,7 +395,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe

// std::cout << "height=" << nHeight << ", reward=" << founderReward << endl;

if(nHeight > founderStartHeight && founderReward && !founderPayment.IsBlockPayeeValid(tx,nHeight,blockReward))
if(nHeight > founderStartHeight && founderReward && !founderPayment.IsBlockPayeeValid(tx, nHeight, blockReward))
return state.DoS(100, false, REJECT_INVALID, "bad-cb-founder-payment-not-found");
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/tx_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CNullAssetTxData;
/** Transaction validation functions */

/** Context-independent validity checks */
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true, bool fMempoolCheck = false, bool fBlockCheck = false);
bool CheckTransaction(const CTransaction& tx, CValidationState& state, int nHeight, CAmount blockReward, bool fCheckDuplicateInputs=true, bool fMempoolCheck = false, bool fBlockCheck = false);

namespace Consensus {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/founder_payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void FounderPayment::FillFounderPayment(CMutableTransaction& txNew, int nBlockHe
txoutFounderRet = CTxOut();
CScript payee;
// Fill payee with the foundFounderRewardStrcutureFounderRewardStrcutureer address
CBitcoinAddress cbAddress(founderAddress);
CAvianAddress cbAddress(founderAddress);
payee = GetScriptForDestination(cbAddress.Get());
// GET FOUNDER PAYMENT VARIABLES SETUP

Expand All @@ -46,7 +46,7 @@ bool FounderPayment::IsBlockPayeeValid(const CTransaction& txNew, const int heig
{
CScript payee;
// fill payee with the founder address
payee = GetScriptForDestination(CBitcoinAddress(founderAddress).Get());
payee = GetScriptForDestination(CAvianAddress(founderAddress).Get());
const CAmount founderReward = getFounderPaymentAmount(height, blockReward);
// std::cout << "founderReward = " << founderReward << endl;
BOOST_FOREACH (const CTxOut& out, txNew.vout) {
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;

// Fill founder payment
FounderPayment founderPayment = chainparams.GetConsensus().nFounderPayment;
founderPayment.FillFounderPayment(coinbaseTx, nHeight, blockReward, pblock->txoutFounder);
Expand Down
8 changes: 4 additions & 4 deletions src/test/assets/asset_tx_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ BOOST_FIXTURE_TEST_SUITE(asset_tx_tests, BasicTestingSetup)
bool fCheckBlock = false;

// Check that the CheckTransaction will fail when trying to add it to the mempool
bool fCheck = !CheckTransaction(tx, state, true, fCheckMempool, fCheckBlock);
bool fCheck = !CheckTransaction(tx, state, 0, 0, true, fCheckMempool, fCheckBlock);

BOOST_CHECK(fCheck);
BOOST_CHECK(state.GetRejectReason() == "bad-mempool-txns-asset-reissued-amount-isn't-zero");
Expand All @@ -539,7 +539,7 @@ BOOST_FIXTURE_TEST_SUITE(asset_tx_tests, BasicTestingSetup)
// Turn on the BIP that enforces the block check
SetEnforcedValues(true);

fCheck = !CheckTransaction(tx, state, true, fCheckMempool, fCheckBlock);
fCheck = !CheckTransaction(tx, state, 0, 0, true, fCheckMempool, fCheckBlock);
BOOST_CHECK(fCheck);
BOOST_CHECK(state.GetRejectReason() == "bad-txns-asset-reissued-amount-isn't-zero");
}
Expand Down Expand Up @@ -591,14 +591,14 @@ BOOST_FIXTURE_TEST_SUITE(asset_tx_tests, BasicTestingSetup)
// Setting the coinbase check to true
// This check should now fail on the CheckTransaction call
SetEnforcedCoinbase(true);
bool fCheck = CheckTransaction(tx, state, true);
bool fCheck = CheckTransaction(tx, state, 0, 0, true);
BOOST_CHECK(!fCheck);
BOOST_CHECK(state.GetRejectReason() == "bad-txns-coinbase-contains-asset-txes");

// Setting the coinbase check to false
// This check should now pass the CheckTransaction call
SetEnforcedCoinbase(false);
fCheck = CheckTransaction(tx, state, true);
fCheck = CheckTransaction(tx, state, 0, 0, true);
BOOST_CHECK(fCheck);

// Remove wallet used for testing
Expand Down
2 changes: 1 addition & 1 deletion src/test/sighash_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
stream >> tx;

CValidationState state;
BOOST_CHECK_MESSAGE(CheckTransaction(*tx, state), strTest);
BOOST_CHECK_MESSAGE(CheckTransaction(*tx, state, 0, 0), strTest);
BOOST_CHECK(state.IsValid());

std::vector<unsigned char> raw = ParseHex(raw_script);
Expand Down
8 changes: 4 additions & 4 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup)
CTransaction tx(deserialize, stream);

CValidationState state;
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state, 0, 0), strTest);
BOOST_CHECK(state.IsValid());

PrecomputedTransactionData txdata(tx);
Expand Down Expand Up @@ -252,7 +252,7 @@ BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup)
CTransaction tx(deserialize, stream);

CValidationState state;
fValid = CheckTransaction(tx, state) && state.IsValid();
fValid = CheckTransaction(tx, state, 0, 0) && state.IsValid();

PrecomputedTransactionData txdata(tx);
for (unsigned int i = 0; i < tx.vin.size() && fValid; i++)
Expand Down Expand Up @@ -290,11 +290,11 @@ BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup)
CMutableTransaction tx;
stream >> tx;
CValidationState state;
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state) && state.IsValid(), "Simple deserialized transaction should be valid.");
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state, 0, 0) && state.IsValid(), "Simple deserialized transaction should be valid.");

// Check that duplicate txins fail
tx.vin.push_back(tx.vin[0]);
BOOST_CHECK_MESSAGE(!CheckTransaction(tx, state) || !state.IsValid(), "Transaction with duplicate txins should be invalid.");
BOOST_CHECK_MESSAGE(!CheckTransaction(tx, state, 0, 0) || !state.IsValid(), "Transaction with duplicate txins should be invalid.");
}

//
Expand Down
6 changes: 3 additions & 3 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
indexed_transaction_set::iterator i = mapTx.find(hash);
if (i != mapTx.end()) {
CValidationState state;
if (!setAlreadyRemoving.count(hash) && !CheckTransaction(i->GetTx(), state, passets)) {
if (!setAlreadyRemoving.count(hash) && !CheckTransaction(i->GetTx(), state, 0, 0, passets)) {
entries.push_back(&*i);
trans.emplace_back(i->GetTx());
setAlreadyRemoving.insert(hash);
Expand All @@ -905,7 +905,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
indexed_transaction_set::iterator i = mapTx.find(hash);
if (i != mapTx.end()) {
CValidationState state;
if (!setAlreadyRemoving.count(hash) && !CheckTransaction(i->GetTx(), state, passets)) {
if (!setAlreadyRemoving.count(hash) && !CheckTransaction(i->GetTx(), state, 0, 0, passets)) {
entries.push_back(&*i);
trans.emplace_back(i->GetTx());
setAlreadyRemoving.insert(hash);
Expand All @@ -922,7 +922,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
indexed_transaction_set::iterator i = mapTx.find(hash);
if (i != mapTx.end()) {
CValidationState state;
if (!setAlreadyRemoving.count(hash) && !CheckTransaction(i->GetTx(), state, passets)) {
if (!setAlreadyRemoving.count(hash) && !CheckTransaction(i->GetTx(), state, 0, 0, passets)) {
entries.push_back(&*i);
trans.emplace_back(i->GetTx());
setAlreadyRemoving.insert(hash);
Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool

bool fCheckDuplicates = true;
bool fCheckMempool = true;
if (!CheckTransaction(tx, state, fCheckDuplicates, fCheckMempool))
if (!CheckTransaction(tx, state, 0, 0, fCheckDuplicates, fCheckMempool))
return false; // state filled in by CheckTransaction

// Coinbase is only valid in a block, not as a loose transaction
Expand Down Expand Up @@ -4062,7 +4062,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::C
// We want to make sure when nodes shutdown and restart that they still
// verify the blocks in the database correctly even if Enforce Value BIP is active
fCheckBlock = CHECK_BLOCK_TRANSACTION_TRUE;
if (!CheckTransaction(*tx, state, fCheckDuplicates, fCheckMempool, fCheckBlock))
if (!CheckTransaction(*tx, state, nHeight - 1, blockReward, fCheckDuplicates, fCheckMempool, fCheckBlock))
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
strprintf("Transaction check failed (tx hash %s) %s %s", tx->GetHash().ToString(),
state.GetDebugMessage(), state.GetRejectReason()));
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
CWalletTx wtx;
ssValue >> wtx;
CValidationState state;
if (!(CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid())) {
if (!(CheckTransaction(wtx, state, 0, 0) && (wtx.GetHash() == hash) && state.IsValid())) {
// If a client has a wallet.dat that contains asset transactions, but we are syncing the chain.
// we want to make sure that we don't fail to load this wallet transaction just because it is an asset transaction
// before asset are active
Expand Down

0 comments on commit 119222c

Please sign in to comment.