Compare commits

...

5 Commits

Author SHA1 Message Date
terence tsao
a88f237ffc Fix join to avoid recursive call 2025-05-09 20:59:08 -07:00
terence tsao
1dc7e153f6 Update join 2025-05-09 13:22:10 -07:00
terence tsao
49b1cba82e Use little endian for set aggregator index seen 2025-05-09 13:10:37 -07:00
terence tsao
e9807b2a6b Kasey's feedback 2025-05-09 13:05:57 -07:00
terence tsao
e1497c92c6 Optimize by pre allocate slices to avoid runtime growslice 2025-05-09 11:06:45 -07:00
6 changed files with 24 additions and 6 deletions

View File

@@ -29,10 +29,13 @@ func Seed(state state.ReadOnlyBeaconState, epoch primitives.Epoch, domain [bls.D
if err != nil {
return [32]byte{}, err
}
seed := append(domain[:], bytesutil.Bytes8(uint64(epoch))...)
seed = append(seed, randaoMix...)
seed32 := hash.Hash(seed)
var seed [bls.DomainByteLength + 8 + 32]byte
copy(seed[0:], domain[:])
copy(seed[bls.DomainByteLength:], bytesutil.Bytes8(uint64(epoch)))
copy(seed[bls.DomainByteLength+8:], randaoMix)
seed32 := hash.Hash(seed[:])
return seed32, nil
}

View File

@@ -247,7 +247,7 @@ func ComputeDomain(domainType [DomainByteLength]byte, forkVersion, genesisValida
// This returns the bls domain given by the domain type and fork data root.
func domain(domainType [DomainByteLength]byte, forkDataRoot []byte) []byte {
var b []byte
b := make([]byte, 0, 32)
b = append(b, domainType[:4]...)
b = append(b, forkDataRoot[:28]...)
return b

View File

@@ -32,7 +32,7 @@ func ParticipationBitsRoot(bits []byte) ([32]byte, error) {
// it does not have length bytes per chunk.
func packParticipationBits(bytes []byte) ([][32]byte, error) {
numItems := len(bytes)
chunks := make([][32]byte, 0, numItems/32)
chunks := make([][32]byte, 0, (numItems+31)/32)
for i := 0; i < numItems; i += 32 {
j := i + 32
// We create our upper bound index of the chunk, if it is greater than numItems,

View File

@@ -2,6 +2,7 @@ package sync
import (
"context"
"encoding/binary"
"fmt"
"github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain"
@@ -265,7 +266,10 @@ func (s *Service) hasSeenAggregatorIndexEpoch(epoch primitives.Epoch, aggregator
func (s *Service) setAggregatorIndexEpochSeen(epoch primitives.Epoch, aggregatorIndex primitives.ValidatorIndex) {
s.seenAggregatedAttestationLock.Lock()
defer s.seenAggregatedAttestationLock.Unlock()
b := append(bytesutil.Bytes32(uint64(epoch)), bytesutil.Bytes32(uint64(aggregatorIndex))...)
b := make([]byte, 64)
binary.LittleEndian.PutUint64(b, uint64(epoch))
binary.LittleEndian.PutUint64(b[32:], uint64(aggregatorIndex))
s.seenAggregatedAttestationCache.Add(string(b), true)
}

3
changelog/tt_bread.md Normal file
View File

@@ -0,0 +1,3 @@
### Ignored
- Pre allocate slices if we can to avoid grow slice.

View File

@@ -32,6 +32,14 @@ func NewSet() *SignatureBatch {
// Join merges the provided signature batch to out current one.
func (s *SignatureBatch) Join(set *SignatureBatch) *SignatureBatch {
if cap(s.Signatures)-len(s.Signatures) < cap(set.Signatures)-len(set.Signatures) {
set.Signatures = append(set.Signatures, s.Signatures...)
set.PublicKeys = append(set.PublicKeys, s.PublicKeys...)
set.Messages = append(set.Messages, s.Messages...)
set.Descriptions = append(set.Descriptions, s.Descriptions...)
return set
}
s.Signatures = append(s.Signatures, set.Signatures...)
s.PublicKeys = append(s.PublicKeys, set.PublicKeys...)
s.Messages = append(s.Messages, set.Messages...)