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

polygon/p2p: implement download headers #9399

Merged
merged 33 commits into from
Feb 19, 2024
Merged

polygon/p2p: implement download headers #9399

merged 33 commits into from
Feb 19, 2024

Conversation

taratorio
Copy link
Member

No description provided.

polygon/p2p/downloader.go Outdated Show resolved Hide resolved
@taratorio taratorio marked this pull request as ready for review February 12, 2024 14:04
polygon/p2p/downloader.go Outdated Show resolved Hide resolved
Copy link
Contributor

@battlmonstr battlmonstr left a comment

Choose a reason for hiding this comment

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

Good progress 👍 I've commented some things. Going to merge it straight away. Feel free to do the changes in the follow-up PRs.

"github.com/ledgerwatch/erigon/rlp"
)

const reqRespTimeout = 5 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const reqRespTimeout = 5 * time.Second
const responseTimeout = 5 * time.Second

Copy link
Member Author

@taratorio taratorio Feb 20, 2024

Choose a reason for hiding this comment

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

addressed - #9470


const reqRespTimeout = 5 * time.Second

var invalidDownloadHeadersRangeErr = errors.New("invalid download headers range")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var invalidDownloadHeadersRangeErr = errors.New("invalid download headers range")
var invalidDownloadHeadersRangeError = errors.New("invalid download headers range")

Copy link
Member Author

@taratorio taratorio Feb 20, 2024

Choose a reason for hiding this comment

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

Err is a standard go convention naming, I'd prefer if we stick to it
example: ctx.Err()


type RequestIdGenerator func() uint64

type Downloader interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to have a different name for this, because p2p.Downloader and sync.HeaderDownloader are too similar names. Some examples: HeadersChunkDownloader, HeadersSliceDownloader, HeadersRangeDownloader. Consider also "fetcher" instead of "downloader".

Copy link
Member Author

@taratorio taratorio Feb 20, 2024

Choose a reason for hiding this comment

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

I dont want to include the word Header in this because I plan to use this same component for getting block bodies too in the future. Having a separate fetcher/downloader per data model feels too fine grained to me. I can change the naming to just Fetcher

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed - #9470


g.Go(func() error {
select {
case <-ctx.Done():
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unlikely, do we really need to call GetBlockHeaders66 from a goroutine? 🤔 although this code will probably change when you implement the TODO above...

Copy link
Member Author

Choose a reason for hiding this comment

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

yes you are right ill change this

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed - #9470

g, ctx := errgroup.WithContext(ctx)

//
// TODO chunk request into smaller ranges if needed to fit in the 10 MiB response size
Copy link
Contributor

Choose a reason for hiding this comment

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

The limits are: softResponseLimit (2Mb) and MaxHeadersServe (1024) - see AnswerGetBlockHeadersQuery.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks - this is useful

Copy link
Member Author

Choose a reason for hiding this comment

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

updated the TODOs in - #9470

"github.com/ledgerwatch/erigon/rlp"
)

type MessageBroadcaster interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type MessageBroadcaster interface {
type MessageSender interface {

I recommend to avoid "broadcast", because this word is already used to mean P2P broadcast (sending to multiple peers at once).

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed - #9470

Comment on lines +18 to +19
RegisterBlockHeaders66Observer(observer MessageObserver[*sentry.InboundMessage])
UnregisterBlockHeaders66Observer(observer MessageObserver[*sentry.InboundMessage])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
RegisterBlockHeaders66Observer(observer MessageObserver[*sentry.InboundMessage])
UnregisterBlockHeaders66Observer(observer MessageObserver[*sentry.InboundMessage])
RegisterBlockHeadersObserver(observer MessageObserver[*sentry.InboundMessage])
UnregisterBlockHeadersObserver(observer MessageObserver[*sentry.InboundMessage])

Suggest to remove 66 (eth version) from method names here, because it is a lower-level concern.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed - #9470


func (ml *messageListener) statusDataFactory() sentrymulticlient.StatusDataFactory {
return func() *sentry.StatusData {
return &sentry.StatusData{}
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO reminder

Copy link
Member Author

@taratorio taratorio Feb 20, 2024

Choose a reason for hiding this comment

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

I actually dont think updating the status should happen in the message listener - I have plans to add a new component for updating our status but that is something we can do further down the line


func (ml *messageListener) inboundMessageFactory() sentrymulticlient.MessageFactory[*sentry.InboundMessage] {
return func() *sentry.InboundMessage {
return new(sentry.InboundMessage)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks very generic. What's the use case where we need to customize this?

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

if the question is why is the MessageFactory generic - you can have a factory for PeerEvents messages too in addition to a factory for InboundMessage

if err != nil {
return err
}

for len(waypoints) > 0 {
allPeers := hd.sentry.PeersWithBlockNumInfo()
allPeers := hd.p2pService.PeersSyncProgress()
if len(allPeers) == 0 {
hd.logger.Warn(fmt.Sprintf("[%s] zero peers, will try again", headerDownloaderLogPrefix))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remind me to discuss the log levels, and revise the Warn's here.

@battlmonstr battlmonstr merged commit 6b39197 into devel Feb 19, 2024
7 checks passed
@battlmonstr battlmonstr deleted the astrid-sentry branch February 19, 2024 11:29
battlmonstr pushed a commit that referenced this pull request Feb 20, 2024
addresses follow up comments left on
#9399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants