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

[Dynamic Protocol State] Read-only interfaces of protocol state #4579

Merged

Conversation

durkmurder
Copy link
Member

https://github.com/dapperlabs/flow-go/issues/5513

Context

In this PR I've introduced read-only interfaces for accessing the protocol state. Initially we have planned to support two types of queries:

  • ByEpoch - returns information that is static for duration of epoch, can be queried by epoch counter.
  • ByBlockID - returns information which can change from block to block during the epoch duration, can be queried by block ID.

I have implemented only ByBlockID since it's unclear if ByEpoch is needed at this point at all. The only place where we query by-epoch is from consensus committee, which already has a logic for caching epochs on it's own.

Why we can't simplify consensus committee to use protocol state? Replacing existing logic with protocol state is not very practical since the backbone of consensus committee is mapping views to epoch counters. This information is not available in protocol state. With protocol state we can only change from where the data will be fetched:

  • from raw epoch events(which are needed to be processed either way)
  • or from protocol state(after we have processed raw epoch events to obtain the counter)
    To summarize, I don't see too much value in using ByEpoch in consensus committee, so I have omitted it's implementation at this point since it requires building an extra index in database for storing epoch_counter -> protocol_state_id.

As part of this PR I've also changed how GlobalParams work, in current implementation it doesn't return errors anymore since all data must be accessible at any point from any place. GlobalParams will be served only from protocol state when we change implementation of protocol.Snapshot.

@codecov-commenter
Copy link

codecov-commenter commented Jul 24, 2023

Codecov Report

Patch coverage: 17.39% and project coverage change: -0.89% ⚠️

Comparison is base (620d901) 54.82% compared to head (4d3e92f) 53.94%.

Additional details and impacted files
@@                        Coverage Diff                         @@
##           feature/dynamic-protocol-state    #4579      +/-   ##
==================================================================
- Coverage                           54.82%   53.94%   -0.89%     
==================================================================
  Files                                 919      722     -197     
  Lines                               85870    71641   -14229     
==================================================================
- Hits                                47080    38645    -8435     
+ Misses                              35178    30142    -5036     
+ Partials                             3612     2854     -758     
Flag Coverage Δ
unittests 53.94% <17.39%> (-0.89%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
cmd/scaffold.go 14.80% <0.00%> (+0.04%) ⬆️
engine/access/rpc/backend/backend.go 66.45% <0.00%> (+0.81%) ⬆️
engine/access/rpc/backend/backend_network.go 36.25% <0.00%> (+2.13%) ⬆️
utils/unittest/fixtures.go 0.00% <0.00%> (ø)
engine/access/rpc/backend/backend_transactions.go 51.40% <100.00%> (-2.63%) ⬇️
engine/collection/epochmgr/engine.go 71.84% <100.00%> (+0.78%) ⬆️
engine/collection/message_hub/message_hub.go 76.47% <100.00%> (+0.78%) ⬆️
engine/collection/synchronization/engine.go 64.46% <100.00%> (+0.96%) ⬆️

... and 204 files with indirect coverage changes

☔ View full report in Codecov by Sentry.

📢 Have feedback on the report? Share it here.

@durkmurder
Copy link
Member Author

I've accidentally merged PR for state updater, now it's in this PR. Sorry for such confusion. Closed PR has diff and adds changes very locally, so hopefully it isn't too bad.

model/flow/protocol_state.go Show resolved Hide resolved
model/flow/protocol_state.go Outdated Show resolved Hide resolved
state/protocol/badger/snapshot_test.go Outdated Show resolved Hide resolved
state/protocol/badger/snapshot_test.go Outdated Show resolved Hide resolved
state/protocol/badger/snapshot_test.go Outdated Show resolved Hide resolved
state/protocol/protocol_state.go Show resolved Hide resolved
state/protocol/protocol_state/updater.go Outdated Show resolved Hide resolved
state/protocol/protocol_state/updater.go Show resolved Hide resolved
func (s *UpdaterSuite) TestProcessEpochSetupHappyPath() {
setup := unittest.EpochSetupFixture(func(setup *flow.EpochSetup) {
setup.Counter = s.parentProtocolState.CurrentEpochSetup.Counter + 1
setup.Participants[0].InitialWeight = 13
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
setup.Participants[0].InitialWeight = 13

Is this needed?

state/protocol/protocol_state.go Show resolved Hide resolved
cmd/scaffold.go Outdated Show resolved Hide resolved
engine/access/rpc/backend/backend_transactions.go Outdated Show resolved Hide resolved
engine/collection/message_hub/message_hub.go Outdated Show resolved Hide resolved
engine/collection/synchronization/engine.go Outdated Show resolved Hide resolved
Alexander Hentschel and others added 2 commits September 4, 2023 12:18
Co-authored-by: Jordan Schalm <jordan@dapperlabs.com>

// DynamicProtocolStateAdapter implements protocol.DynamicProtocolState by wrapping an InitialProtocolStateAdapter.
type DynamicProtocolStateAdapter struct {
*InitialProtocolStateAdapter
Copy link
Member

Choose a reason for hiding this comment

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

I think we could change this into a value type:

  • this should never be nil
  • improves memory locality
  • InitialProtocolStateAdapter is a pointer to flow.RichProtocolStateEntry, so its hardly any data to copy

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 be inclined to extend RichProtocolStateEntry such that is directly implements the interfaces protocol.DynamicProtocolState and protocol.InitialProtocolState. In other words, merge the implementation of InitialProtocolStateAdapter and DynamicProtocolStateAdapter into RichProtocolStateEntry

Copy link
Member Author

Choose a reason for hiding this comment

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

Mentioned it in #4649

// Entry Returns low-level protocol state entry that was used to initialize this object.
// It shouldn't be used by high-level logic, it is useful for some cases such as bootstrapping.
// Prefer using other methods to access protocol state.
Entry() *flow.RichProtocolStateEntry
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 prefer, if we could remove this method from the API. Presumably, we will use this very rarely in higher-level business logic. But it is dangerous to expose broadly, because it could incentive engineers to use it incorrectly by accident.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a point here. It's dangerous but has it's own usages. I would suggest to implement everything and then try to get rid of it when we see how everything comes together.

state/protocol/protocol_state/updater.go Outdated Show resolved Hide resolved
state/protocol/protocol_state/updater.go Outdated Show resolved Hide resolved
state/protocol/protocol_state/updater.go Outdated Show resolved Hide resolved
state/protocol/protocol_state/updater.go Outdated Show resolved Hide resolved
model/flow/protocol_state.go Outdated Show resolved Hide resolved
model/flow/protocol_state.go Show resolved Hide resolved
model/flow/protocol_state.go Show resolved Hide resolved
model/flow/protocol_state.go Show resolved Hide resolved
model/flow/protocol_state_test.go Outdated Show resolved Hide resolved
Base automatically changed from yurii/5529-dynamic-protocol-state-storage-layer to feature/dynamic-protocol-state September 7, 2023 21:48
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

FVM Benchstat comparison

This branch with compared with the base branch onflow:feature/dynamic-protocol-state commit 620d901

The command (for i in {1..7}; do go test ./fvm ./engine/execution/computation --bench . --tags relic -shuffle=on --benchmem --run ^$; done) was used.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-25.66s ± 0%5.66s ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-25.97s ± 0%5.92s ± 0%~(p=1.000 n=1+1)
 
us/txdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-22.76k ± 0%2.76k ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-22.91k ± 0%2.89k ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-21.65GB ± 0%1.65GB ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-21.70GB ± 0%1.70GB ± 0%~(p=1.000 n=1+1)
 
allocs/opdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-221.9M ± 0%21.9M ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-222.6M ± 0%22.6M ± 0%~(p=1.000 n=1+1)
 

durkmurder and others added 5 commits September 8, 2023 12:33
Co-authored-by: Alexander Hentschel <alex.hentschel@axiomzen.co>
Co-authored-by: Alexander Hentschel <alex.hentschel@axiomzen.co>
@durkmurder durkmurder merged commit b361d16 into feature/dynamic-protocol-state Sep 8, 2023
@durkmurder durkmurder deleted the yurii/5513-read-only-identity-table branch September 8, 2023 13:32
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.

4 participants