|
|
@ -339,6 +339,13 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db) |
|
|
|
#endif |
|
|
|
// All ok - insert into DB
|
|
|
|
{ |
|
|
|
// ensure parent is cached for later addition.
|
|
|
|
// TODO: this is a bit horrible would be better refactored into an enveloping UpgradableGuard
|
|
|
|
// together with an "ensureCachedWithUpdatableLock(l)" method.
|
|
|
|
// This is safe in practice since the caches don't get flushed nearly often enough to be
|
|
|
|
// done here.
|
|
|
|
details(bi.parentHash); |
|
|
|
|
|
|
|
WriteGuard l(x_details); |
|
|
|
m_details[newHash] = BlockDetails((unsigned)pd.number + 1, td, bi.parentHash, {}); |
|
|
|
m_details[bi.parentHash].children.push_back(newHash); |
|
|
@ -455,14 +462,14 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db) |
|
|
|
|
|
|
|
h256s BlockChain::treeRoute(h256 const& _from, h256 const& _to, h256* o_common, bool _pre, bool _post) const |
|
|
|
{ |
|
|
|
// cdebug << "treeRoute" << _from.abridged() << "..." << _to.abridged();
|
|
|
|
cdebug << "treeRoute" << _from.abridged() << "..." << _to.abridged(); |
|
|
|
if (!_from || !_to) |
|
|
|
return h256s(); |
|
|
|
h256s ret; |
|
|
|
h256s back; |
|
|
|
unsigned fn = details(_from).number; |
|
|
|
unsigned tn = details(_to).number; |
|
|
|
// cdebug << "treeRoute" << fn << "..." << tn;
|
|
|
|
cdebug << "treeRoute" << fn << "..." << tn; |
|
|
|
h256 from = _from; |
|
|
|
while (fn > tn) |
|
|
|
{ |
|
|
@ -470,7 +477,7 @@ h256s BlockChain::treeRoute(h256 const& _from, h256 const& _to, h256* o_common, |
|
|
|
ret.push_back(from); |
|
|
|
from = details(from).parent; |
|
|
|
fn--; |
|
|
|
// cdebug << "from:" << fn << _from.abridged();
|
|
|
|
cdebug << "from:" << fn << _from.abridged(); |
|
|
|
} |
|
|
|
h256 to = _to; |
|
|
|
while (fn < tn) |
|
|
@ -479,12 +486,14 @@ h256s BlockChain::treeRoute(h256 const& _from, h256 const& _to, h256* o_common, |
|
|
|
back.push_back(to); |
|
|
|
to = details(to).parent; |
|
|
|
tn--; |
|
|
|
// cdebug << "to:" << tn << _to.abridged();
|
|
|
|
cdebug << "to:" << tn << _to.abridged(); |
|
|
|
} |
|
|
|
while (from != to) |
|
|
|
{ |
|
|
|
assert(from); |
|
|
|
assert(to); |
|
|
|
if (!from) |
|
|
|
assert(from); |
|
|
|
if (!to) |
|
|
|
assert(to); |
|
|
|
from = details(from).parent; |
|
|
|
to = details(to).parent; |
|
|
|
if (_pre) |
|
|
|