Skip to content

Commit

Permalink
Merge with latest hardfork branch
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenLedgerApp committed Jan 23, 2019
1 parent 3e1e5b6 commit 1b9f6c9
Show file tree
Hide file tree
Showing 77 changed files with 3,253 additions and 794 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ script:
- cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage -DBoost_USE_STATIC_LIBS=OFF -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON .
- 'which build-wrapper-linux-x86-64 && build-wrapper-linux-x86-64 --out-dir bw-output make -j 2 cli_wallet witness_node chain_test cli_test || make -j 2 cli_wallet witness_node chain_test cli_test'
- set -o pipefail
- '[ $((`date +%s` - `cat _start_time`)) -gt $((42 * 60)) ] && touch _empty_cache || true'
- '[ -r _empty_cache ] || tests/chain_test 2>&1 | cat'
- '[ -r _empty_cache ] || tests/cli_test 2>&1 | cat'
- 'find libraries/[acdenptuw]*/CMakeFiles/*.dir programs/[cdgjsw]*/CMakeFiles/*.dir -type d | while read d; do gcov -o "$d" "${d/CMakeFiles*.dir//}"/*.cpp; done >/dev/null'
- '( [ -r _empty_cache -o $((`date +%s` - `cat _start_time`)) -gt $((42 * 60)) ] && echo "WARNING! Skipping sonar scanner due to time constraints!" ) || ( which sonar-scanner && sonar-scanner || true )'
- '[ ! -r _empty_cache ] || ( echo "Please restart with populated cache" && false )'
- '[ -r _empty_cache ] || ( which sonar-scanner && sonar-scanner || true )'
- '[ ! -r _empty_cache ] || ( echo "WARNING! Skipped some tests due to compile time! Please restart with populated cache." && false )'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Visit [BitShares.org](https://bitshares.org/) to learn about BitShares and join

Information for developers can be found in the [Bitshares Developer Portal](https://dev.bitshares.works/). Users interested in how bitshares works can go to the [BitShares Documentation](https://how.bitshares.works/) site.

For security issues and bug bounty program please visit [Hack the DEX](https://hackthedex.io).

Getting Started
---------------
Build instructions and additional documentation are available in the
Expand Down
13 changes: 7 additions & 6 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ namespace graphene { namespace app {
}
}

void network_broadcast_api::broadcast_transaction(const signed_transaction& trx)
void network_broadcast_api::broadcast_transaction(const precomputable_transaction& trx)
{
trx.validate();
_app.chain_database()->precompute_parallel( trx ).wait();
_app.chain_database()->push_transaction(trx);
if( _app.p2p_node() != nullptr )
_app.p2p_node()->broadcast_transaction(trx);
}

fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
fc::variant network_broadcast_api::broadcast_transaction_synchronous(const precomputable_transaction& trx)
{
fc::promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
broadcast_transaction_with_callback( [=]( const fc::variant& v ){
broadcast_transaction_with_callback( [prom]( const fc::variant& v ){
prom->set_value(v);
}, trx );

Expand All @@ -179,14 +179,15 @@ namespace graphene { namespace app {

void network_broadcast_api::broadcast_block( const signed_block& b )
{
_app.chain_database()->precompute_parallel( b ).wait();
_app.chain_database()->push_block(b);
if( _app.p2p_node() != nullptr )
_app.p2p_node()->broadcast( net::block_message( b ));
}

void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const signed_transaction& trx)
void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const precomputable_transaction& trx)
{
trx.validate();
_app.chain_database()->precompute_parallel( trx ).wait();
_callbacks[trx.id()] = cb;
_app.chain_database()->push_transaction(trx);
if( _app.p2p_node() != nullptr )
Expand Down
55 changes: 42 additions & 13 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <graphene/app/application.hpp>
#include <graphene/app/plugin.hpp>

#include <graphene/chain/db_with.hpp>
#include <graphene/chain/genesis_state.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <graphene/chain/protocol/types.hpp>
Expand Down Expand Up @@ -169,8 +170,8 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
"seed01.liondani.com:1776", // liondani (GERMANY)
"104.236.144.84:1777", // puppies (USA)
"128.199.143.47:2015", // Harvey (Singapore)
"23.92.53.182:1776", // sahkan (USA)
"192.121.166.162:1776", // sahkan (UK)
"209.105.239.13:1776", // sahkan (USA)
"45.35.12.22:1776", // sahkan (USA)
"51.15.61.160:1776", // lafona (France)
"bts-seed1.abit-more.com:62015", // abit (China)
"node.blckchnd.com:4243", // blckchnd (Germany)
Expand Down Expand Up @@ -394,12 +395,34 @@ void application_impl::startup()
_chain_db->enable_standby_votes_tracking( _options->at("enable-standby-votes-tracking").as<bool>() );
}

if( _options->count("replay-blockchain") )
if( _options->count("replay-blockchain") || _options->count("revalidate-blockchain") )
_chain_db->wipe( _data_dir / "blockchain", false );

try
{
_chain_db->open( _data_dir / "blockchain", initial_state, GRAPHENE_CURRENT_DB_VERSION );
// these flags are used in open() only, i. e. during replay
uint32_t skip;
if( _options->count("revalidate-blockchain") ) // see also handle_block()
{
if( !loaded_checkpoints.empty() )
wlog( "Warning - revalidate will not validate before last checkpoint" );
if( _options->count("force-validate") )
skip = graphene::chain::database::skip_nothing;
else
skip = graphene::chain::database::skip_transaction_signatures;
}
else // no revalidate, skip most checks
skip = graphene::chain::database::skip_witness_signature |
graphene::chain::database::skip_block_size_check |
graphene::chain::database::skip_merkle_check |
graphene::chain::database::skip_transaction_signatures |
graphene::chain::database::skip_transaction_dupe_check |
graphene::chain::database::skip_tapos_check |
graphene::chain::database::skip_witness_schedule_check;

graphene::chain::detail::with_skip_flags( *_chain_db, skip, [this,&initial_state] () {
_chain_db->open( _data_dir / "blockchain", initial_state, GRAPHENE_CURRENT_DB_VERSION );
});
}
catch( const fc::exception& e )
{
Expand Down Expand Up @@ -517,13 +540,17 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg,
FC_ASSERT( (latency.count()/1000) > -5000, "Rejecting block with timestamp in the future" );

try {
// TODO: in the case where this block is valid but on a fork that's too old for us to switch to,
// you can help the network code out by throwing a block_older_than_undo_history exception.
// when the net code sees that, it will stop trying to push blocks from that chain, but
// leave that peer connected so that they can get sync blocks from us
bool result = _chain_db->push_block( blk_msg.block,
(_is_block_producer | _force_validate) ?
database::skip_nothing : database::skip_transaction_signatures );
const uint32_t skip = (_is_block_producer | _force_validate) ?
database::skip_nothing : database::skip_transaction_signatures;
bool result = valve.do_serial( [this,&blk_msg,skip] () {
_chain_db->precompute_parallel( blk_msg.block, skip ).wait();
}, [this,&blk_msg,skip] () {
// TODO: in the case where this block is valid but on a fork that's too old for us to switch to,
// you can help the network code out by throwing a block_older_than_undo_history exception.
// when the net code sees that, it will stop trying to push blocks from that chain, but
// leave that peer connected so that they can get sync blocks from us
return _chain_db->push_block( blk_msg.block, skip );
});

// the block was accepted, so we now know all of the transactions contained in the block
if (!sync_mode)
Expand Down Expand Up @@ -573,6 +600,7 @@ void application_impl::handle_transaction(const graphene::net::trx_message& tran
trx_count = 0;
}

_chain_db->precompute_parallel( transaction_message.trx ).wait();
_chain_db->push_transaction( transaction_message.trx );
} FC_CAPTURE_AND_RETHROW( (transaction_message) ) }

Expand Down Expand Up @@ -961,9 +989,10 @@ void application::set_program_options(boost::program_options::options_descriptio
"Path to create a Genesis State at. If a well-formed JSON file exists at the path, it will be parsed and any "
"missing fields in a Genesis State will be added, and any unknown fields will be removed. If no file or an "
"invalid file is found, it will be replaced with an example Genesis State.")
("replay-blockchain", "Rebuild object graph by replaying all blocks")
("replay-blockchain", "Rebuild object graph by replaying all blocks without validation")
("revalidate-blockchain", "Rebuild object graph by replaying all blocks with full validation")
("resync-blockchain", "Delete all blocks and re-sync with network from scratch")
("force-validate", "Force validation of all transactions")
("force-validate", "Force validation of all transactions during normal operation")
("genesis-timestamp", bpo::value<uint32_t>(),
"Replace timestamp from genesis.json with current time plus this many seconds (experts only!)")
;
Expand Down
4 changes: 4 additions & 0 deletions libraries/app/application_impl.hxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <fc/network/http/websocket.hpp>
#include <fc/thread/parallel.hpp>

#include <graphene/app/application.hpp>
#include <graphene/app/api_access.hpp>
#include <graphene/chain/genesis_state.hpp>
Expand Down Expand Up @@ -194,6 +196,8 @@ class application_impl : public net::node_delegate
std::map<string, std::shared_ptr<abstract_plugin>> _available_plugins;

bool _is_finished_syncing = false;
private:
fc::serial_valve valve;
};

}}} // namespace graphene namespace app namespace detail
42 changes: 21 additions & 21 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ vector<vector<account_id_type>> database_api::get_key_references( vector<public_
*/
vector<vector<account_id_type>> database_api_impl::get_key_references( vector<public_key_type> keys )const
{
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();

vector< vector<account_id_type> > final_result;
final_result.reserve(keys.size());

Expand All @@ -566,28 +570,25 @@ vector<vector<account_id_type>> database_api_impl::get_key_references( vector<pu
subscribe_to_item( a4 );
subscribe_to_item( a5 );

const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
auto itr = refs.account_to_key_memberships.find(key);
vector<account_id_type> result;

for( auto& a : {a1,a2,a3,a4,a5} )
{
auto itr = refs.account_to_address_memberships.find(a);
if( itr != refs.account_to_address_memberships.end() )
{
result.reserve( itr->second.size() );
result.reserve( result.size() + itr->second.size() );
for( auto item : itr->second )
{
result.push_back(item);
}
}
}

auto itr = refs.account_to_key_memberships.find(key);
if( itr != refs.account_to_key_memberships.end() )
{
result.reserve( itr->second.size() );
result.reserve( result.size() + itr->second.size() );
for( auto item : itr->second ) result.push_back(item);
}
final_result.emplace_back( std::move(result) );
Expand Down Expand Up @@ -620,7 +621,7 @@ bool database_api_impl::is_public_key_registered(string public_key) const
return false;
}
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
auto itr = refs.account_to_key_memberships.find(key);
bool is_known = itr != refs.account_to_key_memberships.end();
Expand Down Expand Up @@ -755,6 +756,10 @@ std::map<string,full_account> database_api::get_full_accounts( const vector<stri

std::map<std::string, full_account> database_api_impl::get_full_accounts( const vector<std::string>& names_or_ids, bool subscribe)
{
const auto& proposal_idx = _db.get_index_type<proposal_index>();
const auto& pidx = dynamic_cast<const base_primary_index&>(proposal_idx);
const auto& proposals_by_account = pidx.get_secondary_index<graphene::chain::required_approval_index>();

std::map<std::string, full_account> results;

for (const std::string& account_name_or_id : names_or_ids)
Expand Down Expand Up @@ -784,9 +789,6 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
acnt.cashback_balance = account->cashback_balance(_db);
}
// Add the account's proposals
const auto& proposal_idx = _db.get_index_type<proposal_index>();
const auto& pidx = dynamic_cast<const primary_index<proposal_index>&>(proposal_idx);
const auto& proposals_by_account = pidx.get_secondary_index<graphene::chain::required_approval_index>();
auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id );
if( required_approvals_itr != proposals_by_account._account_to_proposals.end() )
{
Expand All @@ -797,11 +799,9 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const


// Add the account's balances
auto balance_range = _db.get_index_type<account_balance_index>().indices().get<by_account_asset>().equal_range(boost::make_tuple(account->id));
std::for_each(balance_range.first, balance_range.second,
[&acnt](const account_balance_object& balance) {
acnt.balances.emplace_back(balance);
});
const auto& balances = _db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >().get_account_balances( account->id );
for( const auto balance : balances )
acnt.balances.emplace_back( *balance.second );

// Add the account's vesting balances
auto vesting_range = _db.get_index_type<vesting_balance_index>().indices().get<by_account>().equal_range(account->id);
Expand Down Expand Up @@ -869,7 +869,7 @@ vector<account_id_type> database_api::get_account_references( const std::string
vector<account_id_type> database_api_impl::get_account_references( const std::string account_id_or_name )const
{
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
const account_id_type account_id = get_account_from_string(account_id_or_name)->id;
auto itr = refs.account_to_account_memberships.find(account_id);
Expand Down Expand Up @@ -953,10 +953,10 @@ vector<asset> database_api_impl::get_account_balances(const std::string& account
if (assets.empty())
{
// if the caller passes in an empty list of assets, return balances for all assets the account owns
const account_balance_index& balance_index = _db.get_index_type<account_balance_index>();
auto range = balance_index.indices().get<by_account_asset>().equal_range(boost::make_tuple(acnt));
for (const account_balance_object& balance : boost::make_iterator_range(range.first, range.second))
result.push_back(asset(balance.get_balance()));
const auto& balance_index = _db.get_index_type< primary_index< account_balance_index > >();
const auto& balances = balance_index.get_secondary_index< balances_by_account_index >().get_account_balances( acnt );
for( const auto balance : balances )
result.push_back( balance.second->get_balance() );
}
else
{
Expand Down Expand Up @@ -2448,7 +2448,7 @@ void database_api_impl::on_applied_block()
}
if( market.valid() && _market_subscriptions.count(*market) )
// FIXME this may cause fill_order_operation be pushed before order creation
subscribed_markets_ops[*market].emplace_back( std::move( std::make_pair( op.op, op.result ) ) );
subscribed_markets_ops[*market].emplace_back(std::make_pair(op.op, op.result));
}
/// we need to ensure the database_api is not deleted for the life of the async operation
auto capture_this = shared_from_this();
Expand Down
6 changes: 3 additions & 3 deletions libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,19 @@ namespace graphene { namespace app {
* The transaction will be checked for validity in the local database prior to broadcasting. If it fails to
* apply locally, an error will be thrown and the transaction will not be broadcast.
*/
void broadcast_transaction(const signed_transaction& trx);
void broadcast_transaction(const precomputable_transaction& trx);

/** this version of broadcast transaction registers a callback method that will be called when the transaction is
* included into a block. The callback method includes the transaction id, block number, and transaction number in the
* block.
*/
void broadcast_transaction_with_callback( confirmation_callback cb, const signed_transaction& trx);
void broadcast_transaction_with_callback( confirmation_callback cb, const precomputable_transaction& trx);

/** this version of broadcast transaction registers a callback method that will be called when the transaction is
* included into a block. The callback method includes the transaction id, block number, and transaction number in the
* block.
*/
fc::variant broadcast_transaction_synchronous(const signed_transaction& trx);
fc::variant broadcast_transaction_synchronous(const precomputable_transaction& trx);

/**
* @brief Broadcast a signed block to the network
Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ add_library( graphene_chain
protocol/fee_schedule.cpp
protocol/confidential.cpp
protocol/vote.cpp

protocol/htlc.cpp
genesis_state.cpp
get_config.cpp

Expand All @@ -77,6 +77,7 @@ add_library( graphene_chain
vesting_balance_evaluator.cpp
withdraw_permission_evaluator.cpp
worker_evaluator.cpp
htlc_evaluator.cpp
confidential_evaluator.cpp
special_authority.cpp
buyback.cpp
Expand Down
12 changes: 8 additions & 4 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ void verify_account_votes( const database& db, const account_options& options )
}
}


void_result account_create_evaluator::do_evaluate( const account_create_operation& op )
{ try {
database& d = db();
Expand Down Expand Up @@ -318,11 +317,16 @@ void_result account_update_evaluator::do_apply( const account_update_operation&
bool sa_before = acnt->has_special_authority();

// update account statistics
if( o.new_options.valid() && o.new_options->is_voting() != acnt->options.is_voting() )
if( o.new_options.valid() )
{
d.modify( acnt->statistics( d ), []( account_statistics_object& aso )
d.modify( acnt->statistics( d ), [&]( account_statistics_object& aso )
{
aso.is_voting = !aso.is_voting;
if(o.new_options->is_voting() != acnt->options.is_voting())
aso.is_voting = !aso.is_voting;

if((o.new_options->votes != acnt->options.votes ||
o.new_options->voting_account != acnt->options.voting_account))
aso.last_vote_time = d.head_block_time();
} );
}

Expand Down
Loading

0 comments on commit 1b9f6c9

Please sign in to comment.