mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-30 15:48:00 -05:00
Compare commits
13 Commits
debug-stat
...
useNewCach
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f1c4e2b08 | ||
|
|
6387040613 | ||
|
|
1c7077e254 | ||
|
|
9ab7e7d37c | ||
|
|
bf80a5430f | ||
|
|
9aef2c4ee2 | ||
|
|
d094118082 | ||
|
|
c69599f343 | ||
|
|
1e0e5e110a | ||
|
|
8254cb30b4 | ||
|
|
74961eb51f | ||
|
|
514f96ec0e | ||
|
|
cabe7d34b6 |
@@ -16,6 +16,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Process light client finality updates only for new finalized epochs instead of doing it for every block.
|
- Process light client finality updates only for new finalized epochs instead of doing it for every block.
|
||||||
|
- Add more efficient method of computing the cache key for unaggregated attestations.
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ go_test(
|
|||||||
size = "small",
|
size = "small",
|
||||||
srcs = [
|
srcs = [
|
||||||
"batch_verifier_test.go",
|
"batch_verifier_test.go",
|
||||||
|
"benchmark_test.go",
|
||||||
"blobs_test.go",
|
"blobs_test.go",
|
||||||
"block_batcher_test.go",
|
"block_batcher_test.go",
|
||||||
"broadcast_bls_changes_test.go",
|
"broadcast_bls_changes_test.go",
|
||||||
@@ -268,3 +269,20 @@ go_test(
|
|||||||
"@org_golang_google_protobuf//proto:go_default_library",
|
"@org_golang_google_protobuf//proto:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_benchmark_test",
|
||||||
|
size = "medium",
|
||||||
|
srcs = ["benchmark_test.go"],
|
||||||
|
args = [
|
||||||
|
"-test.bench=.",
|
||||||
|
"-test.benchmem",
|
||||||
|
"-test.v",
|
||||||
|
],
|
||||||
|
embed = [":go_default_library"],
|
||||||
|
local = True,
|
||||||
|
tags = [
|
||||||
|
"benchmark",
|
||||||
|
"no-cache",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|||||||
25
beacon-chain/sync/benchmark_test.go
Normal file
25
beacon-chain/sync/benchmark_test.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package sync
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||||
|
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCacheKeyImplementations(b *testing.B) {
|
||||||
|
|
||||||
|
b.Run("Old Cache Key Implementation", func(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b := append(bytesutil.Bytes32(uint64(i)), bytesutil.Bytes32(uint64(i+10))...)
|
||||||
|
b = append(b, bytesutil.SafeCopyBytes([]byte("random"))...)
|
||||||
|
_ = string(b)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
b.Run("New Cache Key Implementation", func(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_ = seenAttCacheKey(primitives.Slot(i), primitives.CommitteeIndex(i+10), []byte("random"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package sync
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -305,9 +306,7 @@ func (s *Service) validateBitLength(
|
|||||||
func (s *Service) hasSeenCommitteeIndicesSlot(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregateBits []byte) bool {
|
func (s *Service) hasSeenCommitteeIndicesSlot(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregateBits []byte) bool {
|
||||||
s.seenUnAggregatedAttestationLock.RLock()
|
s.seenUnAggregatedAttestationLock.RLock()
|
||||||
defer s.seenUnAggregatedAttestationLock.RUnlock()
|
defer s.seenUnAggregatedAttestationLock.RUnlock()
|
||||||
b := append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(uint64(committeeID))...)
|
_, seen := s.seenUnAggregatedAttestationCache.Get(seenAttCacheKey(slot, committeeID, aggregateBits))
|
||||||
b = append(b, aggregateBits...)
|
|
||||||
_, seen := s.seenUnAggregatedAttestationCache.Get(string(b))
|
|
||||||
return seen
|
return seen
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,9 +314,7 @@ func (s *Service) hasSeenCommitteeIndicesSlot(slot primitives.Slot, committeeID
|
|||||||
func (s *Service) setSeenCommitteeIndicesSlot(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregateBits []byte) {
|
func (s *Service) setSeenCommitteeIndicesSlot(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregateBits []byte) {
|
||||||
s.seenUnAggregatedAttestationLock.Lock()
|
s.seenUnAggregatedAttestationLock.Lock()
|
||||||
defer s.seenUnAggregatedAttestationLock.Unlock()
|
defer s.seenUnAggregatedAttestationLock.Unlock()
|
||||||
b := append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(uint64(committeeID))...)
|
s.seenUnAggregatedAttestationCache.Add(seenAttCacheKey(slot, committeeID, aggregateBits), true)
|
||||||
b = append(b, bytesutil.SafeCopyBytes(aggregateBits)...)
|
|
||||||
s.seenUnAggregatedAttestationCache.Add(string(b), true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasBlockAndState returns true if the beacon node knows about a block and associated state in the
|
// hasBlockAndState returns true if the beacon node knows about a block and associated state in the
|
||||||
@@ -327,3 +324,15 @@ func (s *Service) hasBlockAndState(ctx context.Context, blockRoot [32]byte) bool
|
|||||||
hasState := hasStateSummary || s.cfg.beaconDB.HasState(ctx, blockRoot)
|
hasState := hasStateSummary || s.cfg.beaconDB.HasState(ctx, blockRoot)
|
||||||
return hasState && s.cfg.chain.HasBlock(ctx, blockRoot)
|
return hasState && s.cfg.chain.HasBlock(ctx, blockRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Amount of bytes required to store a uint64 value.
|
||||||
|
const uint64ByteLength = 8
|
||||||
|
|
||||||
|
func seenAttCacheKey(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregationBits []byte) string {
|
||||||
|
totalLen := uint64ByteLength + uint64ByteLength + len(aggregationBits)
|
||||||
|
key := make([]byte, totalLen)
|
||||||
|
binary.LittleEndian.PutUint64(key[:8], uint64(slot))
|
||||||
|
binary.LittleEndian.PutUint64(key[8:16], uint64(committeeID))
|
||||||
|
copy(key[16:], aggregationBits)
|
||||||
|
return bytesutil.UnsafeCastToString(key)
|
||||||
|
}
|
||||||
|
|||||||
@@ -327,3 +327,11 @@ func TestService_setSeenCommitteeIndicesSlot(t *testing.T) {
|
|||||||
require.Equal(t, false, s.hasSeenCommitteeIndicesSlot(0, 2, b1))
|
require.Equal(t, false, s.hasSeenCommitteeIndicesSlot(0, 2, b1))
|
||||||
require.Equal(t, true, s.hasSeenCommitteeIndicesSlot(1, 2, b1))
|
require.Equal(t, true, s.hasSeenCommitteeIndicesSlot(1, 2, b1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAttestationCacheKey(t *testing.T) {
|
||||||
|
stringKey := seenAttCacheKey(1, 1024, []byte("aggregation"))
|
||||||
|
wantedKey := append(bytesutil.Bytes8(1), bytesutil.Bytes8(1024)...)
|
||||||
|
wantedKey = append(wantedKey, []byte("aggregation")...)
|
||||||
|
|
||||||
|
require.Equal(t, string(wantedKey), stringKey)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user