diff --git a/libraries/chain/deep_mind.cpp b/libraries/chain/deep_mind.cpp index 634aabe6e6..6a149cdd2a 100644 --- a/libraries/chain/deep_mind.cpp +++ b/libraries/chain/deep_mind.cpp @@ -242,22 +242,57 @@ namespace sysio::chain { ("data", state) ); } - void deep_mind_handler::on_newaccount_resource_limits(const resource_limits::resource_limits_object& limits, const resource_limits::resource_usage_object& usage) - { + + // maintain expected format + struct resource_limits_object { + account_name owner; //< owner should not be changed within a chainbase modifier lambda + + int64_t net_weight = -1; + int64_t cpu_weight = -1; + int64_t ram_bytes = -1; + }; + struct resource_usage_object { + account_name owner; //< owner should not be changed within a chainbase modifier lambda + + resource_limits::usage_accumulator net_usage; + resource_limits::usage_accumulator cpu_usage; + uint64_t ram_usage = 0; + }; + + void deep_mind_handler::on_newaccount_resource_limits(const resource_limits::resource_object& obj) + { + resource_limits_object limits{ + .owner = obj.owner, + .net_weight = obj.net_weight, + .cpu_weight = obj.cpu_weight, + .ram_bytes = obj.ram_bytes, + }; fc_dlog(_logger, "RLIMIT_OP ACCOUNT_LIMITS INS ${data}", ("data", limits) ); + resource_usage_object usage{ + .owner = obj.owner, + .net_usage = obj.net_usage, + .cpu_usage = obj.cpu_usage, + .ram_usage = obj.ram_usage, + }; fc_dlog(_logger, "RLIMIT_OP ACCOUNT_USAGE INS ${data}", ("data", usage) ); } - void deep_mind_handler::on_update_account_usage(const resource_limits::resource_usage_object& usage) + void deep_mind_handler::on_update_account_usage(const resource_limits::resource_object& obj) { + resource_usage_object usage{ + .owner = obj.owner, + .net_usage = obj.net_usage, + .cpu_usage = obj.cpu_usage, + .ram_usage = obj.ram_usage, + }; fc_dlog(_logger, "RLIMIT_OP ACCOUNT_USAGE UPD ${data}", ("data", usage) ); } - void deep_mind_handler::on_set_account_limits(const resource_limits::resource_limits_object& limits) + void deep_mind_handler::on_set_account_limits(const resource_limits::resource_pending_object& limits) { fc_dlog(_logger, "RLIMIT_OP ACCOUNT_LIMITS UPD ${data}", ("data", limits) @@ -311,3 +346,6 @@ namespace sysio::chain { } } + +FC_REFLECT(sysio::chain::resource_limits_object, (owner)(net_weight)(cpu_weight)(ram_bytes)); +FC_REFLECT(sysio::chain::resource_usage_object, (owner)(net_usage)(cpu_usage)(ram_usage)); diff --git a/libraries/chain/include/sysio/chain/deep_mind.hpp b/libraries/chain/include/sysio/chain/deep_mind.hpp index 73893f6ce8..3323d7f142 100644 --- a/libraries/chain/include/sysio/chain/deep_mind.hpp +++ b/libraries/chain/include/sysio/chain/deep_mind.hpp @@ -19,8 +19,8 @@ struct ram_trace; namespace resource_limits { class resource_limits_config_object; class resource_limits_state_object; - struct resource_limits_object; - struct resource_usage_object; + struct resource_object; + struct resource_pending_object; } #define RAM_EVENT_ID( FORMAT, ... ) \ @@ -76,9 +76,9 @@ class deep_mind_handler void on_init_resource_limits(const resource_limits::resource_limits_config_object& config, const resource_limits::resource_limits_state_object& state); void on_update_resource_limits_config(const resource_limits::resource_limits_config_object& config); void on_update_resource_limits_state(const resource_limits::resource_limits_state_object& state); - void on_newaccount_resource_limits(const resource_limits::resource_limits_object& limits, const resource_limits::resource_usage_object& usage); - void on_update_account_usage(const resource_limits::resource_usage_object& usage); - void on_set_account_limits(const resource_limits::resource_limits_object& limits); + void on_newaccount_resource_limits(const resource_limits::resource_object& limits); + void on_update_account_usage(const resource_limits::resource_object& usage); + void on_set_account_limits(const resource_limits::resource_pending_object& limits); // The trace is consumed by the next ram_event or ram_correction void on_ram_trace(std::string&& event_id, const char* family, const char* operation, const char* legacy_tag); void on_ram_event(account_name account, uint64_t new_usage, int64_t delta); diff --git a/libraries/chain/include/sysio/chain/resource_limits_private.hpp b/libraries/chain/include/sysio/chain/resource_limits_private.hpp index f8bc0a55c0..55d196b171 100644 --- a/libraries/chain/include/sysio/chain/resource_limits_private.hpp +++ b/libraries/chain/include/sysio/chain/resource_limits_private.hpp @@ -190,57 +190,47 @@ namespace sysio { namespace chain { namespace resource_limits { using usage_accumulator = impl::exponential_moving_average_accumulator<>; - /** - * Every account that authorizes a transaction is billed for the full size of that transaction. This object - * tracks the average usage of that account. - */ - struct resource_limits_object : public chainbase::object { - - OBJECT_CTOR(resource_limits_object) + struct resource_object : public chainbase::object { + OBJECT_CTOR(resource_object) id_type id; account_name owner; //< owner should not be changed within a chainbase modifier lambda - bool pending = false; //< pending should not be changed within a chainbase modifier lambda int64_t net_weight = -1; int64_t cpu_weight = -1; int64_t ram_bytes = -1; + usage_accumulator net_usage; + usage_accumulator cpu_usage; + uint64_t ram_usage = 0; }; struct by_owner; - struct by_dirty; - using resource_limits_index = chainbase::shared_multi_index_container< - resource_limits_object, + using resource_index = chainbase::shared_multi_index_container< + resource_object, indexed_by< - ordered_unique, member>, - ordered_unique, - composite_key - > + ordered_unique, member>, + ordered_unique, member > > >; - struct resource_usage_object : public chainbase::object { - OBJECT_CTOR(resource_usage_object) + struct resource_pending_object : public chainbase::object { + OBJECT_CTOR(resource_pending_object) id_type id; account_name owner; //< owner should not be changed within a chainbase modifier lambda - usage_accumulator net_usage; - usage_accumulator cpu_usage; - - uint64_t ram_usage = 0; + int64_t net_weight = -1; + int64_t cpu_weight = -1; + int64_t ram_bytes = -1; }; - using resource_usage_index = chainbase::shared_multi_index_container< - resource_usage_object, + using resource_pending_index = chainbase::shared_multi_index_container< + resource_pending_object, indexed_by< - ordered_unique, member>, - ordered_unique, member > + ordered_unique, member>, + ordered_unique, member > > >; @@ -326,15 +316,15 @@ namespace sysio { namespace chain { namespace resource_limits { } } } /// sysio::chain::resource_limits -CHAINBASE_SET_INDEX_TYPE(sysio::chain::resource_limits::resource_limits_object, sysio::chain::resource_limits::resource_limits_index) -CHAINBASE_SET_INDEX_TYPE(sysio::chain::resource_limits::resource_usage_object, sysio::chain::resource_limits::resource_usage_index) +CHAINBASE_SET_INDEX_TYPE(sysio::chain::resource_limits::resource_object, sysio::chain::resource_limits::resource_index) +CHAINBASE_SET_INDEX_TYPE(sysio::chain::resource_limits::resource_pending_object, sysio::chain::resource_limits::resource_pending_index) CHAINBASE_SET_INDEX_TYPE(sysio::chain::resource_limits::resource_limits_config_object, sysio::chain::resource_limits::resource_limits_config_index) CHAINBASE_SET_INDEX_TYPE(sysio::chain::resource_limits::resource_limits_state_object, sysio::chain::resource_limits::resource_limits_state_index) FC_REFLECT(sysio::chain::resource_limits::usage_accumulator, (last_ordinal)(value_ex)(consumed)) // @ignore pending -FC_REFLECT(sysio::chain::resource_limits::resource_limits_object, (owner)(net_weight)(cpu_weight)(ram_bytes)) -FC_REFLECT(sysio::chain::resource_limits::resource_usage_object, (owner)(net_usage)(cpu_usage)(ram_usage)) +FC_REFLECT(sysio::chain::resource_limits::resource_object, (owner)(net_weight)(cpu_weight)(ram_bytes)(net_usage)(cpu_usage)(ram_usage)) +FC_REFLECT(sysio::chain::resource_limits::resource_pending_object, (owner)(net_weight)(cpu_weight)(ram_bytes)) FC_REFLECT(sysio::chain::resource_limits::resource_limits_config_object, (cpu_limit_parameters)(net_limit_parameters)(account_cpu_usage_average_window)(account_net_usage_average_window)) FC_REFLECT(sysio::chain::resource_limits::resource_limits_state_object, (average_block_net_usage)(average_block_cpu_usage)(pending_net_usage)(pending_cpu_usage)(total_net_weight)(total_cpu_weight)(total_ram_bytes)(virtual_net_limit)(virtual_cpu_limit)) diff --git a/libraries/chain/include/sysio/chain/types.hpp b/libraries/chain/include/sysio/chain/types.hpp index 509c845207..061ec9d1fe 100644 --- a/libraries/chain/include/sysio/chain/types.hpp +++ b/libraries/chain/include/sysio/chain/types.hpp @@ -165,8 +165,8 @@ namespace sysio::chain { UNUSED_proxy_vote_object_type, UNUSED_scope_sequence_object_type, table_id_object_type, - resource_limits_object_type, - resource_usage_object_type, + resource_object_type, + resource_pending_object_type, resource_limits_state_object_type, resource_limits_config_object_type, account_history_object_type, ///< Defined by history_plugin diff --git a/libraries/chain/resource_limits.cpp b/libraries/chain/resource_limits.cpp index 5cc868e761..28574db3a1 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -12,8 +12,8 @@ namespace sysio { namespace chain { namespace resource_limits { using resource_index_set = index_set< - resource_limits_index, - resource_usage_index, + resource_index, + resource_pending_index, resource_limits_state_index, resource_limits_config_index >; @@ -96,15 +96,12 @@ void resource_limits_manager::read_from_snapshot( const snapshot_reader_ptr& sna } void resource_limits_manager::initialize_account(const account_name& account, bool is_trx_transient) { - const auto& limits = _db.create([&]( resource_limits_object& bl ) { + const auto& usage = _db.create([&]( resource_object& bl ) { bl.owner = account; }); - const auto& usage = _db.create([&]( resource_usage_object& bu ) { - bu.owner = account; - }); if (auto dm_logger = _get_deep_mind_logger(is_trx_transient)) { - dm_logger->on_newaccount_resource_limits(limits, usage); + dm_logger->on_newaccount_resource_limits(usage); } } @@ -129,7 +126,7 @@ void resource_limits_manager::set_block_parameters(const elastic_limit_parameter void resource_limits_manager::update_account_usage(const accounts_billing_t& accounts, uint32_t time_slot ) { const auto& config = _db.get(); for(const auto& a: accounts | std::views::keys) { - const auto& usage = _db.get( a ); + const auto& usage = _db.get( a ); _db.modify( usage, [&]( auto& bu ){ bu.net_usage.add( 0, time_slot, config.account_net_usage_average_window ); bu.cpu_usage.add( 0, time_slot, config.account_cpu_usage_average_window ); @@ -143,7 +140,7 @@ void resource_limits_manager::add_transaction_usage(const accounts_billing_t& ac for( const auto& [a, billing] : accounts ) { - const auto& usage = _db.get( a ); + const auto& usage = _db.get( a ); int64_t unused; int64_t net_weight; int64_t cpu_weight; @@ -215,7 +212,7 @@ void resource_limits_manager::add_pending_ram_usage( const account_name account, } // wlog("Adding pending RAM usage of ${ram_delta} to account ${account}", ("ram_delta", ram_delta)("account", account)); - const auto& usage = _db.get( account ); + const auto& usage = _db.get( account ); SYS_ASSERT( ram_delta <= 0 || UINT64_MAX - usage.ram_usage >= (uint64_t)ram_delta, transaction_exception, "Ram usage delta would overflow UINT64_MAX"); @@ -234,7 +231,7 @@ void resource_limits_manager::add_pending_ram_usage( const account_name account, void resource_limits_manager::verify_account_ram_usage( const account_name account )const { int64_t ram_bytes; int64_t net_weight; int64_t cpu_weight; get_account_limits( account, ram_bytes, net_weight, cpu_weight ); - const auto& usage = _db.get( account ); + const auto& usage = _db.get( account ); if( ram_bytes >= 0 ) { SYS_ASSERT( usage.ram_usage <= static_cast(ram_bytes), ram_usage_exceeded, @@ -244,26 +241,24 @@ void resource_limits_manager::verify_account_ram_usage( const account_name accou } int64_t resource_limits_manager::get_account_ram_usage( const account_name& name )const { - return _db.get( name ).ram_usage; + return _db.get( name ).ram_usage; } bool resource_limits_manager::set_account_limits( const account_name& account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight, bool is_trx_transient) { - //const auto& usage = _db.get( account ); /* - * Since we need to delay these until the next resource limiting boundary, these are created in a "pending" - * state or adjusted in an existing "pending" state. The chain controller will collapse "pending" state into + * Since we need to delay these until the next resource limiting boundary, these are created in a "pending" object + * or adjusted in an existing "pending" object. The chain controller will collapse "pending" objects into * the actual state at the next appropriate boundary. */ - auto find_or_create_pending_limits = [&]() -> const resource_limits_object& { - const auto* pending_limits = _db.find( boost::make_tuple(true, account) ); + auto find_or_create_pending_limits = [&]() -> const resource_pending_object& { + const auto* pending_limits = _db.find( account ); if (pending_limits == nullptr) { - const auto& limits = _db.get( boost::make_tuple(false, account)); - return _db.create([&](resource_limits_object& pending_limits){ + const auto& limits = _db.get( account ); + return _db.create([&](resource_pending_object& pending_limits){ pending_limits.owner = limits.owner; pending_limits.ram_bytes = limits.ram_bytes; pending_limits.net_weight = limits.net_weight; pending_limits.cpu_weight = limits.cpu_weight; - pending_limits.pending = true; }); } else { return *pending_limits; @@ -288,7 +283,7 @@ bool resource_limits_manager::set_account_limits( const account_name& account, i */ } - _db.modify( limits, [&]( resource_limits_object& pending_limits ){ + _db.modify( limits, [&]( resource_pending_object& pending_limits ){ pending_limits.ram_bytes = ram_bytes; pending_limits.net_weight = net_weight; pending_limits.cpu_weight = cpu_weight; @@ -302,13 +297,13 @@ bool resource_limits_manager::set_account_limits( const account_name& account, i } void resource_limits_manager::get_account_limits( const account_name& account, int64_t& ram_bytes, int64_t& net_weight, int64_t& cpu_weight ) const { - const auto* pending_buo = _db.find( boost::make_tuple(true, account) ); + const auto* pending_buo = _db.find( account ); if (pending_buo) { ram_bytes = pending_buo->ram_bytes; net_weight = pending_buo->net_weight; cpu_weight = pending_buo->cpu_weight; } else { - const auto& buo = _db.get( boost::make_tuple( false, account ) ); + const auto& buo = _db.get( account ); ram_bytes = buo.ram_bytes; net_weight = buo.net_weight; cpu_weight = buo.cpu_weight; @@ -316,7 +311,7 @@ void resource_limits_manager::get_account_limits( const account_name& account, i } bool resource_limits_manager::is_unlimited_cpu( const account_name& account ) const { - const auto* buo = _db.find( boost::make_tuple(false, account) ); + const auto* buo = _db.find( account ); if (buo) { return buo->cpu_weight == -1; } @@ -324,7 +319,7 @@ bool resource_limits_manager::is_unlimited_cpu( const account_name& account ) co } void resource_limits_manager::process_account_limit_updates() { - auto& multi_index = _db.get_mutable_index(); + auto& multi_index = _db.get_mutable_index(); auto& by_owner_index = multi_index.indices().get(); // convenience local lambda to reduce clutter @@ -345,13 +340,10 @@ void resource_limits_manager::process_account_limit_updates() { const auto& state = _db.get(); _db.modify(state, [&](resource_limits_state_object& rso){ while(!by_owner_index.empty()) { - const auto& itr = by_owner_index.lower_bound(boost::make_tuple(true)); - if (itr == by_owner_index.end() || itr->pending!= true) { - break; - } + const auto& itr = by_owner_index.begin(); - const auto& actual_entry = _db.get(boost::make_tuple(false, itr->owner)); - _db.modify(actual_entry, [&](resource_limits_object& rlo){ + const auto& actual_entry = _db.get(itr->owner); + _db.modify(actual_entry, [&](resource_object& rlo){ update_state_and_value(rso.total_ram_bytes, rlo.ram_bytes, itr->ram_bytes, "ram_bytes"); update_state_and_value(rso.total_cpu_weight, rlo.cpu_weight, itr->cpu_weight, "cpu_weight"); update_state_and_value(rso.total_net_weight, rlo.net_weight, itr->net_weight, "net_weight"); @@ -432,7 +424,7 @@ std::pair resource_limits_manager::get_account_cpu_limit_ex( const account_name& name, uint32_t greylist_limit, const std::optional& current_time) const { const auto& state = _db.get(); - const auto& usage = _db.get(name); + const auto& usage = _db.get(name); const auto& config = _db.get(); int64_t cpu_weight, x, y; @@ -494,7 +486,7 @@ std::pair resource_limits_manager::get_account_net_limit_ex( const account_name& name, uint32_t greylist_limit, const std::optional& current_time) const { const auto& config = _db.get(); const auto& state = _db.get(); - const auto& usage = _db.get(name); + const auto& usage = _db.get(name); int64_t net_weight, x, y; get_account_limits( name, x, net_weight, y ); diff --git a/libraries/state_history/create_deltas.cpp b/libraries/state_history/create_deltas.cpp index f8f7279898..2b8e495709 100644 --- a/libraries/state_history/create_deltas.cpp +++ b/libraries/state_history/create_deltas.cpp @@ -13,14 +13,6 @@ bool include_delta(const chain::table_id_object& old, const chain::table_id_obje return old.payer != curr.payer; } -bool include_delta(const chain::resource_limits::resource_limits_object& old, - const chain::resource_limits::resource_limits_object& curr) { - return // - old.net_weight != curr.net_weight || // - old.cpu_weight != curr.cpu_weight || // - old.ram_bytes != curr.ram_bytes; -} - bool include_delta(const chain::resource_limits::resource_limits_state_object& old, const chain::resource_limits::resource_limits_state_object& curr) { return // @@ -151,7 +143,7 @@ void pack_deltas(boost::iostreams::filtering_ostreambuf& obuf, const chainbase:: chain::index256_index*, chain::index_double_index*, chain::index_long_double_index*, chain::global_property_multi_index*, chain::protocol_state_multi_index*, chain::permission_index*, chain::permission_link_index*, - chain::resource_limits::resource_limits_index*, chain::resource_limits::resource_usage_index*, + chain::resource_limits::resource_index*, chain::resource_limits::resource_limits_state_index*, chain::resource_limits::resource_limits_config_index*>()); @@ -175,8 +167,10 @@ void pack_deltas(boost::iostreams::filtering_ostreambuf& obuf, const chainbase:: process_table(ds, "permission", db.get_index(), pack_row); process_table(ds, "permission_link", db.get_index(), pack_row); - process_table(ds, "resource_limits", db.get_index(), pack_row); - process_table(ds, "resource_usage", db.get_index(), pack_row); + auto pack_resource_limit_row = [&](auto& ds, auto& row) { fc::raw::pack(ds, make_history_serial_wrapper(db, row, history_serial_wrapper_enum_t::resource_limits)); }; + process_table(ds, "resource_limits", db.get_index(), pack_resource_limit_row); + auto pack_resource_usage_row = [&](auto& ds, auto& row) { fc::raw::pack(ds, make_history_serial_wrapper(db, row, history_serial_wrapper_enum_t::resource_usage)); }; + process_table(ds, "resource_usage", db.get_index(), pack_resource_usage_row); process_table(ds, "resource_limits_state", db.get_index(), pack_row); process_table(ds, "resource_limits_config", db.get_index(), diff --git a/libraries/state_history/include/sysio/state_history/serialization.hpp b/libraries/state_history/include/sysio/state_history/serialization.hpp index 5b8ef6e43b..440e3ee061 100644 --- a/libraries/state_history/include/sysio/state_history/serialization.hpp +++ b/libraries/state_history/include/sysio/state_history/serialization.hpp @@ -15,6 +15,12 @@ #include +enum class history_serial_wrapper_enum_t { + none, + resource_limits, + resource_usage +}; + template struct history_serial_wrapper_stateless { const T& obj; @@ -22,6 +28,7 @@ struct history_serial_wrapper_stateless { template struct history_serial_wrapper : public history_serial_wrapper_stateless { + history_serial_wrapper_enum_t type = history_serial_wrapper_enum_t::none; const chainbase::database& db; }; @@ -31,8 +38,9 @@ history_serial_wrapper_stateless> make_history_serial_wrapper(co } template -history_serial_wrapper> make_history_serial_wrapper(const chainbase::database& db, const T& obj) { - return {{obj}, db}; +history_serial_wrapper> make_history_serial_wrapper(const chainbase::database& db, const T& obj, + history_serial_wrapper_enum_t type = history_serial_wrapper_enum_t::none) { + return {{obj}, type, db}; } template @@ -473,14 +481,22 @@ datastream& operator<<(datastream& ds, const history_serial_wrapper_stat } template -datastream& operator<<(datastream& ds, const history_serial_wrapper_stateless& obj) { - SYS_ASSERT(!obj.obj.pending, sysio::chain::plugin_exception, - "accepted_block sent while resource_limits_object in pending state"); - fc::raw::pack(ds, fc::unsigned_int(0)); - fc::raw::pack(ds, as_type(obj.obj.owner.to_uint64_t())); - fc::raw::pack(ds, as_type(obj.obj.net_weight)); - fc::raw::pack(ds, as_type(obj.obj.cpu_weight)); - fc::raw::pack(ds, as_type(obj.obj.ram_bytes)); +datastream& operator<<(datastream& ds, const history_serial_wrapper& obj) { + if (obj.type == history_serial_wrapper_enum_t::resource_limits) { + fc::raw::pack(ds, fc::unsigned_int(0)); + fc::raw::pack(ds, as_type(obj.obj.owner.to_uint64_t())); + fc::raw::pack(ds, as_type(obj.obj.net_weight)); + fc::raw::pack(ds, as_type(obj.obj.cpu_weight)); + fc::raw::pack(ds, as_type(obj.obj.ram_bytes)); + } else if (obj.type == history_serial_wrapper_enum_t::resource_usage) { + fc::raw::pack(ds, fc::unsigned_int(0)); + fc::raw::pack(ds, as_type(obj.obj.owner.to_uint64_t())); + fc::raw::pack(ds, make_history_serial_wrapper(as_type(obj.obj.net_usage))); + fc::raw::pack(ds, make_history_serial_wrapper(as_type(obj.obj.cpu_usage))); + fc::raw::pack(ds, as_type(obj.obj.ram_usage)); + } else { + SYS_ASSERT(false, sysio::chain::plugin_exception, "Unexpected type in history_serial_wrapper"); + } return ds; } @@ -493,16 +509,6 @@ datastream& operator<<(datastream& ds, const history_serial_wrapper_stat return ds; } -template -datastream& operator<<(datastream& ds, const history_serial_wrapper& obj) { - fc::raw::pack(ds, fc::unsigned_int(0)); - fc::raw::pack(ds, as_type(obj.obj.owner.to_uint64_t())); - fc::raw::pack(ds, make_history_serial_wrapper(as_type(obj.obj.net_usage))); - fc::raw::pack(ds, make_history_serial_wrapper(as_type(obj.obj.cpu_usage))); - fc::raw::pack(ds, as_type(obj.obj.ram_usage)); - return ds; -} - template datastream& operator<<(datastream& ds, const history_serial_wrapper& obj) { fc::raw::pack(ds, fc::unsigned_int(0)); diff --git a/unittests/auth_tests.cpp b/unittests/auth_tests.cpp index cfef64443f..ece4690eb0 100644 --- a/unittests/auth_tests.cpp +++ b/unittests/auth_tests.cpp @@ -440,7 +440,7 @@ try { const chainbase::database &db = chain.control->db(); - using resource_usage_object = sysio::chain::resource_limits::resource_usage_object; + using resource_object = sysio::chain::resource_limits::resource_object; using by_owner = sysio::chain::resource_limits::by_owner; auto create_acc = [&](account_name a) { @@ -472,9 +472,9 @@ try { create_acc(acc2); - const auto &usage = db.get(acc1); + const auto &usage = db.get(acc1); - const auto &usage2 = db.get(acc1a); + const auto &usage2 = db.get(acc1a); BOOST_TEST(usage.cpu_usage.average() > 0U); BOOST_TEST(usage.net_usage.average() > 0U); diff --git a/unittests/snapshots/snap_v6.bin.gz b/unittests/snapshots/snap_v6.bin.gz index 8fac3be139..fe7d31a8b9 100644 Binary files a/unittests/snapshots/snap_v6.bin.gz and b/unittests/snapshots/snap_v6.bin.gz differ diff --git a/unittests/snapshots/snap_v6.bin.json.gz b/unittests/snapshots/snap_v6.bin.json.gz index 7a37ecccb0..503e1deb67 100644 Binary files a/unittests/snapshots/snap_v6.bin.json.gz and b/unittests/snapshots/snap_v6.bin.json.gz differ diff --git a/unittests/snapshots/snap_v6.json.gz b/unittests/snapshots/snap_v6.json.gz index 024ddae1ab..ac8461e385 100644 Binary files a/unittests/snapshots/snap_v6.json.gz and b/unittests/snapshots/snap_v6.json.gz differ diff --git a/unittests/state_history_tests.cpp b/unittests/state_history_tests.cpp index 2c9d2b1d7c..5a0a00ed76 100644 --- a/unittests/state_history_tests.cpp +++ b/unittests/state_history_tests.cpp @@ -85,7 +85,7 @@ class table_deltas_tester : public tester { } template - vector deserialize_data(deltas_vector::iterator &it) { + static vector deserialize_data(deltas_vector::iterator &it) { vector result; for(size_t i=0; i < it->rows.obj.size(); i++) { sysio::input_stream stream{it->rows.obj[i].second.data(), it->rows.obj[i].second.size()}; @@ -410,7 +410,10 @@ BOOST_AUTO_TEST_CASE(test_deltas_contract) { name="resource_limits"; it = std::find_if(v.begin(), v.end(), find_by_name); - BOOST_REQUIRE(it==v.end()); + BOOST_REQUIRE(it!=v.end()); // updated by onblock in start_block + BOOST_REQUIRE_EQUAL(it->rows.obj.size(), 1u); + auto resources = table_deltas_tester::deserialize_data(it); + BOOST_REQUIRE_EQUAL(resources[0].owner.to_string(), config::system_account_name.to_string()); main.create_account("newacc"_n, config::system_account_name, false, false, false, false); @@ -423,6 +426,10 @@ BOOST_AUTO_TEST_CASE(test_deltas_contract) { name="resource_limits"; it = std::find_if(v.begin(), v.end(), find_by_name); BOOST_REQUIRE(it!=v.end()); + BOOST_REQUIRE_EQUAL(it->rows.obj.size(), 2u); + resources = table_deltas_tester::deserialize_data(it); + BOOST_REQUIRE_EQUAL(resources[0].owner.to_string(), config::system_account_name.to_string()); + BOOST_REQUIRE_EQUAL(resources[1].owner.to_string(), "newacc"); main.produce_block(); @@ -434,7 +441,7 @@ BOOST_AUTO_TEST_CASE(test_deltas_contract) { name="resource_limits"; it = std::find_if(v.begin(), v.end(), find_by_name); - BOOST_REQUIRE(it==v.end()); + BOOST_REQUIRE(it!=v.end()); // updated by onblock in start_block } BOOST_AUTO_TEST_CASE(test_deltas_contract_several_rows){