Skip to content

Commit

Permalink
use separate var for long lines, remove casts
Browse files Browse the repository at this point in the history
  • Loading branch information
kc1116 committed May 15, 2024
1 parent 5b08984 commit 3a1850c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ access(all) contract FlowEpoch {
access(all) fun updateEpochViews(_ newEpochViews: UInt64) {
pre {
FlowEpoch.currentEpochPhase == EpochPhase.STAKINGAUCTION: "Can only update fields during the staking auction"
FlowEpoch.isValidPhaseConfiguration(FlowEpoch.configurableMetadata.numViewsInStakingAuction,
FlowEpoch.configurableMetadata.numViewsInDKGPhase,
newEpochViews): "New Epoch Views must be greater than the sum of staking and DKG Phase views"
FlowEpoch.isValidPhaseConfiguration(auctionLen: FlowEpoch.configurableMetadata.numViewsInStakingAuction,
dkgPhaseLen: FlowEpoch.configurableMetadata.numViewsInDKGPhase,
epochLen: newEpochViews): "New Epoch Views must be greater than the sum of staking and DKG Phase views"
}

FlowEpoch.configurableMetadata.setNumViewsInEpoch(newEpochViews)
Expand Down Expand Up @@ -559,6 +559,11 @@ access(all) contract FlowEpoch {
for nodeID in nodeIDs {
nodes.append(FlowIDTableStaking.NodeInfo(nodeID: nodeID))
}

let dkgPhase1FinalView = startView + numViewsInStakingAuction + numViewsInDKGPhase - 1
let dkgPhase2FinalView = startView + numViewsInStakingAuction + (2 * numViewsInDKGPhase) - 1
let dkgPhase3FinalView = startView + numViewsInStakingAuction + (3 * numViewsInDKGPhase) - 1

/// emit EpochRecover event
emit EpochRecover(
counter: FlowEpoch.proposedEpochCounter(),
Expand All @@ -567,9 +572,9 @@ access(all) contract FlowEpoch {
finalView: endView,
clusterAssignments: clusterAssignments,
randomSource: randomSource,
DKGPhase1FinalView: startView + numViewsInStakingAuction + numViewsInDKGPhase - 1,
DKGPhase2FinalView: startView + numViewsInStakingAuction + (2 * numViewsInDKGPhase) - 1,
DKGPhase3FinalView: startView + numViewsInStakingAuction + (3 * numViewsInDKGPhase) - 1,
DKGPhase1FinalView: dkgPhase1FinalView,
DKGPhase2FinalView: dkgPhase2FinalView,
DKGPhase3FinalView: dkgPhase3FinalView,
targetDuration: targetDuration,
targetEndTime: targetEndTime,
clusterQCVoteData: clusterQCVoteData,
Expand Down Expand Up @@ -883,15 +888,18 @@ access(all) contract FlowEpoch {

self.currentEpochPhase = EpochPhase.EPOCHSETUP

let dkgPhase1FinalView = proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + self.configurableMetadata.numViewsInDKGPhase - 1
let dkgPhase2FinalView = proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + (2 * self.configurableMetadata.numViewsInDKGPhase) - 1
let dkgPhase3FinalView = proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + (3 * self.configurableMetadata.numViewsInDKGPhase) - 1
emit EpochSetup(counter: proposedEpochMetadata.counter,
nodeInfo: nodeInfoArray,
firstView: proposedEpochMetadata.startView,
finalView: proposedEpochMetadata.endView,
collectorClusters: collectorClusters,
randomSource: randomSource,
DKGPhase1FinalView: proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + self.configurableMetadata.numViewsInDKGPhase - 1 as UInt64,
DKGPhase2FinalView: proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + (2 as UInt64 * self.configurableMetadata.numViewsInDKGPhase) - 1 as UInt64,
DKGPhase3FinalView: proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + (3 as UInt64 * self.configurableMetadata.numViewsInDKGPhase) - 1 as UInt64,
DKGPhase1FinalView: dkgPhase1FinalView,
DKGPhase2FinalView: dkgPhase2FinalView,
DKGPhase3FinalView: dkgPhase3FinalView,
targetDuration: proposedTargetDuration,
targetEndTime: proposedTargetEndTime)
}
Expand Down Expand Up @@ -1090,7 +1098,7 @@ access(all) contract FlowEpoch {

/// The proposed Epoch counter is always the current counter plus 1
access(all) view fun proposedEpochCounter(): UInt64 {
return self.currentEpochCounter + 1 as UInt64
return self.currentEpochCounter + 1
}

access(all) fun automaticRewardsEnabled(): Bool {
Expand Down

0 comments on commit 3a1850c

Please sign in to comment.