-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoothing.js
63 lines (59 loc) · 2.54 KB
/
smoothing.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { parentPort, workerData, threadId } from 'node:worker_threads'
import { log, stakingStatus, socketCall, addressToUint64s } from './lib.js'
const possiblyEligibleMinipoolIndexArray = workerData.value
const farPastTime = 0n
const farFutureTime = BigInt(1e18)
async function processNodeSmoothing(i, nodeAddress) {
const minipoolCount = BigInt(await socketCall(
['elState', 'rocketMinipoolManager', 'getNodeMinipoolCount', nodeAddress]))
async function minipoolEligibility(i) {
const minipoolAddress = await socketCall(
['elState', 'rocketMinipoolManager', 'getNodeMinipoolAt', `${nodeAddress},${i}`])
const minipoolStatus = parseInt(await socketCall(['elState', minipoolAddress, 'getStatus']))
const penaltyCount = parseInt(await socketCall(
['elState', 'rocketNetworkPenalties', 'getPenaltyCount', minipoolAddress]))
if (minipoolStatus == stakingStatus) {
if (penaltyCount >= 3)
return 'cheater'
else {
const pubkey = await socketCall(
['elState', 'rocketMinipoolManager', 'getMinipoolPubkey', minipoolAddress])
const index = BigInt(await socketCall(['beacon', 'getIndexFromPubkey', pubkey]))
if (0 <= index) {
const currentIndex = parseInt(Atomics.add(possiblyEligibleMinipoolIndexArray, 0, 1n))
possiblyEligibleMinipoolIndexArray.set(
[index, ...addressToUint64s(minipoolAddress)],
1 + (1 + 3) * currentIndex)
}
return 'staking'
}
}
}
let staking = false
for (const i of Array(parseInt(minipoolCount)).keys()) {
const result = await minipoolEligibility(i)
if (result === 'cheater') {
log(3, `${nodeAddress} is a cheater`)
return
}
else if (result === 'staking')
staking = true
}
if (await socketCall(['nodeSmoothingTimes', nodeAddress, 'check']))
return
if (!staking) {
log(4, `${nodeAddress} has no staking minipools: skipping`)
return
}
const isOptedIn = await socketCall(
['elState', 'rocketNodeManager', 'getSmoothingPoolRegistrationState', nodeAddress])
const statusChangeTime = BigInt(await socketCall(
['elState', 'rocketNodeManager', 'getSmoothingPoolRegistrationChanged', nodeAddress]))
const optInTime = isOptedIn ? statusChangeTime : farPastTime
const optOutTime = isOptedIn ? farFutureTime : statusChangeTime
await socketCall(['nodeSmoothingTimes', nodeAddress, optInTime.toString(), optOutTime.toString()])
}
parentPort.on('message', async (msg) => {
await processNodeSmoothing(msg.i, msg.nodeAddress)
parentPort.postMessage('done')
})