aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain_db.cpp
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2014-10-23 15:37:10 -0400
committerwarptangent <warptangent@inbox.com>2015-01-04 19:01:10 -0800
commitdb00ce0173f49ef9e1d07019b803155c9d4fe945 (patch)
tree85832eac48117bb0b697b7d868de6119270210f0 /src/cryptonote_core/blockchain_db.cpp
parentBlockchainDB unit tests, lmdb linker flag (diff)
downloadmonero-db00ce0173f49ef9e1d07019b803155c9d4fe945.tar.xz
Parts of LMDB impl of BlockchainDB done and working
The rest should just be tedious copypasta and modification.
Diffstat (limited to 'src/cryptonote_core/blockchain_db.cpp')
-rw-r--r--src/cryptonote_core/blockchain_db.cpp47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/cryptonote_core/blockchain_db.cpp b/src/cryptonote_core/blockchain_db.cpp
index 606b34310..02912be10 100644
--- a/src/cryptonote_core/blockchain_db.cpp
+++ b/src/cryptonote_core/blockchain_db.cpp
@@ -62,40 +62,22 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
}
uint64_t BlockchainDB::add_block( const block& blk
- , const size_t& block_size
- , const difficulty_type& cumulative_difficulty
- , const uint64_t& coins_generated
- , const std::vector<transaction>& txs
- )
+ , const size_t& block_size
+ , const difficulty_type& cumulative_difficulty
+ , const uint64_t& coins_generated
+ , const std::vector<transaction>& txs
+ )
{
- try
- {
- // call out to subclass implementation to add the block & metadata
- add_block(blk, block_size, cumulative_difficulty, coins_generated);
+ // call out to subclass implementation to add the block & metadata
+ add_block(blk, block_size, cumulative_difficulty, coins_generated);
- crypto::hash blk_hash = get_block_hash(blk);
- // call out to add the transactions
- for (const transaction& tx : txs)
- {
- add_transaction(blk_hash, tx);
- }
- }
- // in case any of the add_block process goes awry, undo
- catch (const std::exception& e)
+ crypto::hash blk_hash = get_block_hash(blk);
+ // call out to add the transactions
+
+ add_transaction(blk_hash, blk.miner_tx);
+ for (const transaction& tx : txs)
{
- LOG_ERROR("Error adding block to db: " << e.what());
- try
- {
- pop_block();
- }
- // if undoing goes wrong as well, we need to throw, as blockchain
- // will be in a bad state
- catch (const std::exception& e)
- {
- LOG_ERROR("Error undoing partially added block: " << e.what());
- throw;
- }
- throw;
+ add_transaction(blk_hash, tx);
}
return height();
@@ -104,7 +86,10 @@ uint64_t BlockchainDB::add_block( const block& blk
void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs)
{
blk = get_top_block();
+
+ remove_block();
+ remove_transaction(get_transaction_hash(blk.miner_tx));
for (const auto& h : blk.tx_hashes)
{
txs.push_back(get_tx(h));