@@ -2,7 +2,6 @@ import { Inject, Injectable, LoggerService, OnModuleInit } from '@nestjs/common'
2
2
import { LOGGER_PROVIDER } from '@lido-nestjs/logger' ;
3
3
import { GenesisTimeService , SLOTS_PER_EPOCH } from '../genesis-time' ;
4
4
import {
5
- getMaxEffectiveBalance ,
6
5
isFullyWithdrawableValidator ,
7
6
isPartiallyWithdrawableValidator ,
8
7
} from '../../jobs/validators/utils/validator-state-utils' ;
@@ -47,19 +46,24 @@ export class SweepService implements OnModuleInit {
47
46
}
48
47
49
48
private getSweepDelayInEpochsPreElectra ( indexedValidators : IndexedValidator [ ] , epoch : number ) : number {
50
- const totalWithdrawableValidators = this . getWithdrawableValidators ( indexedValidators , epoch ) . length ;
49
+ const totalWithdrawableValidators = this . getWithdrawableValidatorsNumber ( indexedValidators , epoch ) ;
51
50
52
51
const fullSweepInEpochs = totalWithdrawableValidators / MAX_WITHDRAWALS_PER_PAYLOAD / SLOTS_PER_EPOCH ;
53
52
return Math . floor ( fullSweepInEpochs * 0.5 ) ;
54
53
}
55
54
56
55
// pre pectra
57
- private getWithdrawableValidators ( indexedValidators : IndexedValidator [ ] , epoch : number ) {
58
- return indexedValidators . filter (
59
- ( v ) =>
56
+ private getWithdrawableValidatorsNumber ( indexedValidators : IndexedValidator [ ] , epoch : number ) {
57
+ let count = 0 ;
58
+ for ( const v of indexedValidators ) {
59
+ if (
60
60
isPartiallyWithdrawableValidator ( v . validator , parseGwei ( v . balance ) ) ||
61
- isFullyWithdrawableValidator ( v . validator , parseGwei ( v . balance ) , epoch ) ,
62
- ) ;
61
+ isFullyWithdrawableValidator ( v . validator , parseGwei ( v . balance ) , epoch )
62
+ ) {
63
+ count ++ ;
64
+ }
65
+ }
66
+ return count ;
63
67
}
64
68
65
69
private getSweepDelayInEpochsPostElectra ( state : BeaconState , indexedValidators : IndexedValidator [ ] ) : number {
@@ -72,10 +76,13 @@ export class SweepService implements OnModuleInit {
72
76
73
77
private predictWithdrawalsNumberInSweepCycle ( state : BeaconState , indexedValidators : IndexedValidator [ ] ) : number {
74
78
const pendingPartialWithdrawals = this . getPendingPartialWithdrawals ( state ) ;
75
- const validatorsWithdrawals = this . getValidatorsWithdrawals ( state , pendingPartialWithdrawals , indexedValidators ) ;
79
+ const validatorsWithdrawalsNumber = this . getValidatorsWithdrawalsNumber (
80
+ state ,
81
+ pendingPartialWithdrawals ,
82
+ indexedValidators ,
83
+ ) ;
76
84
77
85
const pendingPartialWithdrawalsNumber = pendingPartialWithdrawals . length ;
78
- const validatorsWithdrawalsNumber = validatorsWithdrawals . length ;
79
86
80
87
const partialWithdrawalsMaxRatio =
81
88
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP /
@@ -114,14 +121,14 @@ export class SweepService implements OnModuleInit {
114
121
}
115
122
116
123
// post pectra
117
- getValidatorsWithdrawals (
124
+ getValidatorsWithdrawalsNumber (
118
125
state : BeaconState ,
119
126
partialWithdrawals : Withdrawal [ ] ,
120
127
indexedValidators : IndexedValidator [ ] ,
121
- ) : Withdrawal [ ] {
128
+ ) : number {
122
129
const epoch = Math . ceil ( + state . slot / SLOTS_PER_EPOCH ) ;
123
- const withdrawals : Withdrawal [ ] = [ ] ;
124
130
const partiallyWithdrawnMap : Record < number , number > = { } ;
131
+ let withdrawalsNumber = 0 ;
125
132
126
133
for ( const withdrawal of partialWithdrawals ) {
127
134
partiallyWithdrawnMap [ withdrawal . validatorIndex ] =
@@ -135,13 +142,12 @@ export class SweepService implements OnModuleInit {
135
142
const balance = parseGwei ( state . balances [ validatorIndex ] ) . sub ( partiallyWithdrawnBalance ) ;
136
143
137
144
if ( isFullyWithdrawableValidator ( validator , balance , epoch ) ) {
138
- withdrawals . push ( { validatorIndex , amount : balance } ) ;
145
+ withdrawalsNumber ++ ;
139
146
} else if ( isPartiallyWithdrawableValidator ( validator , balance ) ) {
140
- const maxEffectiveBalance = getMaxEffectiveBalance ( validator ) ;
141
- withdrawals . push ( { validatorIndex, amount : balance . sub ( maxEffectiveBalance ) } ) ;
147
+ withdrawalsNumber ++ ;
142
148
}
143
149
}
144
150
145
- return withdrawals ;
151
+ return withdrawalsNumber ;
146
152
}
147
153
}
0 commit comments