Skip to content

Commit

Permalink
Merge pull request onflow#5968 from onflow/jord/initial-proto-state-r…
Browse files Browse the repository at this point in the history
…efactor

`InitialProtocolState` refactor and epoch protocol sub-state rename
  • Loading branch information
jordanschalm authored May 29, 2024
2 parents 838411f + 3cc4dde commit 29bf6de
Show file tree
Hide file tree
Showing 71 changed files with 895 additions and 1,063 deletions.
2 changes: 1 addition & 1 deletion cmd/bootstrap/cmd/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func constructRootBlock(rootHeader *flow.Header, setup *flow.EpochSetup, commit
Receipts: nil,
Results: nil,
// TODO: shortcut in bootstrapping; we will probably have to start with a non-empty KV store in the future
ProtocolStateID: kvstore.NewDefaultKVStore(inmem.ProtocolStateFromEpochServiceEvents(setup, commit).ID()).ID(),
ProtocolStateID: kvstore.NewDefaultKVStore(inmem.EpochProtocolStateFromServiceEvents(setup, commit).ID()).ID(),
})
return block
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/consensus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func main() {
}).
Component("consensus participant", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
mutableProtocolState := protocol_state.NewMutableProtocolState(
node.Storage.EpochProtocolState,
node.Storage.EpochProtocolStateEntries,
node.Storage.ProtocolKVStore,
node.State.Params(),
node.Storage.Headers,
Expand Down
42 changes: 21 additions & 21 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,30 +1181,30 @@ func (fnb *FlowNodeBuilder) initStorage() error {
setups := bstorage.NewEpochSetups(fnb.Metrics.Cache, fnb.DB)
epochCommits := bstorage.NewEpochCommits(fnb.Metrics.Cache, fnb.DB)
commits := bstorage.NewCommits(fnb.Metrics.Cache, fnb.DB)
protocolState := bstorage.NewProtocolState(fnb.Metrics.Cache, setups, epochCommits, fnb.DB,
bstorage.DefaultProtocolStateCacheSize, bstorage.DefaultProtocolStateByBlockIDCacheSize)
protocolState := bstorage.NewEpochProtocolStateEntries(fnb.Metrics.Cache, setups, epochCommits, fnb.DB,
bstorage.DefaultEpochProtocolStateCacheSize, bstorage.DefaultProtocolStateIndexCacheSize)
protocolKVStores := bstorage.NewProtocolKVStore(fnb.Metrics.Cache, fnb.DB,
bstorage.DefaultProtocolKVStoreCacheSize, bstorage.DefaultProtocolKVStoreByBlockIDCacheSize)
versionBeacons := bstorage.NewVersionBeacons(fnb.DB)

fnb.Storage = Storage{
Headers: headers,
Guarantees: guarantees,
Receipts: receipts,
Results: results,
Seals: seals,
Index: index,
Payloads: payloads,
Blocks: blocks,
QuorumCertificates: qcs,
Transactions: transactions,
Collections: collections,
Setups: setups,
EpochCommits: epochCommits,
VersionBeacons: versionBeacons,
EpochProtocolState: protocolState,
ProtocolKVStore: protocolKVStores,
Commits: commits,
Headers: headers,
Guarantees: guarantees,
Receipts: receipts,
Results: results,
Seals: seals,
Index: index,
Payloads: payloads,
Blocks: blocks,
QuorumCertificates: qcs,
Transactions: transactions,
Collections: collections,
Setups: setups,
EpochCommits: epochCommits,
VersionBeacons: versionBeacons,
EpochProtocolStateEntries: protocolState,
ProtocolKVStore: protocolKVStores,
Commits: commits,
}

return nil
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func (fnb *FlowNodeBuilder) initState() error {
fnb.Storage.QuorumCertificates,
fnb.Storage.Setups,
fnb.Storage.EpochCommits,
fnb.Storage.EpochProtocolState,
fnb.Storage.EpochProtocolStateEntries,
fnb.Storage.ProtocolKVStore,
fnb.Storage.VersionBeacons,
)
Expand Down Expand Up @@ -1342,7 +1342,7 @@ func (fnb *FlowNodeBuilder) initState() error {
fnb.Storage.QuorumCertificates,
fnb.Storage.Setups,
fnb.Storage.EpochCommits,
fnb.Storage.EpochProtocolState,
fnb.Storage.EpochProtocolStateEntries,
fnb.Storage.ProtocolKVStore,
fnb.Storage.VersionBeacons,
fnb.RootSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion cmd/util/cmd/common/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func InitProtocolState(db *badger.DB, storages *storage.All) (protocol.State, er
storages.QuorumCertificates,
storages.Setups,
storages.EpochCommits,
storages.EpochProtocolState,
storages.EpochProtocolStateEntries,
storages.ProtocolKVStore,
storages.VersionBeacons,
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/util/cmd/read-badger/cmd/epoch_protocol_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var epochProtocolStateCmd = &cobra.Command{
}

log.Info().Msgf("getting protocol state by block id: %v", blockID)
protocolState, err := storages.EpochProtocolState.ByBlockID(blockID)
protocolState, err := storages.EpochProtocolStateEntries.ByBlockID(blockID)
if err != nil {
log.Error().Err(err).Msgf("could not get protocol state for block id: %v", blockID)
return
Expand Down
4 changes: 2 additions & 2 deletions consensus/integration/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ func withNextEpoch(
ActiveIdentities: flow.DynamicIdentityEntryListFromIdentities(nextEpochIdentities),
}
// Re-construct epoch protocol state with modified events (constructs ActiveIdentity fields)
epochProtocolState, err = flow.NewRichProtocolStateEntry(
epochProtocolState.ProtocolStateEntry,
epochProtocolState, err = flow.NewRichEpochProtocolStateEntry(
epochProtocolState.EpochProtocolStateEntry,
epochProtocolState.PreviousEpochSetup, epochProtocolState.PreviousEpochCommit,
currEpochSetup, currEpochCommit,
nextEpochSetup, nextEpochCommit)
Expand Down
6 changes: 3 additions & 3 deletions consensus/integration/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func createRootBlockData(participantData *run.ParticipantData) (*flow.Block, *fl
},
)

epochProtocolStateID := inmem.ProtocolStateFromEpochServiceEvents(setup, commit).ID()
epochProtocolStateID := inmem.EpochProtocolStateFromServiceEvents(setup, commit).ID()
root.SetPayload(flow.Payload{ProtocolStateID: kvstore.NewDefaultKVStore(epochProtocolStateID).ID()})
result := unittest.BootstrapExecutionResultFixture(root, unittest.GenesisStateCommitment)
result.ServiceEvents = []flow.ServiceEvent{setup.ServiceEvent(), commit.ServiceEvent()}
Expand Down Expand Up @@ -378,8 +378,8 @@ func createNode(
qcsDB := storage.NewQuorumCertificates(metricsCollector, db, storage.DefaultCacheSize)
setupsDB := storage.NewEpochSetups(metricsCollector, db)
commitsDB := storage.NewEpochCommits(metricsCollector, db)
protocolStateDB := storage.NewProtocolState(metricsCollector, setupsDB, commitsDB, db,
storage.DefaultProtocolStateCacheSize, storage.DefaultProtocolStateByBlockIDCacheSize)
protocolStateDB := storage.NewEpochProtocolStateEntries(metricsCollector, setupsDB, commitsDB, db,
storage.DefaultEpochProtocolStateCacheSize, storage.DefaultProtocolStateIndexCacheSize)
protocokKVStoreDB := storage.NewProtocolKVStore(metricsCollector, db,
storage.DefaultProtocolKVStoreCacheSize, storage.DefaultProtocolKVStoreByBlockIDCacheSize)
versionBeaconDB := storage.NewVersionBeacons(db)
Expand Down
2 changes: 1 addition & 1 deletion engine/collection/test/cluster_switchover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewClusterSwitchoverTestCase(t *testing.T, conf ClusterSwitchoverTestConf)

seal.ResultID = result.ID()
root.Payload.ProtocolStateID = kvstore.NewDefaultKVStore(
inmem.ProtocolStateFromEpochServiceEvents(setup, commit).ID()).ID()
inmem.EpochProtocolStateFromServiceEvents(setup, commit).ID()).ID()
tc.root, err = inmem.SnapshotFromBootstrapState(root, result, seal, qc)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion engine/common/follower/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestFollowerHappyPath(t *testing.T) {
all.QuorumCertificates,
all.Setups,
all.EpochCommits,
all.EpochProtocolState,
all.EpochProtocolStateEntries,
all.ProtocolKVStore,
all.VersionBeacons,
rootSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion engine/testutil/mock/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type GenericNode struct {
Results storage.ExecutionResults
Setups storage.EpochSetups
EpochCommits storage.EpochCommits
EpochProtocolState storage.ProtocolState
EpochProtocolState storage.EpochProtocolStateEntries
ProtocolKVStore storage.ProtocolKVStore
State protocol.ParticipantState
Index storage.Index
Expand Down
4 changes: 2 additions & 2 deletions engine/testutil/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func GenericNodeWithStateFixture(t testing.TB,
Results: stateFixture.Storage.Results,
Setups: stateFixture.Storage.Setups,
EpochCommits: stateFixture.Storage.EpochCommits,
EpochProtocolState: stateFixture.Storage.EpochProtocolState,
EpochProtocolState: stateFixture.Storage.EpochProtocolStateEntries,
ProtocolKVStore: stateFixture.Storage.ProtocolKVStore,
State: stateFixture.State,
Index: stateFixture.Storage.Index,
Expand Down Expand Up @@ -245,7 +245,7 @@ func CompleteStateFixture(
s.QuorumCertificates,
s.Setups,
s.EpochCommits,
s.EpochProtocolState,
s.EpochProtocolStateEntries,
s.ProtocolKVStore,
s.VersionBeacons,
rootSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion engine/verification/utils/unittest/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func bootstrapSystem(
identities = append(identities, verID.Identity())

mutableProtocolState := protocol_state.NewMutableProtocolState(
stateFixture.Storage.EpochProtocolState,
stateFixture.Storage.EpochProtocolStateEntries,
stateFixture.Storage.ProtocolKVStore,
stateFixture.State.Params(),
stateFixture.Storage.Headers,
Expand Down
4 changes: 2 additions & 2 deletions integration/testnet/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ func (c *Container) OpenState() (*state.State, error) {
qcs := storage.NewQuorumCertificates(metrics, db, storage.DefaultCacheSize)
setups := storage.NewEpochSetups(metrics, db)
commits := storage.NewEpochCommits(metrics, db)
protocolState := storage.NewProtocolState(metrics, setups, commits, db,
storage.DefaultProtocolStateCacheSize, storage.DefaultProtocolStateByBlockIDCacheSize)
protocolState := storage.NewEpochProtocolStateEntries(metrics, setups, commits, db,
storage.DefaultEpochProtocolStateCacheSize, storage.DefaultProtocolStateIndexCacheSize)
protocolKVStates := storage.NewProtocolKVStore(metrics, db,
storage.DefaultProtocolKVStoreCacheSize, storage.DefaultProtocolKVStoreByBlockIDCacheSize)
versionBeacons := storage.NewVersionBeacons(db)
Expand Down
2 changes: 1 addition & 1 deletion integration/testnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ func BootstrapNetwork(networkConf NetworkConfig, bootstrapDir string, chainID fl
}
root.SetPayload(unittest.PayloadFixture(unittest.WithProtocolStateID(
networkConf.KVStoreFactory(
inmem.ProtocolStateFromEpochServiceEvents(epochSetup, epochCommit).ID(),
inmem.EpochProtocolStateFromServiceEvents(epochSetup, epochCommit).ID(),
).ID(),
)))

Expand Down
Loading

0 comments on commit 29bf6de

Please sign in to comment.