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

Introduce caching of PowerTable CIDs #784

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Introduce caching of PowerTable CIDs #784

merged 3 commits into from
Dec 11, 2024

Conversation

Kubuxu
Copy link
Contributor

@Kubuxu Kubuxu commented Dec 10, 2024

First commit is a refactor, second one is the change.

@Kubuxu Kubuxu force-pushed the feat/ptcid-cache branch 3 times, most recently from 8417b74 to 6140b92 Compare December 10, 2024 17:40
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 69 lines in your changes missing coverage. Please review.

Project coverage is 69.42%. Comparing base (6c3d2de) to head (e800ac7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
consensus_inputs.go 61.23% 47 Missing and 22 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #784      +/-   ##
==========================================
- Coverage   69.79%   69.42%   -0.37%     
==========================================
  Files          76       77       +1     
  Lines        7870     7896      +26     
==========================================
- Hits         5493     5482      -11     
- Misses       1931     1961      +30     
- Partials      446      453       +7     
Files with missing lines Coverage Δ
host.go 65.70% <100.00%> (-0.17%) ⬇️
consensus_inputs.go 61.23% <61.23%> (ø)

... and 4 files with indirect coverage changes

@Kubuxu Kubuxu marked this pull request as ready for review December 10, 2024 18:31
@BigLep BigLep requested a review from masih December 10, 2024 22:01
Copy link
Member

@masih masih left a comment

Choose a reason for hiding this comment

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

No blockers 👍 Logic looks correct, tests pass.

Now that the committee and proposal provider is refactored, it would be nice to get the simulation tests to use the same logic instead if a total re-implementation of them.

cache, err := lru.New[string, cid.Cid](256) // keep a bit more than 2x max ECChain size
if err != nil {
// panic as it only depends on the size
panic(fmt.Errorf("could not create cache: %w", 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 would return an error based on the principle that panics should be used rarely. I understand there are pre-existing practices in this repo on use of panic. So not a blocker for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a pet peeve of mine not to introduce errors, especially in constructors, when they cannot happen.

consensus_inputs.go Show resolved Hide resolved
}

func (h *gpbftInputs) getPowerTableCIDForTipset(ctx context.Context, tsk gpbft.TipSetKey) (cid.Cid, error) {
sTSK := string(tsk)
Copy link
Member

Choose a reason for hiding this comment

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

How big do tipset keys get? do we want to hash these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on expectation ~5x the hash size

return ptCid, nil
}

func (h *gpbftInputs) collectChain(ctx context.Context, base ec.TipSet, head ec.TipSet) ([]ec.TipSet, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This function would collect the entire chain that could be finalised irrespective of max chain length of 100. Right?

Specifically, during bootstrap this function would, at best, collect a chain of 900, then a chain of 800, 700, and so on even though each instance would only use at most 100 tipsets of the returned chain as proposal.

Is that the most efficient we can be here? How fast/expensive is GetParent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't that expensive in comparison to getting the power table, it could be more efficient but it is tricky given null rounds.

consensus_inputs.go Outdated Show resolved Hide resolved
Co-authored-by: Masih H. Derkani <[email protected]>
@Kubuxu Kubuxu added this pull request to the merge queue Dec 11, 2024
Merged via the queue into main with commit be650d0 Dec 11, 2024
12 of 13 checks passed
@Kubuxu Kubuxu deleted the feat/ptcid-cache branch December 11, 2024 12:38
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.

2 participants