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

Extract p2p::FinalizerCommits component #753

Closed
wants to merge 8 commits into from

Conversation

frolosofsky
Copy link
Member

Signed-off-by: Stanislav Frolov [email protected]

This PR extracts basement changes from #744. No logical changes in the code.

  1. Move p2p commits handlers from src/finalizarion/p2p* to src/p2p/finalizer_commits*.
  2. Rename commits to FinalizerCommits in type and file names.
  3. Pack commits handlers in the component FinalizerCommits.
  4. Adjust "relaxing" of the code by newlines to ease merge with Implement commits full sync #744.
  5. Adds PushMessage helper function to net_processing.

@frolosofsky frolosofsky added the refactoring Changes which clean up code but don't change the user-visible behavior label Mar 7, 2019
@frolosofsky frolosofsky added this to the 0.1 milestone Mar 7, 2019
@frolosofsky frolosofsky self-assigned this Mar 7, 2019
@frolosofsky frolosofsky requested review from AM5800 and a team March 7, 2019 15:03
src/p2p/finalizer_commits_impl.h Outdated Show resolved Hide resolved
src/p2p/finalizer_commits.h Outdated Show resolved Hide resolved
src/injector.h Show resolved Hide resolved
src/p2p/finalizer_commits_types.cpp Show resolved Hide resolved
src/p2p/finalizer_commits_impl.h Outdated Show resolved Hide resolved
src/p2p/finalizer_commits_impl.cpp Outdated Show resolved Hide resolved
src/p2p/finalizer_commits_types.h Outdated Show resolved Hide resolved
src/p2p/finalizer_commits_impl.cpp Outdated Show resolved Hide resolved
src/p2p/finalizer_commits_impl.cpp Outdated Show resolved Hide resolved
src/p2p/finalizer_commits_impl.cpp Outdated Show resolved Hide resolved
@frolosofsky
Copy link
Member Author

@scravy While answering your questions I had to refer the parent PR #744 plenty of times. Maybe it makes sense to close this PR and keep the changeset as part of #744?

Signed-off-by: Stanislav Frolov <[email protected]>
Signed-off-by: Stanislav Frolov <[email protected]>
Signed-off-by: Stanislav Frolov <[email protected]>
Signed-off-by: Stanislav Frolov <[email protected]>
Signed-off-by: Stanislav Frolov <[email protected]>
Signed-off-by: Stanislav Frolov <[email protected]>
Signed-off-by: Stanislav Frolov <[email protected]>
@scravy
Copy link
Member

scravy commented Mar 11, 2019

While answering your questions I had to refer the parent PR #744 plenty of times. Maybe it makes sense to close this PR and keep the changeset as part of #744?

I for one do not mind either way. Of course it's always nicer to have smaller pieces to review, but if the individual pieces do not make sense. I am mostly just wondering about tests and TODOs. Since it is a component it should be testable as a unit. If it's simpler to have it as part of #744, well then.

@frolosofsky
Copy link
Member Author

I ported all the fix to the main PR. Feel free to review them #744.

Copy link
Member

@Gnappuraz Gnappuraz left a comment

Choose a reason for hiding this comment

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

utACK 67c5e83

class FinalizerCommitsHandler {
public:
//! \brief Process getcommits message
virtual void OnGetCommits(
Copy link
Member

Choose a reason for hiding this comment

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

WDYS about Process<message name> pattern name? Basically, call it ProcessGetCommits as this is the function which processes getcommits p2p message. It matches quite well with the existing functions we have e,g. ProcessNewBlock, with the comment above and is invoked in the net_processing.cpp file.

For me, OnGetCommits looks like the event that was produced by ProcessGetCommits function and other components can subscribe to.

Copy link
Member Author

Choose a reason for hiding this comment

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

Although this function processes getcommits message, the component is designed like a handler that responses on network events so that on_<message> sounds reasonable to me. Also, in python, we use on_<message> pattern. After all, every function processes something...

But, If others want to rename it to Processes<message>, I will rename.

}
best_index = index;

} else if (index->nHeight > best_index->nHeight && m_active_chain->Contains(*index)) {
Copy link
Member

Choose a reason for hiding this comment

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

&& m_active_chain->Contains(*index) can be ommited as we get index from m_active_chain so it must be there.


FinalizerCommitsResponse response;
do {
walk = m_active_chain->AtHeight(walk->nHeight + 1);
Copy link
Member

Choose a reason for hiding this comment

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

nit: CChain has Next function, could be used instead of manually computing the height.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's staking::ActiveChain component which doesn't have such function. Will extend and update this code.

// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef UNITE_P2P_FINALIZER_COMMITS_HANDLER
Copy link
Member

Choose a reason for hiding this comment

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

Include guards usually end with _H. Would be good to keep the same pattern as in other files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm anybody cares about such a "pattern"? Will do!

// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef UNITE_P2P_FINALIZER_COMMITS_HANDLER_IMPL
Copy link
Member

Choose a reason for hiding this comment

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

would be good to add _H to the include guard to keep the same naming.


namespace p2p {

class FinalizerCommitsHandlerImpl : public ::p2p::FinalizerCommitsHandler {
Copy link
Member

Choose a reason for hiding this comment

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

I see we put implementation classes directly to the cpp. Then we can hide it even inside the anonymous namespace. What is the reason for exposing FinalizerCommitsHandlerImpl?

nit: ::p2p:: can be ommited.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason is the unit tests.

Copy link
Member

Choose a reason for hiding this comment

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

::p2p:: can be ommited.

// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef UNITE_FINALIZATION_P2P
#define UNITE_FINALIZATION_P2P
#ifndef UNITE_P2P_FINALIZER_COMMITS_TYPES
Copy link
Member

Choose a reason for hiding this comment

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

would be good to add _H to include guard

@frolosofsky
Copy link
Member Author

I guess we decided to have solid #744 instead of splitting.

@frolosofsky frolosofsky deleted the p2p-finalizer-commits branch April 1, 2019 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Changes which clean up code but don't change the user-visible behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants