Browse Source

--ask and --bid

cl-refactor
Gav Wood 10 years ago
parent
commit
fdff985a30
  1. 45
      eth/main.cpp
  2. 20
      libethereum/EthereumHost.cpp
  3. 4
      libethereum/EthereumHost.h
  4. 13
      libethereum/State.h

45
eth/main.cpp

@ -124,9 +124,11 @@ void help()
<< " --password <password> Give a password for a private key." << endl << " --password <password> Give a password for a private key." << endl
<< endl << endl
<< "Client transacting:" << endl << "Client transacting:" << endl
<< " -B,--block-fees <n> Set the block fee profit in the reference unit e.g. ¢ (default: 15)." << endl /*<< " -B,--block-fees <n> Set the block fee profit in the reference unit e.g. ¢ (default: 15)." << endl
<< " -e,--ether-price <n> Set the ether price in the reference unit e.g. ¢ (default: 30.679)." << endl << " -e,--ether-price <n> 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 <wei> Set the minimum ask gas price under which no transactions will be mined (default 500000000000)." << endl
<< " --bid <wei> Set the bid gas price for to pay for transactions (default 500000000000)." << endl
<< endl << endl
<< "Client mining:" << endl << "Client mining:" << endl
<< " -a,--address <addr> Set the coinbase (mining payout) address to addr (default: auto)." << endl << " -a,--address <addr> Set the coinbase (mining payout) address to addr (default: auto)." << endl
@ -299,8 +301,10 @@ int main(int argc, char** argv)
/// Transaction params /// Transaction params
TransactionPriority priority = TransactionPriority::Medium; TransactionPriority priority = TransactionPriority::Medium;
double etherPrice = 30.679; // double etherPrice = 30.679;
double blockFees = 15.0; // double blockFees = 15.0;
u256 askPrice("500000000000");
u256 bidPrice("500000000000");
// javascript console // javascript console
bool useConsole = false; 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) else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc)
dbPath = argv[++i]; dbPath = argv[++i];
else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc) /* else if ((arg == "-B" || arg == "--block-fees") && i + 1 < argc)
{ {
try try
{ {
@ -487,6 +491,30 @@ int main(int argc, char** argv)
cerr << "Bad " << arg << " option: " << argv[i] << endl; cerr << "Bad " << arg << " option: " << argv[i] << endl;
return -1; 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) else if ((arg == "-P" || arg == "--priority") && i + 1 < argc)
{ {
@ -730,7 +758,8 @@ int main(int argc, char** argv)
cout << ethCredits(); cout << ethCredits();
web3.setIdealPeerCount(peers); web3.setIdealPeerCount(peers);
std::shared_ptr<eth::BasicGasPricer> gasPricer = make_shared<eth::BasicGasPricer>(u256(double(ether / 1000) / etherPrice), u256(blockFees * 1000)); // std::shared_ptr<eth::BasicGasPricer> gasPricer = make_shared<eth::BasicGasPricer>(u256(double(ether / 1000) / etherPrice), u256(blockFees * 1000));
std::shared_ptr<eth::TrivialGasPricer> gasPricer = make_shared<eth::TrivialGasPricer>(askPrice, bidPrice);
eth::Client* c = nodeMode == NodeMode::Full ? web3.ethereum() : nullptr; eth::Client* c = nodeMode == NodeMode::Full ? web3.ethereum() : nullptr;
StructuredLogger::starting(clientImplString, dev::Version); StructuredLogger::starting(clientImplString, dev::Version);
if (c) if (c)
@ -829,7 +858,7 @@ int main(int argc, char** argv)
iss >> enable; iss >> enable;
c->setForceMining(isTrue(enable)); c->setForceMining(isTrue(enable));
} }
else if (c && cmd == "setblockfees") /* else if (c && cmd == "setblockfees")
{ {
iss >> blockFees; iss >> blockFees;
try try
@ -884,7 +913,7 @@ int main(int argc, char** argv)
cerr << "Unknown priority: " << m << endl; cerr << "Unknown priority: " << m << endl;
} }
cout << "Priority: " << (int)priority << "/8" << endl; cout << "Priority: " << (int)priority << "/8" << endl;
} }*/
else if (cmd == "verbosity") else if (cmd == "verbosity")
{ {
if (iss.peek() != -1) if (iss.peek() != -1)

20
libethereum/EthereumHost.cpp

@ -54,7 +54,7 @@ EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQu
EthereumHost::~EthereumHost() EthereumHost::~EthereumHost()
{ {
forEachPeer([](EthereumPeer* _p) { _p->abortSync(); }); foreachPeer([](EthereumPeer* _p) { _p->abortSync(); });
} }
bool EthereumHost::ensureInitialised() bool EthereumHost::ensureInitialised()
@ -74,7 +74,7 @@ bool EthereumHost::ensureInitialised()
void EthereumHost::reset() void EthereumHost::reset()
{ {
forEachPeer([](EthereumPeer* _p) { _p->abortSync(); }); foreachPeer([](EthereumPeer* _p) { _p->abortSync(); });
m_man.resetToChain(h256s()); m_man.resetToChain(h256s());
m_hashMan.reset(m_chain.number() + 1); m_hashMan.reset(m_chain.number() + 1);
m_needSyncBlocks = true; m_needSyncBlocks = true;
@ -105,7 +105,7 @@ void EthereumHost::doWork()
} }
} }
forEachPeer([](EthereumPeer* _p) { _p->tick(); }); foreachPeer([](EthereumPeer* _p) { _p->tick(); });
// return netChange; // return netChange;
// TODO: Figure out what to do with netChange. // TODO: Figure out what to do with netChange.
@ -125,7 +125,7 @@ void EthereumHost::maintainTransactions()
} }
for (auto const& t: ts) for (auto const& t: ts)
m_transactionsSent.insert(t.first); m_transactionsSent.insert(t.first);
forEachPeerPtr([&](shared_ptr<EthereumPeer> _p) foreachPeerPtr([&](shared_ptr<EthereumPeer> _p)
{ {
bytes b; bytes b;
unsigned n = 0; unsigned n = 0;
@ -148,16 +148,16 @@ void EthereumHost::maintainTransactions()
}); });
} }
void EthereumHost::forEachPeer(std::function<void(EthereumPeer*)> const& _f) const void EthereumHost::foreachPeer(std::function<void(EthereumPeer*)> const& _f) const
{ {
forEachPeerPtr([&](std::shared_ptr<EthereumPeer> _p) foreachPeerPtr([&](std::shared_ptr<EthereumPeer> _p)
{ {
if (_p) if (_p)
_f(_p.get()); _f(_p.get());
}); });
} }
void EthereumHost::forEachPeerPtr(std::function<void(std::shared_ptr<EthereumPeer>)> const& _f) const void EthereumHost::foreachPeerPtr(std::function<void(std::shared_ptr<EthereumPeer>)> const& _f) const
{ {
for (auto s: peerSessions()) for (auto s: peerSessions())
_f(s.first->cap<EthereumPeer>()); _f(s.first->cap<EthereumPeer>());
@ -551,7 +551,7 @@ void EthereumHost::onPeerTransactions(EthereumPeer* _peer, RLP const& _r)
void EthereumHost::continueSync() void EthereumHost::continueSync()
{ {
clog(NetAllDetail) << "Getting help with downloading hashes and blocks"; clog(NetAllDetail) << "Getting help with downloading hashes and blocks";
forEachPeer([&](EthereumPeer* _p) foreachPeer([&](EthereumPeer* _p)
{ {
if (_p->m_asking == Asking::Nothing) if (_p->m_asking == Asking::Nothing)
continueSync(_p); continueSync(_p);
@ -564,7 +564,7 @@ void EthereumHost::continueSync(EthereumPeer* _peer)
bool otherPeerSync = false; bool otherPeerSync = false;
if (m_needSyncHashes && peerShouldGrabChain(_peer)) if (m_needSyncHashes && peerShouldGrabChain(_peer))
{ {
forEachPeer([&](EthereumPeer* _p) foreachPeer([&](EthereumPeer* _p)
{ {
if (_p != _peer && _p->m_asking == Asking::Hashes && _p->m_protocolVersion != protocolVersion()) 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 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. /// 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. /// 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; bool syncing = false;
forEachPeer([&](EthereumPeer* _p) foreachPeer([&](EthereumPeer* _p)
{ {
if (_p->m_asking != Asking::Nothing) if (_p->m_asking != Asking::Nothing)
syncing = true; syncing = true;

4
libethereum/EthereumHost.h

@ -92,8 +92,8 @@ public:
private: private:
std::tuple<std::vector<std::shared_ptr<EthereumPeer>>, std::vector<std::shared_ptr<EthereumPeer>>, std::vector<std::shared_ptr<p2p::Session>>> randomSelection(unsigned _percent = 25, std::function<bool(EthereumPeer*)> const& _allow = [](EthereumPeer const*){ return true; }); std::tuple<std::vector<std::shared_ptr<EthereumPeer>>, std::vector<std::shared_ptr<EthereumPeer>>, std::vector<std::shared_ptr<p2p::Session>>> randomSelection(unsigned _percent = 25, std::function<bool(EthereumPeer*)> const& _allow = [](EthereumPeer const*){ return true; });
void forEachPeerPtr(std::function<void(std::shared_ptr<EthereumPeer>)> const& _f) const; void foreachPeerPtr(std::function<void(std::shared_ptr<EthereumPeer>)> const& _f) const;
void forEachPeer(std::function<void(EthereumPeer*)> const& _f) const; void foreachPeer(std::function<void(EthereumPeer*)> const& _f) const;
bool isSyncing_UNSAFE() 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. /// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network.

13
libethereum/State.h

@ -84,9 +84,16 @@ public:
class TrivialGasPricer: public GasPricer class TrivialGasPricer: public GasPricer
{ {
protected: public:
u256 ask(State const&) const override { return 10 * szabo; } TrivialGasPricer() = default;
u256 bid(TransactionPriority = TransactionPriority::Medium) const override { return 10 * szabo; } 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 enum class Permanence

Loading…
Cancel
Save