Skip to content

Commit 57cea41

Browse files
kkuehlzjhunsaker
authored andcommitted
Only iterate over dirtied accounts in pop_accept/pop_reject
1 parent ca1fcda commit 57cea41

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

category/execution/ethereum/state3/state.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ AccountState &State::current_account_state(Address const &address)
8383
auto const &account_state = original_account_state(address);
8484
it = current_.try_emplace(address, account_state, version_).first;
8585
}
86+
if (!dirty_.empty()) {
87+
dirty_.back().emplace(address);
88+
}
8689
return it->second.current(version_);
8790
}
8891

@@ -122,15 +125,26 @@ State::Map<bytes32_t, vm::SharedVarcode> const &State::code() const
122125

123126
void State::push()
124127
{
128+
MONAD_ASSERT(dirty_.size() == version_);
129+
125130
++version_;
131+
dirty_.emplace_back();
126132
}
127133

128134
void State::pop_accept()
129135
{
130136
MONAD_ASSERT(version_);
131-
132-
for (auto &it : current_) {
133-
it.second.pop_accept(version_);
137+
MONAD_ASSERT(dirty_.size() == version_);
138+
139+
auto accounts = std::move(dirty_.back());
140+
dirty_.pop_back();
141+
for (auto const &dirty_address : accounts) {
142+
auto const it = current_.find(dirty_address);
143+
MONAD_ASSERT(it != current_.end());
144+
it->second.pop_accept(version_);
145+
if (!dirty_.empty()) {
146+
dirty_.back().emplace(dirty_address);
147+
}
134148
}
135149

136150
logs_.pop_accept(version_);
@@ -141,12 +155,16 @@ void State::pop_accept()
141155
void State::pop_reject()
142156
{
143157
MONAD_ASSERT(version_);
158+
MONAD_ASSERT(dirty_.size() == version_);
144159

145160
std::vector<Address> removals;
146-
147-
for (auto &it : current_) {
148-
if (it.second.pop_reject(version_)) {
149-
removals.push_back(it.first);
161+
auto accounts = std::move(dirty_.back());
162+
dirty_.pop_back();
163+
for (auto const &dirty_address : accounts) {
164+
auto const it = current_.find(dirty_address);
165+
MONAD_ASSERT(it != current_.end());
166+
if (it->second.pop_reject(version_)) {
167+
removals.push_back(it->first);
150168
}
151169
}
152170

category/execution/ethereum/state3/state.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <cstddef>
3535
#include <cstdint>
36+
#include <deque>
3637
#include <optional>
3738
#include <vector>
3839

@@ -45,6 +46,9 @@ class State
4546
template <typename K, typename V>
4647
using Map = ankerl::unordered_dense::segmented_map<K, V>;
4748

49+
template <typename K>
50+
using Set = ankerl::unordered_dense::segmented_set<K>;
51+
4852
BlockState &block_state_;
4953

5054
Incarnation const incarnation_;
@@ -59,6 +63,8 @@ class State
5963

6064
unsigned version_{0};
6165

66+
std::deque<Set<Address>> dirty_;
67+
6268
bool const relaxed_validation_{false};
6369

6470
public:

0 commit comments

Comments
 (0)