Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance for test generation and execution #359

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions types/testingutils/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/rsa"
"encoding/hex"
"fmt"
"hash/fnv"
"sync"

spec "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/bloxapp/ssv-spec/types"
Expand All @@ -25,11 +27,34 @@ type testingKeyManager struct {
slashableDataRoots [][]byte
}

var (
instancesMap = make(map[uint64]*testingKeyManager)
mu sync.Mutex
)

func getHash(data [][]byte) uint64 {
h := fnv.New64a()
for _, d := range data {
h.Write(d)
}
return h.Sum64()
}

func NewTestingKeyManager() *testingKeyManager {
return NewTestingKeyManagerWithSlashableRoots([][]byte{})
}

func NewTestingKeyManagerWithSlashableRoots(slashableDataRoots [][]byte) *testingKeyManager {

hash := getHash(slashableDataRoots)

mu.Lock()
defer mu.Unlock()

if instance, ok := instancesMap[hash]; ok {
return instance
}

ret := &testingKeyManager{
keys: map[string]*bls.SecretKey{},
ecdsaKeys: map[string]*ecdsa.PrivateKey{},
Expand Down Expand Up @@ -70,6 +95,9 @@ func NewTestingKeyManagerWithSlashableRoots(slashableDataRoots [][]byte) *testin
for _, o := range Testing13SharesSet().DKGOperators {
ret.ecdsaKeys[o.ETHAddress.String()] = o.SK
}

instancesMap[hash] = ret

return ret
}

Expand Down
Loading