diff --git a/tools/pcli/main.go b/tools/pcli/main.go index 9c88999f8..02416b968 100644 --- a/tools/pcli/main.go +++ b/tools/pcli/main.go @@ -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 = ðpb.SignedVoluntaryExit{} case "voluntary_exit": data = ðpb.VoluntaryExit{} - case "state": - data = ðpb.BeaconState{} + case "state_capella": + data = ðpb.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 := ðpb.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") + } +}