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

header: Extract Head method into separate Head interface, make Syncer implement it #978

Closed
wants to merge 14 commits into from

Conversation

renaynay
Copy link
Member

@renaynay renaynay commented Aug 1, 2022

This PR extracts Head() method into a separate interface and makes Syncer implement it.

Prerequisite for #933 to restrict the State service's access to headers to the only methods it really needs (Head).

@renaynay renaynay self-assigned this Aug 1, 2022
@renaynay renaynay marked this pull request as draft August 1, 2022 15:03
@renaynay renaynay marked this pull request as ready for review August 1, 2022 15:12
header/sync/sync.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2022

Codecov Report

Merging #978 (12aa560) into main (5859938) will increase coverage by 0.23%.
The diff coverage is 81.81%.

@@            Coverage Diff             @@
##             main     #978      +/-   ##
==========================================
+ Coverage   58.56%   58.79%   +0.23%     
==========================================
  Files         131      132       +1     
  Lines        7766     7985     +219     
==========================================
+ Hits         4548     4695     +147     
- Misses       2745     2814      +69     
- Partials      473      476       +3     
Impacted Files Coverage Δ
header/sync/sync.go 69.16% <77.77%> (+3.66%) ⬆️
header/verify.go 82.97% <100.00%> (+1.58%) ⬆️
node/services/service.go 80.66% <100.00%> (-2.79%) ⬇️
node/settings.go 36.36% <100.00%> (+0.80%) ⬆️
node/testing.go 100.00% <100.00%> (ø)
params/network.go 57.14% <100.00%> (+17.14%) ⬆️
cmd/flags_misc.go 42.59% <0.00%> (-11.80%) ⬇️
cmd/env.go 76.47% <0.00%> (ø)
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@@ -22,6 +22,8 @@ type Config struct {
// Note: The trusted does *not* imply Headers are not verified, but trusted as reliable to fetch headers
// at any moment.
TrustedPeers []string
// BlockTime is the block time of the network.
BlockTime time.Duration
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 am still kind of iffy on this being a config value. While it doesn't really impact anything other than the frequency at which the syncer requests a new objective head from its trustedPeer, if we do end up using this config param elsewhere in the code, we would have to be very cautious on how it is used. Wdyt @Wondertan ?

Copy link
Member

Choose a reason for hiding this comment

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

We should not make it part of the config value but a part of params pkg(#790). Taken from the params, the value then gets pass to the Syncer

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, I don't think we should make it an option on the node, as by now.

Copy link
Member Author

Choose a reason for hiding this comment

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

pls check: 9d89774

@@ -13,6 +14,8 @@ const (
// Private can be used to set up any private network, including local testing setups.
// Use CELESTIA_PRIVATE_GENESIS env var to enable Private by specifying its genesis block hash.
Private Network = "private"
// TODO @renaynay @Wondertan: Set this once it's agreed upon, ideally this could point at a core const
Copy link
Member Author

Choose a reason for hiding this comment

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

@renaynay renaynay requested a review from Wondertan August 3, 2022 11:04
// ensure that head returned from trustedPeer is more recent than subjective head
// as it is possible that the trustedPeer's reported head is not current.
if objHead.Height < sbj.Height {
return nil, fmt.Errorf("trusted peer failed to return current network head")
Copy link
Member Author

Choose a reason for hiding this comment

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

return sbj head here bc it's highest we know of at that point

header/sync/sync.go Outdated Show resolved Hide resolved
node/testing.go Outdated Show resolved Hide resolved
header/interface.go Show resolved Hide resolved
header/verify.go Show resolved Hide resolved
Copy link
Member

@Wondertan Wondertan 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 some a few issues here that would be faster to fix in sync on the call

header/sync/sync.go Outdated Show resolved Hide resolved
header/sync/sync.go Outdated Show resolved Hide resolved
header/sync/sync.go Outdated Show resolved Hide resolved
header/sync/sync.go Outdated Show resolved Hide resolved
header/sync/sync.go Show resolved Hide resolved
// return new head
return objHead, nil
}
// objHead was either ignored or rejected, return most current known
Copy link
Member

Choose a reason for hiding this comment

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

not ignored though as per current code, but putting IsBefore case there would make this correct

@Wondertan
Copy link
Member

Implementing the Head method for Syncer is the original goal of this PR. However, some internal logic has to be changed to allow this, and these logic changes are now extracted into #990. This PR should rebase on top of it(after or before merge) and simply implement the Head method

@renaynay
Copy link
Member Author

Already implemented in main

@renaynay renaynay closed this Sep 20, 2022
@renaynay renaynay deleted the head-interface branch September 20, 2022 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:header Extended header
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants