Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine expedited block and xthin block handling #509

Closed
wants to merge 2 commits into from
Closed

Combine expedited block and xthin block handling #509

wants to merge 2 commits into from

Conversation

kyuupichan
Copy link
Contributor

@kyuupichan kyuupichan commented May 3, 2017

A common function that unifies the two message handlers to have a single codepath
for verification. The only differences lie in determining new-ness of the block.
The prior expedited code path used to omit most of the validity checks.

This is built on #482 and #502. Unfortunately they conflict (with trivial resolution as in this PR); it's probably cleanest to apply them in that order.

@@ -5884,13 +5884,13 @@ bool ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vRecv, in
else if (strCommand == NetMsgType::XPEDITEDBLK)
{
// ignore the expedited message unless we are at the chain tip...
if (!fImporting && !fReindex && IsChainNearlySyncd())
if (!fImporting && !fReindex && !IsInitialBlockDownload() && IsThinBlocksEnabled())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers - I changed this because it's now the same condition as the xthin block code path. I'm unsure which one is preferable but am fairly sure they should be the same.

@kyuupichan
Copy link
Contributor Author

Rebased too given the conflict. Now just on top of #502

@sickpig
Copy link
Collaborator

sickpig commented May 4, 2017

@kyuupichan

the failure is due to auto check on formatting for `thinblock.{cpp,h}, the diff started here:

https://travis-ci.org/BitcoinUnlimited/BitcoinUnlimited/jobs/228529744#L1177

the error is raised here:

see https://travis-ci.org/BitcoinUnlimited/BitcoinUnlimited/jobs/228529744#L1244

all the other tests pass.

edit: I'm able to reproduce the result of travis formatting checking on locally puled version of the repo. (i.e.
make -C src check-formatting)

@sickpig
Copy link
Collaborator

sickpig commented May 4, 2017

@kyuupichan, @ftrader and I set up a 3 nodes Xpedited sub net and tested this set up and we verified that the patch achieve the goal of preserving the functionality while at the same time reorganizing the code in a more rational way.

{
Misbehaving(pfrom->GetId(), 10);
return error("%s from peer %s (%d) will not connect, unknown previous block %s",
strCommand, pfrom->addrName.c_str(), pfrom->id, prevHash.ToString());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one of the site blamed to be not properly formatted by clang-format-3.8, this is the actual diff:

--- thinblock.cpp
+++ thinblock.cpp_formatted
@@ -277,8 +277,8 @@
         if (mi == mapBlockIndex.end())
         {
             Misbehaving(pfrom->GetId(), 10);
-            return error("%s from peer %s (%d) will not connect, unknown previous block %s",
-                         strCommand, pfrom->addrName.c_str(), pfrom->id, prevHash.ToString());
+            return error("%s from peer %s (%d) will not connect, unknown previous block %s", strCommand,
+                pfrom->addrName.c_str(), pfrom->id, prevHash.ToString());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll "fix" the formatting.

// Thin block does not fit within our blockchain
Misbehaving(pfrom->GetId(), 100);
return error("%s from peer %s (%d) contextual error: %s", strCommand, pfrom->addrName.c_str(),
pfrom->id, state.GetRejectReason().c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

else
{
LogPrint("thin", "Received %s %s from peer %s (%d). Size %d bytes.\n", strCommand, inv.hash.ToString(),
pfrom->addrName.c_str(), pfrom->id, nSizeThinBlock);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

CInv inv(MSG_BLOCK, thinBlock.header.GetHash());
bool fAlreadyHave = false;

if (nHops > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I there should be some comments regarding what hops is referring to...since we're wedding thinblocks and expedited...we should put some explanation as to why and what these hops are referring to..you could put it here or at the top of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Good idea, I'll add that with the formatting fix.

// Is there a previous block or header to connect with?
{
LOCK(cs_main);
uint256 prevHash = thinBlock.header.hashPrevBlock;
Copy link
Collaborator

@ptschip ptschip May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about all the cs_main locks we're aquiring and releasing and aquiring again...i think we do this about 3 times here. While for thinblock processing it's not a big deal , for expedited it is important. We can easily a 1/10th of second waiting for a cs_main lock. I would look at consolidating them here so that we only take the lock once and hold it until we don't need it...so in checkng the POW (IsThinBlockValid), contextualcheckblockheader and also checking to see if the block connects...etc...all should be under one cs_main lock..rather than aquire/release/aquire/release...cs_main is recursive so you don't need worry about taking it twice, just do not release it until your done with it.

Other than that it all looks pretty good although i havn't tested yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present the PR is a minimal unification of the code which makes it easy to compare to before. Do you mind if locking is improved as a follow-up PR rather than combining it in this one?

Neil Booth added 2 commits May 5, 2017 10:59
A common function that unifies the two message handlers to have a single codepath
for verification.  The only differences lie in determining new-ness of the block.
The prior expedited code path used to omit most of the validity checks.
@gandrewstone
Copy link
Collaborator

I've fixed conflicts and did some log and formatting cleanup and reissued as PR #522. I moved to a new PR since the author is on vacation AFAIK.

@kyuupichan kyuupichan deleted the exp-unify branch May 5, 2017 15:32
@kyuupichan kyuupichan restored the exp-unify branch May 6, 2017 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants