Skip to content

Commit 6a26a50

Browse files
authored
Apply suggestions from code review
1 parent 8e8dd8b commit 6a26a50

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

contracts/epochs/FlowEpoch.cdc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,10 @@ access(all) contract FlowEpoch {
555555
nodes.append(FlowIDTableStaking.NodeInfo(nodeID: nodeID))
556556
}
557557

558-
let numViewsInStakingAuction = stakingEndView - startView
559558
let numViewsInDKGPhase = FlowEpoch.configurableMetadata.numViewsInDKGPhase
560-
let dkgPhase1FinalView = startView + numViewsInStakingAuction + numViewsInDKGPhase - 1
561-
let dkgPhase2FinalView = startView + numViewsInStakingAuction + (2 * numViewsInDKGPhase) - 1
562-
let dkgPhase3FinalView = startView + numViewsInStakingAuction + (3 * numViewsInDKGPhase) - 1
559+
let dkgPhase1FinalView = stakingEndView + numViewsInDKGPhase
560+
let dkgPhase2FinalView = dkgPhase1FinalView + numViewsInDKGPhase
561+
let dkgPhase3FinalView = dkgPhase2FinalView + numViewsInDKGPhase
563562

564563
/// emit EpochRecover event
565564
emit FlowEpoch.EpochRecover(
@@ -697,7 +696,8 @@ access(all) contract FlowEpoch {
697696
/// This function is intended to update the current epoch configuration when a recovery
698697
/// transaction needs to be submitted more than once. This function differs
699698
/// from recoverNewEpoch because it does not increment the epoch counter. It also
700-
/// does not calculate or distribute rewards avoiding double paying rewards for the same epoch.
699+
/// does not calculate or distribute rewards -- calling recoverCurrentEpoch multiple times does not cause multiple reward payouts.
700+
/// Rewards for the recovery epoch will be calculated and paid out during the course of the epoch.
701701
/// This meta data will be emitted in the EpochRecover service event. This function is used
702702
/// within sporks to recover the network from Epoch Fallback Mode (EFM).
703703
access(all) fun recoverCurrentEpoch(recoveryEpochCounter: UInt64,
@@ -1052,7 +1052,7 @@ access(all) contract FlowEpoch {
10521052

10531053
self.currentEpochPhase = EpochPhase.EPOCHSETUP
10541054

1055-
let dkgPhase1FinalView = proposedEpochMetadata.startView + self.configurableMetadata.numViewsInStakingAuction + self.configurableMetadata.numViewsInDKGPhase - 1
1055+
let dkgPhase1FinalView = proposedEpochMetadata.stakingEndView + self.configurableMetadata.numViewsInDKGPhase
10561056
let dkgPhase2FinalView = dkgPhase1FinalView + self.configurableMetadata.numViewsInDKGPhase
10571057
let dkgPhase3FinalView = dkgPhase2FinalView + self.configurableMetadata.numViewsInDKGPhase
10581058
emit EpochSetup(counter: proposedEpochMetadata.counter,

lib/go/test/epoch_test_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ type testEpochConfig struct {
939939
numStakingViews uint64 // num views for staking auction
940940
numDKGViews uint64 // num views for DKG phase
941941
numClusters uint64 // num collector clusters
942-
numEpochAccounts int // num collector clusters
942+
numEpochAccounts int // num accounts to setup for staking
943943
randomSource string // random source
944944
rewardIncreaseFactor string // reward increase factor
945945
}

lib/go/test/flow_epoch_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,8 @@ func TestEpochReset(t *testing.T) {
15261526
// - epoch recover that specifies unsafeAllowOverwrite = true overwrites the current epoch and does not increment the counter.
15271527
func TestEpochRecover(t *testing.T) {
15281528

1529-
// Perform epoch recovery with a new epoch and epoch recover overwriting the current epoch.
1530-
t.Run("Can recover the epoch and have everything return to normal", func(t *testing.T) {
1529+
// Perform epoch recovery by transitioning into a new epoch (counter incremented by one)
1530+
t.Run("Can recover the epoch with a new epoch", func(t *testing.T) {
15311531
epochConfig := &testEpochConfig{
15321532
startEpochCounter: startEpochCounter,
15331533
numEpochViews: numEpochViews,
@@ -1653,7 +1653,7 @@ func TestEpochRecover(t *testing.T) {
16531653
endView uint64 = 160
16541654
targetDuration uint64 = numEpochViews
16551655
// invalid epoch counter when recovering the current epoch the counter should equal the current epoch counter
1656-
epochCounter uint64 = startEpochCounter + 100
1656+
epochCounter uint64 = startEpochCounter + 1
16571657
targetEndTime uint64 = expectedTargetEndTime(epochTimingConfigResult, epochCounter)
16581658
)
16591659
args := getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter)
@@ -1693,7 +1693,7 @@ func TestEpochRecover(t *testing.T) {
16931693
endView uint64 = 160
16941694
targetDuration uint64 = numEpochViews
16951695
// invalid epoch counter when recovering the current epoch the counter should equal the current epoch counter
1696-
epochCounter uint64 = startEpochCounter + 100
1696+
epochCounter uint64 = startEpochCounter
16971697
targetEndTime uint64 = expectedTargetEndTime(epochTimingConfigResult, epochCounter)
16981698
)
16991699
args := getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter)
@@ -2006,8 +2006,8 @@ func getRecoveryTxArgs(
20062006
cadence.NewUInt64(endView),
20072007
cadence.NewUInt64(targetDuration),
20082008
cadence.NewUInt64(targetEndTime),
2009-
cadence.NewArray(collectorClusters), // collectorClusters
2010-
cadence.NewArray(clusterQcVoteData), // clusterQCVoteData
2009+
cadence.NewArray(collectorClusters),
2010+
cadence.NewArray(clusterQcVoteData),
20112011
cadence.NewArray(dkgPubKeysCdc),
20122012
cadence.NewDictionary([]cadence.KeyValuePair{{
20132013
Key: cadence.String(nodeIds[0]),
@@ -2045,9 +2045,9 @@ func verifyEpochRecoverGovernanceTx(
20452045
}
20462046
}
20472047
for i, dkgKeyCdc := range args[8].(cadence.Array).Values {
2048+
// strip `"` characters because the Cadence fmt.Stringer implementation adds them.
20482049
dkgPubKeys[i] = strings.ReplaceAll(dkgKeyCdc.String(), `"`, "")
20492050
}
2050-
numStakingViews := stakingEndView - startView
20512051
// seed is not manually set when recovering the epoch, it is randomly generated
20522052
metadataFields := getEpochMetadata(t, b, env, cadence.NewUInt64(epochCounter))
20532053
seed := strings.ReplaceAll(metadataFields["seed"].String(), `"`, "")
@@ -2073,9 +2073,9 @@ func verifyEpochRecoverGovernanceTx(
20732073
finalView: endView,
20742074
collectorClusters: args[6].(cadence.Array).Values,
20752075
randomSource: seed,
2076-
dkgPhase1FinalView: startView + numStakingViews + numDKGViews - 1,
2077-
dkgPhase2FinalView: startView + numStakingViews + (2 * numDKGViews) - 1,
2078-
dkgPhase3FinalView: startView + numStakingViews + (3 * numDKGViews) - 1,
2076+
dkgPhase1FinalView: stakingEndView + numDKGViews,
2077+
dkgPhase2FinalView: stakingEndView + (2 * numDKGViews),
2078+
dkgPhase3FinalView: stakingEndView + (3 * numDKGViews),
20792079
targetDuration: targetDuration,
20802080
targetEndTime: targetEndTime,
20812081
numberClusterQCs: len(args[6].(cadence.Array).Values),

0 commit comments

Comments
 (0)