Skip to content

Commit d790b1c

Browse files
committed
remove mutable accessor to state
1 parent bb42317 commit d790b1c

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

category/execution/ethereum/state2/block_state.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ vm::SharedVarcode BlockState::read_code(bytes32_t const &code_hash)
151151
bool BlockState::can_merge(State &state) const
152152
{
153153
MONAD_ASSERT(state_);
154-
auto &original = state.original();
154+
auto const &original = state.original();
155155
for (auto &kv : original) {
156156
Address const &address = kv.first;
157-
OriginalAccountState &account_state = kv.second;
157+
OriginalAccountState const &account_state = kv.second;
158158
auto const &account = account_state.account_;
159159
auto const &storage = account_state.storage_;
160160
StateDeltas::const_accessor it{};
@@ -164,7 +164,7 @@ bool BlockState::can_merge(State &state) const
164164
// try to fix original and current in `state` to match the block
165165
// state up until this transaction
166166
if (!state.try_fix_account_mismatch(
167-
address, account_state, it->second.account.second)) {
167+
address, it->second.account.second)) {
168168
return false;
169169
}
170170
}

category/execution/ethereum/state3/state.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ State::Map<Address, OriginalAccountState> const &State::original() const
108108
return original_;
109109
}
110110

111-
State::Map<Address, OriginalAccountState> &State::original()
112-
{
113-
return original_;
114-
}
115-
116111
State::Map<Address, VersionStack<AccountState>> const &State::current() const
117112
{
118113
return current_;
@@ -622,9 +617,11 @@ void State::set_to_state_incarnation(Address const &address)
622617
// if original and current can be adjusted to satisfy min balance, adjust
623618
// both values for merge
624619
bool State::try_fix_account_mismatch(
625-
Address const &address, OriginalAccountState &original_state,
626-
std::optional<Account> const &actual)
620+
Address const &address, std::optional<Account> const &actual)
627621
{
622+
auto const original_it = original_.find(address);
623+
MONAD_ASSERT(original_it != original_.end());
624+
OriginalAccountState &original_state = original_it->second;
628625
auto &original = original_state.account_;
629626
// verify original used and original found are otherwise the same
630627
if (is_dead(original)) {
@@ -655,10 +652,10 @@ bool State::try_fix_account_mismatch(
655652
return false;
656653
}
657654
// adjust balances
658-
auto it = current_.find(address);
659-
if (it != current_.end()) {
660-
MONAD_ASSERT(it->second.size() == 1);
661-
auto &recent_state = it->second.recent();
655+
auto const current_it = current_.find(address);
656+
if (current_it != current_.end()) {
657+
MONAD_ASSERT(current_it->second.size() == 1);
658+
auto &recent_state = current_it->second.recent();
662659
auto &recent = recent_state.account_;
663660
if (!recent) {
664661
return false;

category/execution/ethereum/state3/state.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class State
8989

9090
Map<Address, OriginalAccountState> const &original() const;
9191

92-
Map<Address, OriginalAccountState> &original();
93-
9492
Map<Address, VersionStack<AccountState>> const &current() const;
9593

9694
Map<bytes32_t, vm::SharedVarcode> const &code() const;
@@ -208,8 +206,7 @@ class State
208206
// if original and current can be adjusted to satisfy min balance, adjust
209207
// both values for merge
210208
bool try_fix_account_mismatch(
211-
Address const &, OriginalAccountState &,
212-
std::optional<Account> const &actual);
209+
Address const &, std::optional<Account> const &actual);
213210

214211
/**
215212
* Checks whether the account currently has enough balance to cover `debit`

0 commit comments

Comments
 (0)