diff --git a/src/mappings/contracts.ts b/src/mappings/contracts.ts index b566b4f..f0c1e73 100644 --- a/src/mappings/contracts.ts +++ b/src/mappings/contracts.ts @@ -255,15 +255,15 @@ export async function nodeContractCanceled( await ctx.store.save(savedContract) let savedPublicIPs: PublicIp[] = await ctx.store.find(PublicIp, { where: { contractId: contractID }, relations: { farm: true } }) - savedPublicIPs = await Promise.all(savedPublicIPs.map(async (ip) => { - ip.contractId = BigInt(0) + Promise.all(savedPublicIPs.map(async (ip) => { + ip.contractId = null const farm = await ctx.store.get(Farm, { where: { farmID: ip.farm.farmID } }) if (farm) { farm.freeIps += 1 await ctx.store.save(farm) } - return ip + await ctx.store.save(ip) })) if (savedContract.nodeID) { diff --git a/src/mappings/farms.ts b/src/mappings/farms.ts index 2b2afc9..f54e3d6 100644 --- a/src/mappings/farms.ts +++ b/src/mappings/farms.ts @@ -76,9 +76,10 @@ export async function farmStored( return ctx.store.save(newIP) }) - newFarm.freeIps = newFarm.totalIps await Promise.all(ipPromises) + + newFarm.freeIps = newFarm.totalIps await ctx.store.save(newFarm) } @@ -127,7 +128,7 @@ export async function farmUpdated( savedFarm.freeIps = 0 let eventPublicIPs = farmUpdatedEventParsed.publicIps - await farmUpdatedEventParsed.publicIps.forEach(async ip => { + await Promise.all(farmUpdatedEventParsed.publicIps.map(async ip => { if (ip.ip.toString().indexOf('\x00') >= 0) { return } @@ -157,7 +158,7 @@ export async function farmUpdated( savedFarm.publicIPs.push(newIP) savedFarm.freeIps += 1 } - }) + })) const publicIPsOfFarm = await ctx.store.find(PublicIp, { where: { farm: { id: savedFarm.id } }, relations: { farm: true } }) publicIPsOfFarm.forEach(async ip => { diff --git a/src/mappings/nodes.ts b/src/mappings/nodes.ts index 3283fbd..63df8c2 100644 --- a/src/mappings/nodes.ts +++ b/src/mappings/nodes.ts @@ -194,15 +194,16 @@ export async function nodeUpdated( // calculate free resources difference let prevMRUPercentage = savedNode.totalMRU / BigInt(10) let prevZOSUsedMRU = savedNode.totalMRU - (prevMRUPercentage > BigInt(ZOSMinUsedMemory) ? prevMRUPercentage : BigInt(ZOSMinUsedMemory)) - let curMRUPercentage = nodeEvent.resources.mru / BigInt(10) let curZOSUsedMRU = nodeEvent.resources.mru - (curMRUPercentage > BigInt(ZOSMinUsedMemory) ? curMRUPercentage : BigInt(ZOSMinUsedMemory)) - let mruDiff = curZOSUsedMRU - prevZOSUsedMRU + let contractsUsedMRU = savedNode.totalMRU - savedNode.freeMRU - prevZOSUsedMRU + let newFreeMRU = nodeEvent.resources.mru - contractsUsedMRU - curZOSUsedMRU + let hruDiff = nodeEvent.resources.hru - savedNode.totalHRU - let sruDiff = (nodeEvent.resources.sru - BigInt(ZOSUsedSRU)) - savedNode.totalSRU + let sruDiff = nodeEvent.resources.sru - savedNode.totalSRU - savedNode.freeMRU += mruDiff + savedNode.freeMRU = newFreeMRU savedNode.freeHRU += hruDiff savedNode.freeSRU += sruDiff