From f79e71bcc9289c8f1b5644b8f71a14b37a480287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 15 Sep 2022 18:41:13 +0200 Subject: [PATCH] state: Optimize state access thanks to the journal With the State Journal the backup copy of the state is no longer performed and the memory addresses of the accounts are not changing during execution. This allows us to avoid some copies and lookups. --- test/state/host.cpp | 3 +-- test/state/state.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/state/host.cpp b/test/state/host.cpp index 5e4f405275..31f662df50 100644 --- a/test/state/host.cpp +++ b/test/state/host.cpp @@ -315,8 +315,7 @@ evmc::Result Host::execute_message(const evmc_message& msg) noexcept if (is_precompile(m_rev, msg.code_address)) return call_precompile(m_rev, msg); - // Copy of the code. Revert will invalidate the account. - const auto code = dst_acc != nullptr ? dst_acc->code : bytes{}; + const auto code = dst_acc != nullptr ? bytes_view{dst_acc->code} : bytes_view{}; return m_vm.execute(*this, m_rev, msg, code.data(), code.size()); } diff --git a/test/state/state.cpp b/test/state/state.cpp index 3eaaf7aa0f..0d5043de7a 100644 --- a/test/state/state.cpp +++ b/test/state/state.cpp @@ -393,7 +393,7 @@ std::variant transition(State& state, const gas_used -= refund; assert(gas_used > 0); - state.get(tx.sender).balance += tx_max_cost - gas_used * effective_gas_price; + sender_acc.balance += tx_max_cost - gas_used * effective_gas_price; state.touch(block.coinbase).balance += gas_used * priority_gas_price; // Apply destructs.