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] Protocol state used in FollowerState and ParticipantState #4613

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
31b21f1
Partially integrated state mutator and state updater in FollowerState
durkmurder Aug 3, 2023
e4448c2
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 3, 2023
120caed
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 3, 2023
824ca0e
Updated FollowerState to use protocol state for processing service ev…
durkmurder Aug 4, 2023
8e6749b
Integrated protocol state into State and FollowerState.
durkmurder Aug 7, 2023
c6c45cf
Moved protocol state DB into State
durkmurder Aug 7, 2023
83a1975
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 7, 2023
f89b883
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 7, 2023
2f30d19
Updated Snapshot API to return protocol state. Updated mocks. Updated…
durkmurder Aug 7, 2023
85bb99e
Injected initial protocol state when bootstrapping. Updated how globa…
durkmurder Aug 8, 2023
56a41e1
Fixed cluster tests
durkmurder Aug 8, 2023
14b7d60
Allowed duplicated protocol states
durkmurder Aug 8, 2023
574ec0c
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 8, 2023
947d9bf
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 8, 2023
54e06ab
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 9, 2023
f0d2784
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 9, 2023
5169455
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 9, 2023
4931eb4
Updated protocol state to transition to next epoch as part of block p…
durkmurder Aug 9, 2023
538cb35
Updated initialization of storage components
durkmurder Aug 10, 2023
0ec6c9d
Updated other tests to compile
durkmurder Aug 10, 2023
24b91be
Fixed test setups
durkmurder Aug 10, 2023
7448a84
Added consistensy checks for rich epoch entry constructor. Updated tests
durkmurder Aug 10, 2023
e8ddf6e
Updated converting logic. Fixed tests.
durkmurder Aug 10, 2023
452c7cc
Linted
durkmurder Aug 10, 2023
4bab29f
Removed TODO
durkmurder Aug 10, 2023
1575990
Cleanup. Small refactoring. Godoc updates
durkmurder Aug 10, 2023
1943c0e
Merge branch 'yurii/6802-protocol-state-mutator' of https://github.co…
durkmurder Aug 11, 2023
331133b
Updated usages of Entry
durkmurder Aug 11, 2023
ea78cda
Updated tests
durkmurder Aug 11, 2023
9404402
Merge branch 'yurii/6802-protocol-state-mutator' into yurii/5514-exte…
jordanschalm Aug 24, 2023
f7efa37
Merge branch 'yurii/6802-protocol-state-mutator' into yurii/5514-exte…
jordanschalm Sep 7, 2023
79b2ebb
removed duplicated line in documentation
Sep 8, 2023
4a92bb7
Merge branch 'feature/dynamic-protocol-state' of https://github.com/o…
durkmurder Sep 11, 2023
5b3e65f
Applied suggestions regarding naming
durkmurder Sep 11, 2023
fb23b0d
Updated implementation of protocol state storage. Updated how changes…
durkmurder Sep 11, 2023
0295799
Reordered checks for handleEpochServiceEvents
durkmurder Sep 11, 2023
7027a7b
Removed snapshot strippening. Updated tests
durkmurder Sep 12, 2023
ffed810
Apply suggestions from code review
durkmurder Sep 12, 2023
66edbfa
Updated badger transaction utils
durkmurder Sep 12, 2023
f44720c
Updated how state params are implemented
durkmurder Sep 13, 2023
0e69fa5
Log cleanup for tests
durkmurder Sep 13, 2023
479da3d
Fixed last commit
durkmurder Sep 13, 2023
b4f3fa5
Fixed last commit
durkmurder Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed test setups
  • Loading branch information
durkmurder committed Aug 10, 2023
commit 24b91be9c65739a9be2ca6b525fe5e64716b8297
22 changes: 22 additions & 0 deletions consensus/integration/epoch_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration_test

import (
"github.com/onflow/flow-go/state/protocol"
"testing"
"time"

Expand Down Expand Up @@ -255,5 +256,26 @@ func withNextEpoch(
Map(mapfunc.WithWeight(0))...,
).Sort(order.Canonical)

// update protocol state
protocolState := encodableSnapshot.ProtocolState
// update protocol state identities since we are in committed phase
protocolState.Identities = flow.DynamicIdentityEntryListFromIdentities(encodableSnapshot.Identities)
// setup ID has changed, need to update it
convertedEpochSetup, _ := protocol.ToEpochSetup(inmem.NewEpoch(*currEpoch))
protocolState.CurrentEpochEventIDs.SetupID = convertedEpochSetup.ID()
// create next epoch protocol state
convertedEpochSetup, _ = protocol.ToEpochSetup(inmem.NewEpoch(*encodableSnapshot.Epochs.Next))
convertedEpochCommit, _ := protocol.ToEpochCommit(inmem.NewEpoch(*encodableSnapshot.Epochs.Next))
protocolState.NextEpochProtocolState = &flow.ProtocolStateEntry{
CurrentEpochEventIDs: flow.EventIDs{
SetupID: convertedEpochSetup.ID(),
CommitID: convertedEpochCommit.ID(),
},
PreviousEpochEventIDs: protocolState.CurrentEpochEventIDs,
Identities: flow.DynamicIdentityEntryListFromIdentities(encodableSnapshot.Identities),
InvalidStateTransitionAttempted: false,
NextEpochProtocolState: nil,
}

return inmem.SnapshotFromEncodable(encodableSnapshot)
}
36 changes: 25 additions & 11 deletions state/protocol/badger/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,9 @@ func Bootstrap(
state.metrics.BlockFinalized(block)
}

rootProtocolState, err := root.ProtocolState()
err = state.bootstrapProtocolState(segment, root, protocolState)(tx)
if err != nil {
return fmt.Errorf("could not get root protocol state: %w", err)
}
rootProtocolStateEntry := rootProtocolState.Entry()
err = protocolState.StoreTx(rootProtocolStateEntry.ID(), rootProtocolStateEntry)(tx)
if err != nil {
return fmt.Errorf("could not insert root protocol state: %w", err)
}
err = protocolState.Index(lastFinalized.ID(), rootProtocolStateEntry.ID())(tx)
if err != nil {
return fmt.Errorf("could not index root protocol state: %w", err)
return fmt.Errorf("could not bootstrap protocol state: %w", err)
}

// 7) initialize version beacon
Expand All @@ -230,6 +221,29 @@ func Bootstrap(
return state, nil
}

func (state *State) bootstrapProtocolState(segment *flow.SealingSegment, root protocol.Snapshot, protocolState storage.ProtocolState) func(tx *transaction.Tx) error {
return func(tx *transaction.Tx) error {
rootProtocolState, err := root.ProtocolState()
if err != nil {
return fmt.Errorf("could not get root protocol state: %w", err)
}
rootProtocolStateEntry := rootProtocolState.Entry()
protocolStateID := rootProtocolStateEntry.ID()
err = protocolState.StoreTx(protocolStateID, rootProtocolStateEntry)(tx)
if err != nil {
return fmt.Errorf("could not insert root protocol state: %w", err)
}

for _, block := range segment.AllBlocks() {
err = protocolState.Index(block.ID(), protocolStateID)(tx)
if err != nil {
return fmt.Errorf("could not index root protocol state: %w", err)
}
}
return nil
}
}

// bootstrapSealingSegment inserts all blocks and associated metadata for the
// protocol state root snapshot to disk.
func (state *State) bootstrapSealingSegment(segment *flow.SealingSegment, head *flow.Block, rootSeal *flow.Seal) func(tx *transaction.Tx) error {
Expand Down
4 changes: 4 additions & 0 deletions state/protocol/inmem/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type Epoch struct {

var _ protocol.Epoch = (*Epoch)(nil)

func NewEpoch(enc EncodableEpoch) Epoch {
return Epoch{enc}
}

func (e Epoch) Encodable() EncodableEpoch {
return e.enc
}
Expand Down