Make HardFork object available to BlockchainDB and derived DB implementations

This will later allow the HardFork object's DB update functions to be
called when the DB transaction that persists across block add/remove is
open.
This commit is contained in:
warptangent 2016-02-08 07:51:57 -08:00
parent fd46c96dce
commit 3800875406
No known key found for this signature in database
GPG Key ID: 0E490BEBFBE4E92D
5 changed files with 18 additions and 0 deletions

View File

@ -781,6 +781,8 @@ BlockchainBDB::BlockchainBDB(bool batch_transactions) :
m_batch_transactions = batch_transactions; m_batch_transactions = batch_transactions;
m_write_txn = nullptr; m_write_txn = nullptr;
m_height = 0; m_height = 0;
m_hardfork = nullptr;
} }
void BlockchainBDB::open(const std::string& filename, const int db_flags) void BlockchainBDB::open(const std::string& filename, const int db_flags)

View File

@ -138,6 +138,11 @@ uint64_t BlockchainDB::add_block( const block& blk
return prev_height; return prev_height;
} }
void BlockchainDB::set_hard_fork(HardFork*& hf)
{
m_hardfork = hf;
}
void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs) void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs)
{ {
blk = get_top_block(); blk = get_top_block();

View File

@ -28,12 +28,15 @@
#ifndef BLOCKCHAIN_DB_H #ifndef BLOCKCHAIN_DB_H
#define BLOCKCHAIN_DB_H #define BLOCKCHAIN_DB_H
#pragma once
#include <list> #include <list>
#include <string> #include <string>
#include <exception> #include <exception>
#include "crypto/hash.h" #include "crypto/hash.h"
#include "cryptonote_core/cryptonote_basic.h" #include "cryptonote_core/cryptonote_basic.h"
#include "cryptonote_core/difficulty.h" #include "cryptonote_core/difficulty.h"
#include "cryptonote_core/hardfork.h"
/* DB Driver Interface /* DB Driver Interface
* *
@ -322,6 +325,8 @@ protected:
uint64_t time_commit1 = 0; uint64_t time_commit1 = 0;
bool m_auto_remove_logs = true; bool m_auto_remove_logs = true;
HardFork* m_hardfork;
public: public:
// virtual dtor // virtual dtor
@ -372,6 +377,8 @@ public:
virtual void block_txn_stop() = 0; virtual void block_txn_stop() = 0;
virtual void block_txn_abort() = 0; virtual void block_txn_abort() = 0;
virtual void set_hard_fork(HardFork*& hf);
// adds a block with the given metadata to the top of the blockchain, returns the new height // adds a block with the given metadata to the top of the blockchain, returns the new height
// NOTE: subclass implementations of this (or the functions it calls) need // NOTE: subclass implementations of this (or the functions it calls) need
// to handle undoing any partially-added blocks in the event of a failure. // to handle undoing any partially-added blocks in the event of a failure.

View File

@ -945,6 +945,8 @@ BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
m_write_batch_txn = nullptr; m_write_batch_txn = nullptr;
m_batch_active = false; m_batch_active = false;
m_height = 0; m_height = 0;
m_hardfork = nullptr;
} }
void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)

View File

@ -290,6 +290,8 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain
} }
m_hardfork->init(); m_hardfork->init();
m_db->set_hard_fork(m_hardfork);
// if the blockchain is new, add the genesis block // if the blockchain is new, add the genesis block
// this feels kinda kludgy to do it this way, but can be looked at later. // this feels kinda kludgy to do it this way, but can be looked at later.
// TODO: add function to create and store genesis block, // TODO: add function to create and store genesis block,