diff --git a/eth/main.cpp b/eth/main.cpp index 095540a1c..27e5f4ca0 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -124,9 +124,11 @@ void help() << " --password Give a password for a private key." << endl << endl << "Client transacting:" << endl - << " -B,--block-fees Set the block fee profit in the reference unit e.g. ¢ (default: 15)." << endl + /*<< " -B,--block-fees Set the block fee profit in the reference unit e.g. ¢ (default: 15)." << endl << " -e,--ether-price Set the ether price in the reference unit e.g. ¢ (default: 30.679)." << endl - << " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl + << " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl*/ + << " --ask Set the minimum ask gas price under which no transactions will be mined (default 500000000000)." << endl + << " --bid Set the bid gas price for to pay for transactions (default 500000000000)." << endl << endl << "Client mining:" << endl << " -a,--address Set the coinbase (mining payout) address to addr (default: auto)." << endl @@ -299,8 +301,10 @@ int main(int argc, char** argv) /// Transaction params TransactionPriority priority = TransactionPriority::Medium; - double etherPrice = 30.679; - double blockFees = 15.0; +// double etherPrice = 30.679; +// double blockFees = 15.0; + u256 askPrice("500000000000"); + u256 bidPrice("500000000000"); // javascript console bool useConsole = false; @@ -464,7 +468,7 @@ int main(int argc, char** argv) } else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc) dbPath = argv[++i]; - else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc) +/* else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc) { try { @@ -487,6 +491,30 @@ int main(int argc, char** argv) cerr << "Bad " << arg << " option: " << argv[i] << endl; return -1; } + }*/ + else if (arg == "--ask" && i + 1 < argc) + { + try + { + askPrice = u256(argv[++i]); + } + catch (...) + { + cerr << "Bad " << arg << " option: " << argv[i] << endl; + return -1; + } + } + else if (arg == "--bid" && i + 1 < argc) + { + try + { + bidPrice = u256(argv[++i]); + } + catch (...) + { + cerr << "Bad " << arg << " option: " << argv[i] << endl; + return -1; + } } else if ((arg == "-P" || arg == "--priority") && i + 1 < argc) { @@ -730,7 +758,8 @@ int main(int argc, char** argv) cout << ethCredits(); web3.setIdealPeerCount(peers); - std::shared_ptr gasPricer = make_shared(u256(double(ether / 1000) / etherPrice), u256(blockFees * 1000)); +// std::shared_ptr gasPricer = make_shared(u256(double(ether / 1000) / etherPrice), u256(blockFees * 1000)); + std::shared_ptr gasPricer = make_shared(askPrice, bidPrice); eth::Client* c = nodeMode == NodeMode::Full ? web3.ethereum() : nullptr; StructuredLogger::starting(clientImplString, dev::Version); if (c) @@ -829,7 +858,7 @@ int main(int argc, char** argv) iss >> enable; c->setForceMining(isTrue(enable)); } - else if (c && cmd == "setblockfees") +/* else if (c && cmd == "setblockfees") { iss >> blockFees; try @@ -884,7 +913,7 @@ int main(int argc, char** argv) cerr << "Unknown priority: " << m << endl; } cout << "Priority: " << (int)priority << "/8" << endl; - } + }*/ else if (cmd == "verbosity") { if (iss.peek() != -1) diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index ebbde4d07..68619d627 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -54,7 +54,7 @@ EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQu EthereumHost::~EthereumHost() { - forEachPeer([](EthereumPeer* _p) { _p->abortSync(); }); + foreachPeer([](EthereumPeer* _p) { _p->abortSync(); }); } bool EthereumHost::ensureInitialised() @@ -74,7 +74,7 @@ bool EthereumHost::ensureInitialised() void EthereumHost::reset() { - forEachPeer([](EthereumPeer* _p) { _p->abortSync(); }); + foreachPeer([](EthereumPeer* _p) { _p->abortSync(); }); m_man.resetToChain(h256s()); m_hashMan.reset(m_chain.number() + 1); m_needSyncBlocks = true; @@ -105,7 +105,7 @@ void EthereumHost::doWork() } } - forEachPeer([](EthereumPeer* _p) { _p->tick(); }); + foreachPeer([](EthereumPeer* _p) { _p->tick(); }); // return netChange; // TODO: Figure out what to do with netChange. @@ -125,7 +125,7 @@ void EthereumHost::maintainTransactions() } for (auto const& t: ts) m_transactionsSent.insert(t.first); - forEachPeerPtr([&](shared_ptr _p) + foreachPeerPtr([&](shared_ptr _p) { bytes b; unsigned n = 0; @@ -148,16 +148,16 @@ void EthereumHost::maintainTransactions() }); } -void EthereumHost::forEachPeer(std::function const& _f) const +void EthereumHost::foreachPeer(std::function const& _f) const { - forEachPeerPtr([&](std::shared_ptr _p) + foreachPeerPtr([&](std::shared_ptr _p) { if (_p) _f(_p.get()); }); } -void EthereumHost::forEachPeerPtr(std::function)> const& _f) const +void EthereumHost::foreachPeerPtr(std::function)> const& _f) const { for (auto s: peerSessions()) _f(s.first->cap()); @@ -551,7 +551,7 @@ void EthereumHost::onPeerTransactions(EthereumPeer* _peer, RLP const& _r) void EthereumHost::continueSync() { clog(NetAllDetail) << "Getting help with downloading hashes and blocks"; - forEachPeer([&](EthereumPeer* _p) + foreachPeer([&](EthereumPeer* _p) { if (_p->m_asking == Asking::Nothing) continueSync(_p); @@ -564,7 +564,7 @@ void EthereumHost::continueSync(EthereumPeer* _peer) bool otherPeerSync = false; if (m_needSyncHashes && peerShouldGrabChain(_peer)) { - forEachPeer([&](EthereumPeer* _p) + foreachPeer([&](EthereumPeer* _p) { if (_p != _peer && _p->m_asking == Asking::Hashes && _p->m_protocolVersion != protocolVersion()) otherPeerSync = true; // Already have a peer downloading hash chain with old protocol, do nothing @@ -630,7 +630,7 @@ bool EthereumHost::isSyncing_UNSAFE() const /// We need actual peer information here to handle the case when we are the first ever peer on the network to mine. /// I.e. on a new private network the first node mining has noone to sync with and should start block propogation immediately. bool syncing = false; - forEachPeer([&](EthereumPeer* _p) + foreachPeer([&](EthereumPeer* _p) { if (_p->m_asking != Asking::Nothing) syncing = true; diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index ff0fc9607..8ca815a17 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -92,8 +92,8 @@ public: private: std::tuple>, std::vector>, std::vector>> randomSelection(unsigned _percent = 25, std::function const& _allow = [](EthereumPeer const*){ return true; }); - void forEachPeerPtr(std::function)> const& _f) const; - void forEachPeer(std::function const& _f) const; + void foreachPeerPtr(std::function)> const& _f) const; + void foreachPeer(std::function const& _f) const; bool isSyncing_UNSAFE() const; /// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network. diff --git a/libethereum/State.h b/libethereum/State.h index afdf41735..ea54d153d 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -84,9 +84,16 @@ public: class TrivialGasPricer: public GasPricer { -protected: - u256 ask(State const&) const override { return 10 * szabo; } - u256 bid(TransactionPriority = TransactionPriority::Medium) const override { return 10 * szabo; } +public: + TrivialGasPricer() = default; + TrivialGasPricer(u256 const& _ask, u256 const& _bid): m_ask(_ask), m_bid(_bid) {} + + u256 ask(State const&) const override { return m_ask; } + u256 bid(TransactionPriority = TransactionPriority::Medium) const override { return m_bid; } + +private: + u256 m_ask = 10 * szabo; + u256 m_bid = 10 * szabo; }; enum class Permanence