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

Commit

Permalink
EIP98 - remove medstate root hash from receipts instead of replacing …
Browse files Browse the repository at this point in the history
…it with zero hash
  • Loading branch information
gumb0 committed Apr 26, 2017
1 parent 75c1254 commit 83c5f61
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions libethcore/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ DEV_SIMPLE_EXCEPTION(InvalidParentHash);
DEV_SIMPLE_EXCEPTION(InvalidUncleParentHash);
DEV_SIMPLE_EXCEPTION(InvalidNumber);
DEV_SIMPLE_EXCEPTION(InvalidZeroSignatureTransaction);
DEV_SIMPLE_EXCEPTION(InvalidTransactionReceiptFormat);
DEV_SIMPLE_EXCEPTION(BlockNotFound);
DEV_SIMPLE_EXCEPTION(UnknownParent);

Expand Down
6 changes: 4 additions & 2 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ std::pair<ExecutionResult, TransactionReceipt> State::execute(EnvInfo const& _en
commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);
}

h256 const rootState = _envInfo.number() >= _sealEngine.chainParams().u256Param("metropolisForkBlock") ? h256() : rootHash();
return make_pair(res, TransactionReceipt(rootState, startGasUsed + e.gasUsed(), e.logs()));
TransactionReceipt const receipt = _envInfo.number() >= _sealEngine.chainParams().u256Param("metropolisForkBlock") ?
TransactionReceipt(startGasUsed + e.gasUsed(), e.logs()) :
TransactionReceipt(rootHash(), startGasUsed + e.gasUsed(), e.logs());
return make_pair(res, receipt);
}

void State::executeBlockTransactions(Block const& _block, unsigned _txCount, LastHashes const& _lastHashes, SealEngineFace const& _sealEngine)
Expand Down
26 changes: 21 additions & 5 deletions libethereum/TransactionReceipt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ using namespace dev::eth;
TransactionReceipt::TransactionReceipt(bytesConstRef _rlp)
{
RLP r(_rlp);
m_stateRoot = (h256)r[0];
m_gasUsed = (u256)r[1];
m_bloom = (LogBloom)r[2];
for (auto const& i: r[3])
if (!r.isList() || r.itemCount() < 3 || r.itemCount() > 4)
DEV_SIMPLE_EXCEPTION(InvalidTransactionReceiptFormat);

size_t gasUsedIndex = 0;
if (r.itemCount() == 4)
{
m_stateRoot = (h256)r[0];
gasUsedIndex = 1;
}

m_gasUsed = (u256)r[gasUsedIndex];
m_bloom = (LogBloom)r[gasUsedIndex + 1];
for (auto const& i : r[gasUsedIndex + 2])
m_log.emplace_back(i);

}

TransactionReceipt::TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries const& _log):
Expand All @@ -44,7 +54,13 @@ TransactionReceipt::TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries con

void TransactionReceipt::streamRLP(RLPStream& _s) const
{
_s.appendList(4) << m_stateRoot << m_gasUsed << m_bloom;
if (m_stateRoot)
_s.appendList(4) << m_stateRoot;
else
_s.appendList(3);

_s << m_gasUsed << m_bloom;

_s.appendList(m_log.size());
for (LogEntry const& l: m_log)
l.streamRLP(_s);
Expand Down
1 change: 1 addition & 0 deletions libethereum/TransactionReceipt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TransactionReceipt
public:
TransactionReceipt(bytesConstRef _rlp);
TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries const& _log);
TransactionReceipt(u256 _gasUsed, LogEntries const& _log) : TransactionReceipt(h256(), _gasUsed, _log) {}

h256 const& stateRoot() const { return m_stateRoot; }
u256 const& gasUsed() const { return m_gasUsed; }
Expand Down

0 comments on commit 83c5f61

Please sign in to comment.