Skip to content

Commit

Permalink
Merge pull request #639 from steemit/20161129-steem_v0_16_0
Browse files Browse the repository at this point in the history
Steem 0.16.0
  • Loading branch information
Michael Vandeberg authored Nov 30, 2016
2 parents c4c81cb + 4c4638f commit 9ff5d76
Show file tree
Hide file tree
Showing 224 changed files with 12,041 additions and 9,036 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libraries/fc"]
path = libraries/fc
url = https://github.com/steemit/fc.git
[submodule "libraries/chainbase"]
path = libraries/chainbase
url = https://github.com/steemit/chainbase.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ else( WIN32 ) # Apple AND Linux
if( APPLE )
# Apple Specific Options Here
message( STATUS "Configuring Steem on OS X" )
set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall -Wno-conversion" )
set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" )
else( APPLE )
# Linux Specific Options Here
message( STATUS "Configuring Steem on Linux" )
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN \
mkdir build && \
cd build && \
cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_STEEM_TESTNET=ON \
-DLOW_MEMORY_NODE=OFF \
-DCLEAR_VOTES=ON \
Expand Down
4 changes: 3 additions & 1 deletion libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_subdirectory( fc )
add_subdirectory( db )
add_subdirectory( schema )
add_subdirectory( chainbase )
add_subdirectory( chain )
add_subdirectory( protocol )
add_subdirectory( net )
add_subdirectory( time )
add_subdirectory( utilities )
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_library( steemit_app
${HEADERS}
)

target_link_libraries( steemit_app steemit_chain steemit_tags steemit_follow steemit_mf_plugins fc graphene_db graphene_net graphene_time graphene_utilities )
target_link_libraries( steemit_app steemit_chain steemit_protocol steemit_tags steemit_follow steemit_mf_plugins fc graphene_net graphene_time graphene_utilities )
target_include_directories( steemit_app
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
165 changes: 109 additions & 56 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#include <steemit/app/api_access.hpp>
#include <steemit/app/application.hpp>
#include <steemit/app/impacted.hpp>

#include <steemit/protocol/get_config.hpp>

#include <steemit/chain/database.hpp>
#include <steemit/chain/get_config.hpp>
#include <steemit/chain/steem_objects.hpp>
#include <steemit/chain/transaction_object.hpp>

Expand All @@ -38,6 +40,9 @@
#include <fc/crypto/hex.hpp>
#include <fc/smart_ref_impl.hpp>

#include <graphene/utilities/git_revision.hpp>
#include <fc/git_revision.hpp>

namespace steemit { namespace app {

login_api::login_api(const api_context& ctx)
Expand Down Expand Up @@ -110,6 +115,14 @@ namespace steemit { namespace app {
return it->second;
}

steem_version_info login_api::get_version()
{
return steem_version_info(
fc::string( STEEMIT_BLOCKCHAIN_VERSION ),
fc::string( graphene::utilities::git_revision_sha ),
fc::string( fc::git_revision_sha ) );
}

network_broadcast_api::network_broadcast_api(const api_context& a):_app(a.app)
{
/// NOTE: cannot register callbacks in constructor because shared_from_this() is not valid.
Expand All @@ -125,14 +138,17 @@ namespace steemit { namespace app {

bool network_broadcast_api::check_max_block_age( int32_t max_block_age )
{
if( max_block_age < 0 )
return false;
return _app.chain_database()->with_read_lock( [&]()
{
if( max_block_age < 0 )
return false;

fc::time_point_sec now = graphene::time::now();
std::shared_ptr< database > db = _app.chain_database();
const dynamic_global_property_object& dgpo = db->get_dynamic_global_properties();
fc::time_point_sec now = graphene::time::now();
std::shared_ptr< database > db = _app.chain_database();
const dynamic_global_property_object& dgpo = db->get_dynamic_global_properties();

return ( dgpo.time < now - fc::seconds( max_block_age ) );
return ( dgpo.time < now - fc::seconds( max_block_age ) );
});
}

void network_broadcast_api::set_max_block_age( int32_t max_block_age )
Expand All @@ -142,80 +158,117 @@ namespace steemit { namespace app {

void network_broadcast_api::on_applied_block( const signed_block& b )
{
int32_t block_num = int32_t(b.block_num());
if( _callbacks.size() )
{
/// we need to ensure the database_api is not deleted for the life of the async operation
auto capture_this = shared_from_this();
for( int32_t trx_num = 0; trx_num < b.transactions.size(); ++trx_num )
/// we need to ensure the database_api is not deleted for the life of the async operation
auto capture_this = shared_from_this();

fc::async( [this,capture_this,b]() {
int32_t block_num = int32_t(b.block_num());
if( _callbacks.size() )
{
const auto& trx = b.transactions[trx_num];
auto id = trx.id();
auto itr = _callbacks.find(id);
if( itr != _callbacks.end() )
for( size_t trx_num = 0; trx_num < b.transactions.size(); ++trx_num )
{
const auto& trx = b.transactions[trx_num];
auto id = trx.id();
auto itr = _callbacks.find(id);
if( itr == _callbacks.end() ) continue;
confirmation_callback callback = itr->second;
fc::async( [capture_this,id,block_num,trx_num,callback](){ callback( fc::variant(transaction_confirmation( id, block_num, trx_num, false )) ); } );
_callbacks.erase( itr );
itr->second = [](variant){};
callback( fc::variant(transaction_confirmation( id, block_num, int32_t(trx_num), false )) );
}
}
}

/// clear all expirations
while( true )
{
auto exp_it = _callbacks_expirations.begin();
if( exp_it == _callbacks_expirations.end() )
break;
if( exp_it->first > b.timestamp )
break;
for( const transaction_id_type& txid : exp_it->second )
/// clear all expirations
while( true )
{
auto cb_it = _callbacks.find( txid );
// If it's empty, that means the transaction has been confirmed and has been deleted by the above check.
if( cb_it == _callbacks.end() )
continue;
std::shared_ptr< network_broadcast_api > capture_this = shared_from_this();
confirmation_callback callback = cb_it->second;
transaction_id_type txid_byval = txid; // can't pass in by reference as it's going to be deleted
fc::async( [capture_this,block_num,txid_byval,callback](){ callback( fc::variant(transaction_confirmation{ txid_byval, block_num, -1, true}) ); } );
_callbacks.erase( cb_it );
auto exp_it = _callbacks_expirations.begin();
if( exp_it == _callbacks_expirations.end() )
break;
if( exp_it->first >= b.timestamp )
break;
for( const transaction_id_type& txid : exp_it->second )
{
auto cb_it = _callbacks.find( txid );
// If it's empty, that means the transaction has been confirmed and has been deleted by the above check.
if( cb_it == _callbacks.end() )
continue;

confirmation_callback callback = cb_it->second;
transaction_id_type txid_byval = txid; // can't pass in by reference as it's going to be deleted
callback( fc::variant(transaction_confirmation{ txid_byval, block_num, -1, true}) );

_callbacks.erase( cb_it );
}
_callbacks_expirations.erase( exp_it );
}
_callbacks_expirations.erase( exp_it );
}
}); /// fc::async

}

void network_broadcast_api::broadcast_transaction(const signed_transaction& trx)
{
trx.validate();
FC_ASSERT( !check_max_block_age( _max_block_age ) );
_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);

if( _app._read_only )
{
FC_ASSERT( _app._remote_net_api, "Write node RPC not configured properly or non connected." );
(*_app._remote_net_api)->broadcast_transaction( trx );
}
else
{
FC_ASSERT( !check_max_block_age( _max_block_age ) );
_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);
}
}

fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
{
promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
broadcast_transaction_with_callback( [=]( const fc::variant& v ){
prom->set_value(v);
}, trx );
return future<fc::variant>(prom).wait();
if( _app._read_only )
{
FC_ASSERT( _app._remote_net_api, "Write node RPC not configured properly or non connected." );
return (*_app._remote_net_api)->broadcast_transaction_synchronous( trx );
}
else
{
promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
broadcast_transaction_with_callback( [=]( const fc::variant& v ){
prom->set_value(v);
}, trx );
return future<fc::variant>(prom).wait();
}
}

void network_broadcast_api::broadcast_block( const signed_block& b )
{
_app.chain_database()->push_block(b);
_app.p2p_node()->broadcast( graphene::net::block_message( b ));
if( _app._read_only )
{
FC_ASSERT( _app._remote_net_api, "Write node RPC not configured properly or non connected." );
(*_app._remote_net_api)->broadcast_block( b );
}
else
{
_app.chain_database()->push_block(b);
_app.p2p_node()->broadcast( graphene::net::block_message( b ));
}
}

void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const signed_transaction& trx)
{
FC_ASSERT( !check_max_block_age( _max_block_age ) );
trx.validate();
_callbacks[trx.id()] = cb;
_callbacks_expirations[trx.expiration].push_back(trx.id());
if( _app._read_only )
{
FC_ASSERT( _app._remote_net_api, "Write node RPC not configured properly or non connected." );
(*_app._remote_net_api)->broadcast_transaction_with_callback( cb, trx );
}
else
{
FC_ASSERT( !check_max_block_age( _max_block_age ) );
trx.validate();
_callbacks[trx.id()] = cb;
_callbacks_expirations[trx.expiration].push_back(trx.id());

_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);
_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);
}
}

network_node_api::network_node_api( const api_context& a ) : _app( a.app )
Expand Down
Loading

0 comments on commit 9ff5d76

Please sign in to comment.