Skip to content

Commit

Permalink
do not remove from array while it is being accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Sep 11, 2024
1 parent 5634f76 commit 15b2116
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions contracts/FlowIDTableStaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ access(all) contract FlowIDTableStaking {
let slotLimits: {UInt8: UInt16} = FlowIDTableStaking.getRoleSlotLimits()

let openSlots = FlowIDTableStaking.getOpenNodeSlots()

let nodesToAdd: [String] = []

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

let candidateNodesForRole = candidateNodes[role]!
let nodesToRemoveFromCandidateNodes: [String] = []

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

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

// Remove the refunded nodes from the candidate nodes list
for node in nodesToRemoveFromCandidateNodes {
candidateNodesForRole.remove(key: node)
}

nodesToAdd.appendAll(candidateNodesForRole.keys)

// Add the desired open slots for each role to the current node count
Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

0 comments on commit 15b2116

Please sign in to comment.