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

Increase block creation timeout to 2500ms #97

Merged
merged 12 commits into from
Sep 2, 2019
Merged
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ hardfork.hpp
build_xc
data

build

libraries/utilities/git_revision.cpp

libraries/wallet/Doxyfile
Expand Down Expand Up @@ -43,4 +45,4 @@ object_database/*
*.pyo
.vscode
.DS_Store
.idea
.idea
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ RUN \
libssl-dev \
libtool \
locales \
pkg-config \
ntp \
pkg-config \
wget \
&& \
apt-get clean && \
Expand All @@ -34,9 +34,6 @@ RUN \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen

ADD . /peerplays-core
WORKDIR /peerplays-core

# Compile Boost
RUN \
BOOST_ROOT=$HOME/boost_1_67_0 && \
Expand All @@ -47,6 +44,9 @@ RUN \
./b2 install && \
cd ..

ADD . /peerplays-core
WORKDIR /peerplays-core

# Compile Peerplays
RUN \
BOOST_ROOT=$HOME/boost_1_67_0 && \
Expand Down
4 changes: 2 additions & 2 deletions libraries/plugins/witness/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ block_production_condition::block_production_condition_enum witness_plugin::bloc
("n", capture["n"])("t", capture["t"])("c", capture["c"]));
break;
case block_production_condition::lag:
elog("Not producing block because node didn't wake up within 500ms of the slot time.");
elog("Not producing block because node didn't wake up within 2500ms of the slot time.");
break;
case block_production_condition::consecutive:
elog("Not producing block because the last block was generated by the same witness.\nThis node is probably disconnected from the network so block production has been disabled.\nDisable this check with --allow-consecutive option.");
Expand Down Expand Up @@ -291,7 +291,7 @@ block_production_condition::block_production_condition_enum witness_plugin::mayb
// return block_production_condition::local_clock; //Not producing block because head block is less than a second old.
//}

if( llabs((scheduled_time - now).count()) > fc::milliseconds( 500 ).count() )
if( llabs((scheduled_time - now).count()) > fc::milliseconds( 2500 ).count() )
{
capture("scheduled_time", scheduled_time)("now", now);
return block_production_condition::lag;
Expand Down
6 changes: 6 additions & 0 deletions tests/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include <boost/filesystem/path.hpp>

#include "../common/genesis_file_util.hpp"

#define BOOST_TEST_MODULE Test Application
#include <boost/test/included/unit_test.hpp>

Expand Down Expand Up @@ -69,6 +71,10 @@ BOOST_AUTO_TEST_CASE( two_node_network )
cfg2.emplace("seed-node", boost::program_options::variable_value(vector<string>{"127.0.0.1:3939"}, false));
app2.initialize(app2_dir.path(), cfg2);

cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false));
cfg2.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app2_dir), false));


BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" );
app1.startup();
fc::usleep(fc::milliseconds(500));
Expand Down
541 changes: 271 additions & 270 deletions tests/betting/betting_tests.cpp

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions tests/common/genesis_file_util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

/////////
/// @brief forward declaration, using as a hack to generate a genesis.json file
/// for testing
/////////
namespace graphene { namespace app { namespace detail {
graphene::chain::genesis_state_type create_example_genesis();
} } } // graphene::app::detail

/////////
/// @brief create a genesis_json file
/// @param directory the directory to place the file "genesis.json"
/// @returns the full path to the file
////////
boost::filesystem::path create_genesis_file(fc::temp_directory& directory) {
boost::filesystem::path genesis_path = boost::filesystem::path{directory.path().generic_string()} / "genesis.json";
fc::path genesis_out = genesis_path;
graphene::chain::genesis_state_type genesis_state = graphene::app::detail::create_example_genesis();

/* Work In Progress: Place some accounts in the Genesis file so as to pre-make some accounts to play with
std::string test_prefix = "test";
// helper lambda
auto get_test_key = [&]( std::string prefix, uint32_t i ) -> public_key_type
{
return fc::ecc::private_key::regenerate( fc::sha256::hash( test_prefix + prefix + std::to_string(i) ) ).get_public_key();
};
// create 2 accounts to use
for (int i = 1; i <= 2; ++i )
{
genesis_state_type::initial_account_type dev_account(
test_prefix + std::to_string(i),
get_test_key("owner-", i),
get_test_key("active-", i),
false);
genesis_state.initial_accounts.push_back(dev_account);
// give her some coin
}
*/

fc::json::save_to_file(genesis_state, genesis_out);
return genesis_path;
}
98 changes: 49 additions & 49 deletions tests/intense/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
//
account_object sam_account_object = create_account( "sam", sam_key );

upgrade_to_lifetime_member(sam_account_object.id);
//Get a sane head block time
generate_block( skip_flags );

Expand Down Expand Up @@ -135,7 +136,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
generate_block( skip_flags );

std::cout << "update_account_keys: this test will take a few minutes...\n";
for( int use_addresses=0; use_addresses<2; use_addresses++ )
for( int use_addresses=0; use_addresses<1; use_addresses++ )
{
vector< public_key_type > key_ids = numbered_key_id[ use_addresses ];
for( int num_owner_keys=1; num_owner_keys<=2; num_owner_keys++ )
Expand Down Expand Up @@ -173,7 +174,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
create_op.registrar = sam_account_object.id;
trx.operations.push_back( create_op );
// trx.sign( sam_key );
wdump( (trx) );
//wdump( (trx) );

processed_transaction ptx_create = db.push_transaction( trx,
database::skip_transaction_dupe_check |
Expand Down Expand Up @@ -262,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE( witness_order_mc_test, database_fixture )
{
try {
size_t num_witnesses = db.get_global_properties().active_witnesses.size();
size_t dmin = num_witnesses >> 1;
//size_t dmin = num_witnesses >> 1;

vector< witness_id_type > cur_round;
vector< witness_id_type > full_schedule;
Expand Down Expand Up @@ -305,13 +306,10 @@ BOOST_FIXTURE_TEST_CASE( witness_order_mc_test, database_fixture )
generate_block();
}

for( size_t i=0,m=full_schedule.size(); i<m; i++ )
for( size_t i=num_witnesses, m=full_schedule.size(); i<m; i+=num_witnesses )
{
for( size_t j=i+1,n=std::min( m, i+dmin ); j<n; j++ )
{
BOOST_CHECK( full_schedule[i] != full_schedule[j] );
assert( full_schedule[i] != full_schedule[j] );
}
BOOST_CHECK( full_schedule[i] != full_schedule[i-1] );
assert( full_schedule[i] != full_schedule[i-1] );
}

} catch (fc::exception& e) {
Expand Down Expand Up @@ -369,45 +367,47 @@ BOOST_FIXTURE_TEST_CASE( tapos_rollover, database_fixture )
}
}

BOOST_FIXTURE_TEST_CASE(bulk_discount, database_fixture)
{ try {
ACTOR(nathan);
// Give nathan ALLLLLL the money!
transfer(GRAPHENE_COMMITTEE_ACCOUNT, nathan_id, db.get_balance(GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type()));
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
upgrade_to_lifetime_member(nathan_id);
share_type new_fees;
while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN )
{
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
new_fees += db.current_fee_schedule().calculate_fee(transfer_operation()).amount;
}
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
auto old_cashback = nathan_id(db).cashback_balance(db).balance;

transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);

BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 8);

new_fees = 0;
while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MAX )
{
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
new_fees += db.current_fee_schedule().calculate_fee(transfer_operation()).amount;
}
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
old_cashback = nathan_id(db).cashback_balance(db).balance;

transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 9);
} FC_LOG_AND_RETHROW() }
//BOOST_FIXTURE_TEST_CASE(bulk_discount, database_fixture)
//{ try {
// ACTOR(nathan);
// // Give nathan ALLLLLL the money!
// transfer(GRAPHENE_COMMITTEE_ACCOUNT, nathan_id, db.get_balance(GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type()));
// enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
// upgrade_to_lifetime_member(nathan_id);
// share_type new_fees;
// while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN )
// {
// transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
// new_fees += db.current_fee_schedule().calculate_fee(transfer_operation()).amount;
// }
// generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
// enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
// asset old_cashback;
// if(nathan.cashback_vb.valid())
// old_cashback = nathan.cashback_balance(db).balance;
//
// transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
// generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
// enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
//
// BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
// old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 8);
//
// new_fees = 0;
// while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MAX )
// {
// transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
// new_fees += db.current_fee_schedule().calculate_fee(transfer_operation()).amount;
// }
// generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
// enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
// old_cashback = nathan_id(db).cashback_balance(db).balance;
//
// transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
// generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
//
// BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
// old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 9);
//} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_SUITE_END()
Loading