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] Block payload contains protocol state ID #4868

Merged
merged 97 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
fab98d6
Updated payload to include protocol state ID. Updated some tests and …
durkmurder Aug 3, 2023
0d92777
Merge branch 'yurii/6803-snapshot-updates' of https://github.com/onfl…
durkmurder Aug 14, 2023
b7d5abf
Merge branch 'yurii/6803-snapshot-updates' of https://github.com/onfl…
durkmurder Aug 14, 2023
a3fd425
Updated storage layer to store protocol state ID as part of payload
durkmurder Aug 14, 2023
4ce8280
Updated mutator to check for protocol state ID in blocks that are bei…
durkmurder Aug 14, 2023
13f57f4
Work in progress on updating tests to include correct protocol state ID
durkmurder Aug 14, 2023
9b9e9a8
Updated many tests to properly include protocol state ID
durkmurder Aug 15, 2023
a724030
Merge branch 'feature/dynamic-protocol-state' of https://github.com/o…
durkmurder Oct 9, 2023
d93b659
Updated mutator and updater to be accessed from block builder
durkmurder Oct 9, 2023
3a7f0c8
Updated usage of protocol state updater and mutator. Fixed some issue…
durkmurder Oct 9, 2023
031ebb3
Updated usages of state mutator
durkmurder Oct 9, 2023
e233f05
Fixed compilation issue in updater
durkmurder Oct 9, 2023
df1939b
Updated mutator happy path test
durkmurder Oct 9, 2023
e097f4f
Added an utility function to make easier extend testing. Updated test…
durkmurder Oct 10, 2023
f97e06a
Extracted epoch validity functions into a different module. Updated r…
durkmurder Oct 10, 2023
2f3ae8c
Updated mutator tests regarding epoch service events validity
durkmurder Oct 10, 2023
06d6a1a
Fixed tests that depend on epoch builder
durkmurder Oct 10, 2023
8da7c3e
Fixed next group of protocol tests
durkmurder Oct 10, 2023
9fa6165
More updated to SealingSegment tests
durkmurder Oct 10, 2023
24e984e
Fixed sealing segment tests
durkmurder Oct 10, 2023
40fcdde
Fixed remaining snapshot tests
durkmurder Oct 10, 2023
b344f43
Fixed other broken tests in state/protocol
durkmurder Oct 10, 2023
a0b0ea3
Updated how protocol state is opened and bootstrapped. Fixed tests fo…
durkmurder Oct 11, 2023
f346102
Fixed other tests for state module
durkmurder Oct 11, 2023
9ab6253
Fixed all tests from module package except consensus
durkmurder Oct 12, 2023
d079953
Updated mocks. Updated builder constructor
durkmurder Oct 12, 2023
059bf82
Fixed consensus builder tests
durkmurder Oct 12, 2023
0ac1dd3
Decoupled setting hotstuff fields and producing a signature in block …
durkmurder Oct 12, 2023
d7a6dba
Fixed broken builder tests
durkmurder Oct 12, 2023
f6e0e8b
Fixed some broken tests
durkmurder Oct 13, 2023
b93ae30
Updated protobuf files from onflow/flow. Fixed convert test
durkmurder Oct 13, 2023
67c6799
change expected state comitment hashes
janezpodhostnik Oct 13, 2023
9810f16
Fixed setup of integration tests. Updated go modules
durkmurder Oct 13, 2023
34dde0d
Merge branch 'yurii/5517-extend-payload' of https://github.com/onflow…
durkmurder Oct 13, 2023
652d6dc
Fixed broken execution tests
durkmurder Oct 13, 2023
82b6d1e
Merge branch 'feature/dynamic-protocol-state' of https://github.com/o…
durkmurder Oct 16, 2023
d468da1
Merge branch 'feature/dynamic-protocol-state' of https://github.com/o…
durkmurder Oct 23, 2023
d454e5e
Merge branch 'feature/dynamic-protocol-state' of https://github.com/o…
durkmurder Oct 24, 2023
444459f
Fixed broken tests
durkmurder Oct 24, 2023
084669f
Changed order of InvalidStateTransitionAttempted in updater
durkmurder Oct 24, 2023
7b5135a
Tidy
durkmurder Oct 24, 2023
a46d6d8
Linted and updated error handling
durkmurder Oct 24, 2023
d4d0f9a
Extracted epoch setup and commits events creation from finalize comma…
durkmurder Oct 25, 2023
dc1ecf6
Finished updating rootblock command to correctly generate first epoch…
durkmurder Oct 25, 2023
07167d0
Linted
durkmurder Oct 25, 2023
76b8fa0
Fixed compilation of integration tests
durkmurder Oct 25, 2023
3246926
godoc cleanup
durkmurder Oct 25, 2023
64c9a5c
Godoc and state updater error handling updates
durkmurder Oct 25, 2023
7553ed9
Added tests for ApplyServiceEvents
durkmurder Oct 26, 2023
13e9957
Merge branch 'yurii/5517-extend-payload' of https://github.com/onflow…
durkmurder Oct 26, 2023
aa1169c
Updated tests for protocol state mutator
durkmurder Oct 27, 2023
9e90ac0
Consolidated service events handling in protocol state updater. Updat…
durkmurder Oct 27, 2023
a957702
added minor todo comment for
Oct 28, 2023
e11d0c2
Updated mutator tests to cover all paths in ApplyServiceEvents
durkmurder Oct 30, 2023
80f4bdf
Updated dynamic protocol state main interfaces. Restructured interfac…
durkmurder Oct 31, 2023
8a733b3
Fixed tests for state/protocol/*
durkmurder Oct 31, 2023
74be7f8
Fixed other broken tests. Linted
durkmurder Oct 31, 2023
8f4e038
Updated tests and changed Build signature
durkmurder Oct 31, 2023
4672345
Linted
durkmurder Oct 31, 2023
e7d75cd
Updated godoc
durkmurder Oct 31, 2023
d998fbf
Apply suggestions from code review
durkmurder Nov 1, 2023
b3d92bc
Apply suggestions from code review
durkmurder Nov 1, 2023
164fa95
Renamed seals.go -> payload.go
durkmurder Nov 1, 2023
f1965e1
Updated godocs
durkmurder Nov 1, 2023
bdde391
detailed documentation of `StateMutator.ApplyServiceEvents`
Nov 2, 2023
d0bc661
Apply suggestions from code review
durkmurder Nov 2, 2023
69842cd
Apply suggestions from PR review
durkmurder Nov 2, 2023
f57cb5e
Updated protocol state mutator to rely only on fork-based flag for ep…
durkmurder Nov 2, 2023
6645d1e
Apply suggestions from PR review
durkmurder Nov 2, 2023
7ad9e93
minor documentation tweaks
Nov 3, 2023
139d60a
Update state/protocol/protocol_state/mutator.go
durkmurder Nov 3, 2023
054435d
Linted
durkmurder Nov 3, 2023
203f049
extending and polishing documentation of verification logic for Epoch…
Nov 5, 2023
17f69ed
fixed formatting problem of goDoc
Nov 5, 2023
6da91f5
fixed formatting problem of goDoc
Nov 5, 2023
2c863f3
compactified code
Nov 5, 2023
1e03f9f
minor extension of test description
Nov 5, 2023
98aec88
extended and polished docs for StateMutator
Nov 7, 2023
df1fd29
goDoc polishing of state machine
Nov 7, 2023
2e59e75
typo
Nov 7, 2023
79e079e
minor revision of test names for better readability. e.g. TestHappyPa…
Nov 8, 2023
6a3eb1c
comment formating
Nov 11, 2023
169f5d5
Merge branch 'feature/dynamic-protocol-state' of https://github.com/o…
durkmurder Nov 13, 2023
cb08aa2
Updated modules for insecure and integration
durkmurder Nov 13, 2023
9fc2f66
Merge branch 'yurii/5517-extend-payload' of https://github.com/onflow…
durkmurder Nov 13, 2023
602358f
Apply suggestions from PR review
durkmurder Nov 13, 2023
cbf4149
Apply suggestions from PR review
durkmurder Nov 13, 2023
8264c2a
Introduced DeferredDBUpdated
durkmurder Nov 13, 2023
52bacec
Renamed ProtocolStateForBoostrapState -> ProtocolStateFromEpochServic…
durkmurder Nov 13, 2023
27d32d1
Linted
durkmurder Nov 13, 2023
38b3210
Updated docs and implementation for TestHappyPathWithDbChanges
durkmurder Nov 13, 2023
87f36aa
Removed duplicated tests
durkmurder Nov 14, 2023
761d74a
Added test cases for epoch setup validity
durkmurder Nov 14, 2023
4ba03bc
Updated tests for NewClusterList
durkmurder Nov 14, 2023
fad73b3
Added test for validating extending setup and commit events
durkmurder Nov 14, 2023
45c9081
Linted
durkmurder Nov 14, 2023
a389919
Update state/protocol/protocol_state/mutator_test.go
durkmurder Nov 14, 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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ generate-mocks: install-mock-generators
mockery --name '.*' --dir=storage --case=underscore --output="./storage/mock" --outpkg="mock"
mockery --name '.*' --dir="state/protocol" --case=underscore --output="state/protocol/mock" --outpkg="mock"
mockery --name '.*' --dir="state/protocol/events" --case=underscore --output="./state/protocol/events/mock" --outpkg="mock"
mockery --name '.*' --dir="state/protocol/protocol_state" --case=underscore --output="state/protocol/protocol_state/mock" --outpkg="mock"
mockery --name '.*' --dir=engine/execution/computation/computer --case=underscore --output="./engine/execution/computation/computer/mock" --outpkg="mock"
mockery --name '.*' --dir=engine/execution/state --case=underscore --output="./engine/execution/state/mock" --outpkg="mock"
mockery --name '.*' --dir=engine/collection --case=underscore --output="./engine/collection/mock" --outpkg="mock"
Expand Down
67 changes: 64 additions & 3 deletions cmd/bootstrap/cmd/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,82 @@ import (
"time"

"github.com/onflow/flow-go/cmd/bootstrap/run"
"github.com/onflow/flow-go/model/dkg"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/module/signature"
"github.com/onflow/flow-go/state/protocol/inmem"
)

func constructRootBlock(rootChain string, rootParent string, rootHeight uint64, rootTimestamp string) *flow.Block {

// constructRootHeader constructs a header for the root block.
func constructRootHeader(rootChain string, rootParent string, rootHeight uint64, rootTimestamp string) *flow.Header {
chainID := parseChainID(rootChain)
parentID := parseParentID(rootParent)
height := rootHeight
timestamp := parseRootTimestamp(rootTimestamp)

block := run.GenerateRootBlock(chainID, parentID, height, timestamp)
return run.GenerateRootHeader(chainID, parentID, height, timestamp)
}

// constructRootBlock constructs a valid root block based on the given header, setup, and commit.
func constructRootBlock(rootHeader *flow.Header, setup *flow.EpochSetup, commit *flow.EpochCommit) *flow.Block {
block := &flow.Block{
Header: rootHeader,
Payload: nil,
}
block.SetPayload(flow.Payload{
Guarantees: nil,
Seals: nil,
Receipts: nil,
Results: nil,
ProtocolStateID: inmem.ProtocolStateFromEpochServiceEvents(setup, commit).ID(),
})
return block
}

// constructRootEpochEvents constructs the epoch setup and commit events for the first epoch after spork.
func constructRootEpochEvents(
firstView uint64,
participants flow.IdentityList,
assignments flow.AssignmentList,
clusterQCs []*flow.QuorumCertificate,
dkgData dkg.DKGData) (*flow.EpochSetup, *flow.EpochCommit) {
epochSetup := &flow.EpochSetup{
Counter: flagEpochCounter,
FirstView: firstView,
FinalView: firstView + flagNumViewsInEpoch - 1,
DKGPhase1FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase - 1,
DKGPhase2FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase*2 - 1,
DKGPhase3FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase*3 - 1,
Participants: participants.Sort(order.Canonical[flow.Identity]).ToSkeleton(),
Assignments: assignments,
RandomSource: GenerateRandomSeed(flow.EpochSetupRandomSourceLength),
}

qcsWithSignerIDs := make([]*flow.QuorumCertificateWithSignerIDs, 0, len(clusterQCs))
for i, clusterQC := range clusterQCs {
members := assignments[i]
signerIDs, err := signature.DecodeSignerIndicesToIdentifiers(members, clusterQC.SignerIndices)
if err != nil {
log.Fatal().Err(err).Msgf("could not decode signer IDs from clusterQC at index %v", i)
}
qcsWithSignerIDs = append(qcsWithSignerIDs, &flow.QuorumCertificateWithSignerIDs{
View: clusterQC.View,
BlockID: clusterQC.BlockID,
SignerIDs: signerIDs,
SigData: clusterQC.SigData,
})
}

epochCommit := &flow.EpochCommit{
Counter: flagEpochCounter,
ClusterQCs: flow.ClusterQCVoteDatasFromQCs(qcsWithSignerIDs),
DKGGroupKey: dkgData.PubGroupKey,
DKGParticipantKeys: dkgData.PubKeyShares,
}
return epochSetup, epochCommit
}

func parseChainID(chainID string) flow.ChainID {
switch chainID {
case "main":
Expand Down
18 changes: 18 additions & 0 deletions cmd/bootstrap/cmd/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/onflow/flow-go/model/flow/assignment"
"github.com/onflow/flow-go/model/flow/factory"
"github.com/onflow/flow-go/model/flow/filter"
"github.com/onflow/flow-go/state/protocol"
)

// Construct random cluster assignment with internal and partner nodes.
Expand Down Expand Up @@ -123,3 +124,20 @@ func filterClusterSigners(cluster flow.IdentitySkeletonList, nodeInfos []model.N

return filtered
}

// clusterRootQCsFromEpoch returns a list of cluster root QCs from the given epoch.
func clusterRootQCsFromEpoch(epoch protocol.Epoch) []*flow.QuorumCertificate {
clustering, err := epoch.Clustering()
if err != nil {
log.Fatal().Err(err).Msg("could not get epoch clustering")
}
qcs := make([]*flow.QuorumCertificate, 0, len(clustering))
for i := range clustering {
cluster, err := epoch.Cluster(uint(i))
if err != nil {
log.Fatal().Err(err).Msgf("could not get epoch cluster (index=%d)", i)
}
qcs = append(qcs, cluster.RootQC())
}
return qcs
}
67 changes: 35 additions & 32 deletions cmd/bootstrap/cmd/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ var (
flagPartnerWeights string
flagDKGDataPath string
flagRootBlock string
flagRootEpoch string
flagRootBlockVotesDir string
flagRootCommit string
flagProtocolVersion uint
flagServiceAccountPublicKeyJSON string
flagGenesisTokenSupply string
flagEpochCounter uint64
flagNumViewsInEpoch uint64
flagNumViewsInStakingAuction uint64
flagNumViewsInDKGPhase uint64
flagEpochCommitSafetyThreshold uint64
)

Expand Down Expand Up @@ -91,24 +88,19 @@ func addFinalizeCmdFlags() {
// required parameters for generation of root block, root execution result and root block seal
finalizeCmd.Flags().StringVar(&flagRootBlock, "root-block", "",
"path to a JSON file containing root block")
finalizeCmd.Flags().StringVar(&flagRootEpoch, "root-epoch", "",
"path to a JSON file containing root epoch")
finalizeCmd.Flags().StringVar(&flagRootBlockVotesDir, "root-block-votes-dir", "", "path to directory with votes for root block")
finalizeCmd.Flags().StringVar(&flagRootCommit, "root-commit", "0000000000000000000000000000000000000000000000000000000000000000", "state commitment of root execution state")
finalizeCmd.Flags().Uint64Var(&flagEpochCounter, "epoch-counter", 0, "epoch counter for the epoch beginning with the root block")
finalizeCmd.Flags().Uint64Var(&flagNumViewsInEpoch, "epoch-length", 4000, "length of each epoch measured in views")
finalizeCmd.Flags().Uint64Var(&flagNumViewsInStakingAuction, "epoch-staking-phase-length", 100, "length of the epoch staking phase measured in views")
finalizeCmd.Flags().Uint64Var(&flagNumViewsInDKGPhase, "epoch-dkg-phase-length", 1000, "length of each DKG phase measured in views")
finalizeCmd.Flags().Uint64Var(&flagEpochCommitSafetyThreshold, "epoch-commit-safety-threshold", 500, "defines epoch commitment deadline")
finalizeCmd.Flags().UintVar(&flagProtocolVersion, "protocol-version", flow.DefaultProtocolVersion, "major software version used for the duration of this spork")

cmd.MarkFlagRequired(finalizeCmd, "root-block")
cmd.MarkFlagRequired(finalizeCmd, "root-epoch")
cmd.MarkFlagRequired(finalizeCmd, "root-block-votes-dir")
cmd.MarkFlagRequired(finalizeCmd, "root-commit")
cmd.MarkFlagRequired(finalizeCmd, "epoch-counter")
cmd.MarkFlagRequired(finalizeCmd, "epoch-length")
cmd.MarkFlagRequired(finalizeCmd, "epoch-staking-phase-length")
cmd.MarkFlagRequired(finalizeCmd, "epoch-dkg-phase-length")
cmd.MarkFlagRequired(finalizeCmd, "epoch-commit-safety-threshold")
cmd.MarkFlagRequired(finalizeCmd, "protocol-version")
cmd.MarkFlagRequired(finalizeCmd, "epoch-commit-safety-threshold")

// optional parameters to influence various aspects of identity generation
finalizeCmd.Flags().UintVar(&flagCollectionClusters, "collection-clusters", 2, "number of collection clusters")
Expand Down Expand Up @@ -172,6 +164,11 @@ func finalize(cmd *cobra.Command, args []string) {
dkgData := readDKGData()
log.Info().Msg("")

log.Info().Msg("reading root epoch")
epoch, epochSetup, epochCommit := readRootEpoch()
clusterQCs := clusterRootQCsFromEpoch(epoch)
log.Info().Msg("")

log.Info().Msg("constructing root QC")
rootQC := constructRootQC(
block,
Expand All @@ -182,34 +179,19 @@ func finalize(cmd *cobra.Command, args []string) {
)
log.Info().Msg("")

log.Info().Msg("computing collection node clusters")
assignments, clusters, err := constructClusterAssignment(partnerNodes, internalNodes)
if err != nil {
log.Fatal().Err(err).Msg("unable to generate cluster assignment")
}
log.Info().Msg("")

log.Info().Msg("constructing root blocks for collection node clusters")
clusterBlocks := run.GenerateRootClusterBlocks(flagEpochCounter, clusters)
log.Info().Msg("")

log.Info().Msg("constructing root QCs for collection node clusters")
clusterQCs := constructRootQCsForClusters(clusters, internalNodes, clusterBlocks)
log.Info().Msg("")

// if no root commit is specified, bootstrap an empty execution state
if flagRootCommit == "0000000000000000000000000000000000000000000000000000000000000000" {
generateEmptyExecutionState(
block.Header.ChainID,
assignments,
epochSetup.Assignments,
clusterQCs,
dkgData,
participants,
)
}

log.Info().Msg("constructing root execution result and block seal")
result, seal := constructRootResultAndSeal(flagRootCommit, block, participants, assignments, clusterQCs, dkgData)
result, seal := constructRootResultAndSeal(flagRootCommit, block, epochSetup, epochCommit)
log.Info().Msg("")

// construct serializable root protocol snapshot
Expand Down Expand Up @@ -499,15 +481,36 @@ func mergeNodeInfos(internalNodes, partnerNodes []model.NodeInfo) []model.NodeIn
// readRootBlock reads root block data from disc, this file needs to be prepared with
// rootblock command
func readRootBlock() *flow.Block {
rootBlock, err := utils.ReadRootBlock(flagRootBlock)
rootBlock, err := utils.ReadData[flow.Block](flagRootBlock)
if err != nil {
log.Fatal().Err(err).Msg("could not read root block data")
}
return rootBlock
}

// readRootEpoch reads root epoch data from disc, this file needs to be prepared with
// rootblock command
func readRootEpoch() (protocol.Epoch, *flow.EpochSetup, *flow.EpochCommit) {
encodableEpoch, err := utils.ReadData[inmem.EncodableEpoch](flagRootEpoch)
if err != nil {
log.Fatal().Err(err).Msg("could not read root epoch data")
}
epoch := inmem.NewEpoch(*encodableEpoch)
setup, err := protocol.ToEpochSetup(epoch)
if err != nil {
log.Fatal().Err(err).Msg("could not extract setup event")
}
commit, err := protocol.ToEpochCommit(epoch)
if err != nil {
log.Fatal().Err(err).Msg("could not extract commit event")
}
return epoch, setup, commit
}

// readDKGData reads DKG data from disc, this file needs to be prepared with
// rootblock command
func readDKGData() dkg.DKGData {
encodableDKG, err := utils.ReadDKGData(flagDKGDataPath)
encodableDKG, err := utils.ReadData[inmem.EncodableFullDKG](flagDKGDataPath)
if err != nil {
log.Fatal().Err(err).Msg("could not read DKG data")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/bootstrap/cmd/finalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ const finalizeHappyPathLogs = "collecting partner network and staking keys" +
`reading root block votes` +
`read vote .*` +
`reading dkg data` +
`reading root epoch` +
`constructing root QC` +
`computing collection node clusters` +
`constructing root blocks for collection node clusters` +
`constructing root QCs for collection node clusters` +
`constructing root execution result and block seal` +
`constructing root protocol snapshot` +
`wrote file \S+/root-protocol-state-snapshot.json` +
Expand Down Expand Up @@ -79,6 +77,7 @@ func TestFinalize_HappyPath(t *testing.T) {
flagNumViewsInDKGPhase = 2_000
flagEpochCommitSafetyThreshold = 1_000
flagRootBlock = filepath.Join(bootDir, model.PathRootBlockData)
flagRootEpoch = filepath.Join(bootDir, model.PathRootEpoch)
flagDKGDataPath = filepath.Join(bootDir, model.PathRootDKGData)
flagRootBlockVotesDir = filepath.Join(bootDir, model.DirnameRootBlockVotes)

Expand Down
60 changes: 55 additions & 5 deletions cmd/bootstrap/cmd/rootblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import (
"github.com/spf13/cobra"

"github.com/onflow/flow-go/cmd"
"github.com/onflow/flow-go/cmd/bootstrap/run"
model "github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/order"
"github.com/onflow/flow-go/state/protocol/inmem"
)

var (
flagRootChain string
flagRootParent string
flagRootHeight uint64
flagRootTimestamp string
flagRootChain string
flagRootParent string
flagRootHeight uint64
flagRootTimestamp string
flagEpochCounter uint64
flagNumViewsInEpoch uint64
flagNumViewsInStakingAuction uint64
flagNumViewsInDKGPhase uint64
)

// rootBlockCmd represents the rootBlock command
Expand Down Expand Up @@ -48,6 +55,17 @@ func addRootBlockCmdFlags() {
cmd.MarkFlagRequired(rootBlockCmd, "partner-dir")
cmd.MarkFlagRequired(rootBlockCmd, "partner-weights")

// required parameters for generation of epoch setup and commit events
rootBlockCmd.Flags().Uint64Var(&flagEpochCounter, "epoch-counter", 0, "epoch counter for the epoch beginning with the root block")
rootBlockCmd.Flags().Uint64Var(&flagNumViewsInEpoch, "epoch-length", 4000, "length of each epoch measured in views")
rootBlockCmd.Flags().Uint64Var(&flagNumViewsInStakingAuction, "epoch-staking-phase-length", 100, "length of the epoch staking phase measured in views")
rootBlockCmd.Flags().Uint64Var(&flagNumViewsInDKGPhase, "epoch-dkg-phase-length", 1000, "length of each DKG phase measured in views")

cmd.MarkFlagRequired(rootBlockCmd, "epoch-counter")
cmd.MarkFlagRequired(rootBlockCmd, "epoch-length")
cmd.MarkFlagRequired(rootBlockCmd, "epoch-staking-phase-length")
cmd.MarkFlagRequired(rootBlockCmd, "epoch-dkg-phase-length")

// required parameters for generation of root block, root execution result and root block seal
rootBlockCmd.Flags().StringVar(&flagRootChain, "root-chain", "local", "chain ID for the root block (can be 'main', 'test', 'sandbox', 'bench', or 'local'")
rootBlockCmd.Flags().StringVar(&flagRootParent, "root-parent", "0000000000000000000000000000000000000000000000000000000000000000", "ID for the parent of the root block")
Expand Down Expand Up @@ -92,8 +110,40 @@ func rootBlock(cmd *cobra.Command, args []string) {
dkgData := runBeaconKG(model.FilterByRole(stakingNodes, flow.RoleConsensus))
log.Info().Msg("")

// create flow.IdentityList representation of the participant set
participants := model.ToIdentityList(stakingNodes).Sort(order.Canonical[flow.Identity])

log.Info().Msg("computing collection node clusters")
assignments, clusters, err := constructClusterAssignment(partnerNodes, internalNodes)
if err != nil {
log.Fatal().Err(err).Msg("unable to generate cluster assignment")
}
log.Info().Msg("")

log.Info().Msg("constructing root blocks for collection node clusters")
clusterBlocks := run.GenerateRootClusterBlocks(flagEpochCounter, clusters)
log.Info().Msg("")

log.Info().Msg("constructing root QCs for collection node clusters")
clusterQCs := constructRootQCsForClusters(clusters, internalNodes, clusterBlocks)
log.Info().Msg("")

log.Info().Msg("constructing root header")
header := constructRootHeader(flagRootChain, flagRootParent, flagRootHeight, flagRootTimestamp)
log.Info().Msg("")

log.Info().Msg("constructing epoch events")
epochSetup, epochCommit := constructRootEpochEvents(header.View, participants, assignments, clusterQCs, dkgData)
committedEpoch := inmem.NewCommittedEpoch(epochSetup, epochCommit)
encodableEpoch, err := inmem.FromEpoch(committedEpoch)
if err != nil {
log.Fatal().Msg("could not convert root epoch to encodable")
}
writeJSON(model.PathRootEpoch, encodableEpoch.Encodable())
log.Info().Msg("")

log.Info().Msg("constructing root block")
block := constructRootBlock(flagRootChain, flagRootParent, flagRootHeight, flagRootTimestamp)
block := constructRootBlock(header, epochSetup, epochCommit)
writeJSON(model.PathRootBlockData, block)
log.Info().Msg("")

Expand Down
Loading
Loading