hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
iroha::ametsuchi::StorageImpl Class Reference

#include "storage_impl.hpp"

Inheritance diagram for iroha::ametsuchi::StorageImpl:
Inheritance graph
Collaboration diagram for iroha::ametsuchi::StorageImpl:
Collaboration graph

Public Member Functions

expected::Result< std::unique_ptr< TemporaryWsv >, std::string > createTemporaryWsv () override
 
expected::Result< std::unique_ptr< MutableStorage >, std::string > createMutableStorage () override
 
boost::optional< std::shared_ptr< PeerQuery > > createPeerQuery () const override
 
boost::optional< std::shared_ptr< BlockQuery > > createBlockQuery () const override
 
boost::optional< std::shared_ptr< QueryExecutor > > createQueryExecutor (std::shared_ptr< PendingTransactionStorage > pending_txs_storage, std::shared_ptr< shared_model::interface::QueryResponseFactory > response_factory) const override
 
bool insertBlock (std::shared_ptr< const shared_model::interface::Block > block) override
 
bool insertBlocks (const std::vector< std::shared_ptr< shared_model::interface::Block >> &blocks) override
 
void reset () override
 
void dropStorage () override
 
void freeConnections () override
 
boost::optional< std::unique_ptr< LedgerState > > commit (std::unique_ptr< MutableStorage > mutable_storage) override
 
boost::optional< std::unique_ptr< LedgerState > > commitPrepared (std::shared_ptr< const shared_model::interface::Block > block) override
 
std::shared_ptr< WsvQuerygetWsvQuery () const override
 
std::shared_ptr< BlockQuerygetBlockQuery () const override
 
rxcpp::observable< std::shared_ptr< const shared_model::interface::Block > > on_commit () override
 
void prepareBlock (std::unique_ptr< TemporaryWsv > wsv) override
 
 ~StorageImpl () override
 
- Public Member Functions inherited from iroha::ametsuchi::Storage
virtual ~Storage ()=default
 
- Public Member Functions inherited from iroha::ametsuchi::TemporaryFactory
virtual ~TemporaryFactory ()=default
 
- Public Member Functions inherited from iroha::ametsuchi::MutableFactory
virtual ~MutableFactory ()=default
 
- Public Member Functions inherited from iroha::ametsuchi::PeerQueryFactory
virtual ~PeerQueryFactory ()=default
 
- Public Member Functions inherited from iroha::ametsuchi::BlockQueryFactory
virtual ~BlockQueryFactory ()=default
 
- Public Member Functions inherited from iroha::ametsuchi::QueryExecutorFactory
virtual ~QueryExecutorFactory ()=default
 

Static Public Member Functions

static expected::Result< std::shared_ptr< StorageImpl >, std::string > create (std::string block_store_dir, std::string postgres_connection, std::shared_ptr< shared_model::interface::CommonObjectsFactory > factory, std::shared_ptr< shared_model::interface::BlockJsonConverter > converter, std::shared_ptr< shared_model::interface::PermissionToString > perm_converter, std::unique_ptr< BlockStorageFactory > block_storage_factory, logger::LoggerManagerTreePtr log_manager, size_t pool_size=10)
 

Protected Member Functions

 StorageImpl (std::string block_store_dir, PostgresOptions postgres_options, std::unique_ptr< KeyValueStorage > block_store, std::shared_ptr< soci::connection_pool > connection, std::shared_ptr< shared_model::interface::CommonObjectsFactory > factory, std::shared_ptr< shared_model::interface::BlockJsonConverter > converter, std::shared_ptr< shared_model::interface::PermissionToString > perm_converter, std::unique_ptr< BlockStorageFactory > block_storage_factory, size_t pool_size, bool enable_prepared_blocks, logger::LoggerManagerTreePtr log_manager)
 

Static Protected Member Functions

static expected::Result< bool, std::string > createDatabaseIfNotExist (const std::string &dbname, const std::string &options_str_without_dbname)
 
static expected::Result< ConnectionContext, std::string > initConnections (std::string block_store_dir, logger::LoggerPtr log)
 
static expected::Result< std::shared_ptr< soci::connection_pool >, std::string > initPostgresConnection (std::string &options_str, size_t pool_size)
 

Protected Attributes

const std::string block_store_dir_
 
const PostgresOptions postgres_options_
 

Static Protected Attributes

static const std::string & drop_
 
static const std::string & reset_
 
static const std::string & init_
 

Constructor & Destructor Documentation

iroha::ametsuchi::StorageImpl::~StorageImpl ( )
override

Here is the call graph for this function:

iroha::ametsuchi::StorageImpl::StorageImpl ( std::string  block_store_dir,
PostgresOptions  postgres_options,
std::unique_ptr< KeyValueStorage block_store,
std::shared_ptr< soci::connection_pool >  connection,
std::shared_ptr< shared_model::interface::CommonObjectsFactory factory,
std::shared_ptr< shared_model::interface::BlockJsonConverter converter,
std::shared_ptr< shared_model::interface::PermissionToString perm_converter,
std::unique_ptr< BlockStorageFactory block_storage_factory,
size_t  pool_size,
bool  enable_prepared_blocks,
logger::LoggerManagerTreePtr  log_manager 
)
protected

Here is the call graph for this function:

Here is the caller graph for this function:

Member Function Documentation

boost::optional< std::unique_ptr< LedgerState > > iroha::ametsuchi::StorageImpl::commit ( std::unique_ptr< MutableStorage mutableStorage)
overridevirtual

Commit mutable storage to Ametsuchi. This transforms Ametsuchi to the new state consistent with MutableStorage.

Parameters
mutableStorage
Returns
new state of the ledger, boost::none if commit failed

Implements iroha::ametsuchi::MutableFactory.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::optional< std::unique_ptr< LedgerState > > iroha::ametsuchi::StorageImpl::commitPrepared ( std::shared_ptr< const shared_model::interface::Block block)
overridevirtual

Try to apply prepared block to Ametsuchi.

Returns
state of the ledger if commit is succesful, boost::none if prepared block failed to apply. WSV is not changed in this case.

Implements iroha::ametsuchi::MutableFactory.

Here is the call graph for this function:

expected::Result< std::shared_ptr< StorageImpl >, std::string > iroha::ametsuchi::StorageImpl::create ( std::string  block_store_dir,
std::string  postgres_connection,
std::shared_ptr< shared_model::interface::CommonObjectsFactory factory,
std::shared_ptr< shared_model::interface::BlockJsonConverter converter,
std::shared_ptr< shared_model::interface::PermissionToString perm_converter,
std::unique_ptr< BlockStorageFactory block_storage_factory,
logger::LoggerManagerTreePtr  log_manager,
size_t  pool_size = 10 
)
static

Here is the call graph for this function:

boost::optional< std::shared_ptr< BlockQuery > > iroha::ametsuchi::StorageImpl::createBlockQuery ( ) const
overridevirtual

Creates a block query from the current state.

Returns
Created block query

Implements iroha::ametsuchi::BlockQueryFactory.

Here is the call graph for this function:

expected::Result< bool, std::string > iroha::ametsuchi::StorageImpl::createDatabaseIfNotExist ( const std::string &  dbname,
const std::string &  options_str_without_dbname 
)
staticprotected

Here is the call graph for this function:

Here is the caller graph for this function:

expected::Result< std::unique_ptr< MutableStorage >, std::string > iroha::ametsuchi::StorageImpl::createMutableStorage ( )
overridevirtual

Creates a mutable storage from the current state. Mutable storage is the only way to commit the block to the ledger.

Returns
Created Result with mutable storage or error string

Implements iroha::ametsuchi::MutableFactory.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::optional< std::shared_ptr< PeerQuery > > iroha::ametsuchi::StorageImpl::createPeerQuery ( ) const
overridevirtual

Creates a peer query from the current state.

Returns
Created peer query

Implements iroha::ametsuchi::PeerQueryFactory.

Here is the call graph for this function:

boost::optional< std::shared_ptr< QueryExecutor > > iroha::ametsuchi::StorageImpl::createQueryExecutor ( std::shared_ptr< PendingTransactionStorage pending_txs_storage,
std::shared_ptr< shared_model::interface::QueryResponseFactory response_factory 
) const
overridevirtual

Creates a query executor from the current state

Implements iroha::ametsuchi::QueryExecutorFactory.

expected::Result< std::unique_ptr< TemporaryWsv >, std::string > iroha::ametsuchi::StorageImpl::createTemporaryWsv ( )
overridevirtual

Creates a temporary world state view from the current state. Temporary state will be not committed and will be erased on destructor call. Temporary state might be used for transaction validation.

Returns
Created Result with temporary wsv or string error

Implements iroha::ametsuchi::TemporaryFactory.

void iroha::ametsuchi::StorageImpl::dropStorage ( )
overridevirtual

Remove all information from ledger Tables and the database will be removed too

Implements iroha::ametsuchi::Storage.

Here is the call graph for this function:

void iroha::ametsuchi::StorageImpl::freeConnections ( )
overridevirtual

Implements iroha::ametsuchi::Storage.

Here is the caller graph for this function:

std::shared_ptr< BlockQuery > iroha::ametsuchi::StorageImpl::getBlockQuery ( ) const
overridevirtual

Implements iroha::ametsuchi::Storage.

Here is the caller graph for this function:

std::shared_ptr< WsvQuery > iroha::ametsuchi::StorageImpl::getWsvQuery ( ) const
overridevirtual

Implements iroha::ametsuchi::Storage.

Here is the caller graph for this function:

expected::Result< ConnectionContext, std::string > iroha::ametsuchi::StorageImpl::initConnections ( std::string  block_store_dir,
logger::LoggerPtr  log 
)
staticprotected

Here is the call graph for this function:

Here is the caller graph for this function:

expected::Result< std::shared_ptr< soci::connection_pool >, std::string > iroha::ametsuchi::StorageImpl::initPostgresConnection ( std::string &  options_str,
size_t  pool_size 
)
staticprotected

Here is the call graph for this function:

Here is the caller graph for this function:

bool iroha::ametsuchi::StorageImpl::insertBlock ( std::shared_ptr< const shared_model::interface::Block block)
overridevirtual

Insert block without validation

Parameters
blocks- block for insertion
Returns
true if all blocks are inserted

Implements iroha::ametsuchi::Storage.

Here is the call graph for this function:

bool iroha::ametsuchi::StorageImpl::insertBlocks ( const std::vector< std::shared_ptr< shared_model::interface::Block >> &  blocks)
overridevirtual

Insert blocks without validation

Parameters
blocks- collection of blocks for insertion
Returns
true if inserted

Implements iroha::ametsuchi::Storage.

Here is the call graph for this function:

rxcpp::observable< std::shared_ptr< const shared_model::interface::Block > > iroha::ametsuchi::StorageImpl::on_commit ( )
overridevirtual

method called when block is written to the storage

Returns
observable with the Block committed

Implements iroha::ametsuchi::Storage.

void iroha::ametsuchi::StorageImpl::prepareBlock ( std::unique_ptr< TemporaryWsv wsv)
overridevirtual

Prepare state which was accumulated in temporary WSV. After preparation, this state is not visible until commited.

Parameters
wsv- state which will be prepared.

Implements iroha::ametsuchi::TemporaryFactory.

Here is the call graph for this function:

void iroha::ametsuchi::StorageImpl::reset ( )
overridevirtual

Remove all records from the tables and remove all the blocks

Implements iroha::ametsuchi::Storage.

Here is the call graph for this function:

Member Data Documentation

const std::string iroha::ametsuchi::StorageImpl::block_store_dir_
protected

Folder with raw blocks

const std::string & iroha::ametsuchi::StorageImpl::drop_
staticprotected
Initial value:
= R"(
DROP TABLE IF EXISTS account_has_signatory;
DROP TABLE IF EXISTS account_has_asset;
DROP TABLE IF EXISTS role_has_permissions CASCADE;
DROP TABLE IF EXISTS account_has_roles;
DROP TABLE IF EXISTS account_has_grantable_permissions CASCADE;
DROP TABLE IF EXISTS account;
DROP TABLE IF EXISTS asset;
DROP TABLE IF EXISTS domain;
DROP TABLE IF EXISTS signatory;
DROP TABLE IF EXISTS peer;
DROP TABLE IF EXISTS role;
DROP TABLE IF EXISTS height_by_hash;
DROP INDEX IF EXISTS tx_status_by_hash_hash_index;
DROP TABLE IF EXISTS tx_status_by_hash;
DROP TABLE IF EXISTS height_by_account_set;
DROP TABLE IF EXISTS index_by_creator_height;
DROP TABLE IF EXISTS position_by_account_asset;
DROP TABLE IF EXISTS position_by_hash;
)"
const std::string & iroha::ametsuchi::StorageImpl::init_
staticprotected
const PostgresOptions iroha::ametsuchi::StorageImpl::postgres_options_
protected
const std::string & iroha::ametsuchi::StorageImpl::reset_
staticprotected
Initial value:
= R"(
TRUNCATE TABLE account_has_signatory RESTART IDENTITY CASCADE;
TRUNCATE TABLE account_has_asset RESTART IDENTITY CASCADE;
TRUNCATE TABLE role_has_permissions RESTART IDENTITY CASCADE;
TRUNCATE TABLE account_has_roles RESTART IDENTITY CASCADE;
TRUNCATE TABLE account_has_grantable_permissions RESTART IDENTITY CASCADE;
TRUNCATE TABLE account RESTART IDENTITY CASCADE;
TRUNCATE TABLE asset RESTART IDENTITY CASCADE;
TRUNCATE TABLE domain RESTART IDENTITY CASCADE;
TRUNCATE TABLE signatory RESTART IDENTITY CASCADE;
TRUNCATE TABLE peer RESTART IDENTITY CASCADE;
TRUNCATE TABLE role RESTART IDENTITY CASCADE;
TRUNCATE TABLE position_by_hash RESTART IDENTITY CASCADE;
TRUNCATE TABLE tx_status_by_hash RESTART IDENTITY CASCADE;
TRUNCATE TABLE height_by_account_set RESTART IDENTITY CASCADE;
TRUNCATE TABLE index_by_creator_height RESTART IDENTITY CASCADE;
TRUNCATE TABLE position_by_account_asset RESTART IDENTITY CASCADE;
)"

The documentation for this class was generated from the following files: