From 487349bf099873b28578055358f1c86619ef0711 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 16 Jul 2015 01:29:03 +0200 Subject: [PATCH] All fields of BlockInfo now private. --- alethzero/MainWin.cpp | 34 +++--- ethminer/MinerAux.h | 4 +- evmjit/libevmjit-cpp/JitVM.cpp | 6 +- evmjit/libevmjit/RuntimeManager.cpp | 6 +- exp/main.cpp | 6 +- libethcore/BasicAuthority.cpp | 8 +- libethcore/BlockInfo.cpp | 104 ++++++++--------- libethcore/BlockInfo.h | 91 +++++++++------ libethcore/Common.cpp | 2 +- libethcore/Ethash.cpp | 40 +++---- libethcore/EthashAux.cpp | 2 +- libethereum/BasicGasPricer.cpp | 6 +- libethereum/BlockChain.cpp | 78 +++++-------- libethereum/BlockChain.h | 2 +- libethereum/BlockChainSync.cpp | 6 +- libethereum/BlockQueue.cpp | 50 ++++---- libethereum/Executive.cpp | 10 +- libethereum/State.cpp | 133 +++++++++++----------- libethereum/State.h | 2 +- libevm/ExtVMFace.h | 4 +- libevm/VM.cpp | 10 +- libtestutils/BlockChainLoader.cpp | 2 +- libweb3jsonrpc/JsonHelper.cpp | 22 ++-- test/TestHelper.cpp | 6 +- test/libethereum/ClientBase.cpp | 18 +-- test/libethereum/blockchain.cpp | 78 ++++++------- test/libethereum/genesis.cpp | 2 +- test/libevm/vm.cpp | 12 +- test/libsolidity/SolidityEndToEndTest.cpp | 2 +- third/MainWin.cpp | 2 +- 30 files changed, 378 insertions(+), 370 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 2ee8928f5..ad8f5528c 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -189,7 +189,7 @@ Main::Main(QWidget *parent) : #endif m_servers.append(QString::fromStdString(Host::pocHost() + ":30303")); - cerr << "State root: " << CanonBlockChain::genesis().stateRoot << endl; + cerr << "State root: " << CanonBlockChain::genesis().stateRoot() << endl; auto block = CanonBlockChain::createGenesisBlock(); cerr << "Block Hash: " << CanonBlockChain::genesis().hash() << endl; cerr << "Block RLP: " << RLP(block) << endl; @@ -1629,7 +1629,7 @@ void Main::on_transactionQueue_currentItemChanged() else s << "
Log Bloom: Uneventful
"; s << "
Gas Used: " << receipt.gasUsed() << "
"; - s << "
End State: " << receipt.stateRoot().abridged() << "
"; + s << "
End State: " << receipt.stateRoot()().abridged() << "
"; auto r = receipt.rlp(); s << "
Receipt: " << toString(RLP(r)) << "
"; s << "
Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "
"; @@ -1706,7 +1706,7 @@ void Main::on_blocks_currentItemChanged() if (item->data(Qt::UserRole + 1).isNull()) { char timestamp[64]; - time_t rawTime = (time_t)(uint64_t)info.timestamp; + time_t rawTime = (time_t)(uint64_t)info.timestamp(); strftime(timestamp, 64, "%c", localtime(&rawTime)); s << "

" << h << "

"; s << "

#" << info.number; @@ -1714,7 +1714,7 @@ void Main::on_blocks_currentItemChanged() s << "
D/TD: " << info.difficulty << "/" << details.totalDifficulty << " = 2^" << log2((double)info.difficulty) << "/2^" << log2((double)details.totalDifficulty) << "
"; s << "   Children: " << details.children.size() << ""; s << "
Gas used/limit: " << info.gasUsed << "/" << info.gasLimit << "" << "
"; - s << "
Beneficiary: " << htmlEscaped(pretty(info.coinbaseAddress)) << " " << info.coinbaseAddress << "" << "
"; + s << "
Beneficiary: " << htmlEscaped(pretty(info.coinbaseAddress())) << " " << info.coinbaseAddress() << "" << "
"; s << "
Seed hash: " << info.seedHash() << "" << "
"; s << "
Mix hash: " << info.mixHash << "" << "
"; s << "
Nonce: " << info.nonce << "" << "
"; @@ -1724,7 +1724,7 @@ void Main::on_blocks_currentItemChanged() { auto e = EthashAux::eval(info); s << "
Proof-of-Work: " << e.value << " <= " << (h256)u256((bigint(1) << 256) / info.difficulty) << " (mixhash: " << e.mixHash.abridged() << ")" << "
"; - s << "
Parent: " << info.parentHash << "" << "
"; + s << "
Parent: " << info.parentHash() << "" << "
"; } else { @@ -1732,20 +1732,20 @@ void Main::on_blocks_currentItemChanged() s << "
Parent: It was a virgin birth
"; } // s << "
Bloom: " << details.bloom << ""; - if (!!info.logBloom) - s << "
Log Bloom: " << info.logBloom << "
"; + if (!!info.logBloom()) + s << "
Log Bloom: " << info.logBloom() << "
"; else s << "
Log Bloom: Uneventful
"; - s << "
Transactions: " << block[1].itemCount() << " @" << info.transactionsRoot << "" << "
"; - s << "
Uncles: " << block[2].itemCount() << " @" << info.sha3Uncles << "" << "
"; + s << "
Transactions: " << block[1].itemCount() << " @" << info.transactionsRoot() << "" << "
"; + s << "
Uncles: " << block[2].itemCount() << " @" << info.sha3Uncles() << "" << "
"; for (auto u: block[2]) { BlockInfo uncle = BlockInfo::fromHeader(u.data()); char const* line = "
 "; s << line << "Hash: " << uncle.hash() << "" << "
"; - s << line << "Parent: " << uncle.parentHash << "" << "
"; + s << line << "Parent: " << uncle.parentHash() << "" << ""; s << line << "Number: " << uncle.number << "" << ""; - s << line << "Coinbase: " << htmlEscaped(pretty(uncle.coinbaseAddress)) << " " << uncle.coinbaseAddress << "" << ""; + s << line << "Coinbase: " << htmlEscaped(pretty(uncle.coinbaseAddress())) << " " << uncle.coinbaseAddress() << "" << ""; s << line << "Seed hash: " << uncle.seedHash() << "" << ""; s << line << "Mix hash: " << uncle.mixHash << "" << ""; s << line << "Nonce: " << uncle.nonce << "" << ""; @@ -1754,20 +1754,20 @@ void Main::on_blocks_currentItemChanged() auto e = EthashAux::eval(uncle); s << line << "Proof-of-Work: " << e.value << " <= " << (h256)u256((bigint(1) << 256) / uncle.difficulty) << " (mixhash: " << e.mixHash.abridged() << ")" << ""; } - if (info.parentHash) - s << "
Pre: " << BlockInfo(ethereum()->blockChain().block(info.parentHash)).stateRoot << "" << "
"; + if (info.parentHash()) + s << "
Pre: " << BlockInfo(ethereum()->blockChain().block(info.parentHash())).stateRoot() << "" << "
"; else s << "
Pre: Nothing is before Phil" << "
"; - s << "
Receipts: @" << info.receiptsRoot << ":" << "
"; + s << "
Receipts: @" << info.receiptsRoot() << ":" << "
"; BlockReceipts receipts = ethereum()->blockChain().receipts(h); unsigned ii = 0; for (auto const& i: block[1]) { - s << "
" << sha3(i.data()).abridged() << ": " << receipts.receipts[ii].stateRoot() << " [" << receipts.receipts[ii].gasUsed() << " used]" << "
"; + s << "
" << sha3(i.data()).abridged() << ": " << receipts.receipts[ii].stateRoot()() << " [" << receipts.receipts[ii].gasUsed() << " used]" << "
"; ++ii; } - s << "
Post: " << info.stateRoot << "" << "
"; + s << "
Post: " << info.stateRoot() << "" << "
"; s << "
Dump: " Span(Mono) << toHex(block[0].data()) << "" << "
"; s << "
Receipts-Hex: " Span(Mono) << toHex(receipts.rlp()) << "
"; } @@ -1807,7 +1807,7 @@ void Main::on_blocks_currentItemChanged() else s << "
Log Bloom: Uneventful
"; s << "
Gas Used: " << receipt.gasUsed() << "
"; - s << "
End State: " << receipt.stateRoot().abridged() << "
"; + s << "
End State: " << receipt.stateRoot()().abridged() << "
"; auto r = receipt.rlp(); s << "
Receipt: " << toString(RLP(r)) << "
"; s << "
Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "
"; diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 61fde605d..0d227b1ef 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -398,8 +398,8 @@ private: void doInitDAG(unsigned _n) { BlockInfo bi; - bi.number = _n; - cout << "Initializing DAG for epoch beginning #" << (bi.number / 30000 * 30000) << " (seedhash " << bi.proofCache().abridged() << "). This will take a while." << endl; + bi.number() = _n; + cout << "Initializing DAG for epoch beginning #" << (bi.number() / 30000 * 30000) << " (seedhash " << bi.proofCache().abridged() << "). This will take a while." << endl; Ethash::prep(bi); exit(0); } diff --git a/evmjit/libevmjit-cpp/JitVM.cpp b/evmjit/libevmjit-cpp/JitVM.cpp index 2fb2a0e67..4e1fb66ea 100644 --- a/evmjit/libevmjit-cpp/JitVM.cpp +++ b/evmjit/libevmjit-cpp/JitVM.cpp @@ -24,7 +24,7 @@ bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _on rejected |= io_gas > std::numeric_limits::max(); // Do not accept requests with gas > 2^63 (int64 max) rejected |= _ext.gasPrice > std::numeric_limits::max(); rejected |= _ext.currentBlock.number > std::numeric_limits::max(); - rejected |= _ext.currentBlock.timestamp > std::numeric_limits::max(); + rejected |= _ext.currentBlock.timestamp() > std::numeric_limits::max(); if (rejected) { @@ -41,11 +41,11 @@ bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _on m_data.caller = eth2jit(fromAddress(_ext.caller)); m_data.origin = eth2jit(fromAddress(_ext.origin)); m_data.callValue = eth2jit(_ext.value); - m_data.coinBase = eth2jit(fromAddress(_ext.currentBlock.coinbaseAddress)); + m_data.coinBase = eth2jit(fromAddress(_ext.currentBlock.coinbaseAddress())); m_data.difficulty = eth2jit(_ext.currentBlock.difficulty); m_data.gasLimit = eth2jit(_ext.currentBlock.gasLimit); m_data.number = static_cast(_ext.currentBlock.number); - m_data.timestamp = static_cast(_ext.currentBlock.timestamp); + m_data.timestamp() = static_cast(_ext.currentBlock.timestamp()); m_data.code = _ext.code.data(); m_data.codeSize = _ext.code.size(); m_data.codeHash = eth2jit(_ext.codeHash); diff --git a/evmjit/libevmjit/RuntimeManager.cpp b/evmjit/libevmjit/RuntimeManager.cpp index d48b64bb1..b2c15d7ae 100644 --- a/evmjit/libevmjit/RuntimeManager.cpp +++ b/evmjit/libevmjit/RuntimeManager.cpp @@ -1,7 +1,7 @@ #include "RuntimeManager.h" -#include "preprocessor/llvm_includes_start.h" -#include +#include "preprocessor/llvm_includes_start.h" +#include #include "preprocessor/llvm_includes_end.h" #include "Stack.h" @@ -77,7 +77,7 @@ llvm::Twine getName(RuntimeData::Index _index) case RuntimeData::Difficulty: return "block.difficulty"; case RuntimeData::GasLimit: return "block.gaslimit"; case RuntimeData::Number: return "block.number"; - case RuntimeData::Timestamp: return "block.timestamp"; + case RuntimeData::Timestamp: return "block.timestamp()"; case RuntimeData::Code: return "code.ptr"; case RuntimeData::CodeSize: return "code.size"; } diff --git a/exp/main.cpp b/exp/main.cpp index 4a35068f1..0b740e526 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -85,8 +85,8 @@ int main() BlockInfo bi; bi.difficulty = c_genesisDifficulty; bi.gasLimit = c_genesisGasLimit; - bi.number = 1; - bi.parentHash = sha3("parentHash"); + bi.number() = 1; + bi.parentHash() = sha3("parentHash"); bytes sealedData; @@ -329,7 +329,7 @@ int main() mine(s, bc, se); bytes minedBlock = s.blockData(); - cnote << "Mined block is" << BlockInfo(minedBlock).stateRoot; + cnote << "Mined block is" << BlockInfo(minedBlock).stateRoot(); bc.import(minedBlock, stateDB); cnote << bc; diff --git a/libethcore/BasicAuthority.cpp b/libethcore/BasicAuthority.cpp index 22da67080..7ef3dd21e 100644 --- a/libethcore/BasicAuthority.cpp +++ b/libethcore/BasicAuthority.cpp @@ -44,19 +44,19 @@ void BasicAuthority::BlockHeaderRaw::populateFromHeader(RLP const& _header, Stri m_sig = _header[BlockInfo::BasicFields].toHash(); // check it hashes according to proof of work or that it's the genesis block. - if (_s == CheckEverything && parentHash && !verify()) + if (_s == CheckEverything && m_parentHash && !verify()) { InvalidBlockNonce ex; ex << errinfo_hash256(hashWithout()); - ex << errinfo_difficulty(difficulty); + ex << errinfo_difficulty(m_difficulty); ex << errinfo_target(boundary()); BOOST_THROW_EXCEPTION(ex); } - else if (_s == QuickNonce && parentHash && !preVerify()) + else if (_s == QuickNonce && m_parentHash && !preVerify()) { InvalidBlockNonce ex; ex << errinfo_hash256(hashWithout()); - ex << errinfo_difficulty(difficulty); + ex << errinfo_difficulty(m_difficulty); BOOST_THROW_EXCEPTION(ex); } } diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 64961bc40..266f57cc8 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -32,7 +32,7 @@ using namespace std; using namespace dev; using namespace dev::eth; -BlockInfo::BlockInfo(): timestamp(Invalid256) +BlockInfo::BlockInfo(): m_timestamp(Invalid256) { } @@ -45,26 +45,26 @@ BlockInfo::BlockInfo(bytesConstRef _block, Strictness _s, h256 const& _hashWith, void BlockInfo::clear() { - parentHash = h256(); - sha3Uncles = EmptyListSHA3; - coinbaseAddress = Address(); - stateRoot = EmptyTrie; - transactionsRoot = EmptyTrie; - receiptsRoot = EmptyTrie; - logBloom = LogBloom(); - difficulty = 0; - number = 0; - gasLimit = 0; - gasUsed = 0; - timestamp = 0; - extraData.clear(); + m_parentHash = h256(); + m_sha3Uncles = EmptyListSHA3; + m_coinbaseAddress = Address(); + m_stateRoot = EmptyTrie; + m_transactionsRoot = EmptyTrie; + m_receiptsRoot = EmptyTrie; + m_logBloom = LogBloom(); + m_difficulty = 0; + m_number = 0; + m_gasLimit = 0; + m_gasUsed = 0; + m_timestamp = 0; + m_extraData.clear(); noteDirty(); } h256 const& BlockInfo::boundary() const { - if (!m_boundary && difficulty) - m_boundary = (h256)(u256)((bigint(1) << 256) / difficulty); + if (!m_boundary && m_difficulty) + m_boundary = (h256)(u256)((bigint(1) << 256) / m_difficulty); return m_boundary; } @@ -81,8 +81,8 @@ h256 const& BlockInfo::hashWithout() const void BlockInfo::streamRLPFields(RLPStream& _s) const { - _s << parentHash << sha3Uncles << coinbaseAddress << stateRoot << transactionsRoot << receiptsRoot << logBloom - << difficulty << number << gasLimit << gasUsed << timestamp << extraData; + _s << m_parentHash << m_sha3Uncles << m_coinbaseAddress << m_stateRoot << m_transactionsRoot << m_receiptsRoot << m_logBloom + << m_difficulty << m_number << m_gasLimit << m_gasUsed << m_timestamp << m_extraData; } h256 BlockInfo::headerHashFromBlock(bytesConstRef _block) @@ -110,19 +110,19 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s) int field = 0; try { - parentHash = _header[field = 0].toHash(RLP::VeryStrict); - sha3Uncles = _header[field = 1].toHash(RLP::VeryStrict); - coinbaseAddress = _header[field = 2].toHash
(RLP::VeryStrict); - stateRoot = _header[field = 3].toHash(RLP::VeryStrict); - transactionsRoot = _header[field = 4].toHash(RLP::VeryStrict); - receiptsRoot = _header[field = 5].toHash(RLP::VeryStrict); - logBloom = _header[field = 6].toHash(RLP::VeryStrict); - difficulty = _header[field = 7].toInt(); - number = _header[field = 8].toInt(); - gasLimit = _header[field = 9].toInt(); - gasUsed = _header[field = 10].toInt(); - timestamp = _header[field = 11].toInt(); - extraData = _header[field = 12].toBytes(); + m_parentHash = _header[field = 0].toHash(RLP::VeryStrict); + m_sha3Uncles = _header[field = 1].toHash(RLP::VeryStrict); + m_coinbaseAddress = _header[field = 2].toHash
(RLP::VeryStrict); + m_stateRoot = _header[field = 3].toHash(RLP::VeryStrict); + m_transactionsRoot = _header[field = 4].toHash(RLP::VeryStrict); + m_receiptsRoot = _header[field = 5].toHash(RLP::VeryStrict); + m_logBloom = _header[field = 6].toHash(RLP::VeryStrict); + m_difficulty = _header[field = 7].toInt(); + m_number = _header[field = 8].toInt(); + m_gasLimit = _header[field = 9].toInt(); + m_gasUsed = _header[field = 10].toInt(); + m_timestamp = _header[field = 11].toInt(); + m_extraData = _header[field = 12].toBytes(); } catch (Exception const& _e) { @@ -130,11 +130,11 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s) throw; } - if (number > ~(unsigned)0) + if (m_number > ~(unsigned)0) BOOST_THROW_EXCEPTION(InvalidNumber()); - if (_s != CheckNothing && gasUsed > gasLimit) - BOOST_THROW_EXCEPTION(TooMuchGasUsed() << RequirementError(bigint(gasLimit), bigint(gasUsed)) ); + if (_s != CheckNothing && m_gasUsed > m_gasLimit) + BOOST_THROW_EXCEPTION(TooMuchGasUsed() << RequirementError(bigint(m_gasLimit), bigint(m_gasUsed))); } struct BlockInfoDiagnosticsChannel: public LogChannel { static const char* name() { return EthBlue "▧" EthWhite " ◌"; } static const int verbosity = 9; }; @@ -147,7 +147,7 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const auto expectedRoot = trieRootOver(txList.itemCount(), [&](unsigned i){ return rlp(i); }, [&](unsigned i){ return txList[i].data().toBytes(); }); clog(BlockInfoDiagnosticsChannel) << "Expected trie root:" << toString(expectedRoot); - if (transactionsRoot != expectedRoot) + if (m_transactionsRoot != expectedRoot) { MemoryDB tm; GenericTrieDB transactionsTrie(&tm); @@ -172,52 +172,52 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const for (auto const& t: txs) cdebug << toHex(t); - BOOST_THROW_EXCEPTION(InvalidTransactionsRoot() << Hash256RequirementError(expectedRoot, transactionsRoot)); + BOOST_THROW_EXCEPTION(InvalidTransactionsRoot() << Hash256RequirementError(expectedRoot, m_transactionsRoot)); } clog(BlockInfoDiagnosticsChannel) << "Expected uncle hash:" << toString(sha3(root[2].data())); - if (sha3Uncles != sha3(root[2].data())) + if (m_sha3Uncles != sha3(root[2].data())) BOOST_THROW_EXCEPTION(InvalidUnclesHash()); } void BlockInfo::populateFromParent(BlockInfo const& _parent) { - stateRoot = _parent.stateRoot; - number = _parent.number + 1; - gasLimit = selectGasLimit(_parent); - gasUsed = 0; - difficulty = calculateDifficulty(_parent); - parentHash = _parent.hash(); + m_stateRoot = _parent.stateRoot(); + m_number = _parent.m_number + 1; + m_gasLimit = selectGasLimit(_parent); + m_gasUsed = 0; + m_difficulty = calculateDifficulty(_parent); + m_parentHash = _parent.hash(); } u256 BlockInfo::selectGasLimit(BlockInfo const& _parent) const { - if (!parentHash) + if (!m_parentHash) return c_genesisGasLimit; else // target minimum of 3141592 - if (_parent.gasLimit < c_genesisGasLimit) - return min(c_genesisGasLimit, _parent.gasLimit + _parent.gasLimit / c_gasLimitBoundDivisor - 1); + if (_parent.m_gasLimit < c_genesisGasLimit) + return min(c_genesisGasLimit, _parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor - 1); else - return max(c_genesisGasLimit, _parent.gasLimit - _parent.gasLimit / c_gasLimitBoundDivisor + 1 + (_parent.gasUsed * 6 / 5) / c_gasLimitBoundDivisor); + return max(c_genesisGasLimit, _parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor + 1 + (_parent.m_gasUsed * 6 / 5) / c_gasLimitBoundDivisor); } u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const { - if (!parentHash) + if (!m_parentHash) return (u256)c_genesisDifficulty; else - return max(c_minimumDifficulty, timestamp >= _parent.timestamp + c_durationLimit ? _parent.difficulty - (_parent.difficulty / c_difficultyBoundDivisor) : (_parent.difficulty + (_parent.difficulty / c_difficultyBoundDivisor))); + return max(c_minimumDifficulty, m_timestamp >= _parent.m_timestamp + c_durationLimit ? _parent.m_difficulty - (_parent.m_difficulty / c_difficultyBoundDivisor) : (_parent.m_difficulty + (_parent.m_difficulty / c_difficultyBoundDivisor))); } void BlockInfo::verifyParent(BlockInfo const& _parent) const { // Check timestamp is after previous timestamp. - if (parentHash) + if (m_parentHash) { - if (timestamp <= _parent.timestamp) + if (m_timestamp <= _parent.m_timestamp) BOOST_THROW_EXCEPTION(InvalidTimestamp()); - if (number != _parent.number + 1) + if (m_number != _parent.m_number + 1) BOOST_THROW_EXCEPTION(InvalidNumber()); } } diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index b00fa73fb..67a5397f4 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -81,21 +81,6 @@ struct BlockInfo public: static const unsigned BasicFields = 13; - // TODO: make them all private! - h256 parentHash; - h256 sha3Uncles; - Address coinbaseAddress; - h256 stateRoot; - h256 transactionsRoot; - h256 receiptsRoot; - LogBloom logBloom; - u256 difficulty; // TODO: pull out into BlockHeader - u256 number; - u256 gasLimit; - u256 gasUsed; - u256 timestamp = Invalid256; - bytes extraData; - BlockInfo(); explicit BlockInfo(bytesConstRef _data, Strictness _s = CheckEverything, h256 const& _hashWith = h256(), BlockDataType _bdt = BlockData); explicit BlockInfo(bytes const& _data, Strictness _s = CheckEverything, h256 const& _hashWith = h256(), BlockDataType _bdt = BlockData): BlockInfo(&_data, _s, _hashWith, _bdt) {} @@ -104,23 +89,23 @@ public: static h256 headerHashFromBlock(bytesConstRef _block); static RLP extractHeader(bytesConstRef _block); - explicit operator bool() const { return timestamp != Invalid256; } + explicit operator bool() const { return m_timestamp != Invalid256; } bool operator==(BlockInfo const& _cmp) const { - return parentHash == _cmp.parentHash && - sha3Uncles == _cmp.sha3Uncles && - coinbaseAddress == _cmp.coinbaseAddress && - stateRoot == _cmp.stateRoot && - transactionsRoot == _cmp.transactionsRoot && - receiptsRoot == _cmp.receiptsRoot && - logBloom == _cmp.logBloom && - difficulty == _cmp.difficulty && - number == _cmp.number && - gasLimit == _cmp.gasLimit && - gasUsed == _cmp.gasUsed && - timestamp == _cmp.timestamp && - extraData == _cmp.extraData; + return m_parentHash == _cmp.parentHash() && + m_sha3Uncles == _cmp.sha3Uncles() && + m_coinbaseAddress == _cmp.coinbaseAddress() && + m_stateRoot == _cmp.stateRoot() && + m_transactionsRoot == _cmp.transactionsRoot() && + m_receiptsRoot == _cmp.receiptsRoot() && + m_logBloom == _cmp.logBloom() && + m_difficulty == _cmp.difficulty() && + m_number == _cmp.number() && + m_gasLimit == _cmp.gasLimit() && + m_gasUsed == _cmp.gasUsed() && + m_timestamp == _cmp.timestamp() && + m_extraData == _cmp.extraData(); } bool operator!=(BlockInfo const& _cmp) const { return !operator==(_cmp); } @@ -132,6 +117,31 @@ public: u256 selectGasLimit(BlockInfo const& _parent) const; h256 const& boundary() const; + h256 const& parentHash() const { return m_parentHash; } + h256 const& sha3Uncles() const { return m_sha3Uncles; } + + void setParentHash(h256 const& _v) { m_parentHash = _v; noteDirty(); } + void setSha3Uncles(h256 const& _v) { m_sha3Uncles = _v; noteDirty(); } + void setTimestamp(u256 const& _v) { m_timestamp = _v; noteDirty(); } + void setCoinbaseAddress(Address const& _v) { m_coinbaseAddress = _v; noteDirty(); } + void setRoots(h256 const& _t, h256 const& _r, h256 const& _u, h256 const& _s) { m_transactionsRoot = _t; m_receiptsRoot = _r; m_stateRoot = _s; m_sha3Uncles = _u; noteDirty(); } + void setGasUsed(u256 const& _v) { m_gasUsed = _v; noteDirty(); } + void setExtraData(bytes const& _v) { m_extraData = _v; noteDirty(); } + void setLogBloom(LogBloom const& _v) { m_logBloom = _v; noteDirty(); } + + Address const& coinbaseAddress() const { return m_coinbaseAddress; } + h256 const& stateRoot() const { return m_stateRoot; } + h256 const& transactionsRoot() const { return m_transactionsRoot; } + h256 const& receiptsRoot() const { return m_receiptsRoot; } + LogBloom const& logBloom() const { return m_logBloom; } + u256 const& number() const { return m_number; } + u256 const& gasLimit() const { return m_gasLimit; } + u256 const& gasUsed() const { return m_gasUsed; } + u256 const& timestamp() const { return m_timestamp; } + bytes const& extraData() const { return m_extraData; } + + u256 const& difficulty() const { return m_difficulty; } // TODO: pull out into BlockHeader + /// sha3 of the header only. h256 const& hashWithout() const; h256 const& hash() const { if (m_hash) return m_hash; throw NoHashRecorded(); } @@ -145,6 +155,21 @@ protected: mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised. + h256 m_parentHash; + h256 m_sha3Uncles; + Address m_coinbaseAddress; + h256 m_stateRoot; + h256 m_transactionsRoot; + h256 m_receiptsRoot; + LogBloom m_logBloom; + u256 m_number; + u256 m_gasLimit; + u256 m_gasUsed; + u256 m_timestamp = Invalid256; + bytes m_extraData; + + u256 m_difficulty; // TODO: pull out into BlockHeader + private: mutable h256 m_hashWithout; ///< SHA3 hash of the block header! Not serialised. mutable h256 m_boundary; ///< 2^256 / difficulty @@ -152,9 +177,9 @@ private: inline std::ostream& operator<<(std::ostream& _out, BlockInfo const& _bi) { - _out << _bi.hashWithout() << " " << _bi.parentHash << " " << _bi.sha3Uncles << " " << _bi.coinbaseAddress << " " << _bi.stateRoot << " " << _bi.transactionsRoot << " " << - _bi.receiptsRoot << " " << _bi.logBloom << " " << _bi.difficulty << " " << _bi.number << " " << _bi.gasLimit << " " << - _bi.gasUsed << " " << _bi.timestamp; + _out << _bi.hashWithout() << " " << _bi.parentHash() << " " << _bi.sha3Uncles() << " " << _bi.coinbaseAddress() << " " << _bi.stateRoot() << " " << _bi.transactionsRoot() << " " << + _bi.receiptsRoot() << " " << _bi.logBloom() << " " << _bi.difficulty() << " " << _bi.number() << " " << _bi.gasLimit() << " " << + _bi.gasUsed() << " " << _bi.timestamp(); return _out; } @@ -191,7 +216,7 @@ public: // TODO: consider making private. void verifyParent(BlockHeaderPolished const& _parent) { - if (BlockInfo::parentHash && BlockInfo::parentHash != _parent.hash()) + if (BlockInfo::parentHash() && BlockInfo::parentHash() != _parent.hash()) BOOST_THROW_EXCEPTION(InvalidParentHash()); BlockInfo::verifyParent(_parent); BlockInfoSub::verifyParent(_parent); diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 499854584..05cc45280 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -124,7 +124,7 @@ static void badBlockInfo(BlockInfo const& _bi, string const& _err) ss << c_space << endl; ss << c_border + " Import Failure " + _err + string(max(0, 53 - _err.size()), ' ') + " " + c_border << endl; ss << c_space << endl; - string bin = toString(_bi.number); + string bin = toString(_bi.number()); ss << c_border + (" Guru Meditation #" + string(max(0, 8 - bin.size()), '0') + bin + "." + _bi.hash().abridged() + " ") + c_border << endl; ss << c_space << endl; ss << c_line; diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 128822b80..ee483aa8b 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -62,7 +62,7 @@ namespace eth h256 const& Ethash::BlockHeaderRaw::seedHash() const { if (!m_seedHash) - m_seedHash = EthashAux::seedHash((unsigned)number); + m_seedHash = EthashAux::seedHash((unsigned)m_number); return m_seedHash; } @@ -72,7 +72,7 @@ void Ethash::BlockHeaderRaw::populateFromHeader(RLP const& _header, Strictness _ m_nonce = _header[BlockInfo::BasicFields + 1].toHash(); // check it hashes according to proof of work or that it's the genesis block. - if (_s == CheckEverything && parentHash && !verify()) + if (_s == CheckEverything && m_parentHash && !verify()) { InvalidBlockNonce ex; ex << errinfo_nonce(m_nonce); @@ -81,42 +81,42 @@ void Ethash::BlockHeaderRaw::populateFromHeader(RLP const& _header, Strictness _ EthashProofOfWork::Result er = EthashAux::eval(seedHash(), hashWithout(), m_nonce); ex << errinfo_ethashResult(make_tuple(er.value, er.mixHash)); ex << errinfo_hash256(hashWithout()); - ex << errinfo_difficulty(difficulty); + ex << errinfo_difficulty(m_difficulty); ex << errinfo_target(boundary()); BOOST_THROW_EXCEPTION(ex); } - else if (_s == QuickNonce && parentHash && !preVerify()) + else if (_s == QuickNonce && m_parentHash && !preVerify()) { InvalidBlockNonce ex; ex << errinfo_hash256(hashWithout()); - ex << errinfo_difficulty(difficulty); + ex << errinfo_difficulty(m_difficulty); ex << errinfo_nonce(m_nonce); BOOST_THROW_EXCEPTION(ex); } if (_s != CheckNothing) { - if (difficulty < c_minimumDifficulty) - BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError(bigint(c_minimumDifficulty), bigint(difficulty)) ); + if (m_difficulty < c_minimumDifficulty) + BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError(bigint(c_minimumDifficulty), bigint(m_difficulty)) ); - if (gasLimit < c_minGasLimit) - BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError(bigint(c_minGasLimit), bigint(gasLimit)) ); + if (m_gasLimit < c_minGasLimit) + BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError(bigint(c_minGasLimit), bigint(m_gasLimit)) ); - if (number && extraData.size() > c_maximumExtraDataSize) - BOOST_THROW_EXCEPTION(ExtraDataTooBig() << RequirementError(bigint(c_maximumExtraDataSize), bigint(extraData.size()))); + if (m_number && m_extraData.size() > c_maximumExtraDataSize) + BOOST_THROW_EXCEPTION(ExtraDataTooBig() << RequirementError(bigint(c_maximumExtraDataSize), bigint(m_extraData.size()))); } } void Ethash::BlockHeaderRaw::verifyParent(BlockHeaderRaw const& _parent) { // Check difficulty is correct given the two timestamps. - if (difficulty != calculateDifficulty(_parent)) - BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError((bigint)calculateDifficulty(_parent), (bigint)difficulty)); + if (m_difficulty != calculateDifficulty(_parent)) + BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError((bigint)calculateDifficulty(_parent), (bigint)m_difficulty)); - if (gasLimit < c_minGasLimit || - gasLimit <= _parent.gasLimit - _parent.gasLimit / c_gasLimitBoundDivisor || - gasLimit >= _parent.gasLimit + _parent.gasLimit / c_gasLimitBoundDivisor) - BOOST_THROW_EXCEPTION(InvalidGasLimit() << errinfo_min((bigint)_parent.gasLimit - _parent.gasLimit / c_gasLimitBoundDivisor) << errinfo_got((bigint)gasLimit) << errinfo_max((bigint)_parent.gasLimit + _parent.gasLimit / c_gasLimitBoundDivisor)); + if (m_gasLimit < c_minGasLimit || + m_gasLimit <= _parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor || + m_gasLimit >= _parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor) + BOOST_THROW_EXCEPTION(InvalidGasLimit() << errinfo_min((bigint)_parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor) << errinfo_got((bigint)m_gasLimit) << errinfo_max((bigint)_parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor)); } void Ethash::BlockHeaderRaw::populateFromParent(BlockHeaderRaw const& _parent) @@ -126,7 +126,7 @@ void Ethash::BlockHeaderRaw::populateFromParent(BlockHeaderRaw const& _parent) bool Ethash::BlockHeaderRaw::preVerify() const { - if (number >= ETHASH_EPOCH_LENGTH * 2048) + if (m_number >= ETHASH_EPOCH_LENGTH * 2048) return false; bool ret = !!ethash_quick_check_difficulty( @@ -162,7 +162,7 @@ bool Ethash::BlockHeaderRaw::verify() const cwarn << "headerHash:" << hashWithout(); cwarn << "nonce:" << m_nonce; cwarn << "mixHash:" << m_mixHash; - cwarn << "difficulty:" << difficulty; + cwarn << "difficulty:" << m_difficulty; cwarn << "boundary:" << boundary(); cwarn << "result.value:" << result.value; cwarn << "result.mixHash:" << result.mixHash; @@ -290,7 +290,7 @@ public: m_farm.setWork(m_sealing); m_farm.start(m_sealer); m_farm.setWork(m_sealing); // TODO: take out one before or one after... - Ethash::ensurePrecomputed((unsigned)_bi.number); + Ethash::ensurePrecomputed((unsigned)_bi.number()); } void onSealGenerated(std::function const& _f) override { diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index c511978db..763bea417 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -63,7 +63,7 @@ EthashAux* EthashAux::get() uint64_t EthashAux::cacheSize(BlockInfo const& _header) { - return ethash_get_cachesize((uint64_t)_header.number); + return ethash_get_cachesize((uint64_t)_header.number()); } uint64_t EthashAux::dataSize(uint64_t _blockNumber) diff --git a/libethereum/BasicGasPricer.cpp b/libethereum/BasicGasPricer.cpp index 145d23594..b957966f8 100644 --- a/libethereum/BasicGasPricer.cpp +++ b/libethereum/BasicGasPricer.cpp @@ -30,7 +30,7 @@ void BasicGasPricer::update(BlockChain const& _bc) { unsigned c = 0; h256 p = _bc.currentHash(); - m_gasPerBlock = _bc.info(p).gasLimit; + m_gasPerBlock = _bc.info(p).gasLimit(); map dist; u256 total = 0; @@ -39,7 +39,7 @@ void BasicGasPricer::update(BlockChain const& _bc) while (c < 1000 && p) { BlockInfo bi = _bc.info(p); - if (bi.transactionsRoot != EmptyTrie) + if (bi.transactionsRoot() != EmptyTrie) { auto bb = _bc.block(p); RLP r(bb); @@ -54,7 +54,7 @@ void BasicGasPricer::update(BlockChain const& _bc) i++; } } - p = bi.parentHash; + p = bi.parentHash(); ++c; } diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index aae8cbd10..b696c77bd 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -72,7 +72,7 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, BlockChain const& _bc) { try { BlockInfo d(bytesConstRef(it->value())); - _out << toHex(it->key().ToString()) << ": " << d.number << " @ " << d.parentHash << (cmp == it->key().ToString() ? " BEST" : "") << std::endl; + _out << toHex(it->key().ToString()) << ": " << d.number() << " @ " << d.parentHash() << (cmp == it->key().ToString() ? " BEST" : "") << std::endl; } catch (...) { cwarn << "Invalid DB entry:" << toHex(it->key().ToString()) << " -> " << toHex(bytesConstRef(it->value())); @@ -293,11 +293,11 @@ void BlockChain::rebuild(std::string const& _path, std::function parent is" << bi.parentHash << "; expected" << lastHash << "#" << (d - 1); + cwarn << "DISJOINT CHAIN DETECTED; " << bi.hash() << "#" << d << " -> parent is" << bi.parentHash() << "; expected" << lastHash << "#" << (d - 1); return; } lastHash = bi.hash(); @@ -355,7 +355,7 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB c { // Nonce & uncle nonces already verified in verification thread at this point. ImportRoute r; - DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number), 500) + DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number()), 500) r = import(block.verified, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidSeal & ~ImportRequirements::CheckUncles); fresh += r.liveBlocks; dead += r.deadBlocks; @@ -461,21 +461,21 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& } // Work out its number as the parent's number + 1 - if (!isKnown(_block.info.parentHash)) + if (!isKnown(_block.info.parentHash())) { - clog(BlockChainNote) << _block.info.hash() << ": Unknown parent " << _block.info.parentHash; + clog(BlockChainNote) << _block.info.hash() << ": Unknown parent " << _block.info.parentHash(); // We don't know the parent (yet) - discard for now. It'll get resent to us if we find out about its ancestry later on. BOOST_THROW_EXCEPTION(UnknownParent()); } - auto pd = details(_block.info.parentHash); + auto pd = details(_block.info.parentHash()); if (!pd) { auto pdata = pd.rlp(); clog(BlockChainDebug) << "Details is returning false despite block known:" << RLP(pdata); - auto parentBlock = block(_block.info.parentHash); - clog(BlockChainDebug) << "isKnown:" << isKnown(_block.info.parentHash); - clog(BlockChainDebug) << "last/number:" << m_lastBlockNumber << m_lastBlockHash << _block.info.number; + auto parentBlock = block(_block.info.parentHash()); + clog(BlockChainDebug) << "isKnown:" << isKnown(_block.info.parentHash()); + clog(BlockChainDebug) << "last/number:" << m_lastBlockNumber << m_lastBlockHash << _block.info.number(); clog(BlockChainDebug) << "Block:" << BlockInfo(&parentBlock); clog(BlockChainDebug) << "RLP:" << RLP(parentBlock); clog(BlockChainDebug) << "DATABASE CORRUPTION: CRITICAL FAILURE"; @@ -483,9 +483,9 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& } // Check it's not crazy - if (_block.info.timestamp > (u256)time(0)) + if (_block.info.timestamp() > (u256)time(0)) { - clog(BlockChainChat) << _block.info.hash() << ": Future time " << _block.info.timestamp << " (now at " << time(0) << ")"; + clog(BlockChainChat) << _block.info.hash() << ": Future time " << _block.info.timestamp() << " (now at " << time(0) << ")"; // Block has a timestamp in the future. This is no good. BOOST_THROW_EXCEPTION(FutureTime()); } @@ -543,9 +543,9 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& // together with an "ensureCachedWithUpdatableLock(l)" method. // This is safe in practice since the caches don't get flushed nearly often enough to be // done here. - details(_block.info.parentHash); + details(_block.info.parentHash()); DEV_WRITE_GUARDED(x_details) - m_details[_block.info.parentHash].children.push_back(_block.info.hash()); + m_details[_block.info.parentHash()].children.push_back(_block.info.hash()); #if ETH_TIMED_IMPORTS || !ETH_TRUE collation = t.elapsed(); @@ -554,9 +554,9 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& blocksBatch.Put(toSlice(_block.info.hash()), ldb::Slice(_block.block)); DEV_READ_GUARDED(x_details) - extrasBatch.Put(toSlice(_block.info.parentHash, ExtraDetails), (ldb::Slice)dev::ref(m_details[_block.info.parentHash].rlp())); + extrasBatch.Put(toSlice(_block.info.parentHash(), ExtraDetails), (ldb::Slice)dev::ref(m_details[_block.info.parentHash()].rlp())); - extrasBatch.Put(toSlice(_block.info.hash(), ExtraDetails), (ldb::Slice)dev::ref(BlockDetails((unsigned)pd.number + 1, td, _block.info.parentHash, {}).rlp())); + extrasBatch.Put(toSlice(_block.info.hash(), ExtraDetails), (ldb::Slice)dev::ref(BlockDetails((unsigned)pd.number + 1, td, _block.info.parentHash(), {}).rlp())); extrasBatch.Put(toSlice(_block.info.hash(), ExtraLogBlooms), (ldb::Slice)dev::ref(blb.rlp())); extrasBatch.Put(toSlice(_block.info.hash(), ExtraReceipts), (ldb::Slice)dev::ref(br.rlp())); @@ -585,10 +585,10 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& _block.info.proof.nonce.abridged(), currentHash().abridged(), "", // TODO: remote id ?? - _block.info.parentHash.abridged() + _block.info.parentHash().abridged() ); #endif - // cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children."; + // cnote << "Parent " << bi.parentHash() << " has " << details(bi.parentHash()).children.size() << " children."; h256s route; h256 common; @@ -599,7 +599,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& // don't include bi.hash() in treeRoute, since it's not yet in details DB... // just tack it on afterwards. unsigned commonIndex; - tie(route, common, commonIndex) = treeRoute(last, _block.info.parentHash); + tie(route, common, commonIndex) = treeRoute(last, _block.info.parentHash()); route.push_back(_block.info.hash()); // Most of the time these two will be equal - only when we're doing a chain revert will they not be @@ -630,15 +630,15 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& // Collate logs into blooms. h256s alteredBlooms; { - LogBloom blockBloom = tbi.logBloom; - blockBloom.shiftBloom<3>(sha3(tbi.coinbaseAddress.ref())); + LogBloom blockBloom = tbi.logBloom(); + blockBloom.shiftBloom<3>(sha3(tbi.coinbaseAddress().ref())); // Pre-memoize everything we need before locking x_blocksBlooms - for (unsigned level = 0, index = (unsigned)tbi.number; level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) + for (unsigned level = 0, index = (unsigned)tbi.number(); level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) blocksBlooms(chunkId(level, index / c_bloomIndexSize)); WriteGuard l(x_blocksBlooms); - for (unsigned level = 0, index = (unsigned)tbi.number; level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) + for (unsigned level = 0, index = (unsigned)tbi.number(); level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) { unsigned i = index / c_bloomIndexSize; unsigned o = index % c_bloomIndexSize; @@ -661,23 +661,23 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& ReadGuard l1(x_blocksBlooms); for (auto const& h: alteredBlooms) extrasBatch.Put(toSlice(h, ExtraBlocksBlooms), (ldb::Slice)dev::ref(m_blocksBlooms[h].rlp())); - extrasBatch.Put(toSlice(h256(tbi.number), ExtraBlockHash), (ldb::Slice)dev::ref(BlockHash(tbi.hash()).rlp())); + extrasBatch.Put(toSlice(h256(tbi.number()), ExtraBlockHash), (ldb::Slice)dev::ref(BlockHash(tbi.hash()).rlp())); } // FINALLY! change our best hash. { newLastBlockHash = _block.info.hash(); - newLastBlockNumber = (unsigned)_block.info.number; + newLastBlockNumber = (unsigned)_block.info.number(); } - clog(BlockChainNote) << " Imported and best" << td << " (#" << _block.info.number << "). Has" << (details(_block.info.parentHash).children.size() - 1) << "siblings. Route:" << route; + clog(BlockChainNote) << " Imported and best" << td << " (#" << _block.info.number() << "). Has" << (details(_block.info.parentHash()).children.size() - 1) << "siblings. Route:" << route; #if ETH_USING_ETHASH StructuredLogger::chainNewHead( _block.info.headerHash(WithoutProof).abridged(), _block.info.proof.nonce.abridged(), currentHash().abridged(), - _block.info.parentHash.abridged() + _block.info.parentHash().abridged() ); #endif } @@ -750,7 +750,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& checkBest = t.elapsed(); if (total.elapsed() > 0.5) { - cnote << "SLOW IMPORT:" << _block.info.hash() << " #" << _block.info.number; + cnote << "SLOW IMPORT:" << _block.info.hash() << " #" << _block.info.number(); cnote << " Import took:" << total.elapsed(); cnote << " preliminaryChecks:" << preliminaryChecks; cnote << " enactment:" << enactment; @@ -758,7 +758,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& cnote << " writing:" << writing; cnote << " checkBest:" << checkBest; cnote << " " << _block.transactions.size() << " transactions"; - cnote << " " << _block.info.gasUsed << " gas used"; + cnote << " " << _block.info.gasUsed() << " gas used"; } #endif @@ -861,7 +861,7 @@ void BlockChain::rescue(OverlayDB& _db) cout << "extras..." << flush; details(h); cout << "state..." << flush; - if (_db.exists(bi.stateRoot)) + if (_db.exists(bi.stateRoot())) break; } catch (...) {} @@ -1233,19 +1233,3 @@ State BlockChain::genesisState(OverlayDB const& _db) return ret; } - - - - - - - - - - - - - - - - diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 50965f2b6..3ff85c8a6 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -391,7 +391,7 @@ public: { BlockHeader h(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce); h.verifyInternals(_block); - h.verifyParent(header(h.parentHash)); + h.verifyParent(header(h.parentHash())); res.info = static_cast(h); } catch (Exception& ex) diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index ed022fb75..2141c4587 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -111,7 +111,7 @@ void BlockChainSync::onPeerStatus(std::shared_ptr _peer) unsigned BlockChainSync::estimatedHashes() const { BlockInfo block = host().chain().info(); - time_t lastBlockTime = (block.hash() == host().chain().genesisHash()) ? 1428192000 : (time_t)block.timestamp; + time_t lastBlockTime = (block.hash() == host().chain().genesisHash()) ? 1428192000 : (time_t)block.timestamp(); time_t now = time(0); unsigned blockCount = c_chainReorgSize; if (lastBlockTime > now) @@ -220,9 +220,9 @@ void BlockChainSync::onPeerBlocks(std::shared_ptr _peer, RLP const if (m_state == SyncState::NewBlocks) { BlockInfo bi(_r[i].data()); - if (bi.number > maxUnknownNumber) + if (bi.number() > maxUnknownNumber) { - maxUnknownNumber = bi.number; + maxUnknownNumber = bi.number(); maxUnknown = h; } } diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 6b400b236..c9ee4c1cf 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -101,8 +101,8 @@ void BlockQueue::verifierBody() swap(work, m_unverified.front()); m_unverified.pop_front(); BlockInfo bi; - bi.sha3Uncles = work.hash; - bi.parentHash = work.parentHash; + bi.setSha3Uncles(work.hash); + bi.setParentHash(work.parentHash); m_verifying.emplace_back(move(bi)); } @@ -121,7 +121,7 @@ void BlockQueue::verifierBody() m_readySet.erase(work.hash); m_knownBad.insert(work.hash); for (auto it = m_verifying.begin(); it != m_verifying.end(); ++it) - if (it->verified.info.sha3Uncles == work.hash) + if (it->verified.info.sha3Uncles() == work.hash) { m_verifying.erase(it); goto OK1; @@ -136,11 +136,11 @@ void BlockQueue::verifierBody() { WriteGuard l2(m_lock); unique_lock l(m_verification); - if (!m_verifying.empty() && m_verifying.front().verified.info.sha3Uncles == work.hash) + if (!m_verifying.empty() && m_verifying.front().verified.info.sha3Uncles() == work.hash) { // we're next! m_verifying.pop_front(); - if (m_knownBad.count(res.verified.info.parentHash)) + if (m_knownBad.count(res.verified.info.parentHash())) { m_readySet.erase(res.verified.info.hash()); m_knownBad.insert(res.verified.info.hash()); @@ -154,7 +154,7 @@ void BlockQueue::verifierBody() else { for (auto& i: m_verifying) - if (i.verified.info.sha3Uncles == work.hash) + if (i.verified.info.sha3Uncles() == work.hash) { i = move(res); goto OK; @@ -172,7 +172,7 @@ void BlockQueue::drainVerified_WITH_BOTH_LOCKS() { while (!m_verifying.empty() && !m_verifying.front().blockData.empty()) { - if (m_knownBad.count(m_verifying.front().verified.info.parentHash)) + if (m_knownBad.count(m_verifying.front().verified.info.parentHash())) { m_readySet.erase(m_verifying.front().verified.info.hash()); m_knownBad.insert(m_verifying.front().verified.info.hash()); @@ -213,7 +213,7 @@ ImportResult BlockQueue::import(bytesConstRef _block, bool _isOurs) return ImportResult::Malformed; } - clog(BlockQueueTraceChannel) << "Block" << h << "is" << bi.number << "parent is" << bi.parentHash; + clog(BlockQueueTraceChannel) << "Block" << h << "is" << bi.number() << "parent is" << bi.parentHash(); // Check block doesn't already exist first! if (m_bc->isKnown(h)) @@ -227,38 +227,38 @@ ImportResult BlockQueue::import(bytesConstRef _block, bool _isOurs) // Check it's not in the future (void)_isOurs; - if (bi.timestamp > (u256)time(0)/* && !_isOurs*/) + if (bi.timestamp() > (u256)time(0)/* && !_isOurs*/) { - m_future.insert(make_pair((unsigned)bi.timestamp, make_pair(h, _block.toBytes()))); + m_future.insert(make_pair((unsigned)bi.timestamp(), make_pair(h, _block.toBytes()))); char buf[24]; - time_t bit = (unsigned)bi.timestamp; + time_t bit = (unsigned)bi.timestamp(); if (strftime(buf, 24, "%X", localtime(&bit)) == 0) buf[0] = '\0'; // empty if case strftime fails - clog(BlockQueueTraceChannel) << "OK - queued for future [" << bi.timestamp << "vs" << time(0) << "] - will wait until" << buf; + clog(BlockQueueTraceChannel) << "OK - queued for future [" << bi.timestamp() << "vs" << time(0) << "] - will wait until" << buf; m_unknownSize += _block.size(); m_unknownCount++; - m_difficulty += bi.difficulty; - bool unknown = !m_readySet.count(bi.parentHash) && !m_drainingSet.count(bi.parentHash) && !m_bc->isKnown(bi.parentHash); + m_difficulty += bi.difficulty(); + bool unknown = !m_readySet.count(bi.parentHash()) && !m_drainingSet.count(bi.parentHash()) && !m_bc->isKnown(bi.parentHash()); return unknown ? ImportResult::FutureTimeUnknown : ImportResult::FutureTimeKnown; } else { // We now know it. - if (m_knownBad.count(bi.parentHash)) + if (m_knownBad.count(bi.parentHash())) { m_knownBad.insert(bi.hash()); updateBad_WITH_LOCK(bi.hash()); // bad parent; this is bad too, note it as such return ImportResult::BadChain; } - else if (!m_readySet.count(bi.parentHash) && !m_drainingSet.count(bi.parentHash) && !m_bc->isKnown(bi.parentHash)) + else if (!m_readySet.count(bi.parentHash()) && !m_drainingSet.count(bi.parentHash()) && !m_bc->isKnown(bi.parentHash())) { // We don't know the parent (yet) - queue it up for later. It'll get resent to us if we find out about its ancestry later on. - clog(BlockQueueTraceChannel) << "OK - queued as unknown parent:" << bi.parentHash; - m_unknown.insert(make_pair(bi.parentHash, make_pair(h, _block.toBytes()))); + clog(BlockQueueTraceChannel) << "OK - queued as unknown parent:" << bi.parentHash(); + m_unknown.insert(make_pair(bi.parentHash(), make_pair(h, _block.toBytes()))); m_unknownSet.insert(h); m_unknownSize += _block.size(); - m_difficulty += bi.difficulty; + m_difficulty += bi.difficulty(); m_unknownCount++; return ImportResult::UnknownParent; @@ -268,11 +268,11 @@ ImportResult BlockQueue::import(bytesConstRef _block, bool _isOurs) // If valid, append to blocks. clog(BlockQueueTraceChannel) << "OK - ready for chain insertion."; DEV_GUARDED(m_verification) - m_unverified.push_back(UnverifiedBlock { h, bi.parentHash, _block.toBytes() }); + m_unverified.push_back(UnverifiedBlock { h, bi.parentHash(), _block.toBytes() }); m_moreToVerify.notify_one(); m_readySet.insert(h); m_knownSize += _block.size(); - m_difficulty += bi.difficulty; + m_difficulty += bi.difficulty(); m_knownCount++; noteReady_WITH_LOCK(h); @@ -295,7 +295,7 @@ void BlockQueue::updateBad_WITH_LOCK(h256 const& _bad) std::vector oldVerified; swap(m_verified, oldVerified); for (auto& b: oldVerified) - if (m_knownBad.count(b.verified.info.parentHash) || m_knownBad.count(b.verified.info.hash())) + if (m_knownBad.count(b.verified.info.parentHash()) || m_knownBad.count(b.verified.info.hash())) { m_knownBad.insert(b.verified.info.hash()); m_readySet.erase(b.verified.info.hash()); @@ -321,9 +321,9 @@ void BlockQueue::updateBad_WITH_LOCK(h256 const& _bad) std::deque oldVerifying; swap(m_verifying, oldVerifying); for (auto& b: oldVerifying) - if (m_knownBad.count(b.verified.info.parentHash) || m_knownBad.count(b.verified.info.sha3Uncles)) + if (m_knownBad.count(b.verified.info.parentHash()) || m_knownBad.count(b.verified.info.sha3Uncles())) { - h256 const& h = b.blockData.size() != 0 ? b.verified.info.hash() : b.verified.info.sha3Uncles; + h256 const& h = b.blockData.size() != 0 ? b.verified.info.hash() : b.verified.info.sha3Uncles(); m_knownBad.insert(h); m_readySet.erase(h); collectUnknownBad_WITH_BOTH_LOCKS(h); @@ -460,7 +460,7 @@ void BlockQueue::drain(VerifiedBlocks& o_out, unsigned _max) // TODO: @optimise use map rather than vector & set. auto h = bs.verified.info.hash(); m_drainingSet.insert(h); - m_drainingDifficulty += bs.verified.info.difficulty; + m_drainingDifficulty += bs.verified.info.difficulty(); m_readySet.erase(h); m_knownSize -= bs.verified.block.size(); m_knownCount--; diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 866c9c8f9..e58e1a8c6 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -144,7 +144,7 @@ string StandardTrace::json(bool _styled) const Executive::Executive(State& _s, BlockChain const& _bc, unsigned _level): m_s(_s), - m_lastHashes(_bc.lastHashes((unsigned)_s.info().number - 1)), + m_lastHashes(_bc.lastHashes((unsigned)_s.info().number() - 1)), m_depth(_level) {} @@ -170,11 +170,11 @@ void Executive::initialize(Transaction const& _transaction) // Avoid transactions that would take us beyond the block gas limit. u256 startGasUsed = m_s.gasUsed(); - if (startGasUsed + (bigint)m_t.gas() > m_s.m_currentBlock.gasLimit) + if (startGasUsed + (bigint)m_t.gas() > m_s.m_currentBlock.gasLimit()) { - clog(ExecutiveWarnChannel) << "Too much gas used in this block: Require <" << (m_s.m_currentBlock.gasLimit - startGasUsed) << " Got" << m_t.gas(); + clog(ExecutiveWarnChannel) << "Too much gas used in this block: Require <" << (m_s.m_currentBlock.gasLimit() - startGasUsed) << " Got" << m_t.gas(); m_excepted = TransactionException::BlockGasLimitReached; - BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((bigint)(m_s.m_currentBlock.gasLimit - startGasUsed), (bigint)m_t.gas())); + BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((bigint)(m_s.m_currentBlock.gasLimit() - startGasUsed), (bigint)m_t.gas())); } // Check gas cost is enough. @@ -403,7 +403,7 @@ void Executive::finalize() m_s.addBalance(m_t.sender(), m_gas * m_t.gasPrice()); u256 feesEarned = (m_t.gas() - m_gas) * m_t.gasPrice(); - m_s.addBalance(m_s.m_currentBlock.coinbaseAddress, feesEarned); + m_s.addBalance(m_s.m_currentBlock.coinbaseAddress(), feesEarned); // Suicides... if (m_ext) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index ee2078a07..64daaf5f8 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -105,7 +105,7 @@ State::State(OverlayDB const& _db, BaseState _bs, Address _coinbaseAddress): m_previousBlock.clear(); m_currentBlock.clear(); -// assert(m_state.root() == m_previousBlock.stateRoot); +// assert(m_state.root() == m_previousBlock.stateRoot()); paranoia("end of normal construction.", true); } @@ -123,16 +123,16 @@ PopulationStatistics State::populateFromChain(BlockChain const& _bc, h256 const& auto b = _bc.block(_h); BlockInfo bi(b); - if (bi.number) + if (bi.number()) { // Non-genesis: // 1. Start at parent's end state (state root). - BlockInfo bip(_bc.block(bi.parentHash)); - sync(_bc, bi.parentHash, bip); + BlockInfo bip(_bc.block(bi.parentHash())); + sync(_bc, bi.parentHash(), bip); // 2. Enact the block's transactions onto this state. - m_ourAddress = bi.coinbaseAddress; + m_ourAddress = bi.coinbaseAddress(); Timer t; auto vb = _bc.verifyBlock(&b, function(), _ir); ret.verify = t.elapsed(); @@ -338,9 +338,9 @@ bool State::sync(BlockChain const& _bc, h256 const& _block, BlockInfo const& _bi // Find most recent state dump and replay what's left. // (Most recent state dump might end up being genesis.) - if (m_db.lookup(bi.stateRoot).empty()) + if (m_db.lookup(bi.stateRoot()).empty()) { - cwarn << "Unable to sync to" << bi.hash() << "; state root" << bi.stateRoot << "not found in database."; + cwarn << "Unable to sync to" << bi.hash() << "; state root" << bi.stateRoot() << "not found in database."; cwarn << "Database corrupt: contains block without stateRoot:" << bi; cwarn << "Try rescuing the database by running: eth --rescue"; exit(-1); @@ -357,10 +357,10 @@ bool State::sync(BlockChain const& _bc, h256 const& _block, BlockInfo const& _bi // (Most recent state dump might end up being genesis.) std::vector chain; - while (bi.number != 0 && m_db.lookup(bi.stateRoot).empty()) // while we don't have the state root of the latest block... + while (bi.number() != 0 && m_db.lookup(bi.stateRoot()).empty()) // while we don't have the state root of the latest block... { chain.push_back(bi.hash()); // push back for later replay. - bi.populate(_bc.block(bi.parentHash)); // move to parent. + bi.populate(_bc.block(bi.parentHash())); // move to parent. } m_previousBlock = bi; @@ -402,7 +402,7 @@ u256 State::enactOn(VerifiedBlockRef const& _block, BlockChain const& _bc) #endif // Check family: - BlockInfo biParent = _bc.info(_block.info.parentHash); + BlockInfo biParent = _bc.info(_block.info.parentHash()); _block.info.verifyParent(biParent); #if ETH_TIMED_ENACTMENTS @@ -411,15 +411,15 @@ u256 State::enactOn(VerifiedBlockRef const& _block, BlockChain const& _bc) #endif BlockInfo biGrandParent; - if (biParent.number) - biGrandParent = _bc.info(biParent.parentHash); + if (biParent.number()) + biGrandParent = _bc.info(biParent.parentHash()); #if ETH_TIMED_ENACTMENTS populateGrand = t.elapsed(); t.restart(); #endif - sync(_bc, _block.info.parentHash, BlockInfo()); + sync(_bc, _block.info.parentHash(), BlockInfo()); resetCurrent(); #if ETH_TIMED_ENACTMENTS @@ -462,17 +462,15 @@ void State::resetCurrent() m_cache.clear(); m_touched.clear(); m_currentBlock = BlockInfo(); - m_currentBlock.coinbaseAddress = m_ourAddress; - m_currentBlock.timestamp = max(m_previousBlock.timestamp + 1, (u256)time(0)); - m_currentBlock.transactionsRoot = h256(); - m_currentBlock.sha3Uncles = h256(); + m_currentBlock.setCoinbaseAddress(m_ourAddress); + m_currentBlock.setTimestamp(max(m_previousBlock.timestamp() + 1, (u256)time(0))); m_currentBlock.populateFromParent(m_previousBlock); // Update timestamp according to clock. // TODO: check. m_lastTx = m_db; - m_state.setRoot(m_previousBlock.stateRoot); + m_state.setRoot(m_previousBlock.stateRoot()); m_committedToMine = false; @@ -538,7 +536,7 @@ pair State::sync(BlockChain const& _bc, TransactionQu catch (BlockGasLimitReached const& e) { bigint const& got = *boost::get_error_info(e); - if (got > m_currentBlock.gasLimit) + if (got > m_currentBlock.gasLimit()) { clog(StateTrace) << t.sha3() << "Dropping over-gassy transaction (gas > block's gas limit)"; _tq.drop(t.sha3()); @@ -583,7 +581,7 @@ string State::vmTrace(bytesConstRef _block, BlockChain const& _bc, ImportRequire m_currentBlock.verifyInternals(_block); m_currentBlock.noteDirty(); - LastHashes lh = _bc.lastHashes((unsigned)m_previousBlock.number); + LastHashes lh = _bc.lastHashes((unsigned)m_previousBlock.number()); string ret; unsigned i = 0; @@ -604,12 +602,12 @@ u256 State::enact(VerifiedBlockRef const& _block, BlockChain const& _bc) // m_currentBlock is assumed to be prepopulated and reset. #if !ETH_RELEASE - assert(m_previousBlock.hash() == _block.info.parentHash); - assert(m_currentBlock.parentHash == _block.info.parentHash); - assert(rootHash() == m_previousBlock.stateRoot); + assert(m_previousBlock.hash() == _block.info.parentHash()); + assert(m_currentBlock.parentHash() == _block.info.parentHash()); + assert(rootHash() == m_previousBlock.stateRoot()); #endif - if (m_currentBlock.parentHash != m_previousBlock.hash()) + if (m_currentBlock.parentHash() != m_previousBlock.hash()) // Internal client error. BOOST_THROW_EXCEPTION(InvalidParentHash()); @@ -622,7 +620,7 @@ u256 State::enact(VerifiedBlockRef const& _block, BlockChain const& _bc) LastHashes lh; DEV_TIMED_ABOVE("lastHashes", 500) - lh = _bc.lastHashes((unsigned)m_previousBlock.number); + lh = _bc.lastHashes((unsigned)m_previousBlock.number()); RLP rlp(_block.block); @@ -651,28 +649,28 @@ u256 State::enact(VerifiedBlockRef const& _block, BlockChain const& _bc) } h256 receiptsRoot; - DEV_TIMED_ABOVE("receiptsRoot", 500) + DEV_TIMED_ABOVE(".receiptsRoot()", 500) receiptsRoot = orderedTrieRoot(receipts); - if (receiptsRoot != m_currentBlock.receiptsRoot) + if (receiptsRoot != m_currentBlock.receiptsRoot()) { InvalidReceiptsStateRoot ex; - ex << Hash256RequirementError(receiptsRoot, m_currentBlock.receiptsRoot); + ex << Hash256RequirementError(receiptsRoot, m_currentBlock.receiptsRoot()); ex << errinfo_receipts(receipts); ex << errinfo_vmtrace(vmTrace(_block.block, _bc, ImportRequirements::None)); BOOST_THROW_EXCEPTION(ex); } - if (m_currentBlock.logBloom != logBloom()) + if (m_currentBlock.logBloom() != logBloom()) { InvalidLogBloom ex; - ex << LogBloomRequirementError(logBloom(), m_currentBlock.logBloom); + ex << LogBloomRequirementError(logBloom(), m_currentBlock.logBloom()); ex << errinfo_receipts(receipts); BOOST_THROW_EXCEPTION(ex); } // Initialise total difficulty calculation. - u256 tdIncrease = m_currentBlock.difficulty; + u256 tdIncrease = m_currentBlock.difficulty(); // Check uncles & apply their rewards to state. if (rlp[2].itemCount() > 2) @@ -686,7 +684,7 @@ u256 State::enact(VerifiedBlockRef const& _block, BlockChain const& _bc) vector rewarded; h256Hash excluded; DEV_TIMED_ABOVE("allKin", 500) - excluded = _bc.allKinFrom(m_currentBlock.parentHash, 6); + excluded = _bc.allKinFrom(m_currentBlock.parentHash(), 6); excluded.insert(m_currentBlock.hash()); unsigned ii = 0; @@ -710,22 +708,22 @@ u256 State::enact(VerifiedBlockRef const& _block, BlockChain const& _bc) BlockInfo uncle(i.data(), IgnoreSeal, h, HeaderData); BlockInfo uncleParent; - if (!_bc.isKnown(uncle.parentHash)) + if (!_bc.isKnown(uncle.parentHash())) BOOST_THROW_EXCEPTION(UnknownParent()); - uncleParent = BlockInfo(_bc.block(uncle.parentHash)); + uncleParent = BlockInfo(_bc.block(uncle.parentHash())); - if ((bigint)uncleParent.number < (bigint)m_currentBlock.number - 7) + if ((bigint)uncleParent.number() < (bigint)m_currentBlock.number() - 7) { UncleTooOld ex; - ex << errinfo_uncleNumber(uncle.number); - ex << errinfo_currentNumber(m_currentBlock.number); + ex << errinfo_uncleNumber(uncle.number()); + ex << errinfo_currentNumber(m_currentBlock.number()); BOOST_THROW_EXCEPTION(ex); } - else if (uncle.number == m_currentBlock.number) + else if (uncle.number() == m_currentBlock.number()) { UncleIsBrother ex; - ex << errinfo_uncleNumber(uncle.number); - ex << errinfo_currentNumber(m_currentBlock.number); + ex << errinfo_uncleNumber(uncle.number()); + ex << errinfo_currentNumber(m_currentBlock.number()); BOOST_THROW_EXCEPTION(ex); } uncle.verifyParent(uncleParent); @@ -748,17 +746,17 @@ u256 State::enact(VerifiedBlockRef const& _block, BlockChain const& _bc) commit(); // Hash the state trie and check against the state_root hash in m_currentBlock. - if (m_currentBlock.stateRoot != m_previousBlock.stateRoot && m_currentBlock.stateRoot != rootHash()) + if (m_currentBlock.stateRoot() != m_previousBlock.stateRoot() && m_currentBlock.stateRoot() != rootHash()) { m_db.rollback(); - BOOST_THROW_EXCEPTION(InvalidStateRoot() << Hash256RequirementError(rootHash(), m_currentBlock.stateRoot)); + BOOST_THROW_EXCEPTION(InvalidStateRoot() << Hash256RequirementError(rootHash(), m_currentBlock.stateRoot())); } - if (m_currentBlock.gasUsed != gasUsed()) + if (m_currentBlock.gasUsed() != gasUsed()) { // Rollback the trie. m_db.rollback(); - BOOST_THROW_EXCEPTION(InvalidGasUsed() << RequirementError(bigint(gasUsed()), bigint(m_currentBlock.gasUsed))); + BOOST_THROW_EXCEPTION(InvalidGasUsed() << RequirementError(bigint(gasUsed()), bigint(m_currentBlock.gasUsed()))); } return tdIncrease; @@ -772,7 +770,7 @@ void State::cleanup(bool _fullCommit) // Commit the new trie to disk. if (isChannelVisible()) // Avoid calling toHex if not needed - clog(StateTrace) << "Committing to disk: stateRoot" << m_currentBlock.stateRoot << "=" << rootHash() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); + clog(StateTrace) << "Committing to disk: stateRoot" << m_currentBlock.stateRoot() << "=" << rootHash() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); try { EnforceRefs er(m_db, true); @@ -786,7 +784,7 @@ void State::cleanup(bool _fullCommit) m_db.commit(); if (isChannelVisible()) // Avoid calling toHex if not needed - clog(StateTrace) << "Committed: stateRoot" << m_currentBlock.stateRoot << "=" << rootHash() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); + clog(StateTrace) << "Committed: stateRoot" << m_currentBlock.stateRoot() << "=" << rootHash() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); paranoia("immediately after database commit", true); m_previousBlock = m_currentBlock; @@ -806,7 +804,7 @@ void State::uncommitToMine() { m_cache.clear(); if (!m_transactions.size()) - m_state.setRoot(m_previousBlock.stateRoot); + m_state.setRoot(m_previousBlock.stateRoot()); else m_state.setRoot(m_receipts.back().stateRoot()); m_db = m_lastTx; @@ -878,12 +876,12 @@ void State::commitToMine(BlockChain const& _bc, bytes const& _extraData) RLPStream unclesData; unsigned unclesCount = 0; - if (m_previousBlock.number != 0) + if (m_previousBlock.number() != 0) { // Find great-uncles (or second-cousins or whatever they are) - children of great-grandparents, great-great-grandparents... that were not already uncles in previous generations. -// cout << "Checking " << m_previousBlock.hash << ", parent=" << m_previousBlock.parentHash << endl; - h256Hash excluded = _bc.allKinFrom(m_currentBlock.parentHash, 6); - auto p = m_previousBlock.parentHash; +// cout << "Checking " << m_previousBlock.hash << ", parent=" << m_previousBlock.parentHash() << endl; + h256Hash excluded = _bc.allKinFrom(m_currentBlock.parentHash(), 6); + auto p = m_previousBlock.parentHash(); for (unsigned gen = 0; gen < 6 && p != _bc.genesisHash() && unclesCount < 2; ++gen, p = _bc.details(p).parent) { auto us = _bc.details(p).children; @@ -926,11 +924,6 @@ void State::commitToMine(BlockChain const& _bc, bytes const& _extraData) RLPStream(unclesCount).appendRaw(unclesData.out(), unclesCount).swapOut(m_currentUncles); - m_currentBlock.transactionsRoot = hash256(transactionsMap); - m_currentBlock.receiptsRoot = hash256(receiptsMap); - m_currentBlock.logBloom = logBloom(); - m_currentBlock.sha3Uncles = sha3(m_currentUncles); - // Apply rewards last of all. applyRewards(uncleBlockHeaders); @@ -941,12 +934,18 @@ void State::commitToMine(BlockChain const& _bc, bytes const& _extraData) // cnote << m_state; // cnote << *this; - m_currentBlock.gasUsed = gasUsed(); - m_currentBlock.stateRoot = m_state.root(); - m_currentBlock.parentHash = m_previousBlock.hash(); - m_currentBlock.extraData = _extraData; - if (m_currentBlock.extraData.size() > 32) - m_currentBlock.extraData.resize(32); + m_currentBlock.setLogBloom(logBloom()); + m_currentBlock.setGasUsed(gasUsed()); + m_currentBlock.setRoots(hash256(transactionsMap), hash256(receiptsMap), sha3(m_currentUncles), m_state.root()); + + m_currentBlock.setParentHash(m_previousBlock.hash()); + m_currentBlock.setExtraData(_extraData); + if (m_currentBlock.extraData().size() > 32) + { + auto ed = m_currentBlock.extraData(); + ed.resize(32); + m_currentBlock.setExtraData(ed); + } m_committedToMine = true; } @@ -967,13 +966,13 @@ bool State::sealBlock(bytesConstRef _header) ret.appendRaw(m_currentUncles); ret.swapOut(m_currentBytes); m_currentBlock = BlockInfo(_header, CheckNothing, h256(), HeaderData); - cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash << ")"; + cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash() << ")"; // TODO: move into Sealer StructuredLogger::minedNewBlock( m_currentBlock.hash().abridged(), "", // Can't give the nonce here. "", //TODO: chain head hash here ?? - m_currentBlock.parentHash.abridged() + m_currentBlock.parentHash().abridged() ); // Quickly reset the transactions. @@ -1270,7 +1269,7 @@ State State::fromPending(unsigned _i) const ret.m_cache.clear(); _i = min(_i, m_transactions.size()); if (!_i) - ret.m_state.setRoot(m_previousBlock.stateRoot); + ret.m_state.setRoot(m_previousBlock.stateRoot()); else ret.m_state.setRoot(m_receipts[_i - 1].stateRoot()); while (ret.m_transactions.size() > _i) @@ -1287,10 +1286,10 @@ void State::applyRewards(vector const& _uncleBlockHeaders) u256 r = m_blockReward; for (auto const& i: _uncleBlockHeaders) { - addBalance(i.coinbaseAddress, m_blockReward * (8 + i.number - m_currentBlock.number) / 8); + addBalance(i.coinbaseAddress(), m_blockReward * (8 + i.number() - m_currentBlock.number()) / 8); r += m_blockReward / 32; } - addBalance(m_currentBlock.coinbaseAddress, r); + addBalance(m_currentBlock.coinbaseAddress(), r); } std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s) diff --git a/libethereum/State.h b/libethereum/State.h index 805215ee5..e2bda6f24 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -190,7 +190,7 @@ public: ExecutionResult execute(LastHashes const& _lh, Transaction const& _t, Permanence _p = Permanence::Committed, OnOpFunc const& _onOp = OnOpFunc()); /// Get the remaining gas limit in this block. - u256 gasLimitRemaining() const { return m_currentBlock.gasLimit - gasUsed(); } + u256 gasLimitRemaining() const { return m_currentBlock.gasLimit() - gasUsed(); } /// Check if the address is in use. bool addressInUse(Address _address) const; diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 94c8e2fef..a5c45af26 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -83,7 +83,7 @@ struct LocalisedLogEntry: public LogEntry ): LogEntry(_le), blockHash(_bi.hash()), - blockNumber((BlockNumber)_bi.number), + blockNumber((BlockNumber)_bi.number()), transactionHash(_th), transactionIndex(_ti), logIndex(_li), @@ -205,7 +205,7 @@ public: virtual void revert() {} /// Hash of a block if within the last 256 blocks, or h256() otherwise. - h256 blockhash(u256 _number) { return _number < currentBlock.number && _number >= (std::max(256, currentBlock.number) - 256) ? lastHashes[(unsigned)(currentBlock.number - 1 - _number)] : h256(); } + h256 blockhash(u256 _number) { return _number < currentBlock.number() && _number >= (std::max(256, currentBlock.number()) - 256) ? lastHashes[(unsigned)(currentBlock.number() - 1 - _number)] : h256(); } /// Get the code at the given location in code ROM. byte getCode(u256 _n) const { return _n < code.size() ? code[(size_t)_n] : 0; } diff --git a/libevm/VM.cpp b/libevm/VM.cpp index 2b2ada0ae..f95481c54 100644 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -400,19 +400,19 @@ bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) m_stack.back() = (u256)_ext.blockhash(m_stack.back()); break; case Instruction::COINBASE: - m_stack.push_back((u160)_ext.currentBlock.coinbaseAddress); + m_stack.push_back((u160)_ext.currentBlock.coinbaseAddress()); break; case Instruction::TIMESTAMP: - m_stack.push_back(_ext.currentBlock.timestamp); + m_stack.push_back(_ext.currentBlock.timestamp()); break; case Instruction::NUMBER: - m_stack.push_back(_ext.currentBlock.number); + m_stack.push_back(_ext.currentBlock.number()); break; case Instruction::DIFFICULTY: - m_stack.push_back(_ext.currentBlock.difficulty); + m_stack.push_back(_ext.currentBlock.difficulty()); break; case Instruction::GASLIMIT: - m_stack.push_back(_ext.currentBlock.gasLimit); + m_stack.push_back(_ext.currentBlock.gasLimit()); break; case Instruction::PUSH1: case Instruction::PUSH2: diff --git a/libtestutils/BlockChainLoader.cpp b/libtestutils/BlockChainLoader.cpp index e6c47e2fe..7e08243af 100644 --- a/libtestutils/BlockChainLoader.cpp +++ b/libtestutils/BlockChainLoader.cpp @@ -36,7 +36,7 @@ BlockChainLoader::BlockChainLoader(Json::Value const& _json) // load genesisBlock m_bc.reset(new BlockChain(fromHex(_json["genesisRLP"].asString()), m_dir.path(), WithExisting::Kill)); - assert(m_state.rootHash() == m_bc->info().stateRoot); + assert(m_state.rootHash() == m_bc->info().stateRoot()); // load blocks for (auto const& block: _json["blocks"]) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 15d39bded..fae12708c 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -88,18 +88,18 @@ Json::Value toJson(dev::eth::BlockInfo const& _bi) if (_bi) { res["hash"] = toJS(_bi.hash()); - res["parentHash"] = toJS(_bi.parentHash); - res["sha3Uncles"] = toJS(_bi.sha3Uncles); - res["miner"] = toJS(_bi.coinbaseAddress); - res["stateRoot"] = toJS(_bi.stateRoot); - res["transactionsRoot"] = toJS(_bi.transactionsRoot); + res["parentHash"] = toJS(_bi.parentHash()); + res["sha3Uncles"] = toJS(_bi.sha3Uncles()); + res["miner"] = toJS(_bi.coinbaseAddress()); + res["stateRoot"] = toJS(_bi.stateRoot()); + res["transactionsRoot"] = toJS(_bi.transactionsRoot()); res["difficulty"] = toJS(_bi.difficulty); - res["number"] = toJS(_bi.number); + res["number"] = toJS(_bi.number()); res["gasUsed"] = toJS(_bi.gasUsed); res["gasLimit"] = toJS(_bi.gasLimit); - res["timestamp"] = toJS(_bi.timestamp); - res["extraData"] = toJS(_bi.extraData); - res["logsBloom"] = toJS(_bi.logBloom); + res["timestamp"] = toJS(_bi.timestamp()); + res["extraData"] = toJS(_bi.extraData()); + res["logsBloom"] = toJS(_bi.logBloom()); res["target"] = toJS(_bi.boundary()); // TODO: move into ProofOfWork. @@ -140,7 +140,7 @@ Json::Value toJson(dev::eth::BlockInfo const& _bi, BlockDetails const& _bd, Uncl res["uncles"].append(toJS(h)); res["transactions"] = Json::Value(Json::arrayValue); for (unsigned i = 0; i < _ts.size(); i++) - res["transactions"].append(toJson(_ts[i], std::make_pair(_bi.hash(), i), (BlockNumber)_bi.number)); + res["transactions"].append(toJson(_ts[i], std::make_pair(_bi.hash(), i), (BlockNumber)_bi.number())); } return res; } @@ -176,7 +176,7 @@ Json::Value toJson(dev::eth::TransactionSkeleton const& _t) Json::Value toJson(dev::eth::TransactionReceipt const& _t) { Json::Value res; - res["stateRoot"] = toJS(_t.stateRoot()); + res["stateRoot"] = toJS(_t.stateRoot()()); res["gasUsed"] = toJS(_t.gasUsed()); res["bloom"] = toJS(_t.bloom()); res["log"] = dev::toJson(_t.log()); diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index b43c4db51..bae980a7e 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -151,12 +151,12 @@ void ImportTest::importEnv(json_spirit::mObject& _o) assert(_o.count("currentCoinbase") > 0); assert(_o.count("currentNumber") > 0); - m_environment.currentBlock.parentHash = h256(_o["previousHash"].get_str()); + m_environment.currentBlock.parentHash() = h256(_o["previousHash"].get_str()); m_environment.currentBlock.number = toInt(_o["currentNumber"]); m_environment.currentBlock.gasLimit = toInt(_o["currentGasLimit"]); m_environment.currentBlock.difficulty = toInt(_o["currentDifficulty"]); - m_environment.currentBlock.timestamp = toInt(_o["currentTimestamp"]); - m_environment.currentBlock.coinbaseAddress = Address(_o["currentCoinbase"].get_str()); + m_environment.currentBlock.timestamp() = toInt(_o["currentTimestamp"]); + m_environment.currentBlock.coinbaseAddress() = Address(_o["currentCoinbase"].get_str()); m_statePre.m_previousBlock = m_environment.previousBlock; m_statePre.m_currentBlock = m_environment.currentBlock; diff --git a/test/libethereum/ClientBase.cpp b/test/libethereum/ClientBase.cpp index 9ee93779e..7dbc5c91e 100644 --- a/test/libethereum/ClientBase.cpp +++ b/test/libethereum/ClientBase.cpp @@ -117,14 +117,14 @@ BOOST_AUTO_TEST_CASE(blocks) u256 expectedBlockInfoTimestamp = u256(_b["timestamp"].asString()); h256 expectedBlockInfoTransactionsRoot = h256(fromHex(_b["transactionsTrie"].asString())); h256 expectedBlockInfoUncldeHash = h256(fromHex(_b["uncleHash"].asString())); - ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom); - ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress); + ETH_CHECK_EQUAL(expectedBlockInfoBloom, _blockInfo.logBloom()); + ETH_CHECK_EQUAL(expectedBlockInfoCoinbase, _blockInfo.coinbaseAddress()); ETH_CHECK_EQUAL(expectedBlockInfoDifficulty, _blockInfo.difficulty); ETH_CHECK_EQUAL_COLLECTIONS( expectedBlockInfoExtraData.begin(), expectedBlockInfoExtraData.end(), - _blockInfo.extraData.begin(), - _blockInfo.extraData.end() + _blockInfo.extraData().begin(), + _blockInfo.extraData().end() ); ETH_CHECK_EQUAL(expectedBlockInfoGasLimit, _blockInfo.gasLimit); ETH_CHECK_EQUAL(expectedBlockInfoGasUsed, _blockInfo.gasUsed); @@ -132,11 +132,11 @@ BOOST_AUTO_TEST_CASE(blocks) ETH_CHECK_EQUAL(expectedBlockInfoMixHash, _blockInfo.mixHash); ETH_CHECK_EQUAL(expectedBlockInfoNonce, _blockInfo.nonce); ETH_CHECK_EQUAL(expectedBlockInfoNumber, _blockInfo.number); - ETH_CHECK_EQUAL(expectedBlockInfoParentHash, _blockInfo.parentHash); - ETH_CHECK_EQUAL(expectedBlockInfoReceiptsRoot, _blockInfo.receiptsRoot); - ETH_CHECK_EQUAL(expectedBlockInfoTimestamp, _blockInfo.timestamp); - ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot); - ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles); + ETH_CHECK_EQUAL(expectedBlockInfoParentHash, _blockInfo.parentHash()); + ETH_CHECK_EQUAL(expectedBlockInfoReceiptsRoot, _blockInfo..receiptsRoot()); + ETH_CHECK_EQUAL(expectedBlockInfoTimestamp, _blockInfo.timestamp()); + ETH_CHECK_EQUAL(expectedBlockInfoTransactionsRoot, _blockInfo.transactionsRoot()); + ETH_CHECK_EQUAL(expectedBlockInfoUncldeHash, _blockInfo.sha3Uncles()); }; BlockInfo blockInfo = _client.blockInfo(blockHash); diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 20f60618f..cf44dfd9f 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -66,7 +66,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) TBOOST_REQUIRE(o.count("pre")); ImportTest importer(o["pre"].get_obj()); TransientDirectory td_stateDB_tmp; - State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path())), BaseState::Empty, biGenesisBlock.coinbaseAddress); + State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path())), BaseState::Empty, biGenesisBlock.coinbaseAddress()); //Imported blocks from the start std::vector blockSets; @@ -76,9 +76,9 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) trueState.commit(); if (_fillin) - biGenesisBlock.stateRoot = trueState.rootHash(); + biGenesisBlock.stateRoot() = trueState.rootHash(); else - TBOOST_CHECK_MESSAGE((biGenesisBlock.stateRoot == trueState.rootHash()), "root hash does not match"); + TBOOST_CHECK_MESSAGE((biGenesisBlock.stateRoot() == trueState.rootHash()), "root hash does not match"); if (_fillin) { @@ -125,7 +125,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) TransientDirectory td_stateDB, td_bc; BlockChain bc(rlpGenesisBlock.out(), td_bc.path(), WithExisting::Kill); - State state(OverlayDB(State::openDB(td_stateDB.path())), BaseState::Empty, biGenesisBlock.coinbaseAddress); + State state(OverlayDB(State::openDB(td_stateDB.path())), BaseState::Empty, biGenesisBlock.coinbaseAddress()); importer.importState(o["pre"].get_obj(), state); state.commit(); @@ -225,7 +225,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) if (vBiUncles.size()) { // update unclehash in case of invalid uncles - current_BlockHeader.sha3Uncles = sha3(uncleStream.out()); + current_BlockHeader.sha3Uncles() = sha3(uncleStream.out()); updatePoW(current_BlockHeader); } @@ -302,7 +302,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) if (o.count("expect") > 0) { stateOptionsMap expectStateMap; - State stateExpect(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); + State stateExpect(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress()); importer.importState(o["expect"].get_obj(), stateExpect, expectStateMap); ImportTest::checkExpectedState(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); o.erase(o.find("expect")); @@ -313,7 +313,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) o["lastblockhash"] = toString(trueBc.info().hash()); //make all values hex in pre section - State prestate(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); + State prestate(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress()); importer.importState(o["pre"].get_obj(), prestate); o["pre"] = fillJsonWithState(prestate); }//_fillin @@ -374,19 +374,19 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) { //Check the fields restored from RLP to original fields TBOOST_CHECK_MESSAGE((blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce)), "hash in given RLP not matching the block hash!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.parentHash == blockFromRlp.parentHash), "parentHash in given RLP not matching the block parentHash!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles), "sha3Uncles in given RLP not matching the block sha3Uncles!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress),"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot), "stateRoot in given RLP not matching the block stateRoot!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot), "transactionsRoot in given RLP not matching the block transactionsRoot!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot), "receiptsRoot in given RLP not matching the block receiptsRoot!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.logBloom == blockFromRlp.logBloom), "logBloom in given RLP not matching the block logBloom!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.parentHash() == blockFromRlp.parentHash()), "parentHash in given RLP not matching the block parentHash!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.sha3Uncles() == blockFromRlp.sha3Uncles()), "sha3Uncles in given RLP not matching the block sha3Uncles!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.coinbaseAddress() == blockFromRlp.coinbaseAddress()),"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.stateRoot() == blockFromRlp.stateRoot()), "stateRoot in given RLP not matching the block stateRoot!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.transactionsRoot() == blockFromRlp.transactionsRoot()), "transactionsRoot in given RLP not matching the block transactionsRoot!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.receiptsRoot() == blockFromRlp.receiptsRoot()), "receiptsRoot in given RLP not matching the block receiptsRoot!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.logBloom() == blockFromRlp.logBloom()), "logBloom in given RLP not matching the block logBloom!"); TBOOST_CHECK_MESSAGE((blockHeaderFromFields.difficulty == blockFromRlp.difficulty), "difficulty in given RLP not matching the block difficulty!"); TBOOST_CHECK_MESSAGE((blockHeaderFromFields.number == blockFromRlp.number), "number in given RLP not matching the block number!"); TBOOST_CHECK_MESSAGE((blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit),"gasLimit in given RLP not matching the block gasLimit!"); TBOOST_CHECK_MESSAGE((blockHeaderFromFields.gasUsed == blockFromRlp.gasUsed), "gasUsed in given RLP not matching the block gasUsed!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.timestamp == blockFromRlp.timestamp), "timestamp in given RLP not matching the block timestamp!"); - TBOOST_CHECK_MESSAGE((blockHeaderFromFields.extraData == blockFromRlp.extraData), "extraData in given RLP not matching the block extraData!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.timestamp() == blockFromRlp.timestamp()), "timestamp in given RLP not matching the block timestamp!"); + TBOOST_CHECK_MESSAGE((blockHeaderFromFields.extraData() == blockFromRlp.extraData()), "extraData in given RLP not matching the block extraData!"); TBOOST_CHECK_MESSAGE((blockHeaderFromFields.mixHash == blockFromRlp.mixHash), "mixHash in given RLP not matching the block mixHash!"); TBOOST_CHECK_MESSAGE((blockHeaderFromFields.nonce == blockFromRlp.nonce), "nonce in given RLP not matching the block nonce!"); @@ -551,7 +551,7 @@ mArray importUncles(mObject const& _blObj, vector& _vBiUncles, vector BlockInfo uncleBlockFromFields = constructBlock(uncleHeaderObj); // make uncle header valid - uncleBlockFromFields.timestamp = (u256)time(0); + uncleBlockFromFields.timestamp() = (u256)time(0); cnote << "uncle block n = " << toString(uncleBlockFromFields.number); if (_vBiBlocks.size() > 2) { @@ -568,15 +568,15 @@ mArray importUncles(mObject const& _blObj, vector& _vBiUncles, vector uncleBlockFromFields.difficulty = overwrite == "difficulty" ? toInt(uncleHeaderObj["difficulty"]) : uncleBlockFromFields.difficulty; uncleBlockFromFields.gasLimit = overwrite == "gasLimit" ? toInt(uncleHeaderObj["gasLimit"]) : uncleBlockFromFields.gasLimit; uncleBlockFromFields.gasUsed = overwrite == "gasUsed" ? toInt(uncleHeaderObj["gasUsed"]) : uncleBlockFromFields.gasUsed; - uncleBlockFromFields.parentHash = overwrite == "parentHash" ? h256(uncleHeaderObj["parentHash"].get_str()) : uncleBlockFromFields.parentHash; - uncleBlockFromFields.stateRoot = overwrite == "stateRoot" ? h256(uncleHeaderObj["stateRoot"].get_str()) : uncleBlockFromFields.stateRoot; + uncleBlockFromFields.parentHash() = overwrite == "parentHash" ? h256(uncleHeaderObj["parentHash"].get_str()) : uncleBlockFromFields.parentHash(); + uncleBlockFromFields.stateRoot() = overwrite == "stateRoot" ? h256(uncleHeaderObj["stateRoot"].get_str()) : uncleBlockFromFields.stateRoot(); if (overwrite == "parentHashIsBlocksParent") uncleBlockFromFields.populateFromParent(_vBiBlocks[_vBiBlocks.size() - 1]); if (overwrite == "timestamp") { - uncleBlockFromFields.timestamp = toInt(uncleHeaderObj["timestamp"]); + uncleBlockFromFields.timestamp() = toInt(uncleHeaderObj["timestamp"]); uncleBlockFromFields.difficulty = uncleBlockFromFields.calculateDifficulty(_vBiBlocks[(size_t)uncleBlockFromFields.number - 1]); } } @@ -660,19 +660,19 @@ void overwriteBlockHeader(BlockInfo& _header, mObject& _blObj) { BlockInfo tmp = _header; if (ho.count("parentHash")) - tmp.parentHash = h256(ho["parentHash"].get_str()); + tmp.parentHash() = h256(ho["parentHash"].get_str()); if (ho.count("uncleHash")) - tmp.sha3Uncles = h256(ho["uncleHash"].get_str()); + tmp.sha3Uncles() = h256(ho["uncleHash"].get_str()); if (ho.count("coinbase")) - tmp.coinbaseAddress = Address(ho["coinbase"].get_str()); + tmp.coinbaseAddress() = Address(ho["coinbase"].get_str()); if (ho.count("stateRoot")) - tmp.stateRoot = h256(ho["stateRoot"].get_str()); + tmp.stateRoot() = h256(ho["stateRoot"].get_str()); if (ho.count("transactionsTrie")) - tmp.transactionsRoot = h256(ho["transactionsTrie"].get_str()); + tmp.transactionsRoot() = h256(ho["transactionsTrie"].get_str()); if (ho.count("receiptTrie")) - tmp.receiptsRoot = h256(ho["receiptTrie"].get_str()); + tmp.receiptsRoot() = h256(ho["receiptTrie"].get_str()); if (ho.count("bloom")) - tmp.logBloom = LogBloom(ho["bloom"].get_str()); + tmp.logBloom() = LogBloom(ho["bloom"].get_str()); if (ho.count("difficulty")) tmp.difficulty = toInt(ho["difficulty"]); if (ho.count("number")) @@ -682,9 +682,9 @@ void overwriteBlockHeader(BlockInfo& _header, mObject& _blObj) if (ho.count("gasUsed")) tmp.gasUsed = toInt(ho["gasUsed"]); if (ho.count("timestamp")) - tmp.timestamp = toInt(ho["timestamp"]); + tmp.timestamp() = toInt(ho["timestamp"]); if (ho.count("extraData")) - tmp.extraData = importByteArray(ho["extraData"].get_str()); + tmp.extraData() = importByteArray(ho["extraData"].get_str()); // find new valid nonce if (tmp != _header && tmp.difficulty) @@ -751,19 +751,19 @@ mArray writeTransactionsToJson(Transactions const& txs) mObject writeBlockHeaderToJson(mObject& _o, BlockInfo const& _bi) { - _o["parentHash"] = toString(_bi.parentHash); - _o["uncleHash"] = toString(_bi.sha3Uncles); - _o["coinbase"] = toString(_bi.coinbaseAddress); - _o["stateRoot"] = toString(_bi.stateRoot); - _o["transactionsTrie"] = toString(_bi.transactionsRoot); - _o["receiptTrie"] = toString(_bi.receiptsRoot); - _o["bloom"] = toString(_bi.logBloom); + _o["parentHash"] = toString(_bi.parentHash()); + _o["uncleHash"] = toString(_bi.sha3Uncles()); + _o["coinbase"] = toString(_bi.coinbaseAddress()); + _o["stateRoot"] = toString(_bi.stateRoot()); + _o["transactionsTrie"] = toString(_bi.transactionsRoot()); + _o["receiptTrie"] = toString(_bi.receiptsRoot()); + _o["bloom"] = toString(_bi.logBloom()); _o["difficulty"] = toCompactHex(_bi.difficulty, HexPrefix::Add, 1); - _o["number"] = toCompactHex(_bi.number, HexPrefix::Add, 1); + _o["number"] = toCompactHex(_bi.number(), HexPrefix::Add, 1); _o["gasLimit"] = toCompactHex(_bi.gasLimit, HexPrefix::Add, 1); _o["gasUsed"] = toCompactHex(_bi.gasUsed, HexPrefix::Add, 1); - _o["timestamp"] = toCompactHex(_bi.timestamp, HexPrefix::Add, 1); - _o["extraData"] = toHex(_bi.extraData, 2, HexPrefix::Add); + _o["timestamp"] = toCompactHex(_bi.timestamp(), HexPrefix::Add, 1); + _o["extraData"] = toHex(_bi.extraData(), 2, HexPrefix::Add); _o["mixHash"] = toString(_bi.mixHash); _o["nonce"] = toString(_bi.nonce); _o["hash"] = toString(_bi.hash()); diff --git a/test/libethereum/genesis.cpp b/test/libethereum/genesis.cpp index 02ff4517a..2d5a2faa6 100644 --- a/test/libethereum/genesis.cpp +++ b/test/libethereum/genesis.cpp @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(genesis_tests) js::mObject o = v.get_obj(); - BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot, h256(o["genesis_state_root"].get_str())); + BOOST_CHECK_EQUAL(CanonBlockChain::genesis().stateRoot(), h256(o["genesis_state_root"].get_str())); BOOST_CHECK_EQUAL(toHex(CanonBlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); BOOST_CHECK_EQUAL(BlockInfo::headerHash(CanonBlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); } diff --git a/test/libevm/vm.cpp b/test/libevm/vm.cpp index fdfb180fb..28b2e43ab 100644 --- a/test/libevm/vm.cpp +++ b/test/libevm/vm.cpp @@ -83,10 +83,10 @@ void FakeExtVM::reset(u256 _myBalance, u256 _myNonce, map const& _st mObject FakeExtVM::exportEnv() { mObject ret; - ret["previousHash"] = toString(currentBlock.parentHash); + ret["previousHash"] = toString(currentBlock.parentHash()); ret["currentDifficulty"] = toCompactHex(currentBlock.difficulty, HexPrefix::Add, 1); - ret["currentTimestamp"] = toCompactHex(currentBlock.timestamp, HexPrefix::Add, 1); - ret["currentCoinbase"] = toString(currentBlock.coinbaseAddress); + ret["currentTimestamp"] = toCompactHex(currentBlock.timestamp(), HexPrefix::Add, 1); + ret["currentCoinbase"] = toString(currentBlock.coinbaseAddress()); ret["currentNumber"] = toCompactHex(currentBlock.number, HexPrefix::Add, 1); ret["currentGasLimit"] = toCompactHex(currentBlock.gasLimit, HexPrefix::Add, 1); return ret; @@ -102,13 +102,13 @@ void FakeExtVM::importEnv(mObject& _o) assert(_o.count("currentCoinbase") > 0); assert(_o.count("currentNumber") > 0); - currentBlock.parentHash = h256(_o["previousHash"].get_str()); + currentBlock.parentHash() = h256(_o["previousHash"].get_str()); currentBlock.number = toInt(_o["currentNumber"]); lastHashes = test::lastHashes(currentBlock.number); currentBlock.gasLimit = toInt(_o["currentGasLimit"]); currentBlock.difficulty = toInt(_o["currentDifficulty"]); - currentBlock.timestamp = toInt(_o["currentTimestamp"]); - currentBlock.coinbaseAddress = Address(_o["currentCoinbase"].get_str()); + currentBlock.timestamp() = toInt(_o["currentTimestamp"]); + currentBlock.coinbaseAddress() = Address(_o["currentCoinbase"].get_str()); } mObject FakeExtVM::exportState() diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 9f806347e..be44ea009 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1187,7 +1187,7 @@ BOOST_AUTO_TEST_CASE(now) { char const* sourceCode = "contract test {\n" " function someInfo() returns (bool success) {\n" - " return block.timestamp == now && now > 0;\n" + " return block.timestamp() == now && now > 0;\n" " }\n" "}\n"; compileAndRun(sourceCode); diff --git a/third/MainWin.cpp b/third/MainWin.cpp index f2a90cc0b..a3b05572f 100644 --- a/third/MainWin.cpp +++ b/third/MainWin.cpp @@ -100,7 +100,7 @@ Main::Main(QWidget *parent) : setWindowFlags(Qt::Window); ui->setupUi(this); - cerr << "State root: " << CanonBlockChain::genesis().stateRoot << endl; + cerr << "State root: " << CanonBlockChain::genesis().stateRoot() << endl; auto gb = CanonBlockChain::createGenesisBlock(); cerr << "Block Hash: " << sha3(gb) << endl; cerr << "Block RLP: " << RLP(gb) << endl;