From 77a44c0f1b73b526a9736bd8539ea19bc498b6bc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 19 Feb 2014 23:56:33 +0000 Subject: [PATCH] Do transactions in correct order. Another minor fix. --- alethzero/MainWin.cpp | 21 ++++++++++----------- libethereum/Client.h | 2 +- libethereum/Instruction.h | 2 +- libethereum/State.cpp | 12 ++++++++---- libethereum/State.h | 5 +++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index ed9a0978f..6d0bd5151 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -190,20 +190,19 @@ void Main::refresh() } ui->transactionQueue->clear(); - for (pair const& i: m_client->pending()) + for (Transaction const& t: m_client->pending()) { - Transaction t = i.second; QString s = t.receiveAddress ? QString("%1 [%4] %2 %5> %3") .arg(formatBalance(t.value).c_str()) - .arg(t.safeSender().abridged().c_str()) - .arg(t.receiveAddress.abridged().c_str()) + .arg(render(t.safeSender())) + .arg(render(t.receiveAddress)) .arg((unsigned)t.nonce) .arg(m_client->state().isContractAddress(t.receiveAddress) ? '*' : '-') : QString("%1 [%4] %2 +> %3") .arg(formatBalance(t.value).c_str()) - .arg(t.safeSender().abridged().c_str()) - .arg(right160(t.sha3()).abridged().c_str()) + .arg(render(t.safeSender())) + .arg(render(right160(t.sha3()))) .arg((unsigned)t.nonce); ui->transactionQueue->addItem(s); } @@ -222,14 +221,14 @@ void Main::refresh() QString s = t.receiveAddress ? QString(" %1 [%4] %2 %5> %3") .arg(formatBalance(t.value).c_str()) - .arg(t.safeSender().abridged().c_str()) - .arg(t.receiveAddress.abridged().c_str()) + .arg(render(t.safeSender())) + .arg(render(t.receiveAddress)) .arg((unsigned)t.nonce) .arg(m_client->state().isContractAddress(t.receiveAddress) ? '*' : '-') : QString(" %1 [%4] %2 +> %3") .arg(formatBalance(t.value).c_str()) - .arg(t.safeSender().abridged().c_str()) - .arg(right160(t.sha3()).abridged().c_str()) + .arg(render(t.safeSender())) + .arg(render(right160(t.sha3()))) .arg((unsigned)t.nonce); QListWidgetItem* txItem = new QListWidgetItem(s, ui->blocks); txItem->setData(Qt::UserRole, QByteArray((char const*)h.data(), h.size)); @@ -247,7 +246,7 @@ void Main::refresh() for (auto i: m_myKeys) { u256 b = m_client->state().balance(i.address()); - (new QListWidgetItem(QString("%1 [%3] @ %2").arg(formatBalance(b).c_str()).arg(i.address().abridged().c_str()).arg((unsigned)m_client->state().transactionsFrom(i.address())), ui->ourAccounts)) + (new QListWidgetItem(QString("%1 [%3] @ %2").arg(formatBalance(b).c_str()).arg(render(i.address())).arg((unsigned)m_client->state().transactionsFrom(i.address())), ui->ourAccounts)) ->setData(Qt::UserRole, QByteArray((char const*)i.address().data(), Address::size)); totalBalance += b; } diff --git a/libethereum/Client.h b/libethereum/Client.h index ab377d73d..9a4c68e54 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -102,7 +102,7 @@ public: /// Get the object representing the current canonical blockchain. BlockChain const& blockChain() const { return m_bc; } /// Get a map containing each of the pending transactions. - std::map const& pending() const { return m_postMine.pending(); } + Transactions const& pending() const { return m_postMine.pending(); } void setClientVersion(std::string const& _name) { m_clientVersion = _name; } diff --git a/libethereum/Instruction.h b/libethereum/Instruction.h index 657153d05..1c17e61a6 100644 --- a/libethereum/Instruction.h +++ b/libethereum/Instruction.h @@ -176,7 +176,7 @@ static const std::map c_instructions = { "BLK_NUMBER", Instruction::BLK_NUMBER }, { "BLK_DIFFICULTY", Instruction::BLK_DIFFICULTY }, { "BLK_NONCE", Instruction::BLK_NONCE }, - { "BASFEEE", Instruction::BASEFEE }, + { "BASEFEE", Instruction::BASEFEE }, { "SHA256", Instruction::SHA256 }, { "RIPEMD160", Instruction::RIPEMD160 }, { "ECMUL", Instruction::ECMUL }, diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 7f0affcae..2d080aab0 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -111,6 +111,7 @@ State::State(State const& _s): m_db(_s.m_db), m_state(&m_db, _s.m_state.root()), m_transactions(_s.m_transactions), + m_transactionSet(_s.m_transactionSet), m_cache(_s.m_cache), m_previousBlock(_s.m_previousBlock), m_currentBlock(_s.m_currentBlock), @@ -126,6 +127,7 @@ State& State::operator=(State const& _s) m_db = _s.m_db; m_state.open(&m_db, _s.m_state.root()); m_transactions = _s.m_transactions; + m_transactionSet = _s.m_transactionSet; m_cache = _s.m_cache; m_previousBlock = _s.m_previousBlock; m_currentBlock = _s.m_currentBlock; @@ -271,6 +273,7 @@ map State::addresses() const void State::resetCurrent() { m_transactions.clear(); + m_transactionSet.clear(); m_cache.clear(); m_currentBlock = BlockInfo(); m_currentBlock.coinbaseAddress = m_ourAddress; @@ -291,7 +294,7 @@ bool State::cull(TransactionQueue& _tq) const auto ts = _tq.transactions(); for (auto const& i: ts) { - if (!m_transactions.count(i.first)) + if (!m_transactionSet.count(i.first)) { try { @@ -319,7 +322,7 @@ bool State::sync(TransactionQueue& _tq) auto ts = _tq.transactions(); for (auto const& i: ts) { - if (!m_transactions.count(i.first)) + if (!m_transactionSet.count(i.first)) { // don't have it yet! Execute it now. try @@ -472,7 +475,7 @@ void State::commitToMine(BlockChain const& _bc) RLPStream txs(m_transactions.size()); for (auto const& i: m_transactions) - i.second.fillStream(txs); + i.fillStream(txs); txs.swapOut(m_currentTxs); uncles.swapOut(m_currentUncles); @@ -625,7 +628,8 @@ void State::execute(bytesConstRef _rlp) // NOTE: Here, contract-originated transactions will not get added to the transaction list. // If this is wrong, move this line into execute(Transaction const& _t, Address _sender) and // don't forget to allow unsigned transactions in the tx list if they concur with the script execution. - m_transactions.insert(make_pair(t.sha3(), t)); + m_transactions.push_back(t); + m_transactionSet.insert(t.sha3()); } void State::applyRewards(Addresses const& _uncleAddresses) diff --git a/libethereum/State.h b/libethereum/State.h index af7166eb5..5b0992e0b 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -171,7 +171,7 @@ public: h256 rootHash() const { return m_state.root(); } /// Get the list of pending transactions. - std::map const& pending() const { return m_transactions; } + Transactions const& pending() const { return m_transactions; } /// Execute all transactions within a given block. /// @returns the additional total difficulty. @@ -229,7 +229,8 @@ private: Overlay m_db; ///< Our overlay for the state tree. TrieDB m_state; ///< Our state tree, as an Overlay DB. - std::map m_transactions; ///< The current list of transactions that we've included in the state. + Transactions m_transactions; ///< The current list of transactions that we've included in the state. + std::set m_transactionSet; ///< The set of transaction hashes that we've included in the state. mutable std::map m_cache; ///< Our address cache. This stores the states of each address that has (or at least might have) been changed.