Skip to content

Commit

Permalink
Merge pull request #1903 from manikey123/bts1733
Browse files Browse the repository at this point in the history
BTS PR 1733: Make more API limitations configurable
  • Loading branch information
pmconrad authored Aug 22, 2019
2 parents 82d900f + daf32ec commit 16f3990
Show file tree
Hide file tree
Showing 7 changed files with 477 additions and 58 deletions.
85 changes: 70 additions & 15 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,39 @@ void application_impl::set_api_limit() {
if(_options->count("api-limit-list-htlcs")){
_app_options.api_limit_list_htlcs = _options->at("api-limit-list-htlcs").as<uint64_t>();
}
if(_options->count("api-limit-lookup-accounts")) {
_app_options.api_limit_lookup_accounts = _options->at("api-limit-lookup-accounts").as<uint64_t>();
}
if(_options->count("api-limit-lookup-witness-accounts")) {
_app_options.api_limit_lookup_witness_accounts = _options->at("api-limit-lookup-witness-accounts").as<uint64_t>();
}
if(_options->count("api-limit-lookup-committee-member-accounts")) {
_app_options.api_limit_lookup_committee_member_accounts = _options->at("api-limit-lookup-committee-member-accounts").as<uint64_t>();
}
if(_options->count("api-limit-lookup-vote-ids")) {
_app_options.api_limit_lookup_vote_ids = _options->at("api-limit-lookup-vote-ids").as<uint64_t>();
}
if(_options->count("api-limit-get-account-limit-orders")) {
_app_options.api_limit_get_account_limit_orders = _options->at("api-limit-get-account-limit-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-collateral-bids")) {
_app_options.api_limit_get_collateral_bids = _options->at("api-limit-get-collateral-bids").as<uint64_t>();
}
if(_options->count("api-limit-get-top-markets")) {
_app_options.api_limit_get_top_markets = _options->at("api-limit-get-top-markets").as<uint64_t>();
}
if(_options->count("api-limit-get-trade-history")) {
_app_options.api_limit_get_trade_history = _options->at("api-limit-get-trade-history").as<uint64_t>();
}
if(_options->count("api-limit-get-trade-history-by-sequence")) {
_app_options.api_limit_get_trade_history_by_sequence = _options->at("api-limit-get-trade-history-by-sequence").as<uint64_t>();
}
if(_options->count("api-limit-get-withdraw-permissions-by-giver")) {
_app_options.api_limit_get_withdraw_permissions_by_giver = _options->at("api-limit-get-withdraw-permissions-by-giver").as<uint64_t>();
}
if(_options->count("api-limit-get-withdraw-permissions-by-recipient")) {
_app_options.api_limit_get_withdraw_permissions_by_recipient = _options->at("api-limit-get-withdraw-permissions-by-recipient").as<uint64_t>();
}
}

void application_impl::startup()
Expand Down Expand Up @@ -1015,35 +1048,57 @@ void application::set_program_options(boost::program_options::options_descriptio
"Whether to enable tracking of votes of standby witnesses and committee members. "
"Set it to true to provide accurate data to API clients, set to false for slightly better performance.")
("api-limit-get-account-history-operations",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_account_history_operations to set its default limit value as 100")
"For history_api::get_account_history_operations to set max limit value")
("api-limit-get-account-history",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_account_history to set its default limit value as 100")
"For history_api::get_account_history to set max limit value")
("api-limit-get-grouped-limit-orders",boost::program_options::value<uint64_t>()->default_value(101),
"For orders_api::get_grouped_limit_orders to set its default limit value as 101")
"For orders_api::get_grouped_limit_orders to set max limit value")
("api-limit-get-relative-account-history",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_relative_account_history to set its default limit value as 100")
"For history_api::get_relative_account_history to set max limit value")
("api-limit-get-account-history-by-operations",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_account_history_by_operations to set its default limit value as 100")
"For history_api::get_account_history_by_operations to set max limit value")
("api-limit-get-asset-holders",boost::program_options::value<uint64_t>()->default_value(100),
"For asset_api::get_asset_holders to set its default limit value as 100")
"For asset_api::get_asset_holders to set max limit value")
("api-limit-get-key-references",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_key_references to set its default limit value as 100")
"For database_api_impl::get_key_references to set max limit value")
("api-limit-get-htlc-by",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_htlc_by_from and get_htlc_by_to to set its default limit value as 100")
"For database_api_impl::get_htlc_by_from and get_htlc_by_to to set max limit value")
("api-limit-get-full-accounts",boost::program_options::value<uint64_t>()->default_value(10),
"For database_api_impl::get_full_accounts to set its account default limit values as 10")
"For database_api_impl::get_full_accounts to set max limit value")
("api-limit-get-full-accounts-lists",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_full_accounts to set its lists default limit values as 100")
"For database_api_impl::get_full_accounts to set max limit value")
("api-limit-get-call-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_call_orders and get_call_orders_by_account to set its default limit values as 300")
"For database_api_impl::get_call_orders and get_call_orders_by_account to set max limit value")
("api-limit-get-settle-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_settle_orders and get_settle_orders_by_account to set its default limit values as 300")
"For database_api_impl::get_settle_orders and get_settle_orders_by_account to set max limit value")
("api-limit-get-assets",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::list_assets and get_assets_by_issuer to set its default limit values as 101")
"For database_api_impl::list_assets and get_assets_by_issuer to set max limit value")
("api-limit-get-limit-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_limit_orders to set its default limit value as 300")
"For database_api_impl::get_limit_orders to set max limit value")
("api-limit-get-order-book",boost::program_options::value<uint64_t>()->default_value(50),
"For database_api_impl::get_order_book to set its default limit value as 50")
"For database_api_impl::get_order_book to set max limit value")
("api-limit-lookup-accounts",boost::program_options::value<uint64_t>()->default_value(1000),
"For database_api_impl::lookup_accounts to set max limit value")
("api-limit-lookup-witness-accounts",boost::program_options::value<uint64_t>()->default_value(1000),
"For database_api_impl::lookup_witness_accounts to set max limit value")
("api-limit-lookup-committee-member-accounts",boost::program_options::value<uint64_t>()->default_value(1000),
"For database_api_impl::lookup_committee_member_accounts to set max limit value")
("api-limit-lookup-vote-ids",boost::program_options::value<uint64_t>()->default_value(1000),
"For database_api_impl::lookup_vote_ids to set max limit value")
("api-limit-get-account-limit-orders",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::get_account_limit_orders to set max limit value")
("api-limit-get-collateral-bids",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_collateral_bids to set max limit value")
("api-limit-get-top-markets",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_top_markets to set max limit value")
("api-limit-get-trade-history",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_trade_history to set max limit value")
("api-limit-get-trade-history-by-sequence",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_trade_history_by_sequence to set max limit value")
("api-limit-get-withdraw-permissions-by-giver",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::get_withdraw_permissions_by_giver to set max limit value")
("api-limit-get-withdraw-permissions-by-recipient",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::get_withdraw_permissions_by_recipient to set max limit value")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down
27 changes: 13 additions & 14 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ map<string,account_id_type> database_api_impl::lookup_accounts( const string& lo
uint32_t limit,
optional<bool> subscribe )const
{
FC_ASSERT( limit <= 1000 );
FC_ASSERT( limit <= _app_options->api_limit_lookup_accounts );
const auto& accounts_by_name = _db.get_index_type<account_index>().indices().get<by_name>();
map<string,account_id_type> result;

Expand Down Expand Up @@ -982,7 +982,7 @@ vector<limit_order_object> database_api_impl::get_account_limit_orders(
const string& account_name_or_id, const string &base, const string &quote,
uint32_t limit, optional<limit_order_id_type> ostart_id, optional<price> ostart_price )
{
FC_ASSERT( limit <= 101 );
FC_ASSERT( limit <= _app_options->api_limit_get_account_limit_orders );

vector<limit_order_object> results;
uint32_t count = 0;
Expand Down Expand Up @@ -1197,7 +1197,7 @@ vector<collateral_bid_object> database_api::get_collateral_bids( const std::stri
vector<collateral_bid_object> database_api_impl::get_collateral_bids( const std::string& asset,
uint32_t limit, uint32_t skip )const
{ try {
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= _app_options->api_limit_get_collateral_bids );
const asset_id_type asset_id = get_asset_from_string(asset)->id;
const asset_object& swan = asset_id(_db);
FC_ASSERT( swan.is_market_issued() );
Expand Down Expand Up @@ -1313,9 +1313,8 @@ order_book database_api::get_order_book( const string& base, const string& quote

order_book database_api_impl::get_order_book( const string& base, const string& quote, unsigned limit )const
{
uint64_t api_limit_get_order_book=_app_options->api_limit_get_order_book;
FC_ASSERT( limit <= api_limit_get_order_book );

FC_ASSERT( limit <= _app_options->api_limit_get_order_book );

order_book result;
result.base = base;
result.quote = quote;
Expand Down Expand Up @@ -1364,7 +1363,7 @@ vector<market_ticker> database_api_impl::get_top_markets(uint32_t limit)const
{
FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." );

FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= _app_options->api_limit_get_top_markets );

const auto& volume_idx = _db.get_index_type<market_ticker_index>().indices().get<by_volume>();
auto itr = volume_idx.rbegin();
Expand Down Expand Up @@ -1402,7 +1401,7 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
{
FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." );

FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= _app_options->api_limit_get_trade_history );

auto assets = lookup_asset_symbols( {base, quote} );
FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) );
Expand Down Expand Up @@ -1494,7 +1493,7 @@ vector<market_trade> database_api_impl::get_trade_history_by_sequence(
{
FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." );

FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= _app_options->api_limit_get_trade_history_by_sequence );
FC_ASSERT( start >= 0 );
int64_t start_seq = -start;

Expand Down Expand Up @@ -1628,7 +1627,7 @@ map<string, witness_id_type> database_api::lookup_witness_accounts( const string
map<string, witness_id_type> database_api_impl::lookup_witness_accounts( const string& lower_bound_name,
uint32_t limit )const
{
FC_ASSERT( limit <= 1000 );
FC_ASSERT( limit <= _app_options->api_limit_lookup_witness_accounts );
const auto& witnesses_by_id = _db.get_index_type<witness_index>().indices().get<by_id>();

// we want to order witnesses by account name, but that name is in the account object
Expand Down Expand Up @@ -1710,7 +1709,7 @@ map<string, committee_member_id_type> database_api::lookup_committee_member_acco
map<string, committee_member_id_type> database_api_impl::lookup_committee_member_accounts(
const string& lower_bound_name, uint32_t limit )const
{
FC_ASSERT( limit <= 1000 );
FC_ASSERT( limit <= _app_options->api_limit_lookup_committee_member_accounts );
const auto& committee_members_by_id = _db.get_index_type<committee_member_index>().indices().get<by_id>();

// we want to order committee_members by account name, but that name is in the account object
Expand Down Expand Up @@ -1808,7 +1807,7 @@ vector<variant> database_api::lookup_vote_ids( const vector<vote_id_type>& votes

vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>& votes )const
{
FC_ASSERT( votes.size() < 1000, "Only 1000 votes can be queried at a time" );
FC_ASSERT( votes.size() < _app_options->api_limit_lookup_vote_ids );

const auto& witness_idx = _db.get_index_type<witness_index>().indices().get<by_vote_id>();
const auto& committee_idx = _db.get_index_type<committee_member_index>().indices().get<by_vote_id>();
Expand Down Expand Up @@ -2204,7 +2203,7 @@ vector<withdraw_permission_object> database_api_impl::get_withdraw_permissions_b
withdraw_permission_id_type start,
uint32_t limit)const
{
FC_ASSERT( limit <= 101 );
FC_ASSERT( limit <= _app_options->api_limit_get_withdraw_permissions_by_giver );
vector<withdraw_permission_object> result;

const auto& withdraw_idx = _db.get_index_type<withdraw_permission_index>().indices().get<by_from>();
Expand Down Expand Up @@ -2233,7 +2232,7 @@ vector<withdraw_permission_object> database_api_impl::get_withdraw_permissions_b
withdraw_permission_id_type start,
uint32_t limit)const
{
FC_ASSERT( limit <= 101 );
FC_ASSERT( limit <= _app_options->api_limit_get_withdraw_permissions_by_recipient );
vector<withdraw_permission_object> result;

const auto& withdraw_idx = _db.get_index_type<withdraw_permission_index>().indices().get<by_authorized>();
Expand Down
11 changes: 11 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ namespace graphene { namespace app {
uint64_t api_limit_get_limit_orders = 300;
uint64_t api_limit_get_order_book = 50;
uint64_t api_limit_list_htlcs = 100;
uint64_t api_limit_lookup_accounts = 1000;
uint64_t api_limit_lookup_witness_accounts = 1000;
uint64_t api_limit_lookup_committee_member_accounts = 1000;
uint64_t api_limit_lookup_vote_ids = 1000;
uint64_t api_limit_get_account_limit_orders = 101;
uint64_t api_limit_get_collateral_bids = 100;
uint64_t api_limit_get_top_markets = 100;
uint64_t api_limit_get_trade_history = 100;
uint64_t api_limit_get_trade_history_by_sequence = 100;
uint64_t api_limit_get_withdraw_permissions_by_giver = 101;
uint64_t api_limit_get_withdraw_permissions_by_recipient = 101;
};

class application
Expand Down
Loading

0 comments on commit 16f3990

Please sign in to comment.