Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
The code can be always rolled back to empty, no need to save the old …
Browse files Browse the repository at this point in the history
…code.

Because it's not allowed to overwrite code now.
  • Loading branch information
gumb0 committed Jun 26, 2019
1 parent 60e72b5 commit 0b36dc1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
7 changes: 7 additions & 0 deletions libethereum/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions libethereum/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
4 changes: 2 additions & 2 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 0 additions & 6 deletions libethereum/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ 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):
Expand All @@ -134,11 +133,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<Change>;
Expand Down

0 comments on commit 0b36dc1

Please sign in to comment.