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. 22
      libethereum/EthereumPeer.cpp

4
libethereum/DownloadMan.cpp

@ -66,10 +66,12 @@ h256Set DownloadSub::nextFetch(unsigned _n)
return m_remaining;
}
void DownloadSub::noteBlock(h256 _hash)
bool DownloadSub::noteBlock(h256 _hash)
{
Guard l(m_fetch);
if (m_man && m_indices.count(_hash))
m_man->m_blocksGot += m_indices[_hash];
bool ret = m_remaining.count(_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.
h256Set nextFetch(unsigned _n);
/// Note that we've received a particular block.
void noteBlock(h256 _hash);
/// Note that we've received a particular block. @returns true if we had asked for it but haven't received it yet.
bool noteBlock(h256 _hash);
/// Nothing doing here.
void doneFetch() { resetFetch(); }

2
libethereum/EthereumHost.cpp

@ -202,7 +202,7 @@ void EthereumHost::maintainBlocks(h256 _currentHash)
auto p = j->cap<EthereumPeer>();
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);
if (!p->m_knownBlocks.count(_currentHash))

22
libethereum/EthereumPeer.cpp

@ -425,21 +425,17 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
unsigned future = 0;
unsigned unknown = 0;
unsigned got = 0;
unsigned repeated = 0;
for (unsigned i = 1; i < _r.itemCount(); ++i)
{
auto h = BlockInfo::headerHash(_r[i].data());
m_sub.noteBlock(h);
if (m_sub.noteBlock(h))
{
Guard l(x_knownBlocks);
m_knownBlocks.insert(h);
}
addRating(10);
switch (host()->m_bq.import(_r[i].data(), host()->m_chain))
{
case ImportResult::Success:
addRating(1);
success++;
break;
@ -461,8 +457,14 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
break;
}
}
else
{
addRating(0); // -1?
repeated++;
}
}
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)
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))
{
case ImportResult::Success:
addRating(100);
break;
case ImportResult::FutureTime:
addRating(1);
//TODO: Rating dependent on how far in future it is.
break;
case ImportResult::Malformed:

Loading…
Cancel
Save