Skip to content

Commit

Permalink
Merge branch 'hardfork' into pr-bsip77-icr
Browse files Browse the repository at this point in the history
Resolved conflicts:
- libraries/chain/asset_evaluator.cpp : applied changes from both branches
- libraries/chain/proposal_evaluator.cpp : applied changes from both branches
  • Loading branch information
abitmore committed May 5, 2020
2 parents 2131c68 + ecc5cbb commit f5d4e44
Show file tree
Hide file tree
Showing 38 changed files with 1,177 additions and 216 deletions.
23 changes: 20 additions & 3 deletions libraries/app/api_objects.cpp
Expand Up @@ -38,8 +38,11 @@ market_ticker::market_ticker(const market_ticker_object& mto,
quote = asset_quote.symbol;
percent_change = "0";
lowest_ask = "0";
lowest_ask_base_size = "0";
lowest_ask_quote_size = "0";
highest_bid = "0";

highest_bid_base_size = "0";
highest_bid_quote_size = "0";
fc::uint128_t bv;
fc::uint128_t qv;
price latest_price = asset( mto.latest_base, mto.base ) / asset( mto.latest_quote, mto.quote );
Expand Down Expand Up @@ -68,9 +71,19 @@ market_ticker::market_ticker(const market_ticker_object& mto,
quote_volume = uint128_amount_to_string( qv, asset_quote.precision );

if(!orders.asks.empty())
lowest_ask = orders.asks[0].price;
{
lowest_ask = orders.asks[0].price;
lowest_ask_base_size = orders.asks[0].base;
lowest_ask_quote_size = orders.asks[0].quote;
}

if(!orders.bids.empty())
highest_bid = orders.bids[0].price;
{
highest_bid = orders.bids[0].price;
highest_bid_base_size = orders.bids[0].base;
highest_bid_quote_size = orders.bids[0].quote;
}

}

market_ticker::market_ticker(const fc::time_point_sec& now,
Expand All @@ -82,7 +95,11 @@ market_ticker::market_ticker(const fc::time_point_sec& now,
quote = asset_quote.symbol;
latest = "0";
lowest_ask = "0";
lowest_ask_base_size = "0";
lowest_ask_quote_size = "0";
highest_bid = "0";
highest_bid_base_size = "0";
highest_bid_quote_size = "0";
percent_change = "0";
base_volume = "0";
quote_volume = "0";
Expand Down
77 changes: 3 additions & 74 deletions libraries/app/application.cpp
Expand Up @@ -43,7 +43,6 @@
#include <fc/io/fstream.hpp>
#include <fc/rpc/api_connection.hpp>
#include <fc/rpc/websocket_api.hpp>
#include <fc/network/resolve.hpp>
#include <fc/crypto/base64.hpp>

#include <boost/filesystem/path.hpp>
Expand Down Expand Up @@ -125,62 +124,22 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
if( _options->count("seed-node") )
{
auto seeds = _options->at("seed-node").as<vector<string>>();
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
_p2p_network->add_node(endpoint);
_p2p_network->connect_to_endpoint(endpoint);
}
} catch( const fc::exception& e ) {
wlog( "caught exception ${e} while adding seed node ${endpoint}",
("e", e.to_detail_string())("endpoint", endpoint_string) );
}
}
_p2p_network->add_seed_nodes(seeds);
}

if( _options->count("seed-nodes") )
{
auto seeds_str = _options->at("seed-nodes").as<string>();
auto seeds = fc::json::from_string(seeds_str).as<vector<string>>(2);
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
_p2p_network->add_node(endpoint);
}
} catch( const fc::exception& e ) {
wlog( "caught exception ${e} while adding seed node ${endpoint}",
("e", e.to_detail_string())("endpoint", endpoint_string) );
}
}
_p2p_network->add_seed_nodes(seeds);
}
else
{
// https://bitsharestalk.org/index.php/topic,23715.0.html
vector<string> seeds = {
#include "../egenesis/seed-nodes.txt"
};
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
_p2p_network->add_node(endpoint);
}
} catch( const fc::exception& e ) {
wlog( "caught exception ${e} while adding seed node ${endpoint}",
("e", e.to_detail_string())("endpoint", endpoint_string) );
}
}
_p2p_network->add_seed_nodes(seeds);
}

if( _options->count("p2p-endpoint") )
Expand All @@ -196,36 +155,6 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
std::vector<uint32_t>());
} FC_CAPTURE_AND_RETHROW() }

std::vector<fc::ip::endpoint> application_impl::resolve_string_to_ip_endpoints(const std::string& endpoint_string)
{
try
{
string::size_type colon_pos = endpoint_string.find(':');
if (colon_pos == std::string::npos)
FC_THROW("Missing required port number in endpoint string \"${endpoint_string}\"",
("endpoint_string", endpoint_string));
std::string port_string = endpoint_string.substr(colon_pos + 1);
try
{
uint16_t port = boost::lexical_cast<uint16_t>(port_string);

std::string hostname = endpoint_string.substr(0, colon_pos);
std::vector<fc::ip::endpoint> endpoints = fc::resolve(hostname, port);
if (endpoints.empty())
FC_THROW_EXCEPTION( fc::unknown_host_exception,
"The host name can not be resolved: ${hostname}",
("hostname", hostname) );
return endpoints;
}
catch (const boost::bad_lexical_cast&)
{
FC_THROW("Bad port: ${port}", ("port", port_string));
}
}
FC_CAPTURE_AND_RETHROW((endpoint_string))
}


void application_impl::new_connection( const fc::http::websocket_connection_ptr& c )
{
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_NET_MAX_NESTED_OBJECTS);
Expand Down
2 changes: 0 additions & 2 deletions libraries/app/application_impl.hxx
Expand Up @@ -22,8 +22,6 @@ class application_impl : public net::node_delegate

void reset_p2p_node(const fc::path& data_dir);

std::vector<fc::ip::endpoint> resolve_string_to_ip_endpoints(const std::string& endpoint_string);

void new_connection( const fc::http::websocket_connection_ptr& c );

void reset_websocket_server();
Expand Down
7 changes: 6 additions & 1 deletion libraries/app/include/graphene/app/api_objects.hpp
Expand Up @@ -100,7 +100,11 @@ namespace graphene { namespace app {
string quote;
string latest;
string lowest_ask;
string lowest_ask_base_size;
string lowest_ask_quote_size;
string highest_bid;
string highest_bid_base_size;
string highest_bid_quote_size;
string percent_change;
string base_volume;
string quote_volume;
Expand Down Expand Up @@ -178,7 +182,8 @@ FC_REFLECT( graphene::app::full_account,
FC_REFLECT( graphene::app::order, (price)(quote)(base) );
FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) );
FC_REFLECT( graphene::app::market_ticker,
(time)(base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume) );
(time)(base)(quote)(latest)(lowest_ask)(lowest_ask_base_size)(lowest_ask_quote_size)
(highest_bid)(highest_bid_base_size)(highest_bid_quote_size)(percent_change)(base_volume)(quote_volume) );
FC_REFLECT( graphene::app::market_volume, (time)(base)(quote)(base_volume)(quote_volume) );
FC_REFLECT( graphene::app::market_trade, (sequence)(date)(price)(amount)(value)(side1_account_id)(side2_account_id) );

Expand Down
67 changes: 56 additions & 11 deletions libraries/chain/asset_evaluator.cpp
Expand Up @@ -50,7 +50,7 @@ namespace detail {
void check_asset_options_hf_bsip81(const fc::time_point_sec& block_time, const asset_options& options)
{
if (block_time < HARDFORK_BSIP_81_TIME) {
// Taker fees should be zero until activation of BSIP81
// Taker fees should not be set until activation of BSIP81
FC_ASSERT(!options.extensions.value.taker_fee_percent.valid(),
"Taker fee percent should not be defined before HARDFORK_BSIP_81_TIME");
}
Expand All @@ -65,7 +65,16 @@ namespace detail {
"Initial collateral ratio should not be defined before HARDFORK_BSIP_77_TIME");
}
}
}

void check_asset_claim_fees_hardfork_87_74_collatfee(const fc::time_point_sec& block_time, const asset_claim_fees_operation& op)
{
// HF_REMOVABLE: Following hardfork check should be removable after hardfork date passes:
FC_ASSERT( !op.extensions.value.claim_from_asset_id.valid() ||
block_time >= HARDFORK_CORE_BSIP_87_74_COLLATFEE_TIME,
"Collateral-denominated fees are not yet active and therefore cannot be claimed." );
}

} // graphene::chain::detail

void_result asset_create_evaluator::do_evaluate( const asset_create_operation& op )
{ try {
Expand Down Expand Up @@ -468,6 +477,9 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita
FC_ASSERT( asset_obj.dynamic_asset_data_id(d).current_supply == 0,
"Cannot update a bitasset if there is already a current supply." );

FC_ASSERT( asset_obj.dynamic_asset_data_id(d).accumulated_collateral_fees == 0,
"Must claim collateral-denominated fees before changing backing asset." );

const asset_object& new_backing_asset = op.new_options.short_backing_asset(d); // check if the asset exists

if( after_hf_core_922_931 )
Expand Down Expand Up @@ -944,25 +956,58 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope
} FC_CAPTURE_AND_RETHROW((o)) }



/***
* @brief evaluator for asset_claim_fees operation
*
* Checks that we are able to claim fees denominated in asset Y (the amount_to_claim asset),
* from some container asset X which is presumed to have accumulated the fees we wish to claim.
* The container asset is either explicitly named in the extensions, or else assumed as the same
* asset as the amount_to_claim asset. Evaluation fails if either (a) operation issuer is not
* the same as the container_asset issuer, or (b) container_asset has no fee bucket for
* amount_to_claim asset, or (c) accumulated fees are insufficient to cover amount claimed.
*/
void_result asset_claim_fees_evaluator::do_evaluate( const asset_claim_fees_operation& o )
{ try {
FC_ASSERT( o.amount_to_claim.asset_id(db()).issuer == o.issuer, "Asset fees may only be claimed by the issuer" );
const database& d = db();

detail::check_asset_claim_fees_hardfork_87_74_collatfee(d.head_block_time(), o); // HF_REMOVABLE

container_asset = o.extensions.value.claim_from_asset_id.valid() ?
&(*o.extensions.value.claim_from_asset_id)(d) : &o.amount_to_claim.asset_id(d);

FC_ASSERT( container_asset->issuer == o.issuer, "Asset fees may only be claimed by the issuer" );
FC_ASSERT( container_asset->can_accumulate_fee(d,o.amount_to_claim),
"Asset ${a} (${id}) is not backed by asset (${fid}) and does not hold it as fees.",
("a",container_asset->symbol)("id",container_asset->id)("fid",o.amount_to_claim.asset_id) );

container_ddo = &container_asset->dynamic_asset_data_id(d);

FC_ASSERT( o.amount_to_claim.amount <= ((container_asset->get_id() == o.amount_to_claim.asset_id) ?
container_ddo->accumulated_fees :
container_ddo->accumulated_collateral_fees),
"Attempt to claim more fees than have accumulated within asset ${a} (${id})",
("a",container_asset->symbol)("id",container_asset->id)("ddo",*container_ddo) );

return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }


/***
* @brief apply asset_claim_fees operation
*/
void_result asset_claim_fees_evaluator::do_apply( const asset_claim_fees_operation& o )
{ try {
database& d = db();

const asset_object& a = o.amount_to_claim.asset_id(d);
const asset_dynamic_data_object& addo = a.dynamic_asset_data_id(d);
FC_ASSERT( o.amount_to_claim.amount <= addo.accumulated_fees, "Attempt to claim more fees than have accumulated", ("addo",addo) );

d.modify( addo, [&]( asset_dynamic_data_object& _addo ) {
_addo.accumulated_fees -= o.amount_to_claim.amount;
});
if ( container_asset->get_id() == o.amount_to_claim.asset_id ) {
d.modify( *container_ddo, [&o]( asset_dynamic_data_object& _addo ) {
_addo.accumulated_fees -= o.amount_to_claim.amount;
});
} else {
d.modify( *container_ddo, [&o]( asset_dynamic_data_object& _addo ) {
_addo.accumulated_collateral_fees -= o.amount_to_claim.amount;
});
}

d.adjust_balance( o.issuer, o.amount_to_claim );

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/asset_object.cpp
Expand Up @@ -205,7 +205,7 @@ string asset_object::amount_to_string(share_type amount) const
}

FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::db::object),
(current_supply)(confidential_supply)(accumulated_fees)(fee_pool) )
(current_supply)(confidential_supply)(accumulated_fees)(accumulated_collateral_fees)(fee_pool) )

FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::db::object),
(asset_id)
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/hardfork.d/CORE_BSIP64.hf
@@ -0,0 +1,4 @@
// bitshares BSIP 64 HTLC modifications
#ifndef HARDFORK_CORE_BSIP64_TIME
#define HARDFORK_CORE_BSIP64_TIME (fc::time_point_sec( 1600000000 ) ) // Sep 2020
#endif
7 changes: 7 additions & 0 deletions libraries/chain/hardfork.d/CORE_BSIP_87_74_COLLATFEE.hf
@@ -0,0 +1,7 @@
// This hardfork enables the extension to asset_claim_fees_operation to claim collateral-denominated fees.
// These fees are collected by BSIPs 87 and 74. This should be set to match the earlier of either
// HARDFORK_CORE_BSIP87_TIME or HARDFORK_CORE_BSIP74_TIME.
// This hardfork check should be removable after the hardfork date passes.
#ifndef HARDFORK_CORE_BSIP_87_74_COLLATFEE_TIME
#define HARDFORK_CORE_BSIP_87_74_COLLATFEE_TIME (fc::time_point_sec( 1679955066 ) ) // Temporary date until actual hardfork date is set
#endif

0 comments on commit f5d4e44

Please sign in to comment.