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

[FLIP 204] Add targetDuration to EpochSetup #396

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub contract FlowEpoch {
DKGPhase2FinalView: UInt64,
DKGPhase3FinalView: UInt64,

/// The target duration for the upcoming epoch, in seconds
targetDuration: UInt64,
/// The target end time for the upcoming epoch, specified in second-precision Unix time
targetEndTime: UInt64
)
Expand Down Expand Up @@ -693,7 +695,9 @@ pub contract FlowEpoch {
dkgKeys: [])

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

self.saveEpochMetadata(proposedEpochMetadata)

Expand All @@ -708,6 +712,7 @@ pub contract FlowEpoch {
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,
targetDuration: proposedTargetDuration,
targetEndTime: proposedTargetEndTime)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion lib/go/test/epoch_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type EpochSetup struct {
dkgPhase1FinalView uint64
dkgPhase2FinalView uint64
dkgPhase3FinalView uint64
targetDuration uint64
targetEndTime uint64
}

Expand Down Expand Up @@ -163,10 +164,14 @@ func (evt EpochSetupEvent) dkgFinalViews() (cadence.UInt64, cadence.UInt64, cade
return fields[6].(cadence.UInt64), fields[7].(cadence.UInt64), fields[8].(cadence.UInt64)
}

func (evt EpochSetupEvent) targetEndTime() cadence.UInt64 {
func (evt EpochSetupEvent) targetDuration() cadence.UInt64 {
return evt.Value.Fields[9].(cadence.UInt64)
}

func (evt EpochSetupEvent) targetEndTime() cadence.UInt64 {
return evt.Value.Fields[10].(cadence.UInt64)
}

type EpochCommitEvent flow.Event

func (evt EpochCommitEvent) Counter() cadence.UInt64 {
Expand Down Expand Up @@ -667,6 +672,7 @@ func verifyEpochSetup(
assertEqual(t, cadence.NewUInt64(expectedSetup.dkgPhase1FinalView), phase1View)
assertEqual(t, cadence.NewUInt64(expectedSetup.dkgPhase2FinalView), phase2View)
assertEqual(t, cadence.NewUInt64(expectedSetup.dkgPhase3FinalView), phase3View)
assertEqual(t, cadence.NewUInt64(expectedSetup.targetDuration), emittedEvent.targetDuration())
assertEqual(t, cadence.NewUInt64(expectedSetup.targetEndTime), emittedEvent.targetEndTime())
}

Expand Down
1 change: 1 addition & 0 deletions lib/go/test/flow_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ func TestEpochAdvance(t *testing.T) {
dkgPhase1FinalView: startView + numEpochViews + numStakingViews + numDKGViews - 1,
dkgPhase2FinalView: startView + numEpochViews + numStakingViews + 2*numDKGViews - 1,
dkgPhase3FinalView: startView + numEpochViews + numStakingViews + 3*numDKGViews - 1,
targetDuration: numEpochViews,
targetEndTime: expectedTargetEndTime(epochTimingConfigResult, startEpochCounter+1),
})

Expand Down
Loading