-
Notifications
You must be signed in to change notification settings - Fork 17
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
Feat: add subjective init opts #37
Conversation
ee058ca
to
2da10fd
Compare
Codecov Report
@@ 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
|
4cf22ca
to
1917417
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
for _, peer := range peers { | ||
peerset = append(peerset, peer.ID) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
if err != nil { // DISCUSS(team): should we return an error here or just use the trustedPeers? | ||
var zero H | ||
return zero, err |
There was a problem hiding this comment.
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
cf34029
to
1c68702
Compare
There was a problem hiding this 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
Superseded by other PRs |
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