mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
Added a safety check to block template update
This commit is contained in:
parent
7eec4d742c
commit
8a27a8cce4
2 changed files with 14 additions and 0 deletions
|
@ -364,8 +364,14 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet
|
||||||
|
|
||||||
m_numTransactionHashes = m_mempoolTxsOrder.size();
|
m_numTransactionHashes = m_mempoolTxsOrder.size();
|
||||||
m_transactionHashes.assign(HASH_SIZE, 0);
|
m_transactionHashes.assign(HASH_SIZE, 0);
|
||||||
|
m_transactionHashesSet.clear();
|
||||||
|
m_transactionHashesSet.reserve(m_mempoolTxsOrder.size());
|
||||||
for (size_t i = 0; i < m_mempoolTxsOrder.size(); ++i) {
|
for (size_t i = 0; i < m_mempoolTxsOrder.size(); ++i) {
|
||||||
const TxMempoolData& tx = m_mempoolTxs[m_mempoolTxsOrder[i]];
|
const TxMempoolData& tx = m_mempoolTxs[m_mempoolTxsOrder[i]];
|
||||||
|
if (!m_transactionHashesSet.insert(tx.id).second) {
|
||||||
|
LOGERR(1, "Added transaction " << tx.id << " twice. Fix the code!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
m_transactionHashes.insert(m_transactionHashes.end(), tx.id.h, tx.id.h + HASH_SIZE);
|
m_transactionHashes.insert(m_transactionHashes.end(), tx.id.h, tx.id.h + HASH_SIZE);
|
||||||
final_fees += tx.fee;
|
final_fees += tx.fee;
|
||||||
final_weight += tx.weight;
|
final_weight += tx.weight;
|
||||||
|
@ -445,8 +451,14 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet
|
||||||
|
|
||||||
m_numTransactionHashes = m_mempoolTxsOrder.size();
|
m_numTransactionHashes = m_mempoolTxsOrder.size();
|
||||||
m_transactionHashes.assign(HASH_SIZE, 0);
|
m_transactionHashes.assign(HASH_SIZE, 0);
|
||||||
|
m_transactionHashesSet.clear();
|
||||||
|
m_transactionHashesSet.reserve(m_mempoolTxsOrder.size());
|
||||||
for (size_t i = 0; i < m_mempoolTxsOrder.size(); ++i) {
|
for (size_t i = 0; i < m_mempoolTxsOrder.size(); ++i) {
|
||||||
const TxMempoolData& tx = m_mempoolTxs[m_mempoolTxsOrder[i]];
|
const TxMempoolData& tx = m_mempoolTxs[m_mempoolTxsOrder[i]];
|
||||||
|
if (!m_transactionHashesSet.insert(tx.id).second) {
|
||||||
|
LOGERR(1, "Added transaction " << tx.id << " twice. Fix the code!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
m_transactionHashes.insert(m_transactionHashes.end(), tx.id.h, tx.id.h + HASH_SIZE);
|
m_transactionHashes.insert(m_transactionHashes.end(), tx.id.h, tx.id.h + HASH_SIZE);
|
||||||
final_fees += tx.fee;
|
final_fees += tx.fee;
|
||||||
final_weight += tx.weight;
|
final_weight += tx.weight;
|
||||||
|
@ -620,6 +632,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet
|
||||||
m_blockHeader.clear();
|
m_blockHeader.clear();
|
||||||
m_minerTxExtra.clear();
|
m_minerTxExtra.clear();
|
||||||
m_transactionHashes.clear();
|
m_transactionHashes.clear();
|
||||||
|
m_transactionHashesSet.clear();
|
||||||
m_rewards.clear();
|
m_rewards.clear();
|
||||||
m_mempoolTxs.clear();
|
m_mempoolTxs.clear();
|
||||||
m_mempoolTxsOrder.clear();
|
m_mempoolTxsOrder.clear();
|
||||||
|
|
|
@ -103,6 +103,7 @@ private:
|
||||||
std::vector<uint8_t> m_blockHeader;
|
std::vector<uint8_t> m_blockHeader;
|
||||||
std::vector<uint8_t> m_minerTxExtra;
|
std::vector<uint8_t> m_minerTxExtra;
|
||||||
std::vector<uint8_t> m_transactionHashes;
|
std::vector<uint8_t> m_transactionHashes;
|
||||||
|
unordered_set<hash> m_transactionHashesSet;
|
||||||
std::vector<uint64_t> m_rewards;
|
std::vector<uint64_t> m_rewards;
|
||||||
std::vector<TxMempoolData> m_mempoolTxs;
|
std::vector<TxMempoolData> m_mempoolTxs;
|
||||||
std::vector<int> m_mempoolTxsOrder;
|
std::vector<int> m_mempoolTxsOrder;
|
||||||
|
|
Loading…
Reference in a new issue