@@ -27,47 +27,42 @@ using namespace chrono;
27
27
using namespace dev ;
28
28
using namespace eth ;
29
29
30
- h256 const & BlockHeader::seedHash () const
31
- {
32
- if (!m_seedHash)
33
- m_seedHash = EthashAux::seedHash ((unsigned )m_number);
34
- return m_seedHash;
35
- }
36
-
37
- EthashAux* EthashAux::get ()
30
+ EthashAux& EthashAux::get ()
38
31
{
39
32
static EthashAux instance;
40
- return & instance;
33
+ return instance;
41
34
}
42
35
43
36
h256 EthashAux::seedHash (unsigned _number)
44
37
{
45
38
unsigned epoch = _number / ETHASH_EPOCH_LENGTH;
46
- Guard l (get ()->x_epochs );
47
- if (epoch >= get ()->m_seedHashes .size ())
39
+ EthashAux& ethash = EthashAux::get ();
40
+ Guard l (ethash.x_epochs );
41
+ if (epoch >= ethash.m_seedHashes .size ())
48
42
{
49
43
h256 ret;
50
44
unsigned n = 0 ;
51
- if (!get ()-> m_seedHashes .empty ())
45
+ if (!ethash. m_seedHashes .empty ())
52
46
{
53
- ret = get ()-> m_seedHashes .back ();
54
- n = get ()-> m_seedHashes .size () - 1 ;
47
+ ret = ethash. m_seedHashes .back ();
48
+ n = ethash. m_seedHashes .size () - 1 ;
55
49
}
56
- get ()-> m_seedHashes .resize (epoch + 1 );
50
+ ethash. m_seedHashes .resize (epoch + 1 );
57
51
for (; n <= epoch; ++n, ret = sha3 (ret))
58
- get ()-> m_seedHashes [n] = ret;
52
+ ethash. m_seedHashes [n] = ret;
59
53
}
60
- return get ()-> m_seedHashes [epoch];
54
+ return ethash. m_seedHashes [epoch];
61
55
}
62
56
63
57
uint64_t EthashAux::number (h256 const & _seedHash)
64
58
{
65
- Guard l (get ()->x_epochs );
59
+ EthashAux& ethash = EthashAux::get ();
60
+ Guard l (ethash.x_epochs );
66
61
unsigned epoch = 0 ;
67
- auto epochIter = get ()-> m_epochs .find (_seedHash);
68
- if (epochIter == get ()-> m_epochs .end ())
62
+ auto epochIter = ethash. m_epochs .find (_seedHash);
63
+ if (epochIter == ethash. m_epochs .end ())
69
64
{
70
- for (h256 h; h != _seedHash && epoch < 2048 ; ++epoch, h = sha3 (h), get ()-> m_epochs [h] = epoch) {}
65
+ for (h256 h; h != _seedHash && epoch < 2048 ; ++epoch, h = sha3 (h), ethash. m_epochs [h] = epoch) {}
71
66
if (epoch == 2048 )
72
67
{
73
68
std::ostringstream error;
@@ -82,10 +77,13 @@ uint64_t EthashAux::number(h256 const& _seedHash)
82
77
83
78
EthashAux::LightType EthashAux::light (h256 const & _seedHash)
84
79
{
85
- Guard l (get ()->x_lights );
86
- if (get ()->m_lights .count (_seedHash))
87
- return get ()->m_lights .at (_seedHash);
88
- return (get ()->m_lights [_seedHash] = make_shared<LightAllocation>(_seedHash));
80
+ // TODO: Use epoch number instead of seed hash?
81
+
82
+ EthashAux& ethash = EthashAux::get ();
83
+ Guard l (ethash.x_lights );
84
+ if (ethash.m_lights .count (_seedHash))
85
+ return ethash.m_lights .at (_seedHash);
86
+ return (ethash.m_lights [_seedHash] = make_shared<LightAllocation>(_seedHash));
89
87
}
90
88
91
89
EthashAux::LightAllocation::LightAllocation (h256 const & _seedHash)
@@ -119,7 +117,7 @@ Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, uint64_t
119
117
{
120
118
try
121
119
{
122
- return EthashAux:: get ()-> light (_seedHash)->compute (_headerHash, _nonce);
120
+ return get (). light (_seedHash)->compute (_headerHash, _nonce);
123
121
}
124
122
catch (...)
125
123
{
0 commit comments