Skip to content

Commit

Permalink
Don't curve the storage bw, if no authorization from the account. #720
Browse files Browse the repository at this point in the history
  • Loading branch information
afalaleev committed May 23, 2019
1 parent d31b851 commit a28279b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
8 changes: 7 additions & 1 deletion libraries/chain/apply_context.cpp
Expand Up @@ -544,15 +544,21 @@ storage_payer_info apply_context::get_storage_payer( account_name owner, account
}

void apply_context::add_storage_usage( const storage_payer_info& storage ) {
bool is_authorized = false;

if( storage.delta > 0 ) {
if( !(privileged || storage.payer == receiver) ) {
EOS_ASSERT( control.is_ram_billing_in_notify_allowed() || (receiver == act.account), subjective_block_production_exception,
"Cannot charge RAM to other accounts during notify." );
require_authorization( storage.payer );
}

is_authorized = true;
} else {
is_authorized = has_authorization( storage.payer );
}

trx_context.add_storage_usage( storage );
trx_context.add_storage_usage( storage, is_authorized );
}

int apply_context::get_action( uint32_t type, uint32_t index, char* buffer, size_t buffer_size )const
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/chaindb/controller.cpp
Expand Up @@ -97,9 +97,9 @@ namespace cyberway { namespace chaindb {
} else if (BOOST_LIKELY(!!apply_ctx)) {
apply_ctx->add_storage_usage(*this);
} else if (!!transaction_ctx) {
transaction_ctx->add_storage_usage(*this);
transaction_ctx->add_storage_usage(*this, false);
} else if (!!resource_mng) {
resource_mng->add_storage_usage(payer, delta, time_slot);
resource_mng->add_storage_usage(payer, delta, time_slot, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/resource_limits.hpp
Expand Up @@ -67,7 +67,7 @@ namespace resource_limits {

void add_transaction_usage( const flat_set<account_name>& accounts, uint64_t cpu_usage, uint64_t net_usage, uint64_t ram_usage, fc::time_point pending_block_time );

void add_storage_usage(const account_name& account, int64_t delta, uint32_t time_slot);
void add_storage_usage(const account_name& account, int64_t delta, uint32_t time_slot, bool);

void process_block_usage(uint32_t time_slot);

Expand Down
Expand Up @@ -114,7 +114,7 @@ namespace eosio { namespace chain {

int64_t get_min_cpu_limit()const;

void add_storage_usage( const storage_payer_info& );
void add_storage_usage( const storage_payer_info&, bool is_authorized );

// TODO: request bw, why provided?
// uint64_t get_provided_net_limit(account_name account) const;
Expand Down
8 changes: 7 additions & 1 deletion libraries/chain/resource_limits.cpp
Expand Up @@ -171,10 +171,16 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
});
}

void resource_limits_manager::add_storage_usage(const account_name& account, int64_t delta, uint32_t time_slot) {
void resource_limits_manager::add_storage_usage(const account_name& account, int64_t delta, uint32_t time_slot, bool is_authorized) {
if (delta == 0) {
return;
}

// don't `curve the storage bw`, if no signature from the account
if (!is_authorized && delta < 0 ) {
return;
}

const auto& config = _chaindb.get<resource_limits_config_object>();
auto state_table = _chaindb.get_table<resource_limits_state_object>();
const auto& state = state_table.get();
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/transaction_context.cpp
Expand Up @@ -573,7 +573,7 @@ namespace bacc = boost::accumulators;
}
}

void transaction_context::add_storage_usage( const storage_payer_info& storage ) {
void transaction_context::add_storage_usage( const storage_payer_info& storage, const bool is_authorized ) {
storage_bytes += storage.delta;
check_storage_usage();

Expand All @@ -583,7 +583,7 @@ namespace bacc = boost::accumulators;
}

auto& rl = control.get_mutable_resource_limits_manager();
rl.add_storage_usage(storage.payer, storage.delta, control.pending_block_slot());
rl.add_storage_usage(storage.payer, storage.delta, control.pending_block_slot(), is_authorized);
}

int64_t transaction_context::get_billed_cpu_time(fc::time_point now)const {
Expand Down

0 comments on commit a28279b

Please sign in to comment.