mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 20:50:05 +00:00
Faster BLS publickey.Copy (#4770)
* Use balancesLength and randaoMixesLength to save copy on read * use a cheaper copy for BLS publickey.Copy() * Merge branch 'master' into bls-better-copy * Merge refs/heads/master into bls-better-copy * Merge refs/heads/master into bls-better-copy * Merge refs/heads/master into bls-better-copy * Merge refs/heads/master into bls-better-copy * Merge branch 'master' of github.com:prysmaticlabs/prysm into bls-better-copy * quick test * Merge refs/heads/master into bls-better-copy
This commit is contained in:
parent
3a9c8eb8b1
commit
c7fb28d42e
@ -153,10 +153,8 @@ func (p *PublicKey) Marshal() []byte {
|
||||
|
||||
// Copy the public key to a new pointer reference.
|
||||
func (p *PublicKey) Copy() (*PublicKey, error) {
|
||||
rawBytes := p.p.Serialize()
|
||||
newKey := &bls12.PublicKey{}
|
||||
err := newKey.Deserialize(rawBytes)
|
||||
return &PublicKey{p: newKey}, err
|
||||
np := *p.p
|
||||
return &PublicKey{p: &np}, nil
|
||||
}
|
||||
|
||||
// Aggregate two public keys.
|
||||
|
@ -278,3 +278,15 @@ func TestSignatureFromBytes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicKey_Copy(t *testing.T) {
|
||||
pubkeyA := bls.RandKey().PublicKey()
|
||||
pubkeyBytes := pubkeyA.Marshal()
|
||||
|
||||
pubkeyB, _ := pubkeyA.Copy()
|
||||
pubkeyB.Aggregate(bls.RandKey().PublicKey())
|
||||
|
||||
if !bytes.Equal(pubkeyA.Marshal(), pubkeyBytes) {
|
||||
t.Fatal("Pubkey was mutated after copy")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user