Skip to content

Commit 8f8fc0f

Browse files
committed
do not remove from array while it is being accessed
1 parent 71ea0df commit 8f8fc0f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

contracts/FlowIDTableStaking.cdc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ access(all) contract FlowIDTableStaking {
11561156
let slotLimits: {UInt8: UInt16} = FlowIDTableStaking.getRoleSlotLimits()
11571157

11581158
let openSlots = FlowIDTableStaking.getOpenNodeSlots()
1159-
1159+
11601160
let nodesToAdd: [String] = []
11611161

11621162
// Load and reset the candidate node list
@@ -1167,6 +1167,7 @@ access(all) contract FlowIDTableStaking {
11671167
for role in currentNodeCount.keys {
11681168

11691169
let candidateNodesForRole = candidateNodes[role]!
1170+
let nodesToRemoveFromCandidateNodes: [String] = []
11701171

11711172
if currentNodeCount[role]! >= slotLimits[role]! {
11721173
// if all slots are full, remove and refund all pending nodes
@@ -1199,7 +1200,7 @@ access(all) contract FlowIDTableStaking {
11991200
for nodeIndex in deletionList.keys {
12001201
let nodeID = candidateNodesForRole.keys[nodeIndex]
12011202
self.removeAndRefundNodeRecord(nodeID)
1202-
candidateNodesForRole.remove(key: nodeID)
1203+
nodesToRemoveFromCandidateNodes.append(nodeID)
12031204
}
12041205

12051206
// Set the current node count for the role to the limit for the role, since they were all filled
@@ -1212,6 +1213,11 @@ access(all) contract FlowIDTableStaking {
12121213
currentNodeCount[role] = currentNodeCount[role]! + UInt16(candidateNodesForRole.keys.length)
12131214
}
12141215

1216+
// Remove the refunded nodes from the candidate nodes list
1217+
for node in nodesToRemoveFromCandidateNodes {
1218+
candidateNodesForRole.remove(key: node)
1219+
}
1220+
12151221
nodesToAdd.appendAll(candidateNodesForRole.keys)
12161222

12171223
// Add the desired open slots for each role to the current node count

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.

0 commit comments

Comments
 (0)