Skip to content

Commit

Permalink
state: Simplify code modification indicator in StateDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast authored and gumb0 committed Jan 27, 2025
1 parent fabb2f0 commit ba4cfb9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
3 changes: 1 addition & 2 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ StateDiff State::build_diff(evmc_revision rev) const

// Output only the new code.
// TODO: Output also the code hash. It will be needed for DB update and MPT hash.
// TODO: Only use "code_changed" flag to indicate the code change.
if ((m.just_created && !m.code.empty()) || m.code_changed)
a.code = m.code;
if (m.code_changed && m.code.empty())
a.code_cleared = true;

for (const auto& [k, v] : m.storage)
{
Expand Down
7 changes: 2 additions & 5 deletions test/state/state_diff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ struct StateDiff
/// TODO: Currently it is not guaranteed the value is different from the initial one.
uint256 balance;

/// New account code. If empty, it means the code has not changed.
bytes code;

/// If true, account code was emptied due to resetting EIP-7702 delegation.
bool code_cleared = false;
/// New or modified account code. If bytes are empty, it means the code has been cleared.
std::optional<bytes> code;

/// The list of the account's storage modifications: key => new value.
/// The value 0 means the storage entry is deleted.
Expand Down
6 changes: 2 additions & 4 deletions test/state/test_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ void TestState::apply(const state::StateDiff& diff)
auto& a = (*this)[m.addr];
a.nonce = m.nonce;
a.balance = m.balance;
if (!m.code.empty())
a.code = m.code; // TODO: Consider taking rvalue ref to avoid code copy.
if (m.code_cleared)
a.code.clear();
if (m.code.has_value())
a.code = *m.code; // TODO: Consider taking rvalue ref to avoid code copy.
for (const auto& [k, v] : m.modified_storage)
{
if (v)
Expand Down

0 comments on commit ba4cfb9

Please sign in to comment.