mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
caf9bdbc6f
* commit initial work * checkpoint current work * gaz * checkpoint * req/resp changes * initial-sync * finally works * fix error * fix bugs * fix issue * fix issues * fix refs * tests * more text fixes * more text fixes * more text fixes * fix tests * fix tests * tests * finally fix builds * finally * comments * fix fuzz * share common library * fix * fix * add in more defensive nil checks * add in more defensive nil checks * imports * Apply suggestions from code review Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Update shared/interfaces/block_interface.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Update shared/interfaces/block_wrapper.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Update shared/interfaces/block_interface.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * imports * fix bad changes * fix * terence's review * terence's review * fmt * Update beacon-chain/rpc/beacon/blocks.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * fix tests * fix * fix all tests Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
package attestations
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/blockutil"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/bls/common"
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func BenchmarkAggregateAttestations_Aggregate(b *testing.B) {
|
|
// Override expensive BLS aggregation method with cheap no-op such that this benchmark profiles
|
|
// the logic of aggregation selection rather than BLS logic.
|
|
aggregateSignatures = func(sigs []common.Signature) common.Signature {
|
|
return sigs[0]
|
|
}
|
|
signatureFromBytes = func(sig []byte) (common.Signature, error) {
|
|
return bls.NewAggregateSignature(), nil
|
|
}
|
|
defer func() {
|
|
aggregateSignatures = bls.AggregateSignatures
|
|
signatureFromBytes = bls.SignatureFromBytes
|
|
}()
|
|
|
|
bitlistLen := params.BeaconConfig().MaxValidatorsPerCommittee
|
|
|
|
tests := []struct {
|
|
name string
|
|
inputs []bitfield.Bitlist
|
|
}{
|
|
{
|
|
name: "256 attestations with single bit set",
|
|
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
|
|
},
|
|
{
|
|
name: "256 attestations with 64 random bits set",
|
|
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
|
|
},
|
|
{
|
|
name: "512 attestations with single bit set",
|
|
inputs: aggtesting.BitlistsWithSingleBitSet(512, bitlistLen),
|
|
},
|
|
{
|
|
name: "1024 attestations with 64 random bits set",
|
|
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 1024, bitlistLen, 64),
|
|
},
|
|
}
|
|
|
|
runner := func(atts []*ethpb.Attestation) {
|
|
attsCopy := make([]*ethpb.Attestation, len(atts))
|
|
for i, att := range atts {
|
|
attsCopy[i] = blockutil.CopyAttestation(att)
|
|
}
|
|
_, err := Aggregate(attsCopy)
|
|
require.NoError(b, err)
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
b.Run(fmt.Sprintf("naive_%s", tt.name), func(b *testing.B) {
|
|
b.StopTimer()
|
|
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
|
|
AttestationAggregationStrategy: string(NaiveAggregation),
|
|
})
|
|
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
|
|
defer resetCfg()
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
runner(atts)
|
|
}
|
|
})
|
|
b.Run(fmt.Sprintf("max-cover_%s", tt.name), func(b *testing.B) {
|
|
b.StopTimer()
|
|
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
|
|
AttestationAggregationStrategy: string(MaxCoverAggregation),
|
|
})
|
|
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
|
|
defer resetCfg()
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
runner(atts)
|
|
}
|
|
})
|
|
b.Run(fmt.Sprintf("opt-max-cover_%s", tt.name), func(b *testing.B) {
|
|
b.StopTimer()
|
|
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
|
|
AttestationAggregationStrategy: string(OptMaxCoverAggregation),
|
|
})
|
|
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
|
|
defer resetCfg()
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
runner(atts)
|
|
}
|
|
})
|
|
}
|
|
}
|