Browse Source

Merge branch 'develop' into crypto

cl-refactor
subtly 10 years ago
parent
commit
329461561f
  1. 18
      libdevcore/Common.cpp
  2. 17
      libdevcore/Common.h
  3. 16
      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 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;
}
} }

17
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 asserts(A) ::dev::assertAux(A, #A, __LINE__, __FILE__, ETH_FUNC)
#define assertsEqual(A, B) ::dev::assertEqualAux(A, B, #A, #B, __LINE__, __FILE__, ETH_FUNC) #define assertsEqual(A, B) ::dev::assertEqualAux(A, B, #A, #B, __LINE__, __FILE__, ETH_FUNC)
#if defined(__GNUC__) inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func)
__attribute__((gnu_inline, always_inline)) {
bool ret = _a;
if (!ret)
{
std::cerr << "Assertion failed:" << _aStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl;
#if ETH_DEBUG
debug_break();
#endif #endif
inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func); }
return !ret;
}
template<class A, class B> 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) 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; bool ret = _a == _b;

16
libethereum/EthereumHost.cpp

@ -148,17 +148,19 @@ void EthereumHost::doWork()
{ {
bool netChange = ensureInitialised(); bool netChange = ensureInitialised();
auto h = m_chain.currentHash(); auto h = m_chain.currentHash();
maintainTransactions(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); maintainBlocks(h);
}
// return netChange; // return netChange;
// TODO: Figure out what to do with netChange. // TODO: Figure out what to do with netChange.
(void)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. // Send any new transactions.
for (auto const& p: peers()) for (auto const& p: peers())
if (auto ep = p->cap<EthereumPeer>()) if (auto ep = p->cap<EthereumPeer>())
@ -166,7 +168,7 @@ void EthereumHost::maintainTransactions(h256 _currentHash)
bytes b; bytes b;
unsigned n = 0; unsigned n = 0;
for (auto const& i: m_tq.transactions()) 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; b += i.second;
++n; ++n;
@ -186,8 +188,8 @@ void EthereumHost::maintainTransactions(h256 _currentHash)
void EthereumHost::maintainBlocks(h256 _currentHash) void EthereumHost::maintainBlocks(h256 _currentHash)
{ {
// If we've finished our initial sync send any new blocks. // Send any new blocks.
if (!isSyncing() && m_chain.isKnown(m_latestBlockSent) && m_chain.details(m_latestBlockSent).totalDifficulty < m_chain.details(_currentHash).totalDifficulty) if (m_chain.details(m_latestBlockSent).totalDifficulty < m_chain.details(_currentHash).totalDifficulty)
{ {
clog(NetMessageSummary) << "Sending a new block (current is" << _currentHash << ", was" << m_latestBlockSent << ")"; 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. /// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network.
void doWork(); void doWork();
void maintainTransactions(h256 _currentBlock); void maintainTransactions();
void maintainBlocks(h256 _currentBlock); void maintainBlocks(h256 _currentBlock);
/// Get a bunch of needed blocks. /// 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" : ""); 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; RLPStream s;
if (_a == Asking::State) if (_a == Asking::State)
{ {
if (m_asking == Asking::Nothing) if (m_asking == Asking::Nothing)
@ -324,11 +328,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
} }
break; break;
} }
case GetTransactionsPacket: case GetTransactionsPacket: break; // DEPRECATED.
{
m_requireTransactions = true;
break;
}
case TransactionsPacket: case TransactionsPacket:
{ {
clogS(NetMessageSummary) << "Transactions (" << dec << (_r.itemCount() - 1) << "entries)"; 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); auto nonceReq = m_s.transactionsFrom(m_sender);
if (m_t.nonce != nonceReq) 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)); 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. // 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) 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()); BOOST_THROW_EXCEPTION(GasPriceTooLow());
} }
@ -70,7 +70,7 @@ bool Executive::setup(bytesConstRef _rlp)
if (m_t.gas < gasCost) 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()); BOOST_THROW_EXCEPTION(OutOfGas());
} }
@ -79,14 +79,14 @@ bool Executive::setup(bytesConstRef _rlp)
// Avoid unaffordable transactions. // Avoid unaffordable transactions.
if (m_s.balance(m_sender) < cost) 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()); BOOST_THROW_EXCEPTION(NotEnoughCash());
} }
u256 startGasUsed = m_s.gasUsed(); u256 startGasUsed = m_s.gasUsed();
if (startGasUsed + m_t.gas > m_s.m_currentBlock.gasLimit) 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()); BOOST_THROW_EXCEPTION(BlockGasLimitReached());
} }
@ -94,7 +94,7 @@ bool Executive::setup(bytesConstRef _rlp)
m_s.noteSending(m_sender); m_s.noteSending(m_sender);
// Pay... // 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); m_s.subBalance(m_sender, cost);
if (m_ms) if (m_ms)

3
libethereum/State.h

@ -47,8 +47,9 @@ namespace eth
class BlockChain; 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 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 struct TransactionReceipt
{ {

Loading…
Cancel
Save