From e0991f6e6907dc796ba3563dc86d3a0c60afcd68 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Mon, 20 Jan 2025 16:15:44 -0500 Subject: [PATCH] Avoid database update when new ram is not issued with every block. --- contracts/eosio.system/src/eosio.system.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index d345087a..e9bc9888 100644 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -95,23 +95,24 @@ namespace eosiosystem { if( cbt <= _gstate2.last_ram_increase ) return; - auto itr = _rammarket.find(ramcore_symbol.raw()); - auto new_ram = (cbt.slot - _gstate2.last_ram_increase.slot)*_gstate2.new_ram_per_block; - _gstate.max_ram_size += new_ram; + if (_gstate2.new_ram_per_block != 0) { + auto itr = _rammarket.find(ramcore_symbol.raw()); + auto new_ram = (cbt.slot - _gstate2.last_ram_increase.slot) * _gstate2.new_ram_per_block; + _gstate.max_ram_size += new_ram; + + /** + * Increase the amount of ram for sale based upon the change in max ram size. + */ + _rammarket.modify(itr, same_payer, [&](auto& m) { m.base.balance.amount += new_ram; }); + } - /** - * Increase the amount of ram for sale based upon the change in max ram size. - */ - _rammarket.modify( itr, same_payer, [&]( auto& m ) { - m.base.balance.amount += new_ram; - }); _gstate2.last_ram_increase = cbt; } void system_contract::setramrate( uint16_t bytes_per_block ) { require_auth( get_self() ); - update_ram_supply(); + update_ram_supply(); // make sure all previous blocks are accounted at the old rate before updating the rate _gstate2.new_ram_per_block = bytes_per_block; }