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

Add node ID to index mapping to DKG data model #441

Merged
merged 49 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
dd90e0e
define ResultSubmission struct
jordanschalm Aug 7, 2024
7638aeb
annotate required changes
jordanschalm Aug 7, 2024
4e0bc0c
setup test framework
jordanschalm Aug 7, 2024
22ba195
add preliminary new fields to EpochCommit
jordanschalm Aug 8, 2024
e37f616
add submission tracker sketch
jordanschalm Aug 8, 2024
26039c5
ResultSubmission tests
jordanschalm Sep 11, 2024
88cd509
ResultSubmission docs
jordanschalm Sep 11, 2024
829586b
addSubmission method
jordanschalm Sep 12, 2024
db7aa57
add tx todos
jordanschalm Sep 12, 2024
14a70ab
add init test, validation on ResultSubmission init
jordanschalm Sep 13, 2024
c6e6369
test comments
jordanschalm Sep 13, 2024
cb02364
basic SubmissionTracker tests
jordanschalm Sep 13, 2024
e694f71
update other contract methods to use SubmissionTracker
jordanschalm Sep 13, 2024
854a570
add dummy values for EpochCommit event
jordanschalm Sep 13, 2024
257ddb6
add docs
jordanschalm Sep 13, 2024
5d9f137
add exceedsThreshold test
jordanschalm Sep 13, 2024
94c8cbb
Merge branch 'feature/efm-recovery' into jord/6213-dkg-mapping
jordanschalm Sep 13, 2024
027e41d
update FlowEpoch to compile
jordanschalm Sep 13, 2024
b1afc65
update transactions
jordanschalm Sep 13, 2024
56b12c1
improve representation for "empty submissions"
jordanschalm Sep 14, 2024
507a454
add test for empty submission
jordanschalm Sep 14, 2024
a9d24b4
test empty submission exceeds threshold
jordanschalm Sep 14, 2024
023faed
fix go test: send submission
jordanschalm Sep 14, 2024
5f236fb
wip
jordanschalm Sep 16, 2024
423fb44
remove '
jordanschalm Sep 16, 2024
23ade80
incredibly, the tests are passing
jordanschalm Sep 16, 2024
8f669f1
note where tests still need updating
jordanschalm Sep 16, 2024
060fbb5
consistent terminology: empty submission
jordanschalm Sep 17, 2024
3553260
resolve some todos
jordanschalm Sep 17, 2024
9db9ab8
fix empty submission dkg tests
jordanschalm Sep 17, 2024
135cad6
fix epoch tests
jordanschalm Sep 17, 2024
80f1f91
rename publish admin script
jordanschalm Sep 17, 2024
1fd997b
store as much as possible in EpochMetadata
jordanschalm Sep 17, 2024
9b623b3
build static files
jordanschalm Sep 17, 2024
3e32ac5
make more functions view
jordanschalm Sep 17, 2024
af7e508
fix test
jordanschalm Sep 17, 2024
07090b8
rename isValidNilSubmission
jordanschalm Oct 3, 2024
ed047b9
update error messages
jordanschalm Oct 10, 2024
3aee4ca
go generate
jordanschalm Oct 10, 2024
50e054a
Apply suggestions from code review
jordanschalm Oct 10, 2024
526bdbe
2nd pass over error messages
jordanschalm Oct 10, 2024
ecbf7bb
Merge branch 'jord/6213-dkg-mapping' of github.com:onflow/flow-core-c…
jordanschalm Oct 10, 2024
464db6d
fix empty whiteboard message test
jordanschalm Oct 10, 2024
4e09f85
improve post whiteboard message test
jordanschalm Oct 10, 2024
6931e78
rm dupe test
jordanschalm Oct 10, 2024
f292cc7
address remaining todos in tests
jordanschalm Oct 11, 2024
187728f
add preconditions for dkg enabled
jordanschalm Oct 15, 2024
a7f9805
fix message, generate
jordanschalm Oct 15, 2024
b24c015
add documentation for test helper functions
jordanschalm Oct 15, 2024
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
476 changes: 314 additions & 162 deletions contracts/epochs/FlowDKG.cdc

Large diffs are not rendered by default.

41 changes: 25 additions & 16 deletions contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ access(all) contract FlowEpoch {
/// The resulting public keys from the DKG process, encoded as by the flow-go
/// crypto library, then hex-encoded.
/// Group public key is the first element, followed by the individual keys
dkgPubKeys: [String]
dkgPubKeys: [String],

dkgGroupKey: String,

dkgIdMapping: {String: Int},
)

/// Contains specific metadata about a particular epoch
Expand Down Expand Up @@ -184,7 +188,10 @@ access(all) contract FlowEpoch {

/// The public keys associated with the Distributed Key Generation
/// process that consensus nodes participate in
/// Group key is the last element at index: length - 1
/// The first element is the group public key, followed by n participant public keys.
/// NOTE: This data structure was updated to include a mapping from node ID to DKG index.
/// Because structures cannot be updated in Cadence, we include the groupPubKey and pubKeys
/// fields here (idMapping field is omitted).
access(all) var dkgKeys: [String]

init(counter: UInt64,
Expand Down Expand Up @@ -230,12 +237,16 @@ access(all) contract FlowEpoch {
self.clusterQCs = qcs
}

access(account) fun setDKGGroupKey(keys: [String]) {
/// Sets the DKG group key (keys[0]) and participant keys (keys[1:]) from the DKG result.
/// NOTE: This data structure was updated to include a mapping from node ID to DKG index.
/// Because structures cannot be updated in Cadence, we include the groupPubKey and pubKeys
/// fields here (idMapping field is omitted).
access(account) fun setDKGKeys(keys: [String]) {
self.dkgKeys = keys
}
}

/// Metadata that is managed and can be changed by the Admin///
/// Metadata that is managed and can be changed by the Admin
access(all) struct Config {
/// The number of views in an entire epoch
access(all) var numViewsInEpoch: UInt64
Expand Down Expand Up @@ -769,27 +780,25 @@ access(all) contract FlowEpoch {
clusterQCs.append(certificate)
}

// Set cluster QCs in the proposed epoch metadata
// and stop QC voting
// Set cluster QCs in the proposed epoch metadata and stop QC voting
let proposedEpochMetadata = self.getEpochMetadata(self.proposedEpochCounter())!
proposedEpochMetadata.setClusterQCs(qcs: clusterQCs)

// Set DKG result keys in the proposed epoch metadata
// and stop DKG
let dkgKeys = FlowDKG.dkgCompleted()!
let unwrappedKeys: [String] = []
for key in dkgKeys {
unwrappedKeys.append(key!)
}
proposedEpochMetadata.setDKGGroupKey(keys: unwrappedKeys)

// Set DKG result in the proposed epoch metadata and stop DKG
let dkgResult = FlowDKG.dkgCompleted()!
// Construct a partial representation of the DKG result for storage in the epoch metadata.
// See setDKGKeys documentation for context on why the node ID mapping is omitted here.
let dkgPubKeys = [dkgResult.groupPubKey!].concat(dkgResult.pubKeys!)
proposedEpochMetadata.setDKGKeys(keys: dkgPubKeys)
self.saveEpochMetadata(proposedEpochMetadata)

self.currentEpochPhase = EpochPhase.EPOCHCOMMIT

emit EpochCommit(counter: self.proposedEpochCounter(),
clusterQCs: clusterQCs,
dkgPubKeys: unwrappedKeys)
dkgPubKeys: dkgResult.pubKeys!,
dkgGroupKey: dkgResult.groupPubKey!,
dkgIdMapping: dkgResult.idMapping!)
}

/// Borrow a reference to the FlowIDTableStaking Admin resource
Expand Down
12 changes: 6 additions & 6 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions lib/go/templates/flow_dkg_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ const (

// Admin Transactions

startDKGFilename = "dkg/admin/start_dkg.cdc"
nextPhaseFilename = "dkg/admin/next_phase.cdc"
stopDKGFilename = "dkg/admin/stop_dkg.cdc"
forceStopDKGFilename = "dkg/admin/force_stop_dkg.cdc"
setSafeThresholdFilename = "dkg/admin/set_safe_threshold.cdc"
publishParticipantFilename = "dkg/admin/publish_participant.cdc"
startDKGFilename = "dkg/admin/start_dkg.cdc"
nextPhaseFilename = "dkg/admin/next_phase.cdc"
stopDKGFilename = "dkg/admin/stop_dkg.cdc"
forceStopDKGFilename = "dkg/admin/force_stop_dkg.cdc"
setSafeThresholdFilename = "dkg/admin/set_safe_threshold.cdc"
publishDKGAdminFilename = "dkg/admin/publish_admin.cdc"

// Node Transactions

createParticipantFilename = "dkg/create_participant.cdc"
sendWhiteBoardMessageFilename = "dkg/send_whiteboard_message.cdc"
sendFinalSubmissionFilename = "dkg/send_final_submission.cdc"
createParticipantFilename = "dkg/create_participant.cdc"
sendWhiteBoardMessageFilename = "dkg/send_whiteboard_message.cdc"
sendFinalSubmissionFilename = "dkg/send_final_submission.cdc"
sendEmptyFinalSubmissionFilename = "dkg/send_empty_final_submission.cdc"

// Scripts

Expand Down Expand Up @@ -68,8 +69,8 @@ func GenerateSetSafeThresholdScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

func GeneratePublishDKGParticipantScript(env Environment) []byte {
code := assets.MustAssetString(publishParticipantFilename)
func GeneratePublishDKGAdminScript(env Environment) []byte {
code := assets.MustAssetString(publishDKGAdminFilename)

return []byte(ReplaceAddresses(code, env))
}
Expand Down Expand Up @@ -97,6 +98,13 @@ func GenerateSendDKGFinalSubmissionScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

// GenerateSendEmptyDKGFinalSubmissionScript generates a script that sends an empty dkg final submission for a node
func GenerateSendEmptyDKGFinalSubmissionScript(env Environment) []byte {
code := assets.MustAssetString(sendEmptyFinalSubmissionFilename)

return []byte(ReplaceAddresses(code, env))
}

// Scripts

func GenerateGetDKGEnabledScript(env Environment) []byte {
Expand Down
Loading
Loading