Skip to content

Commit 59b7108

Browse files
committed
add dkgIdMapping
1 parent 48a491c commit 59b7108

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

contracts/epochs/FlowEpoch.cdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ access(all) contract FlowEpoch {
215215
216216
// TODO(EFM, #6213): include id->index mapping
217217
dkgPubKeys: [String],
218+
dkgIdMapping: {String: Int},
218219
)
219220

220221
/// Contains specific metadata about a particular epoch
@@ -526,6 +527,7 @@ access(all) contract FlowEpoch {
526527
targetEndTime: UInt64,
527528
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
528529
dkgPubKeys: [String],
530+
dkgIdMapping: {String: Int},
529531
) {
530532
self.recoverEpochPreChecks(
531533
startView: startView,
@@ -562,6 +564,7 @@ access(all) contract FlowEpoch {
562564
targetEndTime: targetEndTime,
563565
clusterQCVoteData: clusterQCVoteData,
564566
dkgPubKeys: dkgPubKeys,
567+
dkgIdMapping: dkgIdMapping,
565568
)
566569
}
567570

@@ -622,6 +625,7 @@ access(all) contract FlowEpoch {
622625
clusterAssignments: [[String]],
623626
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
624627
dkgPubKeys: [String],
628+
dkgIdMapping: {String: Int},
625629
nodeIDs: [String])
626630
{
627631
// sanity check recovery epoch counter should increment current epoch counter
@@ -667,6 +671,7 @@ access(all) contract FlowEpoch {
667671
targetEndTime: targetEndTime,
668672
clusterQCVoteData: clusterQCVoteData,
669673
dkgPubKeys: dkgPubKeys,
674+
dkgIdMapping: dkgIdMapping,
670675
)
671676

672677
/// Start a new Epoch, which increments the current epoch counter
@@ -689,6 +694,7 @@ access(all) contract FlowEpoch {
689694
clusterAssignments: [[String]],
690695
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
691696
dkgPubKeys: [String],
697+
dkgIdMapping: {String: Int},
692698
nodeIDs: [String])
693699
{
694700
// sanity check recovery epoch counter should be the current epoch counter
@@ -729,6 +735,7 @@ access(all) contract FlowEpoch {
729735
targetEndTime: targetEndTime,
730736
clusterQCVoteData: clusterQCVoteData,
731737
dkgPubKeys: dkgPubKeys,
738+
dkgIdMapping: dkgIdMapping,
732739
)
733740
}
734741

lib/go/contracts/internal/assets/assets.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/go/templates/internal/assets/assets.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/go/test/epoch_test_helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type EpochRecover struct {
148148
targetEndTime uint64
149149
numberClusterQCs int
150150
dkgPubKeys []string
151+
dkgIdMapping cadence.Dictionary
151152
}
152153

153154
type EpochRecoverEvent flow.Event
@@ -850,6 +851,7 @@ func verifyEpochRecover(
850851
assertEqual(t, cadence.NewUInt64(expectedRecover.targetEndTime), emittedEvent.TargetEndTime())
851852
assertEqual(t, expectedRecover.numberClusterQCs, len(emittedEvent.ClusterQCVoteData().Values))
852853
assertEqual(t, len(expectedRecover.dkgPubKeys), len(emittedEvent.DKGPubKeys().Values))
854+
assertEqual(t, len(expectedRecover.dkgIdMapping.Pairs), len(emittedEvent.DKGPubKeys().Values))
853855
}
854856

855857
func getEpochMetadata(t *testing.T, b emulator.Emulator, env templates.Environment, counter cadence.Value) map[string]cadence.Value {

lib/go/test/flow_epoch_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ func TestEpochRecover(t *testing.T) {
16021602
)
16031603
args := getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, startEpochCounter)
16041604
// overwrite the current epoch by setting unsafe overwrite to true
1605-
args[10] = cadence.NewBool(true)
1605+
args[11] = cadence.NewBool(true)
16061606
tx := createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
16071607
for _, arg := range args {
16081608
tx.AddArgument(arg)
@@ -1709,6 +1709,7 @@ func TestEpochRecover(t *testing.T) {
17091709
clusterAssignments: [[String]],
17101710
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
17111711
dkgPubKeys: [String],
1712+
dkgIdMapping: {String: Int},
17121713
nodeIDs: [String],
17131714
unsafeAllowOverwrite: Bool) {
17141715
@@ -1726,6 +1727,7 @@ func TestEpochRecover(t *testing.T) {
17261727
clusterAssignments: clusterAssignments,
17271728
clusterQCVoteData: clusterQCVoteData,
17281729
dkgPubKeys: dkgPubKeys,
1730+
dkgIdMapping: dkgIdMapping,
17291731
nodeIDs: nodeIDs
17301732
)
17311733
}
@@ -1994,7 +1996,6 @@ func getRecoveryTxArgs(
19941996
for i, id := range nodeIds {
19951997
nodeIDs[i], _ = cadence.NewString(id)
19961998
}
1997-
19981999
clusterQcVoteData := convertClusterQcsCdc(env, collectorClusters)
19992000
return []cadence.Value{
20002001
cadence.NewUInt64(epochCounter),
@@ -2006,6 +2007,10 @@ func getRecoveryTxArgs(
20062007
cadence.NewArray(collectorClusters), // collectorClusters
20072008
cadence.NewArray(clusterQcVoteData), // clusterQCVoteData
20082009
cadence.NewArray(dkgPubKeysCdc),
2010+
cadence.NewDictionary([]cadence.KeyValuePair{{
2011+
Key: cadence.String(nodeIds[0]),
2012+
Value: cadence.NewInt(0),
2013+
}}),
20092014
cadence.NewArray(nodeIDs),
20102015
cadence.NewBool(false), // recover EFM with a new epoch, set unsafeAllowOverwrite to false
20112016
}
@@ -2030,6 +2035,13 @@ func verifyEpochRecoverGovernanceTx(
20302035
args []cadence.Value,
20312036
) {
20322037
dkgPubKeys := make([]string, len(args[8].(cadence.Array).Values))
2038+
dkgIdMappingKVP := make([]cadence.KeyValuePair, len(dkgPubKeys))
2039+
for i, _ := range dkgPubKeys {
2040+
dkgIdMappingKVP[i] = cadence.KeyValuePair{
2041+
Key: cadence.String(fmt.Sprintf("node_%d", i)),
2042+
Value: cadence.NewInt(i),
2043+
}
2044+
}
20332045
for i, dkgKeyCdc := range args[8].(cadence.Array).Values {
20342046
dkgPubKeys[i] = strings.ReplaceAll(dkgKeyCdc.String(), `"`, "")
20352047
}
@@ -2066,6 +2078,7 @@ func verifyEpochRecoverGovernanceTx(
20662078
targetEndTime: targetEndTime,
20672079
numberClusterQCs: len(args[6].(cadence.Array).Values),
20682080
dkgPubKeys: dkgPubKeys,
2081+
dkgIdMapping: cadence.NewDictionary(dkgIdMappingKVP),
20692082
}
20702083
verifyEpochRecover(t, adapter, idTableAddress, expectedRecoverEvent)
20712084
}

transactions/epoch/admin/recover_epoch.cdc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ transaction(recoveryEpochCounter: UInt64,
2020
clusterAssignments: [[String]],
2121
clusterQCVoteData: [FlowClusterQC.ClusterQCVoteData],
2222
dkgPubKeys: [String],
23+
dkgIdMapping: {String: Int},
2324
nodeIDs: [String],
2425
unsafeAllowOverwrite: Bool) {
2526

@@ -40,6 +41,7 @@ transaction(recoveryEpochCounter: UInt64,
4041
clusterAssignments: clusterAssignments,
4142
clusterQCVoteData: clusterQCVoteData,
4243
dkgPubKeys: dkgPubKeys,
44+
dkgIdMapping: dkgIdMapping,
4345
nodeIDs: nodeIDs
4446
)
4547
} else {
@@ -57,6 +59,7 @@ transaction(recoveryEpochCounter: UInt64,
5759
clusterAssignments: clusterAssignments,
5860
clusterQCVoteData: clusterQCVoteData,
5961
dkgPubKeys: dkgPubKeys,
62+
dkgIdMapping: dkgIdMapping,
6063
nodeIDs: nodeIDs
6164
)
6265
}

0 commit comments

Comments
 (0)