Skip to content

Commit 568129d

Browse files
authored
Merge pull request #5336 from onflow/jordan/sync-dyn-proto-state--master
Feature: Dynamic Protocol State
2 parents 443ba43 + 321a9e2 commit 568129d

File tree

390 files changed

+11225
-5378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

390 files changed

+11225
-5378
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
/cmd/util/util
88
/cmd/bootstrap/bootstrap
99

10+
# Test ouput of bootstrapping CLI
11+
cmd/bootstrap/bootstrap-example
1012

1113
# Test binary, build with `go test -c`
1214
*.test

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ generate-fvm-env-wrappers:
156156
generate-mocks: install-mock-generators
157157
mockery --name '(Connector|PingInfoProvider)' --dir=network/p2p --case=underscore --output="./network/mocknetwork" --outpkg="mocknetwork"
158158
CGO_CFLAGS=$(CRYPTO_FLAG) mockgen -destination=storage/mocks/storage.go -package=mocks github.com/onflow/flow-go/storage Blocks,Headers,Payloads,Collections,Commits,Events,ServiceEvents,TransactionResults
159-
CGO_CFLAGS=$(CRYPTO_FLAG) mockgen -destination=module/mocks/network.go -package=mocks github.com/onflow/flow-go/module Local,Requester
159+
# MERGE: Line below commented out on HEAD, uncommented on master
160+
#CGO_CFLAGS=$(CRYPTO_FLAG) mockgen -destination=module/mocks/network.go -package=mocks github.com/onflow/flow-go/module Local,Requester
160161
CGO_CFLAGS=$(CRYPTO_FLAG) mockgen -destination=network/mocknetwork/mock_network.go -package=mocknetwork github.com/onflow/flow-go/network EngineRegistry
161162
mockery --name='.*' --dir=integration/benchmark/mocksiface --case=underscore --output="integration/benchmark/mock" --outpkg="mock"
162163
mockery --name=ExecutionDataStore --dir=module/executiondatasync/execution_data --case=underscore --output="./module/executiondatasync/execution_data/mock" --outpkg="mock"
@@ -178,6 +179,7 @@ generate-mocks: install-mock-generators
178179
mockery --name '.*' --dir=storage --case=underscore --output="./storage/mock" --outpkg="mock"
179180
mockery --name '.*' --dir="state/protocol" --case=underscore --output="state/protocol/mock" --outpkg="mock"
180181
mockery --name '.*' --dir="state/protocol/events" --case=underscore --output="./state/protocol/events/mock" --outpkg="mock"
182+
mockery --name '.*' --dir="state/protocol/protocol_state" --case=underscore --output="state/protocol/protocol_state/mock" --outpkg="mock"
181183
mockery --name '.*' --dir=engine/execution/computation/computer --case=underscore --output="./engine/execution/computation/computer/mock" --outpkg="mock"
182184
mockery --name '.*' --dir=engine/execution/state --case=underscore --output="./engine/execution/state/mock" --outpkg="mock"
183185
mockery --name '.*' --dir=engine/collection --case=underscore --output="./engine/collection/mock" --outpkg="mock"

cmd/access/node_builder/access_node_builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,8 +1240,8 @@ func (builder *FlowAccessNodeBuilder) InitIDProviders() {
12401240
builder.SyncEngineParticipantsProviderFactory = func() module.IdentifierProvider {
12411241
return id.NewIdentityFilterIdentifierProvider(
12421242
filter.And(
1243-
filter.HasRole(flow.RoleConsensus),
1244-
filter.Not(filter.HasNodeID(node.Me.NodeID())),
1243+
filter.HasRole[flow.Identity](flow.RoleConsensus),
1244+
filter.Not(filter.HasNodeID[flow.Identity](node.Me.NodeID())),
12451245
underlay.NotEjectedFilter,
12461246
),
12471247
builder.IdentityProvider,
@@ -1574,7 +1574,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
15741574
node.Me,
15751575
node.State,
15761576
channels.RequestCollections,
1577-
filter.HasRole(flow.RoleCollection),
1577+
filter.HasRole[flow.Identity](flow.RoleCollection),
15781578
func() flow.Entity { return &flow.Collection{} },
15791579
)
15801580
if err != nil {

cmd/bootstrap/README.md

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,60 @@ Each input is a config file specified as a command line parameter:
9797

9898
#### Example
9999
```bash
100-
go run ./cmd/bootstrap finalize \
101-
--root-chain main \
102-
--root-height 0 \
103-
--root-parent 0000000000000000000000000000000000000000000000000000000000000000 \
104-
--root-commit 4b8d01975cf0cd23e046b1fae36518e542f92a6e35bedd627c43da30f4ae761a \
105-
--config ./cmd/bootstrap/example_files/node-config.json \
106-
--partner-dir ./cmd/bootstrap/example_files/partner-node-infos \
107-
--partner-weights ./cmd/bootstrap/example_files/partner-weights.json \
108-
--epoch-counter 1 \
109-
-o ./bootstrap/root-infos
100+
go run . genconfig \
101+
--address-format "%s%d-example.onflow.org:3569" \
102+
--access 2 \
103+
--collection 4 \
104+
--consensus 3 \
105+
--execution 2 \
106+
--verification 3 \
107+
--weight 100 \
108+
-o ./ \
109+
--config ./bootstrap-example/node-config.json
110+
111+
```
112+
113+
```bash
114+
go run . keygen \
115+
--machine-account \
116+
--config ./bootstrap-example/node-config.json \
117+
-o ./bootstrap-example/keys
118+
119+
```
120+
121+
```bash
122+
go run . rootblock \
123+
--root-chain bench \
124+
--root-height 0 \
125+
--root-parent 0000000000000000000000000000000000000000000000000000000000000000 \
126+
--epoch-counter 0 \
127+
--epoch-length 30000 \
128+
--epoch-staking-phase-length 20000 \
129+
--epoch-dkg-phase-length 2000 \
130+
--collection-clusters 1 \
131+
--protocol-version=0 \
132+
--epoch-commit-safety-threshold=1000 \
133+
--config ./bootstrap-example/node-config.json \
134+
-o ./bootstrap-example \
135+
--partner-dir ./example_files/partner-node-infos \
136+
--partner-weights ./example_files/partner-weights.json \
137+
--internal-priv-dir ./bootstrap-example/keys
138+
```
139+
140+
```bash
141+
go run . finalize \
142+
--config ./bootstrap-example/node-config.json \
143+
--partner-dir ./example_files/partner-node-infos \
144+
--partner-weights ./example_files/partner-weights.json \
145+
--internal-priv-dir ./bootstrap-example/keys/private-root-information \
146+
--dkg-data ./bootstrap-example/private-root-information/root-dkg-data.priv.json \
147+
--root-block ./bootstrap-example/public-root-information/root-block.json \
148+
--intermediary-bootstrapping-data ./bootstrap-example/public-root-information/intermediary-bootstrapping-data.json \
149+
--root-block-votes-dir ./bootstrap-example/public-root-information/root-block-votes/ \
150+
--root-commit 0000000000000000000000000000000000000000000000000000000000000000 \
151+
--genesis-token-supply="1000000000.0" \
152+
--service-account-public-key-json "{\"PublicKey\":\"R7MTEDdLclRLrj2MI1hcp4ucgRTpR15PCHAWLM5nks6Y3H7+PGkfZTP2di2jbITooWO4DD1yqaBSAVK8iQ6i0A==\",\"SignAlgo\":2,\"HashAlgo\":1,\"SeqNumber\":0,\"Weight\":1000}" \
153+
-o ./bootstrap-example
110154
```
111155

112156
#### Generated output files

cmd/bootstrap/cmd/block.go

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,81 @@ import (
55
"time"
66

77
"github.com/onflow/flow-go/cmd/bootstrap/run"
8+
"github.com/onflow/flow-go/model/dkg"
89
"github.com/onflow/flow-go/model/flow"
10+
"github.com/onflow/flow-go/module/signature"
11+
"github.com/onflow/flow-go/state/protocol/inmem"
912
)
1013

11-
func constructRootBlock(rootChain string, rootParent string, rootHeight uint64, rootTimestamp string) *flow.Block {
12-
14+
// constructRootHeader constructs a header for the root block.
15+
func constructRootHeader(rootChain string, rootParent string, rootHeight uint64, rootTimestamp string) *flow.Header {
1316
chainID := parseChainID(rootChain)
1417
parentID := parseParentID(rootParent)
1518
height := rootHeight
1619
timestamp := parseRootTimestamp(rootTimestamp)
1720

18-
block := run.GenerateRootBlock(chainID, parentID, height, timestamp)
21+
return run.GenerateRootHeader(chainID, parentID, height, timestamp)
22+
}
1923

24+
// constructRootBlock constructs a valid root block based on the given header, setup, and commit.
25+
func constructRootBlock(rootHeader *flow.Header, setup *flow.EpochSetup, commit *flow.EpochCommit) *flow.Block {
26+
block := &flow.Block{
27+
Header: rootHeader,
28+
Payload: nil,
29+
}
30+
block.SetPayload(flow.Payload{
31+
Guarantees: nil,
32+
Seals: nil,
33+
Receipts: nil,
34+
Results: nil,
35+
ProtocolStateID: inmem.ProtocolStateFromEpochServiceEvents(setup, commit).ID(),
36+
})
2037
return block
2138
}
2239

40+
// constructRootEpochEvents constructs the epoch setup and commit events for the first epoch after spork.
41+
func constructRootEpochEvents(
42+
firstView uint64,
43+
participants flow.IdentityList,
44+
assignments flow.AssignmentList,
45+
clusterQCs []*flow.QuorumCertificate,
46+
dkgData dkg.DKGData) (*flow.EpochSetup, *flow.EpochCommit) {
47+
epochSetup := &flow.EpochSetup{
48+
Counter: flagEpochCounter,
49+
FirstView: firstView,
50+
FinalView: firstView + flagNumViewsInEpoch - 1,
51+
DKGPhase1FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase - 1,
52+
DKGPhase2FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase*2 - 1,
53+
DKGPhase3FinalView: firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase*3 - 1,
54+
Participants: participants.Sort(flow.Canonical[flow.Identity]).ToSkeleton(),
55+
Assignments: assignments,
56+
RandomSource: GenerateRandomSeed(flow.EpochSetupRandomSourceLength),
57+
}
58+
59+
qcsWithSignerIDs := make([]*flow.QuorumCertificateWithSignerIDs, 0, len(clusterQCs))
60+
for i, clusterQC := range clusterQCs {
61+
members := assignments[i]
62+
signerIDs, err := signature.DecodeSignerIndicesToIdentifiers(members, clusterQC.SignerIndices)
63+
if err != nil {
64+
log.Fatal().Err(err).Msgf("could not decode signer IDs from clusterQC at index %v", i)
65+
}
66+
qcsWithSignerIDs = append(qcsWithSignerIDs, &flow.QuorumCertificateWithSignerIDs{
67+
View: clusterQC.View,
68+
BlockID: clusterQC.BlockID,
69+
SignerIDs: signerIDs,
70+
SigData: clusterQC.SigData,
71+
})
72+
}
73+
74+
epochCommit := &flow.EpochCommit{
75+
Counter: flagEpochCounter,
76+
ClusterQCs: flow.ClusterQCVoteDatasFromQCs(qcsWithSignerIDs),
77+
DKGGroupKey: dkgData.PubGroupKey,
78+
DKGParticipantKeys: dkgData.PubKeyShares,
79+
}
80+
return epochSetup, epochCommit
81+
}
82+
2383
func parseChainID(chainID string) flow.ChainID {
2484
switch chainID {
2585
case "main":

cmd/bootstrap/cmd/clusters.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
// of succeeding the assignment by re-running the function without increasing the internal nodes ratio.
2727
func constructClusterAssignment(partnerNodes, internalNodes []model.NodeInfo) (flow.AssignmentList, flow.ClusterList, error) {
2828

29-
partners := model.ToIdentityList(partnerNodes).Filter(filter.HasRole(flow.RoleCollection))
30-
internals := model.ToIdentityList(internalNodes).Filter(filter.HasRole(flow.RoleCollection))
29+
partners := model.ToIdentityList(partnerNodes).Filter(filter.HasRole[flow.Identity](flow.RoleCollection))
30+
internals := model.ToIdentityList(internalNodes).Filter(filter.HasRole[flow.Identity](flow.RoleCollection))
3131
nClusters := int(flagCollectionClusters)
3232
nCollectors := len(partners) + len(internals)
3333

@@ -73,7 +73,7 @@ func constructClusterAssignment(partnerNodes, internalNodes []model.NodeInfo) (f
7373
assignments := assignment.FromIdentifierLists(identifierLists)
7474

7575
collectors := append(partners, internals...)
76-
clusters, err := factory.NewClusterList(assignments, collectors)
76+
clusters, err := factory.NewClusterList(assignments, collectors.ToSkeleton())
7777
if err != nil {
7878
log.Fatal().Err(err).Msg("could not create cluster list")
7979
}
@@ -109,7 +109,7 @@ func constructRootQCsForClusters(
109109
// Filters a list of nodes to include only nodes that will sign the QC for the
110110
// given cluster. The resulting list of nodes is only nodes that are in the
111111
// given cluster AND are not partner nodes (ie. we have the private keys).
112-
func filterClusterSigners(cluster flow.IdentityList, nodeInfos []model.NodeInfo) []model.NodeInfo {
112+
func filterClusterSigners(cluster flow.IdentitySkeletonList, nodeInfos []model.NodeInfo) []model.NodeInfo {
113113

114114
var filtered []model.NodeInfo
115115
for _, node := range nodeInfos {

cmd/bootstrap/cmd/constraints.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import (
1212
func ensureUniformNodeWeightsPerRole(allNodes flow.IdentityList) {
1313
// ensure all nodes of the same role have equal weight
1414
for _, role := range flow.Roles() {
15-
withRole := allNodes.Filter(filter.HasRole(role))
15+
withRole := allNodes.Filter(filter.HasRole[flow.Identity](role))
1616
// each role has at least one node so it's safe to access withRole[0]
17-
expectedWeight := withRole[0].Weight
17+
expectedWeight := withRole[0].InitialWeight
1818
for _, node := range withRole {
19-
if node.Weight != expectedWeight {
19+
if node.InitialWeight != expectedWeight {
2020
log.Fatal().Msgf(
2121
"will not bootstrap configuration with non-equal weights\n"+
2222
"found nodes with role %s and weight1=%d, weight2=%d",
23-
role, expectedWeight, node.Weight)
23+
role, expectedWeight, node.InitialWeight)
2424
}
2525
}
2626
}

0 commit comments

Comments
 (0)