@@ -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
123126void State::push ()
124127{
128+ MONAD_ASSERT (dirty_.size () == version_);
129+
125130 ++version_;
131+ dirty_.emplace_back ();
126132}
127133
128134void 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()
141155void 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
0 commit comments