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

ETCM-1023: Block fetching and -building flow #1108

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

jvdp
Copy link
Contributor

@jvdp jvdp commented Aug 20, 2021

Implements a flow that construct blocks from messages from the PeerEventBus, and hooks it into RegularSync via a temporary block buffer data structure and flow (as proof of concept.)

[update 23/8]: Just tested this on Sagano and it regular-syncs up to the best block and then remains stuck there. So it's close.

@jvdp jvdp changed the title Block fetching and -building flow ETCM-1023: Block fetching and -building flow Aug 20, 2021
@jvdp jvdp marked this pull request as ready for review August 20, 2021 15:41
* @param byParent in-memory buffer of blocks retrievable by parentHash. Only one block per parent is kept, last received wins.
* @param branchFound branch found from given best branch, as a list of blocks. They are removed from the buffer.
*/
case class BranchBuffer(byParent: Map[Hash, Block] = Map.empty, branchFound: Queue[Block] = Queue.empty) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need a branch buffer if we immediately store everything?

Copy link
Contributor Author

@jvdp jvdp Aug 25, 2021

Choose a reason for hiding this comment

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

We don't immediately store everything; only rooted blocks / branches, with the reasoning that these blocks have passed the proof of work threshold and so should be relatively safe to store without DoS concerns.

(With the caveat that we should also not store super old blocks; we have been discussing a "settled block" concept that we can also use for this.)

Copy link
Contributor

Choose a reason for hiding this comment

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

got it. how much work do you think it takes to turn this into a structure that supports parallel branches? and can the current one be used in any way as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current one is able to sync Sagano fully, but then might get stuck on a dead branch.

I think I'm close to one that will work for parallel branches for my current ticket (1059.)

* @param bodiesRequest information for requesting bodies corresponding to newly outstanding headers
* @param result blocks produced by matching received headers with received bodies
*/
case class FetchState(
Copy link
Contributor

Choose a reason for hiding this comment

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

so in the end we still can't get rid of the state? this was one of the goals we defined. We still can do it by using sync processing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this isn't a state in the imperative 'shared mutable state' sense; it's kept by the scan operator. This is a more functional approach.

PeerEventBusActor
.messageSource(
peerEventBus,
PeerEventBusActor.SubscriptionClassifier
Copy link
Contributor

Choose a reason for hiding this comment

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

if you're replacing the PeerRequestHandler here then PeerDisconnectedClassifier is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not replacing PeerRequestHandler yet. What's missing is a piece of Flow that manages the sending of headers requests and handling those disconnection and best block messages (and more?)

Copy link
Contributor

Choose a reason for hiding this comment

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

but it's gonna replace it in future? just pointing out what should be there if we proceed with this

Copy link
Contributor Author

@jvdp jvdp Aug 25, 2021

Choose a reason for hiding this comment

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

I sorta misspoke. It's largely replacing PeerRequestHandler but by replacing BlockFetcher. FastSync (until rewritten) still uses PeerRequestHandler so it's not replacing it in that sense.

@jvdp jvdp force-pushed the feature/ETCM-1023-fetched-blocks-stream branch from 30136c1 to 4890acd Compare August 26, 2021 16:02
@jvdp
Copy link
Contributor Author

jvdp commented Aug 26, 2021

So after some discussion we've decided to abandon the PeerEventBus-based block stream and stick with the plans for the FetcherService method, but it's left in for now to test the better BranchBuffer during development.

@nrdxp nrdxp force-pushed the develop branch 6 times, most recently from 22e35b2 to 63187a8 Compare December 12, 2021 19:21
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.

3 participants