Skip to content

Commit

Permalink
Merge pull request #15 from migalabs/feature/optimize_lido_curated_ro…
Browse files Browse the repository at this point in the history
…utine

optimize curated module routine using getSigningKeys
  • Loading branch information
santi1234567 authored Dec 26, 2024
2 parents 0dc000a + c7d8737 commit b405fc8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
46 changes: 23 additions & 23 deletions identify/lido.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"sync"

db "github.com/migalabs/eth-pokhar/db"
"github.com/migalabs/eth-pokhar/lido"
"github.com/migalabs/eth-pokhar/lido/csm"
"github.com/migalabs/eth-pokhar/lido/curated"
log "github.com/sirupsen/logrus"
)

const maxBatchSize = 100
const maxBatchSize = 500

func (i *Identify) IdentifyLidoValidators() error {
log.Debug("Identifying lido curated module validators")
Expand Down Expand Up @@ -208,41 +209,40 @@ func (i *Identify) processCuratedOperatorKeys(operator curated.NodeOperator, ope

operatorName := curated.GetOperatorName(operator)
log.Infof("Getting new keys for operator %v", operatorName)
if operator.TotalSigningKeys-operatorValidatorCount == 0 {
remainingKeys := operator.TotalSigningKeys - operatorValidatorCount
if remainingKeys == 0 {
log.Infof("No new keys for operator %v", operatorName)
return nil
}
remainingKeys := operator.TotalSigningKeys - operatorValidatorCount
savedKeys := int64(0)
var validatorPubkeys []string
var batchSize uint64
var batchIndex uint64
for keyIndex := operatorValidatorCount; keyIndex < operator.TotalSigningKeys; keyIndex++ {

offset := operatorValidatorCount
for {
if i.stop {
break
}
if validatorPubkeys == nil {
batchIndex = 0
batchSize = min(remainingKeys, maxBatchSize)
validatorPubkeys = make([]string, batchSize)
}
limit := min(remainingKeys-offset, maxBatchSize)
validatorPubkeys = make([]string, limit)

key, err := lidoContract.GetOperatorKey(operator, keyIndex)
operatorKeys, err := lidoContract.GetOperatorKeys(operator, offset, limit)
if err != nil {
return err
}
validatorPubkeys[batchIndex] = hex.EncodeToString(key.Key)
isLastKey := keyIndex == operator.TotalSigningKeys-1
remainingKeys--
if batchIndex == batchSize-1 || isLastKey {
log.Debugf("Inserting %v keys for operator %v into the database", batchSize, operatorName)
count := i.dbClient.CopyLidoOperatorValidators(operatorName, operator.Index, validatorPubkeys, db.LidoProtocolCurated)
log.Debugf("Inserted %v validators for operator %v. %v remaining", count, operatorName, remainingKeys)
validatorPubkeys = nil
savedKeys += int64(batchSize)
} else {
batchIndex++
for i := uint64(0); i < limit; i++ {
key := operatorKeys.PubKeys[i*lido.PublicKeyLength : (i+1)*lido.PublicKeyLength]
validatorPubkeys[i] = hex.EncodeToString(key)
}

log.Debugf("Inserting %v keys for operator %v into the database", limit, operatorName)
count := i.dbClient.CopyLidoOperatorValidators(operatorName, operator.Index, validatorPubkeys, db.LidoProtocolCurated)
log.Debugf("Inserted %v validators for operator %v. %v remaining", count, operatorName, remainingKeys)
savedKeys += count
done := limit < maxBatchSize
if done {
break
}
offset += limit
}
log.Infof("Got %v new keys for operator %v", savedKeys, operatorName)

Expand Down
22 changes: 11 additions & 11 deletions lido/curated/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ func (l *CuratedModuleContract) GetOperatorData(index *big.Int) (NodeOperator, e
}, nil
}

func (l *CuratedModuleContract) GetOperatorKey(operator NodeOperator, keyIndex uint64) (OperatorKey, error) {
func (l *CuratedModuleContract) GetOperatorKeys(operator NodeOperator, offset uint64, limit uint64) (OperatorKeys, error) {
result, err := lido.RetryContractCall(func() (interface{}, error) {
return l.contract.GetSigningKey(nil, big.NewInt(int64(operator.Index)), big.NewInt(int64(keyIndex)))
return l.contract.GetSigningKeys(nil, big.NewInt(int64(operator.Index)), big.NewInt(int64(offset)), big.NewInt(int64(limit)))
})
if err != nil {
return OperatorKey{}, err
return OperatorKeys{}, err
}
key := result.(struct {
Key []byte
DepositSignature []byte
Used bool
operatorKeys := result.(struct {
Pubkeys []byte
Signatures []byte
Used []bool
})
return OperatorKey{
Key: key.Key,
DepositSignature: key.DepositSignature,
Used: key.Used,
return OperatorKeys{
PubKeys: operatorKeys.Pubkeys,
Signatures: operatorKeys.Signatures,
Used: operatorKeys.Used,
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions lido/curated/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type NodeOperator struct {
UsedSigningKeys uint64
}

type OperatorKey struct {
Key []byte
DepositSignature []byte
Used bool
type OperatorKeys struct {
PubKeys []byte
Signatures []byte
Used []bool
}

0 comments on commit b405fc8

Please sign in to comment.