mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
b030771174
* first version * cli context * fix service * starting change to ccache * ristretto cache * added test * test on evict * remove evict test * test onevict * comment for exported flag * update all span maps on load * fix setup db * span cache added to help flags * start save cache on exit * save cache to db before close * comment fix * fix flags * setup db new * nishant feedback * workspace cr * lint fix * fix calls * start db * fix test * Update slasher/db/db.go Co-Authored-By: Nishant Das <nishdas93@gmail.com> * add flag * nishant feedback * export Config * fix imports * fix imports * fix imports * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * remove mod print Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Nishant Das <nish1993@hotmail.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
163 lines
4.3 KiB
Go
163 lines
4.3 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/slasher/db"
|
|
"github.com/prysmaticlabs/prysm/slasher/flags"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var appFlags = []cli.Flag{
|
|
flags.CertFlag,
|
|
flags.RPCPort,
|
|
flags.KeyFlag,
|
|
flags.UseSpanCacheFlag,
|
|
}
|
|
|
|
func BenchmarkMinSpan(b *testing.B) {
|
|
diffs := []uint64{2, 10, 100, 1000, 10000, 53999}
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
|
ctx := cli.NewContext(app, set, nil)
|
|
dbs := db.SetupSlasherDB(b, ctx)
|
|
defer db.TeardownSlasherDB(b, dbs)
|
|
|
|
context := context.Background()
|
|
slasherServer := &Server{
|
|
SlasherDB: dbs,
|
|
}
|
|
for _, diff := range diffs {
|
|
b.Run(fmt.Sprintf("MinSpan_diff_%d", diff), func(ib *testing.B) {
|
|
for i := uint64(0); i < uint64(ib.N); i++ {
|
|
spanMap, err := slasherServer.SlasherDB.ValidatorSpansMap(i % 10)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_, _, err = slasherServer.DetectAndUpdateMinEpochSpan(context, i, i+diff, i%10, spanMap)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkMaxSpan(b *testing.B) {
|
|
diffs := []uint64{2, 10, 100, 1000, 10000, 53999}
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
|
ctx := cli.NewContext(app, set, nil)
|
|
dbs := db.SetupSlasherDB(b, ctx)
|
|
defer db.TeardownSlasherDB(b, dbs)
|
|
|
|
context := context.Background()
|
|
slasherServer := &Server{
|
|
SlasherDB: dbs,
|
|
}
|
|
for _, diff := range diffs {
|
|
b.Run(fmt.Sprintf("MaxSpan_diff_%d", diff), func(ib *testing.B) {
|
|
for i := uint64(0); i < uint64(ib.N); i++ {
|
|
spanMap, err := slasherServer.SlasherDB.ValidatorSpansMap(i % 10)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_, _, err = slasherServer.DetectAndUpdateMaxEpochSpan(context, diff, diff+i, i%10, spanMap)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkDetectSpan(b *testing.B) {
|
|
diffs := []uint64{2, 10, 100, 1000, 10000, 53999}
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
|
ctx := cli.NewContext(app, set, nil)
|
|
dbs := db.SetupSlasherDB(b, ctx)
|
|
defer db.TeardownSlasherDB(b, dbs)
|
|
|
|
slasherServer := &Server{
|
|
SlasherDB: dbs,
|
|
}
|
|
for _, diff := range diffs {
|
|
b.Run(fmt.Sprintf("Detect_MaxSpan_diff_%d", diff), func(ib *testing.B) {
|
|
for i := uint64(0); i < uint64(ib.N); i++ {
|
|
spanMap, err := slasherServer.SlasherDB.ValidatorSpansMap(i % 10)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_, _, _, err = slasherServer.detectSlashingByEpochSpan(i, i+diff, spanMap, detectMax)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
for _, diff := range diffs {
|
|
b.Run(fmt.Sprintf("Detect_MinSpan_diff_%d", diff), func(ib *testing.B) {
|
|
for i := uint64(0); i < uint64(ib.N); i++ {
|
|
spanMap, err := slasherServer.SlasherDB.ValidatorSpansMap(i % 10)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
_, _, _, err = slasherServer.detectSlashingByEpochSpan(i, i+diff, spanMap, detectMin)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkCheckAttestations(b *testing.B) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
|
ctx := cli.NewContext(app, set, nil)
|
|
dbs := db.SetupSlasherDB(b, ctx)
|
|
defer db.TeardownSlasherDB(b, dbs)
|
|
context := context.Background()
|
|
slasherServer := &Server{
|
|
ctx: context,
|
|
SlasherDB: dbs,
|
|
}
|
|
var cb []uint64
|
|
for i := uint64(0); i < 100; i++ {
|
|
cb = append(cb, i)
|
|
}
|
|
ia1 := ðpb.IndexedAttestation{
|
|
AttestingIndices: cb,
|
|
Signature: make([]byte, 96),
|
|
Data: ðpb.AttestationData{
|
|
CommitteeIndex: 0,
|
|
BeaconBlockRoot: make([]byte, 32),
|
|
Source: ðpb.Checkpoint{Epoch: 2},
|
|
Target: ðpb.Checkpoint{Epoch: 4},
|
|
},
|
|
}
|
|
b.ResetTimer()
|
|
for i := uint64(0); i < uint64(b.N); i++ {
|
|
ia1.Data.Target.Epoch = i + 1
|
|
ia1.Data.Source.Epoch = i
|
|
ia1.Data.Slot = (i + 1) * params.BeaconConfig().SlotsPerEpoch
|
|
root := []byte(strconv.Itoa(int(i)))
|
|
ia1.Data.BeaconBlockRoot = append(root, ia1.Data.BeaconBlockRoot[len(root):]...)
|
|
if _, err := slasherServer.IsSlashableAttestation(context, ia1); err != nil {
|
|
b.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
}
|
|
|
|
}
|