Skip to content

Commit

Permalink
Merge branch 'master' into bitshares
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Oct 21, 2015
2 parents 4e443bd + bf4f9ab commit 3bc8832
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 21 deletions.
44 changes: 41 additions & 3 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,47 @@ namespace detail {
{
ilog("Replaying blockchain on user request.");
_chain_db->reindex(_data_dir/"blockchain", initial_state());
} else if( clean )
_chain_db->open(_data_dir / "blockchain", initial_state);
else {
} else if( clean ) {

auto is_new = [&]() -> bool
{
// directory doesn't exist
if( !fc::exists( _data_dir ) )
return true;
// if directory exists but is empty, return true; else false.
return ( fc::directory_iterator( _data_dir ) == fc::directory_iterator() );
};

auto is_outdated = [&]() -> bool
{
if( !fc::exists( _data_dir / "db_version" ) )
return true;
std::string version_str;
fc::read_file_contents( _data_dir / "db_version", version_str );
return (version_str != GRAPHENE_CURRENT_DB_VERSION);
};
if( !is_new() && is_outdated() )
{
ilog("Replaying blockchain due to version upgrade");

fc::remove_all( _data_dir / "db_version" );
_chain_db->reindex(_data_dir / "blockchain", initial_state());

// doing this down here helps ensure that DB will be wiped
// if any of the above steps were interrupted on a previous run
if( !fc::exists( _data_dir / "db_version" ) )
{
std::ofstream db_version(
(_data_dir / "db_version").generic_string().c_str(),
std::ios::out | std::ios::binary | std::ios::trunc );
std::string version_string = GRAPHENE_CURRENT_DB_VERSION;
db_version.write( version_string.c_str(), version_string.size() );
db_version.close();
}
} else {
_chain_db->open(_data_dir / "blockchain", initial_state);
}
} else {
wlog("Detected unclean shutdown. Replaying blockchain...");
_chain_db->reindex(_data_dir / "blockchain", initial_state());
}
Expand Down
11 changes: 11 additions & 0 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr == asset_indx.end() );

auto dotpos = op.symbol.find( '.' );
if( dotpos != std::string::npos ) {
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
}


core_fee_paid -= core_fee_paid.value/2;

if( op.bitasset_opts )
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ void database::pop_block()
{ try {
_pending_tx_session.reset();
auto head_id = head_block_id();
idump((head_id)(head_block_num()));
optional<signed_block> head_block = fetch_block_by_id( head_id );
GRAPHENE_ASSERT( head_block.valid(), pop_empty_chain, "there are no blocks to pop" );
pop_undo();
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/db_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ void database::debug_dump()
edump( (total_balances[asset_id_type()].value)(core_asset_data.current_supply.value ));
}

edump((core_in_orders)(reported_core_in_orders));

/*
const auto& vbidx = db.get_index_type<simple_index<vesting_balance_object>>();
Expand Down
25 changes: 13 additions & 12 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE( call_order_update_test )
{
try {
ACTORS((dan)(sam));
const auto& bitusd = create_bitasset("BITUSD", sam.id);
const auto& bitusd = create_bitasset("USDBIT", sam.id);
const auto& core = asset_id_type()(db);

transfer(committee_account, dan_id, asset(10000000));
Expand Down Expand Up @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE( margin_call_limit_test )
{ try {
ACTORS((buyer)(seller)(borrower)(borrower2)(feedproducer));

const auto& bitusd = create_bitasset("BITUSD", feedproducer_id);
const auto& bitusd = create_bitasset("USDBIT", feedproducer_id);
const auto& core = asset_id_type()(db);

int64_t init_balance(1000000);
Expand Down Expand Up @@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE( black_swan )
{ try {
ACTORS((buyer)(seller)(borrower)(borrower2)(feedproducer));

const auto& bitusd = create_bitasset("BITUSD", feedproducer_id);
const auto& bitusd = create_bitasset("USDBIT", feedproducer_id);
const auto& core = asset_id_type()(db);

int64_t init_balance(1000000);
Expand Down Expand Up @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE( black_swan_issue_346 )

auto setup_asset = [&]() -> const asset_object&
{
const asset_object& bitusd = create_bitasset("BITUSD"+fc::to_string(trial)+"X", feeder_id);
const asset_object& bitusd = create_bitasset("USDBIT"+fc::to_string(trial)+"X", feeder_id);
update_feed_producers( bitusd, {feeder.id} );
BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() );
trial++;
Expand All @@ -319,6 +319,7 @@ BOOST_AUTO_TEST_CASE( black_swan_issue_346 )
{
price_feed feed;
feed.settlement_price = settlement_price;
feed.core_exchange_rate = settlement_price;
wdump( (feed.max_short_squeeze_price()) );
publish_feed( bitusd, feeder, feed );
};
Expand Down Expand Up @@ -599,11 +600,11 @@ BOOST_AUTO_TEST_CASE( create_committee_member )
BOOST_AUTO_TEST_CASE( create_mia )
{
try {
const asset_object& bitusd = create_bitasset( "BITUSD" );
BOOST_CHECK(bitusd.symbol == "BITUSD");
const asset_object& bitusd = create_bitasset( "USDBIT" );
BOOST_CHECK(bitusd.symbol == "USDBIT");
BOOST_CHECK(bitusd.bitasset_data(db).options.short_backing_asset == asset_id_type());
BOOST_CHECK(bitusd.dynamic_asset_data_id(db).current_supply == 0);
GRAPHENE_REQUIRE_THROW( create_bitasset("BITUSD"), fc::exception);
GRAPHENE_REQUIRE_THROW( create_bitasset("USDBIT"), fc::exception);
} catch ( const fc::exception& e ) {
elog( "${e}", ("e", e.to_detail_string() ) );
throw;
Expand All @@ -615,7 +616,7 @@ BOOST_AUTO_TEST_CASE( update_mia )
try {
INVOKE(create_mia);
generate_block();
const asset_object& bit_usd = get_asset("BITUSD");
const asset_object& bit_usd = get_asset("USDBIT");

asset_update_operation op;
op.issuer = bit_usd.issuer;
Expand Down Expand Up @@ -1123,7 +1124,7 @@ BOOST_AUTO_TEST_CASE( witness_feeds )
try {
INVOKE( create_mia );
{
auto& current = get_asset( "BITUSD" );
auto& current = get_asset( "USDBIT" );
asset_update_operation uop;
uop.issuer = current.issuer;
uop.asset_to_update = current.id;
Expand All @@ -1134,7 +1135,7 @@ BOOST_AUTO_TEST_CASE( witness_feeds )
trx.clear();
}
generate_block();
const asset_object& bit_usd = get_asset("BITUSD");
const asset_object& bit_usd = get_asset("USDBIT");
auto& global_props = db.get_global_properties();
const vector<account_id_type> active_witnesses(global_props.witness_accounts.begin(),
global_props.witness_accounts.end());
Expand Down Expand Up @@ -1369,7 +1370,7 @@ BOOST_AUTO_TEST_CASE( reserve_asset_test )
try
{
ACTORS((alice)(bob)(sam)(judge));
const auto& basset = create_bitasset("BITUSD", judge_id);
const auto& basset = create_bitasset("USDBIT", judge_id);
const auto& uasset = create_user_issued_asset("TEST");
const auto& passet = create_prediction_market("PMARK", judge_id);
const auto& casset = asset_id_type()(db);
Expand Down Expand Up @@ -1454,7 +1455,7 @@ BOOST_AUTO_TEST_CASE( cover_with_collateral_test )
try
{
ACTORS((alice)(bob)(sam));
const auto& bitusd = create_bitasset("BITUSD", sam_id);
const auto& bitusd = create_bitasset("USDBIT", sam_id);
const auto& core = asset_id_type()(db);

BOOST_TEST_MESSAGE( "Setting price feed to $0.02 / 100" );
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/operation_tests2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_delete )
BOOST_AUTO_TEST_CASE( mia_feeds )
{ try {
ACTORS((nathan)(dan)(ben)(vikram));
asset_id_type bit_usd_id = create_bitasset("BITUSD").id;
asset_id_type bit_usd_id = create_bitasset("USDBIT").id;

{
asset_update_operation op;
Expand Down Expand Up @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds )
BOOST_AUTO_TEST_CASE( feed_limit_test )
{ try {
INVOKE( mia_feeds );
const asset_object& bit_usd = get_asset("BITUSD");
const asset_object& bit_usd = get_asset("USDBIT");
const asset_bitasset_data_object& bitasset = bit_usd.bitasset_data(db);
GET_ACTOR(nathan);

Expand Down Expand Up @@ -472,7 +472,7 @@ BOOST_AUTO_TEST_CASE( global_settle_test )
{
try {
ACTORS((nathan)(ben)(valentine)(dan));
asset_id_type bit_usd_id = create_bitasset("BITUSD", nathan_id, 100, global_settle | charge_market_fee).get_id();
asset_id_type bit_usd_id = create_bitasset("USDBIT", nathan_id, 100, global_settle | charge_market_fee).get_id();

update_feed_producers( bit_usd_id(db), { nathan_id } );

Expand Down Expand Up @@ -829,7 +829,7 @@ BOOST_AUTO_TEST_CASE( force_settle_test )
transfer(account_id_type()(db), shorter5_id(db), asset(initial_balance));

asset_id_type bitusd_id = create_bitasset(
"BITUSD",
"USDBIT",
nathan_id,
100,
disable_force_settle
Expand Down

0 comments on commit 3bc8832

Please sign in to comment.