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

multi: Fast relay checked tip blocks. #1443

Merged
merged 4 commits into from
Sep 10, 2018

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 10, 2018

This PR consists of several commits which ultimately immediately relays blocks that intend to extend the main chain to the rest of the network directly after they have passed all sanity and contextual checks rather than waiting for the more expensive connection code to complete.

This is acceptable because blocks that pass all of the aforementioned checks and then fail to connect are quite rare since it takes a significant amount of work to create a block which satisfies the proof of work requirement as well as all other checks up to that point.

The first commit adds a new function to peer named QueueInventoryImmediate which allows an inventory vector to be queued for immediate send versus the standard trickling batched inventory queue method while still respecting the functionality which filters attempts to notify peers about inventory that they are already known to have.

The second commit modifies the infrastructure for server inventory relay to allow the caller to specify the inventory should be announced immediately versus using the typical trickle mechanism, updates all callers in the repository accordingly, and changes the relay of accepted blocks use the new ability.

The third commit adds a new notification type to blockchain named NTNewTipBlockChecked which allows the caller to be notified when a block that intents to extend the main chain has passed all sanity and contextual checks such as having valid proof of work, valid merkle and stake roots, and only containing allowed votes and revocations.

Finally, the fourth commit makes use of the newly exposed notification from blockchain to relay the block the rest of the network at that point rather as previously described.

@davecgh davecgh added this to the 1.4.0 milestone Sep 10, 2018
Copy link
Member

@matheusd matheusd left a comment

Choose a reason for hiding this comment

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

Working as intended. Tested by adding some instrumentation and using a serial network layout:

https://gist.github.com/matheusd/c2d4e13cb2c68121680955e777c5057d

// Typically, a caller would want to use this notification to relay the
// block to the rest of the network without needing to wait for the more
// time consuming full connection to take place.
NTNewTipBlockChecked NotificationType = iota
Copy link
Member

Choose a reason for hiding this comment

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

why can't this be added to the end, to leave the other constants the same values?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to have them defined in the order they are invoked.

Copy link
Member

Choose a reason for hiding this comment

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

But it's a breaking change

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, these constants should only be referred to by their name, not literals, and afaik they are not serialized anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. They are not serialized anywhere.

This adds a new function to peers which allows an inventory vector to be
queued for immediate send versus the standard trickling batched
inventory queue method while still respecting the functionality which
filters attempts to notify peers about inventory that they are already
known to have.
This modifies the infrastructure for the server inventory relay to allow
the caller to specify the inventory should be announced immediately
versus using the typical trickle mechanism.

It also updates all callers in the repository and changes the relay of
accepted blocks use the new ability.
This adds a new notification type to blockchain which allows the caller
to be notified when a block that intents to extend the main chain has
passed all sanity and contextual checks such as having valid proof of
work, valid merkle and stake roots, and only containing allowed votes
and revocations.

The intention is to allow faster relay of new tip blocks throughout the
network by providing a means to relay it before the more expensive
connection code takes place even though it may ultimately fail to
connect.

This is acceptable because blocks that pass all of the aforementioned
checks and then fail to connect are quite rare since it takes a
significant amount of work to create a block which satisfies the proof
of work requirement as well as all other checks up to that point.
This makes use of the newly exposed notification from blockchain when a
block that intends to extend the main chain has passed all sanity and
contextual checks to relay the block the rest of the network at that
point rather than needing to wait for the more expensive connection code
to complete.
@davecgh davecgh force-pushed the multi_immediate_block_relay branch from 38ba952 to fefb892 Compare September 10, 2018 15:04
@davecgh davecgh merged commit fefb892 into decred:master Sep 10, 2018
@davecgh davecgh deleted the multi_immediate_block_relay branch September 10, 2018 21:33
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