Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jordan Schalm <jordan@dapperlabs.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
  • Loading branch information
3 people authored May 13, 2024
1 parent 28a5b3d commit 38fab1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
5 changes: 4 additions & 1 deletion contracts/epochs/FlowClusterQC.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ access(all) contract FlowClusterQC {
/// Represents the quorum certificate vote data for a signer
/// of the certificate.
access(all) struct ClusterQCVoteData {
/// The vote signatures from all the nodes in the cluster
/// The hex-encoded vote signatures from all the nodes in the cluster
access(all) let voteSignatures: [String]

/// The node IDs that correspond to each vote
access(all) let voterIDs: [String]

init(signatures: [String], message: String, voterIDs: [String]) {
pre {
signatures.length == voterIDs.length: "must have exactly one vote signature per signer ID"
}
self.voteSignatures = signatures
self.voterIDs = voterIDs
}
Expand Down
35 changes: 21 additions & 14 deletions contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ access(all) contract FlowEpoch {
finalView: UInt64,

/// The cluster assignment for the RecoveryEpoch. Each element in the list
/// represents one cluster and contains all the node IDs assigned to that
/// cluster, with their weights and votes
collectorClusters: [[String]],
/// represents one cluster and contains all the node IDs assigned to that cluster.
clusterAssignments: [[String]],

/// The source of randomness to seed the leader selection algorithm with
/// for the upcoming epoch.
Expand All @@ -192,8 +191,12 @@ access(all) contract FlowEpoch {
/// using the same procedure as during a spork.
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],

/// The DKG public keys passed in the recoverEpoch transaction. These are re-used from the
/// last successful DKG.
/// The DKG public keys passed in the recoverEpoch transaction.
/// Currently, these are re-used from the last successful DKG. Note that this implies that
/// RecoveryEpoch MUST have a consensus committee that is identical to the last successful
/// DKG committee.
/// Group public key is the first element, followed by the individual keys
dkgPubKeys: [String],
)

Expand Down Expand Up @@ -257,7 +260,8 @@ access(all) contract FlowEpoch {
targetDuration: UInt64,
targetEndTime: UInt64,
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
dkgPubKeys: [String]) {
dkgPubKeys: [String]
) {

self.counter = counter
self.nodeIDs = nodeIDs
Expand Down Expand Up @@ -362,7 +366,6 @@ access(all) contract FlowEpoch {
self.dkgKeys = keys
}
}

/// Metadata that is managed and can be changed by the Admin///
access(all) struct Config {
/// The number of views in an entire epoch
Expand Down Expand Up @@ -605,16 +608,20 @@ access(all) contract FlowEpoch {

/// Create the recovery epoch metadata, this struct is used to hold
/// EpochRecover service event data.
let numViewsInStakingAuction = FlowEpoch.configurableMetadata.numViewsInStakingAuction
let numViewsInDKGPhase = FlowEpoch.configurableMetadata.numViewsInDKGPhase

let recoverEpochMetadata = FlowEpoch.RecoverEpochMetadata(
counter: FlowEpoch.proposedEpochCounter(),
nodeIDs: nodeIDs,
firstView: startView,
finalView: endView,
collectorClusters: collectorClusters,
randomSource: randomSource,
dkgPhase1FinalView: startView + FlowEpoch.configurableMetadata.numViewsInStakingAuction + FlowEpoch.configurableMetadata.numViewsInDKGPhase - 1 as UInt64,
dkgPhase2FinalView: startView + FlowEpoch.configurableMetadata.numViewsInStakingAuction + (2 as UInt64 * FlowEpoch.configurableMetadata.numViewsInDKGPhase) - 1 as UInt64,
dkgPhase3FinalView: startView + FlowEpoch.configurableMetadata.numViewsInStakingAuction + (3 as UInt64 * FlowEpoch.configurableMetadata.numViewsInDKGPhase) - 1 as UInt64,
dkgPhase1FinalView: startView + numViewsInStakingAuction + numViewsInDKGPhase - 1,
dkgPhase2FinalView: startView + numViewsInStakingAuction + (2 * numViewsInDKGPhase) - 1,
dkgPhase3FinalView: startView + numViewsInStakingAuction + (3 * numViewsInDKGPhase) - 1,
targetDuration: targetDuration,
targetEndTime: targetEndTime,
clusterQCVoteData: clusterQCVoteData,
Expand All @@ -635,10 +642,11 @@ access(all) contract FlowEpoch {
endView: endView,
stakingEndView: stakingEndView,
// The following fields will be overwritten in `calculateAndSetRewards` below
totalRewards: UFix64(0.0),
totalRewards: 0.0,
collectorClusters: [],
clusterQCs: [],
dkgKeys: dkgPubKeys)
dkgKeys: dkgPubKeys
)

/// Save the new epoch meta data, it will be referenced as
/// the epoch progresses through each phase.
Expand Down Expand Up @@ -716,8 +724,7 @@ access(all) contract FlowEpoch {
access(all) fun advanceBlock() {
/// check if we have recover epoch metadata stored, this indicates the network is in EFM and the heartbeat
/// will emit the EpochRecover event containing information for the recovery epoch.
let recoverEpochMetadata = FlowEpoch.account.storage.load<RecoverEpochMetadata>(from: /storage/recoverEpochMetadataStoragePath)
if recoverEpochMetadata != nil {
if let recoverEpochMetadata = FlowEpoch.account.storage.load<RecoverEpochMetadata>(from: /storage/recoverEpochMetadataStoragePath) {
// Construct the identity table for the recovery epoch
let nodes: [FlowIDTableStaking.NodeInfo] = []
for nodeID in recoverEpochMetadata!.nodeIDs {
Expand Down

0 comments on commit 38fab1a

Please sign in to comment.