From 792b47deba0f41b3cde8e05ba15642729f5e5184 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 16 Feb 2015 12:00:33 +0100 Subject: [PATCH] fix GasUsed bug --- libethcore/BlockInfo.cpp | 4 ++-- libethcore/Exceptions.h | 1 + libethereum/State.cpp | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 3d1bcaa2a..194837818 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -157,8 +157,8 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const { bytes k = rlp(i); t.insert(&k, tr.data()); - u256 gp = tr[1].toInt(); - mgp = min(mgp, gp); + u256 gasprice = tr[1].toInt(); + mgp = min(mgp, gasprice); // the minimum gas price is not used for anything //TODO delete? ++i; } if (transactionsRoot != t.root()) diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index 6127a3d00..3fd62afbd 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -51,6 +51,7 @@ struct UncleTooOld: virtual dev::Exception {}; class UncleInChain: virtual public dev::Exception { public: UncleInChain(h256Set _uncles, h256 _block): m_uncles(_uncles), m_block(_block) {} h256Set m_uncles; h256 m_block; virtual const char* what() const noexcept; }; struct DuplicateUncleNonce: virtual dev::Exception {}; struct InvalidStateRoot: virtual dev::Exception {}; +struct InvalidGasUsed: virtual dev::Exception {}; class InvalidTransactionsHash: virtual public dev::Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual const char* what() const noexcept; }; struct InvalidTransaction: virtual dev::Exception {}; struct InvalidDifficulty: virtual dev::Exception {}; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index beab32abb..5b9da0cdd 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -600,6 +600,13 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) BOOST_THROW_EXCEPTION(InvalidStateRoot()); } + if (m_currentBlock.gasUsed != gasUsed()) + { + // Rollback the trie. + m_db.rollback(); + BOOST_THROW_EXCEPTION(InvalidGasUsed() << RequirementError(bigint(gasUsed()), bigint(m_currentBlock.gasUsed))); + } + return tdIncrease; }