Browse Source

Merge branch 'develop' into crypto

cl-refactor
subtly 10 years ago
parent
commit
329461561f
  1. 18
      libdevcore/Common.cpp
  2. 19
      libdevcore/Common.h
  3. 20
      libethereum/EthereumHost.cpp
  4. 2
      libethereum/EthereumHost.h
  5. 10
      libethereum/EthereumPeer.cpp
  6. 12
      libethereum/Executive.cpp
  7. 3
      libethereum/State.h

18
libdevcore/Common.cpp

@ -27,23 +27,7 @@ using namespace dev;
namespace dev
{
char const* Version = "0.7.3";
char const* Version = "0.7.4";
#if defined(__GNUC__)
__attribute__((gnu_inline, always_inline))
#endif
inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func)
{
bool ret = _a;
if (!ret)
{
std::cerr << "Assertion failed:" << _aStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl;
#if ETH_DEBUG
debug_break();
#endif
}
return !ret;
}
}

19
libdevcore/Common.h

@ -117,15 +117,20 @@ inline unsigned int toLog2(u256 _x)
#define asserts(A) ::dev::assertAux(A, #A, __LINE__, __FILE__, ETH_FUNC)
#define assertsEqual(A, B) ::dev::assertEqualAux(A, B, #A, #B, __LINE__, __FILE__, ETH_FUNC)
#if defined(__GNUC__)
__attribute__((gnu_inline, always_inline))
inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func)
{
bool ret = _a;
if (!ret)
{
std::cerr << "Assertion failed:" << _aStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl;
#if ETH_DEBUG
debug_break();
#endif
inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func);
}
return !ret;
}
template<class A, class B>
#if defined(__GNUC__)
__attribute__((gnu_inline, always_inline))
#endif
inline bool assertEqualAux(A const& _a, B const& _b, char const* _aStr, char const* _bStr, unsigned _line, char const* _file, char const* _func)
{
bool ret = _a == _b;

20
libethereum/EthereumHost.cpp

@ -148,17 +148,19 @@ void EthereumHost::doWork()
{
bool netChange = ensureInitialised();
auto h = m_chain.currentHash();
maintainTransactions(h);
maintainBlocks(h);
// If we've finished our initial sync (including getting all the blocks into the chain so as to reduce invalid transactions), start trading transactions & blocks
if (!isSyncing() && m_chain.isKnown(m_latestBlockSent))
{
maintainTransactions();
maintainBlocks(h);
}
// return netChange;
// TODO: Figure out what to do with netChange.
(void)netChange;
}
void EthereumHost::maintainTransactions(h256 _currentHash)
void EthereumHost::maintainTransactions()
{
bool resendAll = (!isSyncing() && m_chain.isKnown(m_latestBlockSent) && _currentHash != m_latestBlockSent);
// Send any new transactions.
for (auto const& p: peers())
if (auto ep = p->cap<EthereumPeer>())
@ -166,14 +168,14 @@ void EthereumHost::maintainTransactions(h256 _currentHash)
bytes b;
unsigned n = 0;
for (auto const& i: m_tq.transactions())
if ((!m_transactionsSent.count(i.first) && !ep->m_knownTransactions.count(i.first)) || ep->m_requireTransactions || resendAll)
if (ep->m_requireTransactions || (!m_transactionsSent.count(i.first) && !ep->m_knownTransactions.count(i.first)))
{
b += i.second;
++n;
m_transactionsSent.insert(i.first);
}
ep->clearKnownTransactions();
if (n || ep->m_requireTransactions)
{
RLPStream ts;
@ -186,8 +188,8 @@ void EthereumHost::maintainTransactions(h256 _currentHash)
void EthereumHost::maintainBlocks(h256 _currentHash)
{
// If we've finished our initial sync send any new blocks.
if (!isSyncing() && m_chain.isKnown(m_latestBlockSent) && m_chain.details(m_latestBlockSent).totalDifficulty < m_chain.details(_currentHash).totalDifficulty)
// Send any new blocks.
if (m_chain.details(m_latestBlockSent).totalDifficulty < m_chain.details(_currentHash).totalDifficulty)
{
clog(NetMessageSummary) << "Sending a new block (current is" << _currentHash << ", was" << m_latestBlockSent << ")";

2
libethereum/EthereumHost.h

@ -84,7 +84,7 @@ private:
/// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network.
void doWork();
void maintainTransactions(h256 _currentBlock);
void maintainTransactions();
void maintainBlocks(h256 _currentBlock);
/// Get a bunch of needed blocks.

10
libethereum/EthereumPeer.cpp

@ -82,7 +82,11 @@ void EthereumPeer::transition(Asking _a, bool _force)
{
clogS(NetMessageSummary) << "Transition!" << ::toString(_a) << "from" << ::toString(m_asking) << ", " << (isSyncing() ? "syncing" : "holding") << (needsSyncing() ? "& needed" : "");
if (m_asking == Asking::State && _a != Asking::State)
m_requireTransactions = true;
RLPStream s;
if (_a == Asking::State)
{
if (m_asking == Asking::Nothing)
@ -324,11 +328,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
}
break;
}
case GetTransactionsPacket:
{
m_requireTransactions = true;
break;
}
case GetTransactionsPacket: break; // DEPRECATED.
case TransactionsPacket:
{
clogS(NetMessageSummary) << "Transactions (" << dec << (_r.itemCount() - 1) << "entries)";

12
libethereum/Executive.cpp

@ -54,14 +54,14 @@ bool Executive::setup(bytesConstRef _rlp)
auto nonceReq = m_s.transactionsFrom(m_sender);
if (m_t.nonce != nonceReq)
{
clog(StateChat) << "Invalid Nonce: Require" << nonceReq << " Got" << m_t.nonce;
clog(StateDetail) << "Invalid Nonce: Require" << nonceReq << " Got" << m_t.nonce;
BOOST_THROW_EXCEPTION(InvalidNonce(nonceReq, m_t.nonce));
}
// Don't like transactions whose gas price is too low. NOTE: this won't stay here forever - it's just until we get a proper gas price discovery protocol going.
if (m_t.gasPrice < m_s.m_currentBlock.minGasPrice)
{
clog(StateChat) << "Offered gas-price is too low: Require >" << m_s.m_currentBlock.minGasPrice << " Got" << m_t.gasPrice;
clog(StateDetail) << "Offered gas-price is too low: Require >" << m_s.m_currentBlock.minGasPrice << " Got" << m_t.gasPrice;
BOOST_THROW_EXCEPTION(GasPriceTooLow());
}
@ -70,7 +70,7 @@ bool Executive::setup(bytesConstRef _rlp)
if (m_t.gas < gasCost)
{
clog(StateChat) << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas;
clog(StateDetail) << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas;
BOOST_THROW_EXCEPTION(OutOfGas());
}
@ -79,14 +79,14 @@ bool Executive::setup(bytesConstRef _rlp)
// Avoid unaffordable transactions.
if (m_s.balance(m_sender) < cost)
{
clog(StateChat) << "Not enough cash: Require >" << cost << " Got" << m_s.balance(m_sender);
clog(StateDetail) << "Not enough cash: Require >" << cost << " Got" << m_s.balance(m_sender);
BOOST_THROW_EXCEPTION(NotEnoughCash());
}
u256 startGasUsed = m_s.gasUsed();
if (startGasUsed + m_t.gas > m_s.m_currentBlock.gasLimit)
{
clog(StateChat) << "Too much gas used in this block: Require <" << (m_s.m_currentBlock.gasLimit - startGasUsed) << " Got" << m_t.gas;
clog(StateDetail) << "Too much gas used in this block: Require <" << (m_s.m_currentBlock.gasLimit - startGasUsed) << " Got" << m_t.gas;
BOOST_THROW_EXCEPTION(BlockGasLimitReached());
}
@ -94,7 +94,7 @@ bool Executive::setup(bytesConstRef _rlp)
m_s.noteSending(m_sender);
// Pay...
// cnote << "Paying" << formatBalance(cost) << "from sender (includes" << m_t.gas << "gas at" << formatBalance(m_t.gasPrice) << ")";
clog(StateDetail) << "Paying" << formatBalance(cost) << "from sender (includes" << m_t.gas << "gas at" << formatBalance(m_t.gasPrice) << ")";
m_s.subBalance(m_sender, cost);
if (m_ms)

3
libethereum/State.h

@ -47,8 +47,9 @@ namespace eth
class BlockChain;
struct StateChat: public LogChannel { static const char* name() { return "=S="; } static const int verbosity = 4; };
struct StateChat: public LogChannel { static const char* name() { return "-S-"; } static const int verbosity = 4; };
struct StateTrace: public LogChannel { static const char* name() { return "=S="; } static const int verbosity = 7; };
struct StateDetail: public LogChannel { static const char* name() { return "/S/"; } static const int verbosity = 14; };
struct TransactionReceipt
{

Loading…
Cancel
Save