Merge branch 'develop' into feature/GRPH-88

This commit is contained in:
Alfredo Garcia 2019-09-17 15:01:36 -03:00 committed by GitHub
commit 1f4de92d62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 11 deletions

View file

@ -119,9 +119,9 @@ set<account_id_type> account_member_index::get_account_members(const account_obj
result.insert(auth.first); result.insert(auth.first);
return result; return result;
} }
set<public_key_type> account_member_index::get_key_members(const account_object& a)const set<public_key_type, account_member_index::key_compare> account_member_index::get_key_members(const account_object& a)const
{ {
set<public_key_type> result; set<public_key_type, key_compare> result;
for( auto auth : a.owner.key_auths ) for( auto auth : a.owner.key_auths )
result.insert(auth.first); result.insert(auth.first);
for( auto auth : a.active.key_auths ) for( auto auth : a.active.key_auths )
@ -213,7 +213,7 @@ void account_member_index::object_modified(const object& after)
{ {
set<public_key_type> after_key_members = get_key_members(a); set<public_key_type, key_compare> after_key_members = get_key_members(a);
vector<public_key_type> removed; removed.reserve(before_key_members.size()); vector<public_key_type> removed; removed.reserve(before_key_members.size());
std::set_difference(before_key_members.begin(), before_key_members.end(), std::set_difference(before_key_members.begin(), before_key_members.end(),

View file

@ -672,9 +672,14 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
auto& trx_idx = get_mutable_index_type<transaction_index>(); auto& trx_idx = get_mutable_index_type<transaction_index>();
const chain_id_type& chain_id = get_chain_id(); const chain_id_type& chain_id = get_chain_id();
auto trx_id = trx.id(); transaction_id_type trx_id;
FC_ASSERT( (skip & skip_transaction_dupe_check) ||
trx_idx.indices().get<by_trx_id>().find(trx_id) == trx_idx.indices().get<by_trx_id>().end() ); if( !(skip & skip_transaction_dupe_check) )
{
trx_id = trx.id();
FC_ASSERT( trx_idx.indices().get<by_trx_id>().find(trx_id) == trx_idx.indices().get<by_trx_id>().end() );
}
transaction_evaluation_state eval_state(this); transaction_evaluation_state eval_state(this);
const chain_parameters& chain_parameters = get_global_properties().parameters; const chain_parameters& chain_parameters = get_global_properties().parameters;
eval_state._trx = &trx; eval_state._trx = &trx;
@ -708,7 +713,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
//Insert transaction into unique transactions database. //Insert transaction into unique transactions database.
if( !(skip & skip_transaction_dupe_check) ) if( !(skip & skip_transaction_dupe_check) )
{ {
create<transaction_object>([&](transaction_object& transaction) { create<transaction_object>([&trx_id,&trx](transaction_object& transaction) {
transaction.trx_id = trx_id; transaction.trx_id = trx_id;
transaction.trx = trx; transaction.trx = trx;
}); });

View file

@ -119,7 +119,9 @@ void database::reindex(fc::path data_dir, const genesis_state_type& initial_allo
void database::wipe(const fc::path& data_dir, bool include_blocks) void database::wipe(const fc::path& data_dir, bool include_blocks)
{ {
ilog("Wiping database", ("include_blocks", include_blocks)); ilog("Wiping database", ("include_blocks", include_blocks));
close(); if (_opened) {
close();
}
object_database::wipe(data_dir); object_database::wipe(data_dir);
if( include_blocks ) if( include_blocks )
fc::remove_all( data_dir / "database" ); fc::remove_all( data_dir / "database" );
@ -148,12 +150,16 @@ void database::open(
("last_block->id", last_block->id())("head_block_num",head_block_num()) ); ("last_block->id", last_block->id())("head_block_num",head_block_num()) );
} }
} }
_opened = true;
} }
FC_CAPTURE_LOG_AND_RETHROW( (data_dir) ) FC_CAPTURE_LOG_AND_RETHROW( (data_dir) )
} }
void database::close(bool rewind) void database::close(bool rewind)
{ {
if (!_opened)
return;
// TODO: Save pending tx's on close() // TODO: Save pending tx's on close()
clear_pending(); clear_pending();
@ -198,6 +204,8 @@ void database::close(bool rewind)
_block_id_to_block.close(); _block_id_to_block.close();
_fork_db.reset(); _fork_db.reset();
_opened = false;
} }
void database::force_slow_replays() void database::force_slow_replays()

View file

@ -278,6 +278,25 @@ namespace graphene { namespace chain {
*/ */
class account_member_index : public secondary_index class account_member_index : public secondary_index
{ {
/* std::less::operator() is less efficient so using key_compare here.
* Let assume that it has two keys key1 and key2 and we want to insert key3.
* the insert function needs to first call std::less::operator() with key1 and key3.
* Assume std::less::operator()(key1, key3) returns false.
* It has to call std::less::operator() again with the keys switched,
* std::less::operator()(key3, key1), to decide whether key1 is equal to key3 or
* key3 is greater than key1. There are two calls to std::less::operator() to make
* a decision if the first call returns false.
* std::map::insert and std::set used key_compare,
* there would be sufficient information to make the right decision using just one call.
*/
class key_compare {
public:
inline bool operator()( const public_key_type& a, const public_key_type& b )const
{
return a.key_data < b.key_data;
}
};
public: public:
virtual void object_inserted( const object& obj ) override; virtual void object_inserted( const object& obj ) override;
virtual void object_removed( const object& obj ) override; virtual void object_removed( const object& obj ) override;
@ -287,18 +306,18 @@ namespace graphene { namespace chain {
/** given an account or key, map it to the set of accounts that reference it in an active or owner authority */ /** given an account or key, map it to the set of accounts that reference it in an active or owner authority */
map< account_id_type, set<account_id_type> > account_to_account_memberships; map< account_id_type, set<account_id_type> > account_to_account_memberships;
map< public_key_type, set<account_id_type> > account_to_key_memberships; map< public_key_type, set<account_id_type>, key_compare > account_to_key_memberships;
/** some accounts use address authorities in the genesis block */ /** some accounts use address authorities in the genesis block */
map< address, set<account_id_type> > account_to_address_memberships; map< address, set<account_id_type> > account_to_address_memberships;
protected: protected:
set<account_id_type> get_account_members( const account_object& a )const; set<account_id_type> get_account_members( const account_object& a )const;
set<public_key_type> get_key_members( const account_object& a )const; set<public_key_type, key_compare> get_key_members( const account_object& a )const;
set<address> get_address_members( const account_object& a )const; set<address> get_address_members( const account_object& a )const;
set<account_id_type> before_account_members; set<account_id_type> before_account_members;
set<public_key_type> before_key_members; set<public_key_type, key_compare> before_key_members;
set<address> before_address_members; set<address> before_address_members;
}; };

View file

@ -561,6 +561,15 @@ namespace graphene { namespace chain {
node_property_object _node_property_object; node_property_object _node_property_object;
fc::hash_ctr_rng<secret_hash_type, 20> _random_number_generator; fc::hash_ctr_rng<secret_hash_type, 20> _random_number_generator;
bool _slow_replays = false; bool _slow_replays = false;
/**
* Whether database is successfully opened or not.
*
* The database is considered open when there's no exception
* or assertion fail during database::open() method, and
* database::close() has not been called, or failed during execution.
*/
bool _opened = false;
}; };
namespace detail namespace detail