Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip secondary indexes during replay #1918

Merged
merged 5 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions libraries/chain/account_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,6 @@ void account_member_index::object_modified(const object& after)

}

void account_referrer_index::object_inserted( const object& obj )
{
}
void account_referrer_index::object_removed( const object& obj )
{
}
void account_referrer_index::about_to_modify( const object& before )
{
}
void account_referrer_index::object_modified( const object& after )
{
}

const uint8_t balances_by_account_index::bits = 20;
const uint64_t balances_by_account_index::mask = (1ULL << balances_by_account_index::bits) - 1;

Expand Down
10 changes: 2 additions & 8 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,12 @@ void database::initialize_indexes()
add_index< primary_index<asset_index, 13> >(); // 8192 assets per chunk
add_index< primary_index<force_settlement_index> >();

auto acnt_index = add_index< primary_index<account_index, 20> >(); // ~1 million accounts per chunk
acnt_index->add_secondary_index<account_member_index>();
acnt_index->add_secondary_index<account_referrer_index>();

add_index< primary_index<account_index, 20> >(); // ~1 million accounts per chunk
add_index< primary_index<committee_member_index, 8> >(); // 256 members per chunk
add_index< primary_index<witness_index, 10> >(); // 1024 witnesses per chunk
add_index< primary_index<limit_order_index > >();
add_index< primary_index<call_order_index > >();

auto prop_index = add_index< primary_index<proposal_index > >();
prop_index->add_secondary_index<required_approval_index>();

add_index< primary_index<proposal_index > >();
add_index< primary_index<withdraw_permission_index > >();
add_index< primary_index<vesting_balance_index> >();
add_index< primary_index<worker_index> >();
Expand Down
16 changes: 0 additions & 16 deletions libraries/chain/include/graphene/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,6 @@ namespace graphene { namespace chain {
};


/**
* @brief This secondary index will allow a reverse lookup of all accounts that have been referred by
* a particular account.
*/
class account_referrer_index : public secondary_index
{
public:
virtual void object_inserted( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;

/** maps the referrer to the set of accounts that they have referred */
map< account_id_type, set<account_id_type> > referred_by;
};

/**
* @brief This secondary index will allow fast access to the balance objects
* that belonging to an account.
Expand Down
9 changes: 9 additions & 0 deletions libraries/plugins/api_helper_indexes/api_helper_indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <graphene/api_helper_indexes/api_helper_indexes.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/proposal_object.hpp>

namespace graphene { namespace api_helper_indexes {

Expand Down Expand Up @@ -149,6 +150,14 @@ void api_helper_indexes::plugin_startup()
amount_in_collateral = database().add_secondary_index< primary_index<call_order_index>, amount_in_collateral_index >();
for( const auto& call : database().get_index_type<call_order_index>().indices() )
amount_in_collateral->object_inserted( call );

auto& account_members = *database().add_secondary_index< primary_index<account_index>, account_member_index >();
for( const auto& account : database().get_index_type< account_index >().indices() )
account_members.object_inserted( account );

auto& approvals = *database().add_secondary_index< primary_index<proposal_index>, required_approval_index >();
for( const auto& proposal : database().get_index_type< proposal_index >().indices() )
approvals.object_inserted( proposal );
}

} }
6 changes: 4 additions & 2 deletions libraries/plugins/grouped_orders/grouped_orders_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,14 @@ void grouped_orders_plugin::plugin_initialize(const boost::program_options::vari
else
my->_tracked_groups = fc::json::from_string("[10,100]").as<flat_set<uint16_t>>(2);

database().add_secondary_index< primary_index<limit_order_index>, detail::limit_order_group_index >( my->_tracked_groups );

} FC_CAPTURE_AND_RETHROW() }

void grouped_orders_plugin::plugin_startup()
{
auto& groups = *database().add_secondary_index< primary_index<limit_order_index>,
detail::limit_order_group_index >( my->_tracked_groups );
for( const auto& order : database().get_index_type< limit_order_index >().indices() )
groups.object_inserted( order );
}

const flat_set<uint16_t>& grouped_orders_plugin::tracked_groups() const
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <graphene/utilities/tempdir.hpp>

#include <graphene/account_history/account_history_plugin.hpp>
#include <graphene/api_helper_indexes/api_helper_indexes.hpp>
#include <graphene/market_history/market_history_plugin.hpp>
#include <graphene/egenesis/egenesis.hpp>
#include <graphene/wallet/wallet.hpp>
Expand Down Expand Up @@ -125,6 +126,7 @@ std::shared_ptr<graphene::app::application> start_application(fc::temp_directory
app1->register_plugin<graphene::account_history::account_history_plugin>(true);
app1->register_plugin< graphene::market_history::market_history_plugin >(true);
app1->register_plugin< graphene::grouped_orders::grouped_orders_plugin>(true);
app1->register_plugin< graphene::api_helper_indexes::api_helper_indexes>(true);
app1->startup_plugins();
boost::program_options::variables_map cfg;
#ifdef _WIN32
Expand Down
28 changes: 17 additions & 11 deletions tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace graphene { namespace chain {
using std::cout;
using std::cerr;

namespace buf = boost::unit_test::framework;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buf is a commonly used abbreviation of buffer, which usually appears as a local variable or a function argument. I hope we don't use it in tests.


void clearable_block::clear()
{
_calculated_merkle_root = checksum_type();
Expand All @@ -70,16 +72,20 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
: app(), db( *app.chain_database() )
{
try {
int argc = boost::unit_test::framework::master_test_suite().argc;
char** argv = boost::unit_test::framework::master_test_suite().argv;
int argc = buf::master_test_suite().argc;
char** argv = buf::master_test_suite().argv;
for( int i=1; i<argc; i++ )
{
const std::string arg = argv[i];
if( arg == "--record-assert-trip" )
fc::enable_record_assert_trip = true;
if( arg == "--show-test-names" )
std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
std::cout << "running test " << buf::current_test_case().p_name << std::endl;
}

const auto current_test_name = buf::current_test_case().p_name.value;
const auto current_test_suite_id = buf::current_test_case().p_parent_id;
const auto current_suite_name = buf::get<boost::unit_test::test_suite>(current_test_suite_id).p_name.value;
auto mhplugin = app.register_plugin<graphene::market_history::market_history_plugin>();
auto goplugin = app.register_plugin<graphene::grouped_orders::grouped_orders_plugin>();
init_account_pub_key = init_account_priv_key.get_public_key();
Expand All @@ -88,7 +94,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)

genesis_state.initial_timestamp = initial_timestamp;

if(boost::unit_test::framework::current_test_case().p_name.value == "hf_935_test") {
if(current_test_name == "hf_935_test") {
genesis_state.initial_active_witnesses = 20;
}
else {
Expand Down Expand Up @@ -125,8 +131,6 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
/**
* Test specific settings
*/
auto current_test_name = boost::unit_test::framework::current_test_case().p_name.value;
auto current_test_suite_id = boost::unit_test::framework::current_test_case().p_parent_id;
if (current_test_name == "get_account_history_operations")
{
options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)75, false)));
Expand Down Expand Up @@ -271,8 +275,8 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
options.insert(std::make_pair("track-account", boost::program_options::variable_value(track_account, false)));
}
// standby votes tracking
if( boost::unit_test::framework::current_test_case().p_name.value == "track_votes_witnesses_disabled" ||
boost::unit_test::framework::current_test_case().p_name.value == "track_votes_committee_disabled") {
if( current_test_name == "track_votes_witnesses_disabled"
|| current_test_name == "track_votes_committee_disabled") {
app.chain_database()->enable_standby_votes_tracking( false );
}
if(current_test_name == "elasticsearch_account_history" || current_test_name == "elasticsearch_suite" ||
Expand All @@ -292,7 +296,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
esplugin->plugin_initialize(options);
esplugin->plugin_startup();
}
else if( boost::unit_test::framework::get<boost::unit_test::test_suite>(current_test_suite_id).p_name.value != "performance_tests" )
else if( current_suite_name != "performance_tests" )
{
auto ahplugin = app.register_plugin<graphene::account_history::account_history_plugin>();
ahplugin->plugin_set_app(&app);
Expand Down Expand Up @@ -323,7 +327,9 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
esobjects_plugin->plugin_initialize(options);
esobjects_plugin->plugin_startup();
}
else if( current_test_name == "asset_in_collateral" )
else if( current_test_name == "asset_in_collateral"
|| current_test_name == "htlc_database_api"
|| current_suite_name == "database_api_tests" )
{
auto ahiplugin = app.register_plugin<graphene::api_helper_indexes::api_helper_indexes>();
ahiplugin->plugin_set_app(&app);
Expand Down Expand Up @@ -431,7 +437,7 @@ string database_fixture::generate_anon_acct_name()
// to workaround issue #46
return "anon-acct-x" + std::to_string( anon_acct_count++ );
}
bool database_fixture::validation_current_test_name_for_setting_api_limit(string & current_test_name) const
bool database_fixture::validation_current_test_name_for_setting_api_limit( const string& current_test_name ) const
{
vector <string> valid_testcase {"api_limit_get_account_history_operations","api_limit_get_account_history"
,"api_limit_get_grouped_limit_orders","api_limit_get_relative_account_history"
Expand Down
2 changes: 1 addition & 1 deletion tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ struct database_fixture {

vector< operation_history_object > get_operation_history( account_id_type account_id )const;
vector< graphene::market_history::order_history_object > get_market_order_history( asset_id_type a, asset_id_type b )const;
bool validation_current_test_name_for_setting_api_limit (string & current_test_name) const;
bool validation_current_test_name_for_setting_api_limit( const string& current_test_name )const;

/****
* @brief return htlc fee parameters
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/database_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ BOOST_AUTO_TEST_CASE( required_approval_index_test ) // see https://github.com/b

database db1;
db1.initialize_indexes();
const auto& proposals = db1.get_index_type< primary_index< proposal_index > >();
const auto& required_approvals = proposals.get_secondary_index< required_approval_index >()._account_to_proposals;
const auto& required_approvals = db1.add_secondary_index<primary_index<proposal_index>, required_approval_index>()
->_account_to_proposals;

// Create a proposal
const auto& prop = db1.create<proposal_object>( [this,alice_id,agnetha_id]( object& o ) {
Expand Down Expand Up @@ -279,8 +279,8 @@ BOOST_AUTO_TEST_CASE( required_approval_index_test ) // see https://github.com/b
database db2;
db2.initialize_indexes();
const auto& reloaded_proposals = db2.get_index_type< primary_index< proposal_index > >();
const auto& reloaded_approvals = reloaded_proposals.get_secondary_index<required_approval_index>()
._account_to_proposals;
const auto& reloaded_approvals = db2.add_secondary_index<primary_index<proposal_index>, required_approval_index>()
->_account_to_proposals;
const_cast< primary_index< proposal_index >& >( reloaded_proposals ).load( serialized );
const auto& prop2 = *reloaded_proposals.indices().begin();

Expand Down