2020-07-03 14:37:54 +00:00
|
|
|
package attestations
|
|
|
|
|
|
|
|
import (
|
2021-02-04 00:58:33 +00:00
|
|
|
"fmt"
|
2020-07-03 14:37:54 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-05-26 18:33:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/copyutil"
|
2021-05-26 16:19:54 +00:00
|
|
|
|
2020-07-03 14:37:54 +00:00
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
2021-06-02 23:49:52 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
2020-07-03 14:37:54 +00:00
|
|
|
aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
2020-10-30 19:06:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls/common"
|
2021-01-21 14:29:17 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
2020-07-03 14:37:54 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2020-07-18 16:31:42 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-07-03 14:37:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2020-10-30 19:06:33 +00:00
|
|
|
aggregateSignatures = func(sigs []common.Signature) common.Signature {
|
2020-07-03 14:37:54 +00:00
|
|
|
return sigs[0]
|
|
|
|
}
|
2020-10-30 19:06:33 +00:00
|
|
|
signatureFromBytes = func(sig []byte) (common.Signature, error) {
|
2020-07-03 14:37:54 +00:00
|
|
|
return bls.NewAggregateSignature(), nil
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
aggregateSignatures = bls.AggregateSignatures
|
|
|
|
signatureFromBytes = bls.SignatureFromBytes
|
|
|
|
}()
|
|
|
|
|
|
|
|
bitlistLen := params.BeaconConfig().MaxValidatorsPerCommittee
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
inputs []bitfield.Bitlist
|
|
|
|
}{
|
|
|
|
{
|
2021-02-04 00:58:33 +00:00
|
|
|
name: "256 attestations with single bit set",
|
|
|
|
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
|
2020-07-03 14:37:54 +00:00
|
|
|
},
|
2021-01-21 14:29:17 +00:00
|
|
|
{
|
|
|
|
name: "256 attestations with 64 random bits set",
|
2020-10-12 08:11:05 +00:00
|
|
|
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
|
2020-07-03 14:37:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "512 attestations with single bit set",
|
2020-10-12 08:11:05 +00:00
|
|
|
inputs: aggtesting.BitlistsWithSingleBitSet(512, bitlistLen),
|
2020-07-03 14:37:54 +00:00
|
|
|
},
|
|
|
|
{
|
2021-02-04 00:58:33 +00:00
|
|
|
name: "1024 attestations with 64 random bits set",
|
|
|
|
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 1024, bitlistLen, 64),
|
2020-07-03 14:37:54 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-04 00:58:33 +00:00
|
|
|
runner := func(atts []*ethpb.Attestation) {
|
|
|
|
attsCopy := make([]*ethpb.Attestation, len(atts))
|
|
|
|
for i, att := range atts {
|
2021-05-26 18:33:46 +00:00
|
|
|
attsCopy[i] = copyutil.CopyAttestation(att)
|
2021-01-21 14:29:17 +00:00
|
|
|
}
|
2021-02-04 00:58:33 +00:00
|
|
|
_, err := Aggregate(attsCopy)
|
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
2021-01-21 14:29:17 +00:00
|
|
|
|
2021-02-04 00:58:33 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-07-03 14:37:54 +00:00
|
|
|
})
|
2021-02-04 00:58:33 +00:00
|
|
|
b.Run(fmt.Sprintf("max-cover_%s", tt.name), func(b *testing.B) {
|
|
|
|
b.StopTimer()
|
|
|
|
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
|
|
|
|
AttestationAggregationStrategy: string(MaxCoverAggregation),
|
2021-01-21 14:29:17 +00:00
|
|
|
})
|
2021-02-04 00:58:33 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-03 14:37:54 +00:00
|
|
|
}
|