-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduties.js
43 lines (40 loc) · 1.77 KB
/
duties.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { uint64sToAddress, socketCall, log } from './lib.js'
import { parentPort, workerData, threadId } from 'node:worker_threads'
const possiblyEligibleMinipoolIndexArray = workerData.value
const possiblyEligibleMinipools = new Map()
let i = 0
const possiblyEligibleMinipoolIndices = possiblyEligibleMinipoolIndexArray[0]
while (i < possiblyEligibleMinipoolIndices) {
const [index, minipoolAddress0, minipoolAddress1, minipoolAddress2] =
possiblyEligibleMinipoolIndexArray.slice(1 + (1 + 3) * i, 1 + (1 + 3) * ++i)
possiblyEligibleMinipools.set(parseInt(index),
uint64sToAddress([minipoolAddress0, minipoolAddress1, minipoolAddress2]))
}
async function processCommittees(epochIndex) {
const duties = []
const committees = await socketCall(['beacon', 'getCommittees', epochIndex])
log(4, `${threadId} processing ${committees.length} committees for ${epochIndex}`)
for (const committee of committees) {
const slotIndex = BigInt(committee.slot)
const committeeIndex = BigInt(committee.index)
duties.push(slotIndex.toString(), committeeIndex.toString())
const lengthIndex = duties.length
duties.push(0)
for (const [position, validatorIndexStr] of committee.validators.entries()) {
const validatorIndex = parseInt(validatorIndexStr)
if (!possiblyEligibleMinipools.has(validatorIndex)) continue
const minipoolAddress = possiblyEligibleMinipools.get(validatorIndex)
duties[lengthIndex]++
duties.push(minipoolAddress, position.toString())
}
if (duties[lengthIndex])
duties[lengthIndex] = duties[lengthIndex].toString()
else
duties.splice(-3, 3)
}
await socketCall(['duties', epochIndex, duties.join()])
}
parentPort.on('message', async (msg) => {
await processCommittees(msg)
parentPort.postMessage('done')
})