diff --git a/libethereum/Account.cpp b/libethereum/Account.cpp index ba2b6af615d..1753891220e 100644 --- a/libethereum/Account.cpp +++ b/libethereum/Account.cpp @@ -41,6 +41,13 @@ void Account::setCode(bytes&& _code) m_codeHash = sha3(m_codeCache); } +void Account::resetCode() +{ + m_codeCache.clear(); + m_hasNewCode = false; + m_codeHash = EmptySHA3; +} + u256 Account::originalStorageValue(u256 const& _key, OverlayDB const& _db) const { auto it = m_storageOriginal.find(_key); diff --git a/libethereum/Account.h b/libethereum/Account.h index 1628a81c0e0..9c154df3fc2 100644 --- a/libethereum/Account.h +++ b/libethereum/Account.h @@ -173,6 +173,9 @@ class Account /// Sets the code of the account. Used by "create" messages. void setCode(bytes&& _code); + /// Reset the code set by previous setCode + void resetCode(); + /// Specify to the object what the actual code is for the account. @a _code must have a SHA3 /// equal to codeHash(). void noteCode(bytesConstRef _code) { assert(sha3(_code) == m_codeHash); m_codeCache = _code.toBytes(); } diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 660e1cacdb7..f8d4664bc47 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -518,7 +518,7 @@ bytes const& State::code(Address const& _addr) const void State::setCode(Address const& _address, bytes&& _code) { - m_changeLog.emplace_back(_address, code(_address)); + m_changeLog.emplace_back(Change::Code, _address); m_cache[_address].setCode(std::move(_code)); } @@ -583,7 +583,7 @@ void State::rollback(size_t _savepoint) m_cache.erase(change.address); break; case Change::Code: - account.setCode(std::move(change.oldCode)); + account.resetCode(); break; case Change::Touch: account.untouch(); diff --git a/libethereum/State.h b/libethereum/State.h index 671a2af04fa..964be6d357f 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -116,13 +116,11 @@ struct Change Address address; ///< Changed account address. u256 value; ///< Change value, e.g. balance, storage and nonce. u256 key; ///< Storage key. Last because used only in one case. - bytes oldCode; ///< Code overwritten by CREATE, empty except in case of address collision. /// Helper constructor to make change log update more readable. Change(Kind _kind, Address const& _addr, u256 const& _value = 0): kind(_kind), address(_addr), value(_value) { - assert(_kind != Code); // For this the special constructor needs to be used. } /// Helper constructor especially for storage change log. @@ -134,11 +132,6 @@ struct Change Change(Address const& _addr, u256 const& _value): kind(Nonce), address(_addr), value(_value) {} - - /// Helper constructor especially for new code change log. - Change(Address const& _addr, bytes const& _oldCode): - kind(Code), address(_addr), oldCode(_oldCode) - {} }; using ChangeLog = std::vector;