@@ -5,6 +5,7 @@ package warp
55
66import (
77 "context"
8+ "fmt"
89 "math"
910 "testing"
1011
@@ -304,3 +305,41 @@ func TestSumWeight(t *testing.T) {
304305 })
305306 }
306307}
308+
309+ func BenchmarkGetCanonicalValidatorSet (b * testing.B ) {
310+ pChainHeight := uint64 (1 )
311+ subnetID := ids .GenerateTestID ()
312+ numNodes := 10_000
313+ getValidatorOutputs := make ([]* validators.GetValidatorOutput , 0 , numNodes )
314+ for i := 0 ; i < numNodes ; i ++ {
315+ nodeID := ids .GenerateTestNodeID ()
316+ blsPrivateKey , err := bls .NewSecretKey ()
317+ require .NoError (b , err )
318+ blsPublicKey := bls .PublicFromSecretKey (blsPrivateKey )
319+ getValidatorOutputs = append (getValidatorOutputs , & validators.GetValidatorOutput {
320+ NodeID : nodeID ,
321+ PublicKey : blsPublicKey ,
322+ Weight : 20 ,
323+ })
324+ }
325+
326+ for _ , size := range []int {0 , 1 , 10 , 100 , 1_000 , 10_000 } {
327+ getValidatorsOutput := make (map [ids.NodeID ]* validators.GetValidatorOutput )
328+ for i := 0 ; i < size ; i ++ {
329+ validator := getValidatorOutputs [i ]
330+ getValidatorsOutput [validator .NodeID ] = validator
331+ }
332+ validatorState := & validators.TestState {
333+ GetValidatorSetF : func (context.Context , uint64 , ids.ID ) (map [ids.NodeID ]* validators.GetValidatorOutput , error ) {
334+ return getValidatorsOutput , nil
335+ },
336+ }
337+
338+ b .Run (fmt .Sprintf ("%d" , size ), func (b * testing.B ) {
339+ for i := 0 ; i < b .N ; i ++ {
340+ _ , _ , err := GetCanonicalValidatorSet (context .Background (), validatorState , pChainHeight , subnetID )
341+ require .NoError (b , err )
342+ }
343+ })
344+ }
345+ }
0 commit comments