Browse Source

Do transactions in correct order.

Another minor fix.
cl-refactor
Gav Wood 11 years ago
parent
commit
77a44c0f1b
  1. 21
      alethzero/MainWin.cpp
  2. 2
      libethereum/Client.h
  3. 2
      libethereum/Instruction.h
  4. 12
      libethereum/State.cpp
  5. 5
      libethereum/State.h

21
alethzero/MainWin.cpp

@ -190,20 +190,19 @@ void Main::refresh()
}
ui->transactionQueue->clear();
for (pair<h256, Transaction> 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;
}

2
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<h256, Transaction> const& pending() const { return m_postMine.pending(); }
Transactions const& pending() const { return m_postMine.pending(); }
void setClientVersion(std::string const& _name) { m_clientVersion = _name; }

2
libethereum/Instruction.h

@ -176,7 +176,7 @@ static const std::map<std::string, Instruction> 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 },

12
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<Address, u256> 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)

5
libethereum/State.h

@ -171,7 +171,7 @@ public:
h256 rootHash() const { return m_state.root(); }
/// Get the list of pending transactions.
std::map<h256, Transaction> 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<Address, Overlay> m_state; ///< Our state tree, as an Overlay DB.
std::map<h256, Transaction> 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<h256> m_transactionSet; ///< The set of transaction hashes that we've included in the state.
mutable std::map<Address, AddressState> m_cache; ///< Our address cache. This stores the states of each address that has (or at least might have) been changed.

Loading…
Cancel
Save