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

Feat: add subjective init opts #37

Closed

Conversation

derrandz
Copy link
Contributor

@derrandz derrandz commented Apr 27, 2023

Overview

Allows exchange to request head from non-trusted peers when the store is already initialized with a subjective head.

Part of the ADR 14 efforts
Depends on #36
Resolves #25

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@derrandz derrandz force-pushed the feat/add-subjective-init-opts branch from ee058ca to 2da10fd Compare April 28, 2023 15:19
@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2023

Codecov Report

Merging #37 (2efb743) into main (4a93da2) will decrease coverage by 0.18%.
The diff coverage is 64.04%.

@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   66.22%   66.04%   -0.18%     
==========================================
  Files          35       37       +2     
  Lines        2768     2848      +80     
==========================================
+ Hits         1833     1881      +48     
- Misses        785      808      +23     
- Partials      150      159       +9     
Impacted Files Coverage Δ
interface.go 0.00% <0.00%> (ø)
sync/sync_head.go 60.17% <42.85%> (-1.87%) ⬇️
p2p/peerstore/peerstore.go 55.55% <55.55%> (ø)
p2p/peerstore/testing.go 59.09% <59.09%> (ø)
p2p/peer_tracker.go 76.76% <82.35%> (+0.57%) ⬆️
headertest/store.go 84.74% <100.00%> (ø)
local/exchange.go 47.61% <100.00%> (ø)
p2p/exchange.go 81.33% <100.00%> (+0.08%) ⬆️
p2p/options.go 47.36% <100.00%> (+3.70%) ⬆️
store/store.go 63.19% <100.00%> (ø)
... and 1 more

... and 2 files with indirect coverage changes

@derrandz derrandz force-pushed the feat/add-subjective-init-opts branch 2 times, most recently from 4cf22ca to 1917417 Compare April 28, 2023 17:43
Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

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

there are a lot of random ints in TestExchange_RequestHead_WithSubjectiveInitOpt, can you clean them up so that it's undertandable what's going on and what's expected?

interface.go Outdated

type Option func(*HeadOptions)

type HeadOptions struct {
Copy link
Member

Choose a reason for hiding this comment

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

I'd call this RequestOptions because we can eventually extend other methods with opts too

p2p/exchange.go Outdated
@@ -38,7 +38,8 @@ type Exchange[H header.Header] struct {
trustedPeers func() peer.IDSlice
peerTracker *peerTracker

Params ClientParameters
Params ClientParameters
headOpts header.HeadOptions
Copy link
Member

Choose a reason for hiding this comment

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

?

p2p/exchange.go Outdated
log.Debug("requesting head")

for _, opt := range opts {
opt(&ex.headOpts)
Copy link
Member

Choose a reason for hiding this comment

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

load a default RequestOptions and range over it to apply opt

no need to store on exchange -- also every time there would be a request with opt, it would modify request options for the entire exchange and not just on a per call basis.

p2p/exchange.go Outdated
Comment on lines 136 to 139
for _, peer := range peers {
peerset = append(peerset, peer.ID)
}
Copy link
Member

Choose a reason for hiding this comment

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

just overwrite peerset with peers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they are not of the same type and no need for refactors to make em so

p2p/exchange.go Outdated
if !ex.headOpts.SubjectiveInit {
// otherwise, node has a chain head that is NOT outdated so we can actually request random peers in
// addition to trusted
peers, err := ex.Params.peerstore.Load(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

also remember that peerstore doesn't necessarily have to be set so you'd also have to ensure that peerstore is not nil

p2p/exchange.go Outdated
Comment on lines 131 to 133
if err != nil { // DISCUSS(team): should we return an error here or just use the trustedPeers?
var zero H
return zero, err
Copy link
Member

Choose a reason for hiding this comment

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

i'd return the err

@derrandz derrandz force-pushed the feat/add-subjective-init-opts branch from cf34029 to 1c68702 Compare May 9, 2023 14:56
@derrandz derrandz marked this pull request as ready for review May 9, 2023 14:57
Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

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

Gave some feedback to @derrandz in DM regarding decreasing scope of this PR to just

  • introduction of the WithSubjectiveInit option, and
  • extension of Head method to allow ...Option

@renaynay
Copy link
Member

Superseded by other PRs

@renaynay renaynay closed this Aug 16, 2023
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.

p2p: Exchange.Head should be able to get head not only from trusted peers, but from any peer
3 participants