Browse Source

Safer syncing of blockchain/txqueue to state.

Linux build fix.
cl-refactor
Gav Wood 11 years ago
parent
commit
1c4c161726
  1. 2
      CMakeLists.txt
  2. 7
      libethereum/Client.cpp
  3. 12
      libethereum/State.cpp
  4. 9
      libethereum/Transaction.h

2
CMakeLists.txt

@ -5,7 +5,7 @@ set(CMAKE_AUTOMOC ON)
cmake_policy(SET CMP0015 NEW)
set(ETH_VERSION 0.2.8)
set(ETH_VERSION 0.2.9)
set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE})
# Default HEADLESS to 0.

7
libethereum/Client.cpp

@ -100,12 +100,12 @@ void Client::transact(Secret _secret, Address _dest, u256 _amount, u256s _data)
{
lock_guard<mutex> l(m_lock);
Transaction t;
cnote << "New transaction " << t;
t.nonce = m_mined.transactionsFrom(toAddress(_secret));
t.receiveAddress = _dest;
t.value = _amount;
t.data = _data;
t.sign(_secret);
cnote << "New transaction " << t;
m_tq.attemptImport(t.rlp());
m_changed = true;
}
@ -140,8 +140,7 @@ void Client::work()
cnote << "Externally mined block: Restarting mining operation.";
changed = true;
m_miningStarted = true; // need to re-commit to mine.
if (!m_doMine)
m_mined = m_s;
m_mined = m_s;
}
if (m_mined.sync(m_tq))
{
@ -156,8 +155,6 @@ void Client::work()
if (m_miningStarted)
{
lock_guard<mutex> l(m_lock);
m_mined = m_s;
m_mined.sync(m_tq);
m_mined.commitToMine(m_bc);
}

12
libethereum/State.cpp

@ -414,6 +414,12 @@ u256 State::playback(bytesConstRef _block, BlockInfo const& _grandParent, bool _
// (i.e. all the transactions we executed).
void State::commitToMine(BlockChain const& _bc)
{
if (m_previousBlock.hash != m_committedPreviousHash)
{
m_committedPreviousHash = m_previousBlock.hash;
cnote << "Commiting to mine on" << m_previousBlock.hash;
}
if (m_currentBlock.sha3Transactions != h256() || m_currentBlock.sha3Uncles != h256())
return;
@ -459,12 +465,6 @@ void State::commitToMine(BlockChain const& _bc)
MineInfo State::mine(uint _msTimeout)
{
if (m_previousBlock.hash != m_committedPreviousHash)
{
m_committedPreviousHash = m_committedPreviousHash;
cnote << "Commiting to mine on" << m_previousBlock.hash;
}
// Update timestamp according to clock.
m_currentBlock.timestamp = time(0);

9
libethereum/Transaction.h

@ -63,7 +63,14 @@ using Transactions = std::vector<Transaction>;
inline std::ostream& operator<<(std::ostream& _out, Transaction const& _t)
{
_out << "{" << _t.receiveAddress << "/" << _t.nonce << "*" << _t.value << "}";
_out << "{" << _t.receiveAddress << "/" << _t.nonce << "*" << _t.value;
Address s;
try
{
_out << "<-" << _t.sender();
}
catch (...) {}
_out << "}";
return _out;
}

Loading…
Cancel
Save