mirror of
https://github.com/monero-project/monero.git
synced 2024-11-17 08:17:37 +00:00
Merge pull request #1727
0288310e
blockchain_db: add "raw" blobdata getters for block and transaction (moneromooo-monero)
This commit is contained in:
commit
49efd3add9
13 changed files with 230 additions and 87 deletions
|
@ -200,6 +200,45 @@ void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
|
|||
remove_transaction_data(tx_hash, tx);
|
||||
}
|
||||
|
||||
block BlockchainDB::get_block_from_height(const uint64_t& height) const
|
||||
{
|
||||
blobdata bd = get_block_blob_from_height(height);
|
||||
block b;
|
||||
if (!parse_and_validate_block_from_blob(bd, b))
|
||||
throw new DB_ERROR("Failed to parse block from blob retrieved from the db");
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
block BlockchainDB::get_block(const crypto::hash& h) const
|
||||
{
|
||||
blobdata bd = get_block_blob(h);
|
||||
block b;
|
||||
if (!parse_and_validate_block_from_blob(bd, b))
|
||||
throw new DB_ERROR("Failed to parse block from blob retrieved from the db");
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool BlockchainDB::get_tx(const crypto::hash& h, cryptonote::transaction &tx) const
|
||||
{
|
||||
blobdata bd;
|
||||
if (!get_tx_blob(h, bd))
|
||||
return false;
|
||||
if (!parse_and_validate_tx_from_blob(bd, tx))
|
||||
throw new DB_ERROR("Failed to parse transaction from blob retrieved from the db");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
transaction BlockchainDB::get_tx(const crypto::hash& h) const
|
||||
{
|
||||
transaction tx;
|
||||
if (!get_tx(h, tx))
|
||||
throw new TX_DNE(std::string("tx with hash ").append(epee::string_tools::pod_to_hex(h)).append(" not found in db").c_str());
|
||||
return tx;
|
||||
}
|
||||
|
||||
void BlockchainDB::reset_stats()
|
||||
{
|
||||
num_calls = 0;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <string>
|
||||
#include <exception>
|
||||
#include "crypto/hash.h"
|
||||
#include "cryptonote_protocol/blobdatatype.h"
|
||||
#include "cryptonote_basic/cryptonote_basic.h"
|
||||
#include "cryptonote_basic/difficulty.h"
|
||||
#include "cryptonote_basic/hardfork.h"
|
||||
|
@ -754,7 +755,20 @@ public:
|
|||
*
|
||||
* @return the block requested
|
||||
*/
|
||||
virtual block get_block(const crypto::hash& h) const = 0;
|
||||
virtual cryptonote::blobdata get_block_blob(const crypto::hash& h) const = 0;
|
||||
|
||||
/**
|
||||
* @brief fetches the block with the given hash
|
||||
*
|
||||
* Returns the requested block.
|
||||
*
|
||||
* If the block does not exist, the subclass should throw BLOCK_DNE
|
||||
*
|
||||
* @param h the hash to look for
|
||||
*
|
||||
* @return the block requested
|
||||
*/
|
||||
block get_block(const crypto::hash& h) const;
|
||||
|
||||
/**
|
||||
* @brief gets the height of the block with a given hash
|
||||
|
@ -784,7 +798,7 @@ public:
|
|||
virtual block_header get_block_header(const crypto::hash& h) const = 0;
|
||||
|
||||
/**
|
||||
* @brief fetch a block by height
|
||||
* @brief fetch a block blob by height
|
||||
*
|
||||
* The subclass should return the block at the given height.
|
||||
*
|
||||
|
@ -793,9 +807,21 @@ public:
|
|||
*
|
||||
* @param height the height to look for
|
||||
*
|
||||
* @return the block blob
|
||||
*/
|
||||
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t& height) const = 0;
|
||||
|
||||
/**
|
||||
* @brief fetch a block by height
|
||||
*
|
||||
* If the block does not exist, that is to say if the blockchain is not
|
||||
* that high, then the subclass should throw BLOCK_DNE
|
||||
*
|
||||
* @param height the height to look for
|
||||
*
|
||||
* @return the block
|
||||
*/
|
||||
virtual block get_block_from_height(const uint64_t& height) const = 0;
|
||||
block get_block_from_height(const uint64_t& height) const;
|
||||
|
||||
/**
|
||||
* @brief fetch a block's timestamp
|
||||
|
@ -1009,20 +1035,28 @@ public:
|
|||
/**
|
||||
* @brief fetches the transaction with the given hash
|
||||
*
|
||||
* The subclass should return the transaction stored which has the given
|
||||
* hash.
|
||||
*
|
||||
* If the transaction does not exist, the subclass should throw TX_DNE.
|
||||
*
|
||||
* @param h the hash to look for
|
||||
*
|
||||
* @return the transaction with the given hash
|
||||
*/
|
||||
virtual transaction get_tx(const crypto::hash& h) const = 0;
|
||||
transaction get_tx(const crypto::hash& h) const;
|
||||
|
||||
/**
|
||||
* @brief fetches the transaction with the given hash
|
||||
*
|
||||
* If the transaction does not exist, the subclass should return false.
|
||||
*
|
||||
* @param h the hash to look for
|
||||
*
|
||||
* @return true iff the transaction was found
|
||||
*/
|
||||
bool get_tx(const crypto::hash& h, transaction &tx) const;
|
||||
|
||||
/**
|
||||
* @brief fetches the transaction blob with the given hash
|
||||
*
|
||||
* The subclass should return the transaction stored which has the given
|
||||
* hash.
|
||||
*
|
||||
|
@ -1032,7 +1066,7 @@ public:
|
|||
*
|
||||
* @return true iff the transaction was found
|
||||
*/
|
||||
virtual bool get_tx(const crypto::hash& h, transaction &tx) const = 0;
|
||||
virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const = 0;
|
||||
|
||||
/**
|
||||
* @brief fetches the total number of transactions ever
|
||||
|
|
|
@ -1460,12 +1460,12 @@ bool BlockchainLMDB::block_exists(const crypto::hash& h, uint64_t *height) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
block BlockchainLMDB::get_block(const crypto::hash& h) const
|
||||
cryptonote::blobdata BlockchainLMDB::get_block_blob(const crypto::hash& h) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
return get_block_from_height(get_block_height(h));
|
||||
return get_block_blob_from_height(get_block_height(h));
|
||||
}
|
||||
|
||||
uint64_t BlockchainLMDB::get_block_height(const crypto::hash& h) const
|
||||
|
@ -1498,7 +1498,7 @@ block_header BlockchainLMDB::get_block_header(const crypto::hash& h) const
|
|||
return get_block(h);
|
||||
}
|
||||
|
||||
block BlockchainLMDB::get_block_from_height(const uint64_t& height) const
|
||||
cryptonote::blobdata BlockchainLMDB::get_block_blob_from_height(const uint64_t& height) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
@ -1519,13 +1519,9 @@ block BlockchainLMDB::get_block_from_height(const uint64_t& height) const
|
|||
blobdata bd;
|
||||
bd.assign(reinterpret_cast<char*>(result.mv_data), result.mv_size);
|
||||
|
||||
block b;
|
||||
if (!parse_and_validate_block_from_blob(bd, b))
|
||||
throw0(DB_ERROR("Failed to parse block from blob retrieved from the db"));
|
||||
|
||||
TXN_POSTFIX_RDONLY();
|
||||
|
||||
return b;
|
||||
return bd;
|
||||
}
|
||||
|
||||
uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height) const
|
||||
|
@ -1868,7 +1864,7 @@ uint64_t BlockchainLMDB::get_tx_unlock_time(const crypto::hash& h) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool BlockchainLMDB::get_tx(const crypto::hash& h, transaction &tx) const
|
||||
bool BlockchainLMDB::get_tx_blob(const crypto::hash& h, cryptonote::blobdata &bd) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
@ -1891,26 +1887,13 @@ bool BlockchainLMDB::get_tx(const crypto::hash& h, transaction &tx) const
|
|||
else if (get_result)
|
||||
throw0(DB_ERROR(lmdb_error("DB error attempting to fetch tx from hash", get_result).c_str()));
|
||||
|
||||
blobdata bd;
|
||||
bd.assign(reinterpret_cast<char*>(result.mv_data), result.mv_size);
|
||||
|
||||
if (!parse_and_validate_tx_from_blob(bd, tx))
|
||||
throw0(DB_ERROR("Failed to parse tx from blob retrieved from the db"));
|
||||
|
||||
TXN_POSTFIX_RDONLY();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
transaction BlockchainLMDB::get_tx(const crypto::hash& h) const
|
||||
{
|
||||
transaction tx;
|
||||
|
||||
if (!get_tx(h, tx))
|
||||
throw1(TX_DNE(std::string("tx with hash ").append(epee::string_tools::pod_to_hex(h)).append(" not found in db").c_str()));
|
||||
return tx;
|
||||
}
|
||||
|
||||
uint64_t BlockchainLMDB::get_tx_count() const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
|
|
|
@ -170,13 +170,13 @@ public:
|
|||
|
||||
virtual bool block_exists(const crypto::hash& h, uint64_t *height = NULL) const;
|
||||
|
||||
virtual block get_block(const crypto::hash& h) const;
|
||||
|
||||
virtual uint64_t get_block_height(const crypto::hash& h) const;
|
||||
|
||||
virtual block_header get_block_header(const crypto::hash& h) const;
|
||||
|
||||
virtual block get_block_from_height(const uint64_t& height) const;
|
||||
virtual cryptonote::blobdata get_block_blob(const crypto::hash& h) const;
|
||||
|
||||
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t& height) const;
|
||||
|
||||
virtual uint64_t get_block_timestamp(const uint64_t& height) const;
|
||||
|
||||
|
@ -207,9 +207,7 @@ public:
|
|||
|
||||
virtual uint64_t get_tx_unlock_time(const crypto::hash& h) const;
|
||||
|
||||
virtual transaction get_tx(const crypto::hash& h) const;
|
||||
|
||||
virtual bool get_tx(const crypto::hash& h, transaction &tx) const;
|
||||
virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const;
|
||||
|
||||
virtual uint64_t get_tx_count() const;
|
||||
|
||||
|
|
|
@ -1431,7 +1431,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs) const
|
||||
bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks, std::list<cryptonote::blobdata>& txs) const
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
@ -1443,17 +1443,17 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block
|
|||
return false;
|
||||
}
|
||||
|
||||
for(const block& blk : blocks)
|
||||
for(const auto& blk : blocks)
|
||||
{
|
||||
std::list<crypto::hash> missed_ids;
|
||||
get_transactions(blk.tx_hashes, txs, missed_ids);
|
||||
get_transactions_blobs(blk.second.tx_hashes, txs, missed_ids);
|
||||
CHECK_AND_ASSERT_MES(!missed_ids.size(), false, "has missed transactions in own block in main blockchain");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks) const
|
||||
bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks) const
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
@ -1462,7 +1462,12 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list<block
|
|||
|
||||
for(size_t i = start_offset; i < start_offset + count && i < m_db->height();i++)
|
||||
{
|
||||
blocks.push_back(m_db->get_block_from_height(i));
|
||||
blocks.push_back(std::make_pair(m_db->get_block_blob_from_height(i), block()));
|
||||
if (!parse_and_validate_block_from_blob(blocks.back().first, blocks.back().second))
|
||||
{
|
||||
LOG_ERROR("Invalid block");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1480,22 +1485,22 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
|
|||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
m_db->block_txn_start(true);
|
||||
rsp.current_blockchain_height = get_current_blockchain_height();
|
||||
std::list<block> blocks;
|
||||
std::list<std::pair<cryptonote::blobdata,block>> blocks;
|
||||
get_blocks(arg.blocks, blocks, rsp.missed_ids);
|
||||
|
||||
for (const auto& bl: blocks)
|
||||
{
|
||||
std::list<crypto::hash> missed_tx_ids;
|
||||
std::list<transaction> txs;
|
||||
std::list<cryptonote::blobdata> txs;
|
||||
|
||||
// FIXME: s/rsp.missed_ids/missed_tx_id/ ? Seems like rsp.missed_ids
|
||||
// is for missed blocks, not missed transactions as well.
|
||||
get_transactions(bl.tx_hashes, txs, missed_tx_ids);
|
||||
get_transactions_blobs(bl.second.tx_hashes, txs, missed_tx_ids);
|
||||
|
||||
if (missed_tx_ids.size() != 0)
|
||||
{
|
||||
LOG_ERROR("Error retrieving blocks, missed " << missed_tx_ids.size()
|
||||
<< " transactions for block with hash: " << get_block_hash(bl)
|
||||
<< " transactions for block with hash: " << get_block_hash(bl.second)
|
||||
<< std::endl
|
||||
);
|
||||
|
||||
|
@ -1510,17 +1515,17 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
|
|||
rsp.blocks.push_back(block_complete_entry());
|
||||
block_complete_entry& e = rsp.blocks.back();
|
||||
//pack block
|
||||
e.block = t_serializable_object_to_blob(bl);
|
||||
e.block = bl.first;
|
||||
//pack transactions
|
||||
for (transaction& tx: txs)
|
||||
e.txs.push_back(t_serializable_object_to_blob(tx));
|
||||
for (const cryptonote::blobdata& tx: txs)
|
||||
e.txs.push_back(tx);
|
||||
}
|
||||
//get another transactions, if need
|
||||
std::list<transaction> txs;
|
||||
get_transactions(arg.txs, txs, rsp.missed_ids);
|
||||
std::list<cryptonote::blobdata> txs;
|
||||
get_transactions_blobs(arg.txs, txs, rsp.missed_ids);
|
||||
//pack aside transactions
|
||||
for (const auto& tx: txs)
|
||||
rsp.txs.push_back(t_serializable_object_to_blob(tx));
|
||||
rsp.txs.push_back(tx);
|
||||
|
||||
m_db->block_txn_stop();
|
||||
return true;
|
||||
|
@ -1889,7 +1894,12 @@ bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container
|
|||
{
|
||||
try
|
||||
{
|
||||
blocks.push_back(m_db->get_block(block_hash));
|
||||
blocks.push_back(std::make_pair(m_db->get_block_blob(block_hash), block()));
|
||||
if (!parse_and_validate_block_from_blob(blocks.back().first, blocks.back().second))
|
||||
{
|
||||
LOG_ERROR("Invalid block");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const BLOCK_DNE& e)
|
||||
{
|
||||
|
@ -1906,6 +1916,30 @@ bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container
|
|||
//TODO: return type should be void, throw on exception
|
||||
// alternatively, return true only if no transactions missed
|
||||
template<class t_ids_container, class t_tx_container, class t_missed_container>
|
||||
bool Blockchain::get_transactions_blobs(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) const
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
||||
for (const auto& tx_hash : txs_ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
cryptonote::blobdata tx;
|
||||
if (m_db->get_tx_blob(tx_hash, tx))
|
||||
txs.push_back(std::move(tx));
|
||||
else
|
||||
missed_txs.push_back(tx_hash);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
template<class t_ids_container, class t_tx_container, class t_missed_container>
|
||||
bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) const
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
|
@ -1915,9 +1949,16 @@ bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container
|
|||
{
|
||||
try
|
||||
{
|
||||
transaction tx;
|
||||
if (m_db->get_tx(tx_hash, tx))
|
||||
txs.push_back(std::move(tx));
|
||||
cryptonote::blobdata tx;
|
||||
if (m_db->get_tx_blob(tx_hash, tx))
|
||||
{
|
||||
txs.push_back(transaction());
|
||||
if (!parse_and_validate_tx_from_blob(tx, txs.back()))
|
||||
{
|
||||
LOG_ERROR("Invalid transaction");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
missed_txs.push_back(tx_hash);
|
||||
}
|
||||
|
@ -2001,7 +2042,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
|
|||
// find split point between ours and foreign blockchain (or start at
|
||||
// blockchain height <req_start_block>), and return up to max_count FULL
|
||||
// blocks by reference.
|
||||
bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const
|
||||
bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
@ -2030,9 +2071,11 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
|
|||
for(size_t i = start_height; i < total_height && count < max_count; i++, count++)
|
||||
{
|
||||
blocks.resize(blocks.size()+1);
|
||||
blocks.back().first = m_db->get_block_from_height(i);
|
||||
blocks.back().first = m_db->get_block_blob_from_height(i);
|
||||
block b;
|
||||
CHECK_AND_ASSERT_MES(parse_and_validate_block_from_blob(blocks.back().first, b), false, "internal error, invalid block");
|
||||
std::list<crypto::hash> mis;
|
||||
get_transactions(blocks.back().first.tx_hashes, blocks.back().second, mis);
|
||||
get_transactions_blobs(b.tx_hashes, blocks.back().second, mis);
|
||||
CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, transaction from block not found");
|
||||
}
|
||||
m_db->block_txn_stop();
|
||||
|
@ -4015,3 +4058,7 @@ bool Blockchain::for_all_outputs(std::function<bool(uint64_t amount, const crypt
|
|||
{
|
||||
return m_db->for_all_outputs(f);;
|
||||
}
|
||||
|
||||
namespace cryptonote {
|
||||
template bool Blockchain::get_transactions(const std::vector<crypto::hash>&, std::list<transaction>&, std::list<crypto::hash>&) const;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace cryptonote
|
|||
*
|
||||
* @return false if start_offset > blockchain height, else true
|
||||
*/
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs) const;
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks, std::list<cryptonote::blobdata>& txs) const;
|
||||
|
||||
/**
|
||||
* @brief get blocks from blocks based on start height and count
|
||||
|
@ -164,7 +164,7 @@ namespace cryptonote
|
|||
*
|
||||
* @return false if start_offset > blockchain height, else true
|
||||
*/
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks) const;
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks) const;
|
||||
|
||||
/**
|
||||
* @brief compiles a list of all blocks stored as alternative chains
|
||||
|
@ -407,7 +407,7 @@ namespace cryptonote
|
|||
*
|
||||
* @return true if a block found in common or req_start_block specified, else false
|
||||
*/
|
||||
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const;
|
||||
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const;
|
||||
|
||||
/**
|
||||
* @brief retrieves a set of blocks and their transactions, and possibly other transactions
|
||||
|
@ -621,9 +621,10 @@ namespace cryptonote
|
|||
* @return false if an unexpected exception occurs, else true
|
||||
*/
|
||||
template<class t_ids_container, class t_tx_container, class t_missed_container>
|
||||
bool get_transactions_blobs(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) const;
|
||||
template<class t_ids_container, class t_tx_container, class t_missed_container>
|
||||
bool get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) const;
|
||||
|
||||
|
||||
//debug functions
|
||||
|
||||
/**
|
||||
|
|
|
@ -198,15 +198,31 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs) const
|
||||
bool core::get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks, std::list<cryptonote::blobdata>& txs) const
|
||||
{
|
||||
return m_blockchain_storage.get_blocks(start_offset, count, blocks, txs);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks) const
|
||||
bool core::get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks) const
|
||||
{
|
||||
return m_blockchain_storage.get_blocks(start_offset, count, blocks);
|
||||
} //-----------------------------------------------------------------------------------------------
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks) const
|
||||
{
|
||||
std::list<std::pair<cryptonote::blobdata, cryptonote::block>> bs;
|
||||
if (!m_blockchain_storage.get_blocks(start_offset, count, bs))
|
||||
return false;
|
||||
for (const auto &b: bs)
|
||||
blocks.push_back(b.second);
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::blobdata>& txs, std::list<crypto::hash>& missed_txs) const
|
||||
{
|
||||
return m_blockchain_storage.get_transactions_blobs(txs_ids, txs, missed_txs);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<transaction>& txs, std::list<crypto::hash>& missed_txs) const
|
||||
{
|
||||
return m_blockchain_storage.get_transactions(txs_ids, txs, missed_txs);
|
||||
|
@ -795,7 +811,7 @@ namespace cryptonote
|
|||
return m_blockchain_storage.find_blockchain_supplement(qblock_ids, resp);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const
|
||||
bool core::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const
|
||||
{
|
||||
return m_blockchain_storage.find_blockchain_supplement(req_start_block, qblock_ids, blocks, total_height, start_height, max_count);
|
||||
}
|
||||
|
@ -863,8 +879,8 @@ namespace cryptonote
|
|||
arg.hop = 0;
|
||||
arg.current_blockchain_height = m_blockchain_storage.get_current_blockchain_height();
|
||||
std::list<crypto::hash> missed_txs;
|
||||
std::list<transaction> txs;
|
||||
m_blockchain_storage.get_transactions(b.tx_hashes, txs, missed_txs);
|
||||
std::list<cryptonote::blobdata> txs;
|
||||
m_blockchain_storage.get_transactions_blobs(b.tx_hashes, txs, missed_txs);
|
||||
if(missed_txs.size() && m_blockchain_storage.get_block_id_by_height(get_block_height(b)) != get_block_hash(b))
|
||||
{
|
||||
LOG_PRINT_L1("Block found but, seems that reorganize just happened after that, do not relay this block");
|
||||
|
@ -876,7 +892,7 @@ namespace cryptonote
|
|||
block_to_blob(b, arg.b.block);
|
||||
//pack transactions
|
||||
for(auto& tx: txs)
|
||||
arg.b.txs.push_back(t_serializable_object_to_blob(tx));
|
||||
arg.b.txs.push_back(tx);
|
||||
|
||||
m_pprotocol->relay_block(arg, exclude_context);
|
||||
}
|
||||
|
|
|
@ -287,16 +287,23 @@ namespace cryptonote
|
|||
bool get_blockchain_top(uint64_t& height, crypto::hash& top_id) const;
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::get_blocks(uint64_t, size_t, std::list<block>&, std::list<transaction>&) const
|
||||
* @copydoc Blockchain::get_blocks(uint64_t, size_t, std::list<std::pair<cryptonote::blobdata,block>>&, std::list<transaction>&) const
|
||||
*
|
||||
* @note see Blockchain::get_blocks(uint64_t, size_t, std::list<block>&, std::list<transaction>&) const
|
||||
* @note see Blockchain::get_blocks(uint64_t, size_t, std::list<std::pair<cryptonote::blobdata,block>>&, std::list<transaction>&) const
|
||||
*/
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs) const;
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks, std::list<cryptonote::blobdata>& txs) const;
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::get_blocks(uint64_t, size_t, std::list<block>&) const
|
||||
* @copydoc Blockchain::get_blocks(uint64_t, size_t, std::list<std::pair<cryptonote::blobdata,block>>&) const
|
||||
*
|
||||
* @note see Blockchain::get_blocks(uint64_t, size_t, std::list<block>&) const
|
||||
* @note see Blockchain::get_blocks(uint64_t, size_t, std::list<std::pair<cryptonote::blobdata,block>>&) const
|
||||
*/
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata,block>>& blocks) const;
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::get_blocks(uint64_t, size_t, std::list<std::pair<cryptonote::blobdata,block>>&) const
|
||||
*
|
||||
* @note see Blockchain::get_blocks(uint64_t, size_t, std::list<std::pair<cryptonote::blobdata,block>>&) const
|
||||
*/
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks) const;
|
||||
|
||||
|
@ -318,6 +325,13 @@ namespace cryptonote
|
|||
*/
|
||||
crypto::hash get_block_id_by_height(uint64_t height) const;
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::get_transactions
|
||||
*
|
||||
* @note see Blockchain::get_transactions
|
||||
*/
|
||||
bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::blobdata>& txs, std::list<crypto::hash>& missed_txs) const;
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::get_transactions
|
||||
*
|
||||
|
@ -431,11 +445,11 @@ namespace cryptonote
|
|||
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp) const;
|
||||
|
||||
/**
|
||||
* @copydoc Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::list<std::pair<block, std::list<transaction> > >&, uint64_t&, uint64_t&, size_t) const
|
||||
* @copydoc Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > >&, uint64_t&, uint64_t&, size_t) const
|
||||
*
|
||||
* @note see Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::list<std::pair<block, std::list<transaction> > >&, uint64_t&, uint64_t&, size_t) const
|
||||
* @note see Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::list<std::pair<cryptonote::blobdata, std::list<transaction> > >&, uint64_t&, uint64_t&, size_t) const
|
||||
*/
|
||||
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const;
|
||||
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) const;
|
||||
|
||||
/**
|
||||
* @brief gets some stats about the daemon
|
||||
|
|
|
@ -635,6 +635,9 @@ namespace cryptonote
|
|||
{
|
||||
MLOG_P2P_MESSAGE("Received NOTIFY_REQUEST_FLUFFY_MISSING_TX (" << arg.missing_tx_indices.size() << " txes), block hash " << arg.block_hash);
|
||||
|
||||
std::list<std::pair<cryptonote::blobdata, block>> local_blocks;
|
||||
std::list<cryptonote::blobdata> local_txs;
|
||||
|
||||
block b;
|
||||
if (!m_core.get_block_by_hash(arg.block_hash, b))
|
||||
{
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace cryptonote
|
|||
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res)
|
||||
{
|
||||
CHECK_CORE_BUSY();
|
||||
std::list<std::pair<block, std::list<transaction> > > bs;
|
||||
std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > > bs;
|
||||
|
||||
if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
|
||||
{
|
||||
|
@ -159,24 +159,30 @@ namespace cryptonote
|
|||
return false;
|
||||
}
|
||||
|
||||
for(auto& b: bs)
|
||||
for(auto& bd: bs)
|
||||
{
|
||||
res.blocks.resize(res.blocks.size()+1);
|
||||
res.blocks.back().block = block_to_blob(b.first);
|
||||
res.blocks.back().block = bd.first;
|
||||
res.output_indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices());
|
||||
res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices());
|
||||
bool r = m_core.get_tx_outputs_gindexs(get_transaction_hash(b.first.miner_tx), res.output_indices.back().indices.back().indices);
|
||||
block b;
|
||||
if (!parse_and_validate_block_from_blob(bd.first, b))
|
||||
{
|
||||
res.status = "Invalid block";
|
||||
return false;
|
||||
}
|
||||
bool r = m_core.get_tx_outputs_gindexs(get_transaction_hash(b.miner_tx), res.output_indices.back().indices.back().indices);
|
||||
if (!r)
|
||||
{
|
||||
res.status = "Failed";
|
||||
return false;
|
||||
}
|
||||
size_t txidx = 0;
|
||||
for(auto& t: b.second)
|
||||
for(const auto& t: bd.second)
|
||||
{
|
||||
res.blocks.back().txs.push_back(tx_to_blob(t));
|
||||
res.blocks.back().txs.push_back(t);
|
||||
res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices());
|
||||
bool r = m_core.get_tx_outputs_gindexs(b.first.tx_hashes[txidx++], res.output_indices.back().indices.back().indices);
|
||||
bool r = m_core.get_tx_outputs_gindexs(b.tx_hashes[txidx++], res.output_indices.back().indices.back().indices);
|
||||
if (!r)
|
||||
{
|
||||
res.status = "Failed";
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace tests
|
|||
virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {}
|
||||
bool get_testnet() const { return false; }
|
||||
bool get_pool_transaction(const crypto::hash& id, cryptonote::transaction& tx) const { return false; }
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<cryptonote::block>& blocks, std::list<cryptonote::transaction>& txs) const { return false; }
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata, cryptonote::block>>& blocks, std::list<cryptonote::blobdata>& txs) const { return false; }
|
||||
bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::transaction>& txs, std::list<crypto::hash>& missed_txs) const { return false; }
|
||||
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {}
|
||||
bool get_testnet() const { return false; }
|
||||
bool get_pool_transaction(const crypto::hash& id, cryptonote::transaction& tx) const { return false; }
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<cryptonote::block>& blocks, std::list<cryptonote::transaction>& txs) const { return false; }
|
||||
bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata, cryptonote::block>>& blocks, std::list<cryptonote::blobdata>& txs) const { return false; }
|
||||
bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::transaction>& txs, std::list<crypto::hash>& missed_txs) const { return false; }
|
||||
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
|
||||
};
|
||||
|
|
|
@ -59,7 +59,9 @@ public:
|
|||
virtual void block_txn_abort() {}
|
||||
virtual void drop_hard_fork_info() {}
|
||||
virtual bool block_exists(const crypto::hash& h, uint64_t *height) const { return false; }
|
||||
virtual block get_block(const crypto::hash& h) const { return block(); }
|
||||
virtual blobdata get_block_blob_from_height(const uint64_t& height) const { return blobdata(); }
|
||||
virtual blobdata get_block_blob(const crypto::hash& h) const { return blobdata(); }
|
||||
virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const { return false; }
|
||||
virtual uint64_t get_block_height(const crypto::hash& h) const { return 0; }
|
||||
virtual block_header get_block_header(const crypto::hash& h) const { return block_header(); }
|
||||
virtual uint64_t get_block_timestamp(const uint64_t& height) const { return 0; }
|
||||
|
|
Loading…
Reference in a new issue