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

Commit

Permalink
Rollback of NewCode recovers the original code
Browse files Browse the repository at this point in the history
This addresses #4130 together with the corresponding change in the test.
  • Loading branch information
pirapira committed Jun 20, 2017
1 parent b4f5edf commit b5aad08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ bytes const& State::code(Address const& _addr) const

void State::setNewCode(Address const& _address, bytes&& _code)
{
m_changeLog.emplace_back(_address, code(_address));
m_cache[_address].setNewCode(std::move(_code));
m_changeLog.emplace_back(Change::NewCode, _address);
}

h256 State::codeHash(Address const& _a) const
Expand Down Expand Up @@ -512,7 +512,10 @@ void State::rollback(size_t _savepoint)
m_cache.erase(change.address);
break;
case Change::NewCode:
account.resetCode();
if (change.oldCode.empty())
account.resetCode();
else
account.setNewCode(std::move(change.oldCode));
break;
case Change::Touch:
account.untouch();
Expand Down
10 changes: 9 additions & 1 deletion libethereum/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,24 @@ struct Change
Address address; ///< Changed account address.
u256 value; ///< Change value, e.g. balance, storage.
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 != NewCode); // For this the special constructor needs to be used.
}

/// Helper constructor especially for storage change log.
Change(Address const& _addr, u256 const& _key, u256 const& _value):
kind(Storage), address(_addr), value(_value), key(_key)
{}

/// Helper constructor especially for new code change log.
Change(Address const& _addr, bytes const& _oldCode):
kind(NewCode), address(_addr), oldCode(_oldCode)
{}
};

using ChangeLog = std::vector<Change>;
Expand Down

0 comments on commit b5aad08

Please sign in to comment.