Skip to content

Commit

Permalink
Optimization: using cache for p256 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 13, 2023
1 parent 986997d commit e794b37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 3 additions & 6 deletions cmd/mempool/bakers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ func (indexer *Indexer) setEndorsementBakers(ctx context.Context) {
case <-ctx.Done():
return
case endorsement := <-indexer.endorsements:
if err := indexer.db.DB().RunInTransaction(ctx, func(tx *pg.Tx) error {
return indexer.findBaker(ctx, tx, endorsement)
}); err != nil {
log.Err(err).Msg("")
if err := indexer.findBaker(ctx, indexer.db.DB(), endorsement); err != nil {
log.Err(err).Msg("find baker")
}
}
}
Expand Down Expand Up @@ -76,7 +74,6 @@ func (indexer *Indexer) findBaker(ctx context.Context, tx pg.DBI, e *models.Endo
hash := endorsement.Hash(indexer.chainID, forged)
decodedSignature := endorsement.DecodeSignature(e.Signature)

query := tx.Model(e).WherePK()
for i := len(rights) - 1; i >= 0; i-- {
if rights[i].Slots == 0 {
break
Expand All @@ -96,7 +93,7 @@ func (indexer *Indexer) findBaker(ctx context.Context, tx pg.DBI, e *models.Endo
e.Baker = "unknown"
}

_, err = query.Update("baker", e.Baker)
_, err = tx.Model(e).WherePK().Update("baker", e.Baker)
return err
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/mempool/endorsement/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ func ecdsaKeyWithCache(key []byte) (ecdsa.PublicKey, error) {
return ecdsa.PublicKey{}, err
}

return ecdsa.PublicKey{
pk := ecdsa.PublicKey{
Curve: elliptic.P256(),
X: x,
Y: y,
}, nil
}
ecdsaKeysCache[keyString] = pk
return pk, nil
}

// https://stackoverflow.com/a/46289709
Expand Down

0 comments on commit e794b37

Please sign in to comment.