benchmark cold hashing of capella beaconstates (#12516)

* benchmark cold hashing of capella beaconstates

* use since
This commit is contained in:
Potuz 2023-06-12 13:54:43 -03:00 committed by GitHub
parent d5057cfb42
commit 826267310e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import (
"os"
"regexp"
"strings"
"time"
"github.com/kr/pretty"
fssz "github.com/prysmaticlabs/fastssz"
@ -62,7 +63,7 @@ func main() {
"signed_block_header|" +
"signed_voluntary_exit|" +
"voluntary_exit|" +
"state",
"state_capella",
Required: true,
Destination: &sszType,
},
@ -92,8 +93,8 @@ func main() {
data = &ethpb.SignedVoluntaryExit{}
case "voluntary_exit":
data = &ethpb.VoluntaryExit{}
case "state":
data = &ethpb.BeaconState{}
case "state_capella":
data = &ethpb.BeaconStateCapella{}
default:
log.Fatal("Invalid type")
}
@ -101,6 +102,40 @@ func main() {
return nil
},
},
{
Name: "benchmark-hash",
Aliases: []string{"b"},
Usage: "benchmark-hash SSZ data",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "ssz-path",
Usage: "Path to file(ssz)",
Required: true,
Destination: &sszPath,
},
&cli.StringFlag{
Name: "data-type",
Usage: "ssz file data type: " +
"block_capella|" +
"blinded_block_capella|" +
"signed_block_capella|" +
"attestation|" +
"block_header|" +
"deposit|" +
"proposer_slashing|" +
"signed_block_header|" +
"signed_voluntary_exit|" +
"voluntary_exit|" +
"state_capella",
Required: true,
Destination: &sszType,
},
},
Action: func(c *cli.Context) error {
benchmarkHash(sszPath, sszType)
return nil
},
},
{
Name: "state-transition",
Category: "state-transition",
@ -230,3 +265,26 @@ func prettyPrint(sszPath string, data fssz.Unmarshaler) {
str = re.ReplaceAllString(str, "")
fmt.Print(str)
}
func benchmarkHash(sszPath string, sszType string) {
switch sszType {
case "state_capella":
data := &ethpb.BeaconStateCapella{}
if err := dataFetcher(sszPath, data); err != nil {
log.Fatal(err)
}
st, err := state_native.InitializeFromProtoCapella(data)
if err != nil {
log.Fatal("not a state")
}
start := time.Now()
root, err := st.HashTreeRoot(context.Background())
if err != nil {
log.Fatal("couldn't hash")
}
fmt.Printf("Duration: %v HTR: %#x\n", time.Since(start), root)
return
default:
log.Fatal("Invalid type")
}
}