Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 765 Lines • ▼ Show 20 Lines | bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, | ||||
bool fOverrideMempoolLimit, const Amount nAbsurdFee) { | bool fOverrideMempoolLimit, const Amount nAbsurdFee) { | ||||
return AcceptToMemoryPoolWithTime(config, pool, state, tx, fLimitFree, | return AcceptToMemoryPoolWithTime(config, pool, state, tx, fLimitFree, | ||||
pfMissingInputs, GetTime(), | pfMissingInputs, GetTime(), | ||||
fOverrideMempoolLimit, nAbsurdFee); | fOverrideMempoolLimit, nAbsurdFee); | ||||
} | } | ||||
/** | /** | ||||
* Return transaction in txOut, and if it was found inside a block, its hash is | * Return transaction in txOut, and if it was found inside a block, its hash is | ||||
* placed in hashBlock. | * placed in hashBlock. If blockIndex is provided, the transaction is fetched | ||||
* from the corresponding block. | |||||
*/ | */ | ||||
bool GetTransaction(const Config &config, const TxId &txid, | bool GetTransaction(const Config &config, const TxId &txid, | ||||
CTransactionRef &txOut, uint256 &hashBlock, | CTransactionRef &txOut, uint256 &hashBlock, bool fAllowSlow, | ||||
bool fAllowSlow) { | CBlockIndex *blockIndex) { | ||||
CBlockIndex *pindexSlow = nullptr; | CBlockIndex *pindexSlow = blockIndex; | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (!blockIndex) { | |||||
CTransactionRef ptx = g_mempool.get(txid); | CTransactionRef ptx = g_mempool.get(txid); | ||||
if (ptx) { | if (ptx) { | ||||
txOut = ptx; | txOut = ptx; | ||||
return true; | return true; | ||||
} | } | ||||
if (fTxIndex) { | if (fTxIndex) { | ||||
CDiskTxPos postx; | CDiskTxPos postx; | ||||
if (pblocktree->ReadTxIndex(txid, postx)) { | if (pblocktree->ReadTxIndex(txid, postx)) { | ||||
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, | CAutoFile file(OpenBlockFile(postx, true), SER_DISK, | ||||
CLIENT_VERSION); | CLIENT_VERSION); | ||||
if (file.IsNull()) { | if (file.IsNull()) { | ||||
return error("%s: OpenBlockFile failed", __func__); | return error("%s: OpenBlockFile failed", __func__); | ||||
} | } | ||||
CBlockHeader header; | CBlockHeader header; | ||||
try { | try { | ||||
file >> header; | file >> header; | ||||
fseek(file.Get(), postx.nTxOffset, SEEK_CUR); | fseek(file.Get(), postx.nTxOffset, SEEK_CUR); | ||||
file >> txOut; | file >> txOut; | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
return error("%s: Deserialize or I/O error - %s", __func__, | return error("%s: Deserialize or I/O error - %s", __func__, | ||||
e.what()); | e.what()); | ||||
} | } | ||||
hashBlock = header.GetHash(); | hashBlock = header.GetHash(); | ||||
if (txOut->GetId() != txid) { | if (txOut->GetHash() != txid) { | ||||
Fabien: Keep `GetId()` | |||||
return error("%s: txid mismatch", __func__); | return error("%s: txid mismatch", __func__); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
// transaction not found in index, nothing more can be done | // transaction not found in index, nothing more can be done | ||||
return false; | return false; | ||||
} | } | ||||
// use coin database to locate block that contains transaction, and scan it | // use coin database to locate block that contains transaction, and scan | ||||
// it | |||||
if (fAllowSlow) { | if (fAllowSlow) { | ||||
const Coin &coin = AccessByTxid(*pcoinsTip, txid); | const Coin &coin = AccessByTxid(*pcoinsTip, txid); | ||||
if (!coin.IsSpent()) { | if (!coin.IsSpent()) { | ||||
pindexSlow = chainActive[coin.GetHeight()]; | pindexSlow = chainActive[coin.GetHeight()]; | ||||
} | } | ||||
} | } | ||||
} | |||||
if (pindexSlow) { | if (pindexSlow) { | ||||
CBlock block; | CBlock block; | ||||
if (ReadBlockFromDisk(block, pindexSlow, config)) { | if (ReadBlockFromDisk(block, pindexSlow, config)) { | ||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
if (tx->GetId() == txid) { | if (tx->GetId() == txid) { | ||||
txOut = tx; | txOut = tx; | ||||
hashBlock = pindexSlow->GetBlockHash(); | hashBlock = pindexSlow->GetBlockHash(); | ||||
▲ Show 20 Lines • Show All 4,741 Lines • Show Last 20 Lines |
Keep GetId()