Skip to content

Commit

Permalink
cant use timing config in epoch recover
Browse files Browse the repository at this point in the history
- target duration and end time must be provided in governance transaction
  • Loading branch information
kc1116 committed Apr 26, 2024
1 parent 381ca6f commit a4943ec
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
17 changes: 6 additions & 11 deletions contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ access(all) contract FlowEpoch {
/// The deadlines of each phase in the DKG protocol to be completed in the upcoming
/// EpochSetup phase. Deadlines are specified in terms of a consensus view number.
/// When a DKG participant observes a finalized and sealed block with view greater
/// than the given deadline, it can safely transition to the next phase.
/// than the given deadline, it can safely transition to the next phase.
access(all) let dkgPhase1FinalView: UInt64
access(all) let dkgPhase2FinalView: UInt64
access(all) let dkgPhase3FinalView: UInt64
Expand All @@ -249,7 +249,6 @@ access(all) contract FlowEpoch {
nodeIDs: [String],
firstView: UInt64,
finalView: UInt64,
stakingEndView: UInt64,
collectorClusters: [[String]],
randomSource: String,
dkgPhase1FinalView: UInt64,
Expand All @@ -264,7 +263,6 @@ access(all) contract FlowEpoch {
self.nodeIDs = nodeIDs
self.firstView = firstView
self.finalView = finalView
self.stakingEndView = stakingEndView
self.collectorClusters = collectorClusters
self.randomSource = randomSource
self.dkgPhase1FinalView = dkgPhase1FinalView
Expand Down Expand Up @@ -364,7 +362,7 @@ 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 @@ -571,6 +569,8 @@ access(all) contract FlowEpoch {
startView: UInt64,
stakingEndView: UInt64,
endView: UInt64,
targetDuration: UInt64,
targetEndTime: UInt64,
collectorClusters: [[String]],
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
dkgPubKeys: [String],
Expand Down Expand Up @@ -599,11 +599,6 @@ access(all) contract FlowEpoch {
FlowEpoch.borrowDKGAdmin().forceEndDKG()
}

// Compute the target end time for the next epoch
let timingConfig = FlowEpoch.getEpochTimingConfig()
let proposedTargetDuration = timingConfig.duration
let proposedTargetEndTime = timingConfig.getTargetEndTimeForEpoch(FlowEpoch.proposedEpochCounter())

// Create new Epoch metadata for the next epoch
// with the new values
let newEpochMetadata = EpochMetadata(
Expand Down Expand Up @@ -635,8 +630,8 @@ access(all) contract FlowEpoch {
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,
targetDuration: proposedTargetDuration,
targetEndTime: proposedTargetEndTime,
targetDuration: targetDuration,
targetEndTime: targetEndTime,
clusterQCVoteData: clusterQCVoteData,
dkgPubKeys: dkgPubKeys,
)
Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions lib/go/test/flow_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1591,15 +1591,21 @@ func TestEpochRecover(t *testing.T) {
t.Run("Can recover the epoch and have everything return to normal", func(t *testing.T) {
epochTimingConfigResult := executeScriptAndCheck(t, b, templates.GenerateGetEpochTimingConfigScript(env), nil)

var startView uint64 = 100
var stakingEndView uint64 = 120
var endView uint64 = 160
var (
startView uint64 = 100
stakingEndView uint64 = 120
endView uint64 = 160
targetDuration uint64 = numEpochViews
targetEndTime uint64 = expectedTargetEndTime(epochTimingConfigResult, startEpochCounter+1)
)

tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
tx.AddArgument(CadenceString("stillSoRandom"))
tx.AddArgument(cadence.NewUInt64(startView))
tx.AddArgument(cadence.NewUInt64(stakingEndView))
tx.AddArgument(cadence.NewUInt64(endView))
tx.AddArgument(cadence.NewUInt64(targetDuration))
tx.AddArgument(cadence.NewUInt64(targetEndTime))
collectorClusters := make([]cadence.Value, 3)
collectorClusters[0] = cadence.NewArray([]cadence.Value{CadenceString("node_1"), CadenceString("node_2"), CadenceString("node_3")})
collectorClusters[1] = cadence.NewArray([]cadence.Value{CadenceString("node_4"), CadenceString("node_5"), CadenceString("node_6")})
Expand Down Expand Up @@ -1659,8 +1665,8 @@ func TestEpochRecover(t *testing.T) {
dkgPhase1FinalView: startView + numStakingViews + numDKGViews - 1,
dkgPhase2FinalView: startView + numStakingViews + (2 * numDKGViews) - 1,
dkgPhase3FinalView: startView + numStakingViews + (3 * numDKGViews) - 1,
targetDuration: numEpochViews,
targetEndTime: expectedTargetEndTime(epochTimingConfigResult, startEpochCounter+1),
targetDuration: targetDuration,
targetEndTime: targetEndTime,
clusterQCVoteDataLength: 0,
dkgPubKeys: dkgPubKeys,
}
Expand Down
18 changes: 11 additions & 7 deletions transactions/epoch/admin/recover_epoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ transaction(randomSource: String,
startView: UInt64,
stakingEndView: UInt64,
endView: UInt64,
targetDuration: UInt64,
targetEndTime: UInt64,
collectorClusters: [[String]],
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
dkgPubKeys: [String],
Expand All @@ -22,12 +24,14 @@ transaction(randomSource: String,
?? panic("Could not borrow epoch admin from storage path")

epochAdmin.recoverEpoch(randomSource: randomSource,
startView: startView,
stakingEndView: stakingEndView,
endView: endView,
collectorClusters: collectorClusters,
clusterQCVoteData: clusterQCVoteData,
dkgPubKeys: dkgPubKeys,
nodeIDs: nodeIDs)
startView: startView,
stakingEndView: stakingEndView,
endView: endView,
targetDuration: targetDuration,
targetEndTime: targetEndTime,
collectorClusters: collectorClusters,
clusterQCVoteData: clusterQCVoteData,
dkgPubKeys: dkgPubKeys,
nodeIDs: nodeIDs)
}
}

0 comments on commit a4943ec

Please sign in to comment.