Propagate blocks after PoW validation#5713
Conversation
f74ec50 to
7093a31
Compare
Codecov Report
@@ Coverage Diff @@
## master #5713 +/- ##
==========================================
- Coverage 63.23% 63.23% -0.01%
==========================================
Files 353 353
Lines 30245 30276 +31
Branches 3387 3390 +3
==========================================
+ Hits 19126 19144 +18
- Misses 9887 9898 +11
- Partials 1232 1234 +2 |
1e30b99 to
db277ea
Compare
|
Currently propagate all blocks which are imported into the block queue and which pass validation, should only propagate new blocks |
b28a8b6 to
e390d3c
Compare
At the very least we should check if we are currently syncing in aleth/libethereum/EthereumCapability.cpp Lines 955 to 958 in e390d3c Note that we have similar logic in aleth/libethereum/EthereumCapability.cpp Lines 857 to 864 in e390d3c |
5d2ac04 to
9ab9964
Compare
|
Had to do some manual reformatting of the code since I don't have git clang-format working again via the command line after reinstalling my OS so apologies if there are some unnecessary formatting changes in this PR. |
libethereum/Client.cpp
Outdated
| Timer t; | ||
| tie(ir, m_syncBlockQueue, count) = bc().sync(m_bq, m_stateDB, m_syncAmount); | ||
|
|
||
| shared_ptr<VerifiedBlocks> verifiedBlocks = make_shared<VerifiedBlocks>(); |
There was a problem hiding this comment.
shared_ptr is required here since we propagate the blocks on another thread (network thread) so we need to ensure that they are kept around until they can be sent out. We can't just create a copy of the blocks since the copy ctor is deleted.
f7f9b9e to
c8d5b0c
Compare
|
Received some internal RLPX handshake errors during local testing: These appear to be transient, will dig deeper to see if they are related to my changes (I don't think they are since I didn't touch anything related to handshakes but I haven't seen these errors before) [Edit] I haven't been able to replicate this - @gumb0 : Have you seen this before? |
b4e4fb1 to
4adaeaf
Compare
|
Rebased |
4adaeaf to
71b1423
Compare
I investigated and I'm fairly confident that my changes aren't causing this issue. It looks like this error can happen if writing the hello packet during the RLPX handshake fails - we use the aleth/libp2p/RLPxHandshake.cpp Lines 354 to 370 in 78355a2 |
|
Potential optimization - aleth/libethereum/EthereumCapability.cpp Lines 977 to 999 in 0775de0 I think this assumption is incorrect - we should check if a peer knows about a block on a block-by-block basis and only send new blocks to peers who don't know about them. |
0775de0 to
e5466a4
Compare
|
Rebased (to address CHANGELOG conflict) and addressed PR feedback |
2eb39cb to
c66fa7f
Compare
|
cc @gumb0 |
| Timer t; | ||
| tie(ir, m_syncBlockQueue, count) = bc().sync(m_bq, m_stateDB, m_syncAmount); | ||
|
|
||
| std::shared_ptr<VerifiedBlocks> verifiedBlocks = std::make_shared<VerifiedBlocks>(); |
There was a problem hiding this comment.
Could you add an explanation comment why we need a shared_ptr (we need to keep these blocks around until they're later processed in the network thread)
There was a problem hiding this comment.
Ah good suggestion, I had already left a comment in this PR but it would be nice to also have a comment in the code.
Propagate new blocks after we've validated their PoW. PoW (and other checks) are done as a part of importation into the block queue, so we remove blocks from the queue once they've been validated, propagate them to the appropriate peers, then import them into the block chain.
Don't send new blocks if we're not syncing or we're too far behind. This new code follows the logic in EthereumCapability::maintainBlockHashes. Also make some global constants constexpr and rename some constants for consistency reasons.
We perform this check on the network thread because it turns out that std::atomic only supports types with noexcept ctors (i.e. no h256) and using a mutex to synchronize access to the latest block sent info seems like overkill.
Fix bug in randomPeers function
Fix comment formatting, return bad block hashes in BlockChain::sync() via existing tuple rather than via out parameter, remove unused EthereumCapability::randomPartitionPeers, optimize EthereumCapability::randomPeers
c66fa7f to
c3f1b85
Compare
|
Rebased |
Fix some bugs: * Only shuffle the peers list in randomPeers if a subset of them are being returned * Update the hash of the latest block sent in EthereumCapability if we're too far behind - otherwise we'll always be behind and therefore send any new blocks or new block hashes. Also, change the CHANGELOG entry from "added" to "changed" (since this isn't a new feature but modification of existing behavior)
d2b72ae to
8739dd0
Compare
Yeah I think it would be reasonable, but for now I'd avoid further complicating this area of code. It's difficult to test, I'm not even sure whether the current logic works as expected. |
Fix #5371
Propagate new blocks after they've been imported into the block queue and validated. This results in the blocks being sent out faster compared to waiting until they've been imported into the block chain which reduces the uncle rate.