11/*
2- This file is part of cpp-ethereum.
2+ This file is part of cpp-ethereum.
33
4- cpp-ethereum is free software: you can redistribute it and/or modify
5- it under the terms of the GNU General Public License as published by
6- the Free Software Foundation, either version 3 of the License, or
7- (at your option) any later version.
4+ cpp-ethereum is free software: you can redistribute it and/or modify
5+ it under the terms of the GNU General Public License as published by
6+ the Free Software Foundation, either version 3 of the License, or
7+ (at your option) any later version.
88
9- cpp-ethereum is distributed in the hope that it will be useful,
10- but WITHOUT ANY WARRANTY; without even the implied warranty of
11- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12- GNU General Public License for more details.
9+ cpp-ethereum is distributed in the hope that it will be useful,
10+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ GNU General Public License for more details.
1313
14- You should have received a copy of the GNU General Public License
15- along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
14+ You should have received a copy of the GNU General Public License
15+ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616*/
1717/* * @file EthashClient.cpp
1818 * @author Gav Wood <i@gavwood.com>
@@ -30,112 +30,108 @@ namespace fs = boost::filesystem;
3030
3131EthashClient& dev::eth::asEthashClient (Interface& _c)
3232{
33- if (dynamic_cast <Ethash*>(_c.sealEngine ()))
34- return dynamic_cast <EthashClient&>(_c);
35- throw InvalidSealEngine ();
33+ if (dynamic_cast <Ethash*>(_c.sealEngine ()))
34+ return dynamic_cast <EthashClient&>(_c);
35+ throw InvalidSealEngine ();
3636}
3737
3838EthashClient* dev::eth::asEthashClient (Interface* _c)
3939{
40- if (dynamic_cast <Ethash*>(_c->sealEngine ()))
41- return &dynamic_cast <EthashClient&>(*_c);
42- throw InvalidSealEngine ();
40+ if (dynamic_cast <Ethash*>(_c->sealEngine ()))
41+ return &dynamic_cast <EthashClient&>(*_c);
42+ throw InvalidSealEngine ();
4343}
4444
4545DEV_SIMPLE_EXCEPTION (ChainParamsNotEthash);
4646
47- EthashClient::EthashClient (
48- ChainParams const & _params,
49- int _networkID,
50- p2p::Host* _host,
51- std::shared_ptr<GasPricer> _gpForAdoption,
52- fs::path const & _dbPath,
53- WithExisting _forceAction,
54- TransactionQueue::Limits const & _limits
55- ):
56- Client(_params, _networkID, _host, _gpForAdoption, _dbPath, _forceAction, _limits)
47+ EthashClient::EthashClient (ChainParams const & _params, int _networkID, p2p::Host* _host,
48+ std::shared_ptr<GasPricer> _gpForAdoption, fs::path const & _dbPath,
49+ fs::path const & _snapshotPath, WithExisting _forceAction,
50+ TransactionQueue::Limits const & _limits)
51+ : Client(
52+ _params, _networkID, _host, _gpForAdoption, _dbPath, _snapshotPath, _forceAction, _limits)
5753{
58- // will throw if we're not an Ethash seal engine.
59- asEthashClient (*this );
54+ // will throw if we're not an Ethash seal engine.
55+ asEthashClient (*this );
6056}
6157
6258EthashClient::~EthashClient ()
6359{
64- terminate ();
60+ terminate ();
6561}
6662
6763Ethash* EthashClient::ethash () const
6864{
69- return dynamic_cast <Ethash*>(Client::sealEngine ());
65+ return dynamic_cast <Ethash*>(Client::sealEngine ());
7066}
7167
7268bool EthashClient::isMining () const
7369{
74- return ethash ()->farm ().isMining ();
70+ return ethash ()->farm ().isMining ();
7571}
7672
7773WorkingProgress EthashClient::miningProgress () const
7874{
79- if (isMining ())
80- return ethash ()->farm ().miningProgress ();
81- return WorkingProgress ();
75+ if (isMining ())
76+ return ethash ()->farm ().miningProgress ();
77+ return WorkingProgress ();
8278}
8379
8480u256 EthashClient::hashrate () const
8581{
86- u256 r = externalHashrate ();
87- if (isMining ())
88- r += miningProgress ().rate ();
89- return r;
82+ u256 r = externalHashrate ();
83+ if (isMining ())
84+ r += miningProgress ().rate ();
85+ return r;
9086}
9187
9288std::tuple<h256, h256, h256> EthashClient::getEthashWork ()
9389{
94- // lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
95- // this will be reset as soon as a new block arrives, allowing more transactions to be processed.
96- bool oldShould = shouldServeWork ();
97- m_lastGetWork = chrono::system_clock::now ();
98-
99- if (!sealEngine ()->shouldSeal (this ))
100- return std::tuple<h256, h256, h256>();
101-
102- // if this request has made us bother to serve work, prep it now.
103- if (!oldShould && shouldServeWork ())
104- onPostStateChanged ();
105- else
106- // otherwise, set this to true so that it gets prepped next time.
107- m_remoteWorking = true ;
108- ethash ()->manuallySetWork (m_sealingInfo);
109- return std::tuple<h256, h256, h256>(m_sealingInfo.hash (WithoutSeal), Ethash::seedHash (m_sealingInfo), Ethash::boundary (m_sealingInfo));
90+ // lock the work so a later submission isn't invalidated by processing a transaction elsewhere.
91+ // this will be reset as soon as a new block arrives, allowing more transactions to be processed.
92+ bool oldShould = shouldServeWork ();
93+ m_lastGetWork = chrono::system_clock::now ();
94+
95+ if (!sealEngine ()->shouldSeal (this ))
96+ return std::tuple<h256, h256, h256>();
97+
98+ // if this request has made us bother to serve work, prep it now.
99+ if (!oldShould && shouldServeWork ())
100+ onPostStateChanged ();
101+ else
102+ // otherwise, set this to true so that it gets prepped next time.
103+ m_remoteWorking = true ;
104+ ethash ()->manuallySetWork (m_sealingInfo);
105+ return std::tuple<h256, h256, h256>(m_sealingInfo.hash (WithoutSeal), Ethash::seedHash (m_sealingInfo), Ethash::boundary (m_sealingInfo));
110106}
111107
112108bool EthashClient::submitEthashWork (h256 const & _mixHash, h64 const & _nonce)
113109{
114- ethash ()->manuallySubmitWork (_mixHash, _nonce);
115- return true ;
110+ ethash ()->manuallySubmitWork (_mixHash, _nonce);
111+ return true ;
116112}
117113
118114void EthashClient::setShouldPrecomputeDAG (bool _precompute)
119115{
120- bytes trueBytes {1 };
121- bytes falseBytes {0 };
122- sealEngine ()->setOption (" precomputeDAG" , _precompute ? trueBytes: falseBytes);
116+ bytes trueBytes {1 };
117+ bytes falseBytes {0 };
118+ sealEngine ()->setOption (" precomputeDAG" , _precompute ? trueBytes: falseBytes);
123119}
124120
125121void EthashClient::submitExternalHashrate (u256 const & _rate, h256 const & _id)
126122{
127- WriteGuard writeGuard (x_externalRates);
128- m_externalRates[_id] = make_pair (_rate, chrono::steady_clock::now ());
123+ WriteGuard writeGuard (x_externalRates);
124+ m_externalRates[_id] = make_pair (_rate, chrono::steady_clock::now ());
129125}
130126
131127u256 EthashClient::externalHashrate () const
132128{
133- u256 ret = 0 ;
134- WriteGuard writeGuard (x_externalRates);
135- for (auto i = m_externalRates.begin (); i != m_externalRates.end ();)
136- if (chrono::steady_clock::now () - i->second .second > chrono::seconds (5 ))
137- i = m_externalRates.erase (i);
138- else
139- ret += i++->second .first ;
140- return ret;
129+ u256 ret = 0 ;
130+ WriteGuard writeGuard (x_externalRates);
131+ for (auto i = m_externalRates.begin (); i != m_externalRates.end ();)
132+ if (chrono::steady_clock::now () - i->second .second > chrono::seconds (5 ))
133+ i = m_externalRates.erase (i);
134+ else
135+ ret += i++->second .first ;
136+ return ret;
141137}
0 commit comments