Skip to content

Commit

Permalink
state: Optimize state access thanks to the journal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chfast committed Dec 13, 2023
1 parent c5e7dd2 commit f79e71b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions test/state/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ std::variant<TransactionReceipt, std::error_code> 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.
Expand Down

0 comments on commit f79e71b

Please sign in to comment.