Browse Source

Actually use NewBlock

cl-refactor
Gav Wood 10 years ago
parent
commit
d489ef3357
  1. 4
      libethereum/DownloadMan.cpp
  2. 4
      libethereum/DownloadMan.h
  3. 2
      libethereum/EthereumHost.cpp
  4. 62
      libethereum/EthereumPeer.cpp

4
libethereum/DownloadMan.cpp

@ -66,10 +66,12 @@ h256Set DownloadSub::nextFetch(unsigned _n)
return m_remaining; return m_remaining;
} }
void DownloadSub::noteBlock(h256 _hash) bool DownloadSub::noteBlock(h256 _hash)
{ {
Guard l(m_fetch); Guard l(m_fetch);
if (m_man && m_indices.count(_hash)) if (m_man && m_indices.count(_hash))
m_man->m_blocksGot += m_indices[_hash]; m_man->m_blocksGot += m_indices[_hash];
bool ret = m_remaining.count(_hash);
m_remaining.erase(_hash); m_remaining.erase(_hash);
return ret;
} }

4
libethereum/DownloadMan.h

@ -48,8 +48,8 @@ public:
/// Finished last fetch - grab the next bunch of block hashes to download. /// Finished last fetch - grab the next bunch of block hashes to download.
h256Set nextFetch(unsigned _n); h256Set nextFetch(unsigned _n);
/// Note that we've received a particular block. /// Note that we've received a particular block. @returns true if we had asked for it but haven't received it yet.
void noteBlock(h256 _hash); bool noteBlock(h256 _hash);
/// Nothing doing here. /// Nothing doing here.
void doneFetch() { resetFetch(); } void doneFetch() { resetFetch(); }

2
libethereum/EthereumHost.cpp

@ -202,7 +202,7 @@ void EthereumHost::maintainBlocks(h256 _currentHash)
auto p = j->cap<EthereumPeer>(); auto p = j->cap<EthereumPeer>();
RLPStream ts; RLPStream ts;
p->prep(ts, BlocksPacket, hs.size()).appendRaw(bs, hs.size()); p->prep(ts, NewBlockPacket, hs.size()).appendRaw(bs, hs.size());
Guard l(p->x_knownBlocks); Guard l(p->x_knownBlocks);
if (!p->m_knownBlocks.count(_currentHash)) if (!p->m_knownBlocks.count(_currentHash))

62
libethereum/EthereumPeer.cpp

@ -425,44 +425,46 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
unsigned future = 0; unsigned future = 0;
unsigned unknown = 0; unsigned unknown = 0;
unsigned got = 0; unsigned got = 0;
unsigned repeated = 0;
for (unsigned i = 1; i < _r.itemCount(); ++i) for (unsigned i = 1; i < _r.itemCount(); ++i)
{ {
auto h = BlockInfo::headerHash(_r[i].data()); auto h = BlockInfo::headerHash(_r[i].data());
m_sub.noteBlock(h); if (m_sub.noteBlock(h))
{ {
Guard l(x_knownBlocks); addRating(10);
m_knownBlocks.insert(h); switch (host()->m_bq.import(_r[i].data(), host()->m_chain))
{
case ImportResult::Success:
success++;
break;
case ImportResult::Malformed:
disable("Malformed block received.");
return true;
case ImportResult::FutureTime:
future++;
break;
case ImportResult::AlreadyInChain:
case ImportResult::AlreadyKnown:
got++;
break;
case ImportResult::UnknownParent:
unknown++;
break;
}
} }
else
switch (host()->m_bq.import(_r[i].data(), host()->m_chain))
{ {
case ImportResult::Success: addRating(0); // -1?
addRating(1); repeated++;
success++;
break;
case ImportResult::Malformed:
disable("Malformed block received.");
return true;
case ImportResult::FutureTime:
future++;
break;
case ImportResult::AlreadyInChain:
case ImportResult::AlreadyKnown:
got++;
break;
case ImportResult::UnknownParent:
unknown++;
break;
} }
} }
clogS(NetMessageSummary) << dec << success << "imported OK," << unknown << "with unknown parents," << future << "with future timestamps," << got << " already known."; clogS(NetMessageSummary) << dec << success << "imported OK," << unknown << "with unknown parents," << future << "with future timestamps," << got << " already known," << repeated << " repeats received.";
if (m_asking == Asking::Blocks) if (m_asking == Asking::Blocks)
transition(Asking::Blocks); transition(Asking::Blocks);
@ -480,8 +482,10 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
switch (host()->m_bq.import(_r[1].data(), host()->m_chain)) switch (host()->m_bq.import(_r[1].data(), host()->m_chain))
{ {
case ImportResult::Success: case ImportResult::Success:
addRating(100);
break;
case ImportResult::FutureTime: case ImportResult::FutureTime:
addRating(1); //TODO: Rating dependent on how far in future it is.
break; break;
case ImportResult::Malformed: case ImportResult::Malformed:

Loading…
Cancel
Save