mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
enable cryptorand analyzer in slasher (#7417)
This commit is contained in:
@@ -86,6 +86,7 @@
|
|||||||
"only_files": {
|
"only_files": {
|
||||||
"beacon-chain/.*": "",
|
"beacon-chain/.*": "",
|
||||||
"shared/.*": "",
|
"shared/.*": "",
|
||||||
|
"slasher/.*": "",
|
||||||
"validator/.*": ""
|
"validator/.*": ""
|
||||||
},
|
},
|
||||||
"exclude_files": {
|
"exclude_files": {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ go_library(
|
|||||||
importpath = "github.com/prysmaticlabs/prysm/slasher/db/testing",
|
importpath = "github.com/prysmaticlabs/prysm/slasher/db/testing",
|
||||||
visibility = ["//slasher:__subpackages__"],
|
visibility = ["//slasher:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"//shared/rand:go_default_library",
|
||||||
"//shared/testutil:go_default_library",
|
"//shared/testutil:go_default_library",
|
||||||
"//slasher/db:go_default_library",
|
"//slasher/db:go_default_library",
|
||||||
"//slasher/db/kv:go_default_library",
|
"//slasher/db/kv:go_default_library",
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
package testing
|
package testing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||||
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
|
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
|
||||||
"github.com/prysmaticlabs/prysm/slasher/db/kv"
|
"github.com/prysmaticlabs/prysm/slasher/db/kv"
|
||||||
@@ -17,10 +16,7 @@ import (
|
|||||||
|
|
||||||
// SetupSlasherDB instantiates and returns a SlasherDB instance.
|
// SetupSlasherDB instantiates and returns a SlasherDB instance.
|
||||||
func SetupSlasherDB(t testing.TB, spanCacheEnabled bool) *kv.Store {
|
func SetupSlasherDB(t testing.TB, spanCacheEnabled bool) *kv.Store {
|
||||||
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
randPath := rand.NewDeterministicGenerator().Int()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Could not generate random file path: %v", err)
|
|
||||||
}
|
|
||||||
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
||||||
if err := os.RemoveAll(p); err != nil {
|
if err := os.RemoveAll(p); err != nil {
|
||||||
t.Fatalf("Failed to remove directory: %v", err)
|
t.Fatalf("Failed to remove directory: %v", err)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ go_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//shared/params:go_default_library",
|
"//shared/params:go_default_library",
|
||||||
|
"//shared/rand:go_default_library",
|
||||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
package testing
|
package testing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
|
|
||||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||||
"github.com/prysmaticlabs/prysm/shared/params"
|
"github.com/prysmaticlabs/prysm/shared/params"
|
||||||
|
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SignedBlockHeader given slot, proposer index this function generates signed block header.
|
// SignedBlockHeader given slot, proposer index this function generates signed block header.
|
||||||
@@ -43,7 +42,8 @@ func BlockHeader(slot uint64, proposerIdx uint64) (*ethpb.BeaconBlockHeader, err
|
|||||||
|
|
||||||
func genRandomByteArray(length int) ([]byte, error) {
|
func genRandomByteArray(length int) ([]byte, error) {
|
||||||
blk := make([]byte, length)
|
blk := make([]byte, length)
|
||||||
_, err := rand.Read(blk)
|
randGen := rand.NewDeterministicGenerator()
|
||||||
|
_, err := randGen.Read(blk)
|
||||||
return blk, err
|
return blk, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user