@@ -6,12 +6,13 @@ import (
66 "sync"
77
88 db "github.com/migalabs/eth-pokhar/db"
9+ "github.com/migalabs/eth-pokhar/lido"
910 "github.com/migalabs/eth-pokhar/lido/csm"
1011 "github.com/migalabs/eth-pokhar/lido/curated"
1112 log "github.com/sirupsen/logrus"
1213)
1314
14- const maxBatchSize = 100
15+ const maxBatchSize = 500
1516
1617func (i * Identify ) IdentifyLidoValidators () error {
1718 log .Debug ("Identifying lido curated module validators" )
@@ -208,41 +209,40 @@ func (i *Identify) processCuratedOperatorKeys(operator curated.NodeOperator, ope
208209
209210 operatorName := curated .GetOperatorName (operator )
210211 log .Infof ("Getting new keys for operator %v" , operatorName )
211- if operator .TotalSigningKeys - operatorValidatorCount == 0 {
212+ remainingKeys := operator .TotalSigningKeys - operatorValidatorCount
213+ if remainingKeys == 0 {
212214 log .Infof ("No new keys for operator %v" , operatorName )
213215 return nil
214216 }
215- remainingKeys := operator .TotalSigningKeys - operatorValidatorCount
216217 savedKeys := int64 (0 )
217218 var validatorPubkeys []string
218- var batchSize uint64
219- var batchIndex uint64
220- for keyIndex := operatorValidatorCount ; keyIndex < operator . TotalSigningKeys ; keyIndex ++ {
219+
220+ offset := operatorValidatorCount
221+ for {
221222 if i .stop {
222223 break
223224 }
224- if validatorPubkeys == nil {
225- batchIndex = 0
226- batchSize = min (remainingKeys , maxBatchSize )
227- validatorPubkeys = make ([]string , batchSize )
228- }
225+ limit := min (remainingKeys - offset , maxBatchSize )
226+ validatorPubkeys = make ([]string , limit )
229227
230- key , err := lidoContract .GetOperatorKey (operator , keyIndex )
228+ operatorKeys , err := lidoContract .GetOperatorKeys (operator , offset , limit )
231229 if err != nil {
232230 return err
233231 }
234- validatorPubkeys [batchIndex ] = hex .EncodeToString (key .Key )
235- isLastKey := keyIndex == operator .TotalSigningKeys - 1
236- remainingKeys --
237- if batchIndex == batchSize - 1 || isLastKey {
238- log .Debugf ("Inserting %v keys for operator %v into the database" , batchSize , operatorName )
239- count := i .dbClient .CopyLidoOperatorValidators (operatorName , operator .Index , validatorPubkeys , db .LidoProtocolCurated )
240- log .Debugf ("Inserted %v validators for operator %v. %v remaining" , count , operatorName , remainingKeys )
241- validatorPubkeys = nil
242- savedKeys += int64 (batchSize )
243- } else {
244- batchIndex ++
232+ for i := uint64 (0 ); i < limit ; i ++ {
233+ key := operatorKeys .PubKeys [i * lido .PublicKeyLength : (i + 1 )* lido .PublicKeyLength ]
234+ validatorPubkeys [i ] = hex .EncodeToString (key )
235+ }
236+
237+ log .Debugf ("Inserting %v keys for operator %v into the database" , limit , operatorName )
238+ count := i .dbClient .CopyLidoOperatorValidators (operatorName , operator .Index , validatorPubkeys , db .LidoProtocolCurated )
239+ log .Debugf ("Inserted %v validators for operator %v. %v remaining" , count , operatorName , remainingKeys )
240+ savedKeys += count
241+ done := limit < maxBatchSize
242+ if done {
243+ break
245244 }
245+ offset += limit
246246 }
247247 log .Infof ("Got %v new keys for operator %v" , savedKeys , operatorName )
248248
0 commit comments