Browse Source

No fees for miners.

cl-refactor
Gav Wood 11 years ago
parent
commit
d29fbde366
  1. 9
      alethzero/MainWin.cpp
  2. 1
      alethzero/MainWin.h
  3. 12
      libethereum/BlockChain.cpp
  4. 6
      libethereum/BlockInfo.cpp
  5. 2
      libethereum/BlockInfo.h
  6. 7
      libethereum/Dagger.cpp
  7. 6
      libethereum/Dagger.h
  8. 6
      libethereum/Exceptions.h
  9. 9
      libethereum/State.cpp
  10. 2
      libethereum/State.h
  11. 5
      libethereum/TrieDB.h
  12. 8
      test/dagger.cpp

9
alethzero/MainWin.cpp

@ -48,6 +48,8 @@ Main::Main(QWidget *parent) :
srand(time(0));
#endif
on_verbosity_sliderMoved();
statusBar()->addPermanentWidget(ui->balance);
statusBar()->addPermanentWidget(ui->peerCount);
statusBar()->addPermanentWidget(ui->blockChain);
@ -109,7 +111,7 @@ void Main::readSettings()
void Main::refresh()
{
m_client->lock();
if (m_client->changed())
//if (m_client->changed())
{
ui->peerCount->setText(QString::fromStdString(toString(m_client->peerCount())) + " peer(s)");
ui->peers->clear();
@ -171,6 +173,11 @@ void Main::on_ourAccounts_doubleClicked()
qApp->clipboard()->setText(ui->ourAccounts->currentItem()->text().section(" @ ", 1));
}
void Main::on_log_doubleClicked()
{
qApp->clipboard()->setText(ui->log->currentItem()->text());
}
void Main::on_accounts_doubleClicked()
{
qApp->clipboard()->setText(ui->accounts->currentItem()->text().section(" @ ", 1));

1
alethzero/MainWin.h

@ -32,6 +32,7 @@ private slots:
void on_verbosity_sliderMoved();
void on_ourAccounts_doubleClicked();
void on_accounts_doubleClicked();
void on_log_doubleClicked();
void on_quit_triggered() { close(); }
void refresh();

12
libethereum/BlockChain.cpp

@ -131,13 +131,13 @@ void BlockChain::import(bytes const& _block, Overlay const& _db)
throw AlreadyHaveBlock();
}
cout << "Attempting import of " << newHash << "..." << endl;
cnote << "Attempting import of " << newHash << "...";
// Work out its number as the parent's number + 1
auto pd = details(bi.parentHash);
if (!pd)
{
cout << " Unknown parent " << bi.parentHash << endl;
cwarn << " Unknown parent " << bi.parentHash;
// We don't know the parent (yet) - discard for now. It'll get resent to us if we find out about its ancestry later on.
throw UnknownParent();
}
@ -170,19 +170,19 @@ void BlockChain::import(bytes const& _block, Overlay const& _db)
checkConsistency();
// cout << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children." << endl;
// cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children." << endl;
// This might be the new last block...
if (td > m_details[m_lastBlockHash].totalDifficulty)
{
m_lastBlockHash = newHash;
m_detailsDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&newHash, 32));
cout << " Imported and best." << endl;
cnote << " Imported and best.";
}
else
{
cout << " Imported." << endl;
// cerr << "*** WARNING: Imported block not newest (otd=" << m_details[m_lastBlockHash].totalDifficulty << ", td=" << td << ")" << endl;
cnote << " Imported.";
// cwarn << "Imported block not newest (otd=" << m_details[m_lastBlockHash].totalDifficulty << ", td=" << td << ")";
}
}

6
libethereum/BlockInfo.cpp

@ -53,7 +53,7 @@ bytes BlockInfo::createGenesisBlock()
stateRoot = state.root();
}
block.appendList(9) << h256() << sha3EmptyList << h160() << stateRoot << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << (uint)42;
block.appendList(9) << h256() << sha3EmptyList << h160() << stateRoot << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << sha3(bytes(1, 42));
block.appendRaw(RLPEmptyList);
block.appendRaw(RLPEmptyList);
return block.out();
@ -97,7 +97,7 @@ void BlockInfo::populate(bytesConstRef _block)
difficulty = header[field = 5].toInt<u256>();
timestamp = header[field = 6].toInt<u256>();
extraData = header[field = 7].toBytes();
nonce = header[field = 8].toInt<u256>();
nonce = header[field = 8].toHash<h256>();
}
catch (RLP::BadCast)
{
@ -110,7 +110,7 @@ void BlockInfo::populate(bytesConstRef _block)
throw InvalidBlockFormat(2, root[2].data());
// check it hashes according to proof of work or that it's the genesis block.
if (parentHash && !Dagger::verify(headerHashWithoutNonce(), nonce, difficulty))
throw InvalidNonce();
throw InvalidBlockNonce(headerHashWithoutNonce(), nonce, difficulty);
}
void BlockInfo::verifyInternals(bytesConstRef _block) const

2
libethereum/BlockInfo.h

@ -39,7 +39,7 @@ public:
u256 difficulty;
u256 timestamp;
bytes extraData;
u256 nonce;
h256 nonce;
BlockInfo();
explicit BlockInfo(bytesConstRef _block);

7
libethereum/Dagger.cpp

@ -22,11 +22,11 @@ namespace eth
#if FAKE_DAGGER
MineInfo Dagger::mine(u256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout, bool const& _continue)
MineInfo Dagger::mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout, bool const& _continue)
{
MineInfo ret{0, 0, false};
static std::mt19937_64 s_eng((time(0)));
o_solution = std::uniform_int_distribution<uint>(0, ~(uint)0)(s_eng);
u256 s = std::uniform_int_distribution<uint>(0, ~(uint)0)(s_eng);
bigint d = (bigint(1) << 256) / _difficulty;
ret.requirement = toLog2((u256)d);
@ -35,8 +35,9 @@ MineInfo Dagger::mine(u256& o_solution, h256 const& _root, u256 const& _difficul
// [--------*-------------------------]
//
// evaluate until we run out of time
for (auto startTime = steady_clock::now(); (steady_clock::now() - startTime) < milliseconds(_msTimeout) && _continue; o_solution += 1)
for (auto startTime = steady_clock::now(); (steady_clock::now() - startTime) < milliseconds(_msTimeout) && _continue; s++)
{
o_solution = (h256)s;
auto e = (bigint)(u256)eval(_root, o_solution);
ret.best = max(ret.best, toLog2((u256)e));
if (e <= d)

6
libethereum/Dagger.h

@ -24,10 +24,10 @@ struct MineInfo
class Dagger
{
public:
static h256 eval(h256 const& _root, u256 const& _nonce) { h256 b[2] = { _root, (h256)_nonce }; return sha3(bytesConstRef((byte const*)&b[0], 64)); }
static bool verify(h256 const& _root, u256 const& _nonce, u256 const& _difficulty) { return (bigint)(u256)eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; }
static h256 eval(h256 const& _root, h256 const& _nonce) { h256 b[2] = { _root, _nonce }; return sha3(bytesConstRef((byte const*)&b[0], 64)); }
static bool verify(h256 const& _root, h256 const& _nonce, u256 const& _difficulty) { return (bigint)(u256)eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; }
MineInfo mine(u256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout = 100, bool const& _continue = bool(true));
MineInfo mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout = 100, bool const& _continue = bool(true));
};
#else

6
libethereum/Exceptions.h

@ -9,7 +9,7 @@ namespace eth
class Exception: public std::exception
{
public:
virtual std::string description() const { return "Unknown exception"; }
virtual std::string description() const { return typeid(*this).name(); }
virtual char const* what() const noexcept { return typeid(*this).name(); }
};
@ -33,10 +33,12 @@ class InvalidTransactionsHash: public Exception {};
class InvalidTransaction: public Exception {};
class InvalidDifficulty: public Exception {};
class InvalidTimestamp: public Exception {};
class InvalidNonce: public Exception { public: InvalidNonce(u256 _required = 0, u256 _candidate = 0): required(_required), candidate(_candidate) {} u256 required; u256 candidate; };
class InvalidNonce: public Exception { public: InvalidNonce(u256 _required = 0, u256 _candidate = 0): required(_required), candidate(_candidate) {} u256 required; u256 candidate; virtual std::string description() const { return "Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"; } };
class InvalidBlockNonce: public Exception { public: InvalidBlockNonce(h256 _h = h256(), h256 _n = h256(), u256 _d = 0): h(_h), n(_n), d(_d) {} h256 h; h256 n; u256 d; virtual std::string description() const { return "Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"; } };
class InvalidParentHash: public Exception {};
class InvalidContractAddress: public Exception {};
class NoNetworking: public Exception {};
class NoUPnPDevice: public Exception {};
class RootNotFound: public Exception {};
}

9
libethereum/State.cpp

@ -53,7 +53,7 @@ u256 const State::c_extroFee = 40000;
u256 const State::c_cryptoFee = 50000;
u256 const State::c_newContractFee = 60000;
u256 const State::c_txFee = 0;
u256 const State::c_blockReward = 1000000000;
u256 const State::c_blockReward = 1000000000000;
#if NDEBUG
u256 const eth::c_genesisDifficulty = (u256)1 << 22;
@ -319,8 +319,11 @@ u256 State::playback(bytesConstRef _block, BlockInfo const& _grandParent, bool _
// Hash the state trie and check against the state_root hash in m_currentBlock.
if (m_currentBlock.stateRoot != rootHash())
{
cout << "*** BAD STATE ROOT!" << endl;
cout << m_state << endl << TrieDB<Address, Overlay>(&m_db, m_currentBlock.stateRoot);
cwarn << "Bad state root!";
cnote << "Given to be:" << m_currentBlock.stateRoot;
cnote << "Calculated to be:" << rootHash();
cnote << m_state;
cnote << TrieDB<Address, Overlay>(&m_db, m_currentBlock.stateRoot);
// Rollback the trie.
m_db.rollback();
throw InvalidStateRoot();

2
libethereum/State.h

@ -150,7 +150,7 @@ private:
/// Fee-adder on destruction RAII class.
struct MinerFeeAdder
{
~MinerFeeAdder() { state->addBalance(state->m_currentBlock.coinbaseAddress, fee); }
~MinerFeeAdder() { /*state->addBalance(state->m_currentBlock.coinbaseAddress, fee);*/ } // No fees paid now.
State* state;
u256 fee;
};

5
libethereum/TrieDB.h

@ -24,6 +24,7 @@
#include <map>
#include <memory>
#include <leveldb/db.h>
#include "Exceptions.h"
#include "TrieCommon.h"
namespace ldb = leveldb;
@ -108,10 +109,10 @@ public:
GenericTrieDB(DB* _db, h256 _root) { open(_db, _root); }
~GenericTrieDB() {}
void open(DB* _db, h256 _root) { setRoot(_root); m_db = _db; assert(node(m_root).size()); }
void open(DB* _db, h256 _root) { m_db = _db; setRoot(_root); }
void init();
void setRoot(h256 _root) { m_root = _root == h256() ? c_shaNull : _root; /*std::cout << "Setting root to " << _root << " (patched to " << m_root << ")" << std::endl;*/ assert(node(m_root).size()); }
void setRoot(h256 _root) { m_root = _root == h256() ? c_shaNull : _root; /*std::cout << "Setting root to " << _root << " (patched to " << m_root << ")" << std::endl;*/ if (!node(m_root).size()) throw RootNotFound(); }
h256 root() const { assert(node(m_root).size()); h256 ret = (m_root == c_shaNull ? h256() : m_root); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return ret; } // patch the root in the case of the empty trie. TODO: handle this properly.

8
test/dagger.cpp

@ -32,17 +32,17 @@ int daggerTest()
{
Dagger d;
auto s = steady_clock::now();
cout << hex << d.eval((h256)1, 0);
cout << hex << d.eval((h256)1, (h256)0);
cout << " " << dec << duration_cast<milliseconds>(steady_clock::now() - s).count() << " ms" << endl;
cout << hex << d.eval((h256)1, 1);
cout << hex << d.eval((h256)1, (h256)1);
cout << " " << dec << duration_cast<milliseconds>(steady_clock::now() - s).count() << " ms" << endl;
}
{
Dagger d;
auto s = steady_clock::now();
cout << hex << d.eval((h256)1, 0);
cout << hex << d.eval((h256)1, (h256)0);
cout << " " << dec << duration_cast<milliseconds>(steady_clock::now() - s).count() << " ms" << endl;
cout << hex << d.eval((h256)1, 1);
cout << hex << d.eval((h256)1, (h256)1);
cout << " " << dec << duration_cast<milliseconds>(steady_clock::now() - s).count() << " ms" << endl;
}
return 0;

Loading…
Cancel
Save