diff --git a/Dockerfile b/Dockerfile index 3052d24ae0..de75663315 100644 --- a/Dockerfile +++ b/Dockerfile @@ -89,6 +89,20 @@ RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ go build -o ./bin/relay ./cmd +# Traffic Generator V1 build stage +FROM common-builder AS generator-builder +WORKDIR /app/tools/traffic +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -o ./bin/generator ./cmd + +# Traffic Generator V2 build stage +FROM common-builder AS generator2-builder +WORKDIR /app/test/v2 +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + make build + # Final stages for each component FROM alpine:3.18 AS churner COPY --from=churner-builder /app/operators/bin/churner /usr/local/bin @@ -129,3 +143,11 @@ ENTRYPOINT ["controller"] FROM alpine:3.18 AS relay COPY --from=relay-builder /app/relay/bin/relay /usr/local/bin ENTRYPOINT ["relay"] + +FROM alpine:3.18 AS generator +COPY --from=generator-builder /app/tools/traffic/bin/generator /usr/local/bin +ENTRYPOINT ["generator"] + +FROM alpine:3.18 AS generator2 +COPY --from=generator2-builder /app/test/v2/bin/load /usr/local/bin +ENTRYPOINT ["load", "-", "-"] \ No newline at end of file diff --git a/api/clients/v2/dispersal_request_signer_test.go b/api/clients/v2/dispersal_request_signer_test.go index 3e8daa9e7d..aacf96ddfb 100644 --- a/api/clients/v2/dispersal_request_signer_test.go +++ b/api/clients/v2/dispersal_request_signer_test.go @@ -73,7 +73,7 @@ func teardown() { } func TestRequestSigning(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() setup(t) defer teardown() diff --git a/api/clients/v2/payload_disperser.go b/api/clients/v2/payload_disperser.go index 6f7d49ef87..9140baf85f 100644 --- a/api/clients/v2/payload_disperser.go +++ b/api/clients/v2/payload_disperser.go @@ -246,6 +246,8 @@ func (pd *PayloadDisperser) pollBlobStatusUntilCertified( case dispgrpc.BlobStatus_COMPLETE: return blobStatusReply, nil case dispgrpc.BlobStatus_QUEUED, dispgrpc.BlobStatus_ENCODED, dispgrpc.BlobStatus_GATHERING_SIGNATURES: + // TODO (litt): check signing percentage when we are gathering signatures, potentially break + // out of this loop early if we have enough signatures continue default: return nil, fmt.Errorf( diff --git a/api/clients/v2/test/cert_verifier_test.go b/api/clients/v2/test/cert_verifier_test.go index 322e529bfb..9543e504be 100644 --- a/api/clients/v2/test/cert_verifier_test.go +++ b/api/clients/v2/test/cert_verifier_test.go @@ -46,7 +46,7 @@ func TestWaitForBlockNumber(t *testing.T) { waitGroup := sync.WaitGroup{} // start these goroutines in random order, so that it isn't always the same sequence of polling handoffs that gets exercised - indices := testrandom.NewTestRandom(t).Perm(callCount) + indices := testrandom.NewTestRandom().Perm(callCount) for _, index := range indices { waitGroup.Add(1) diff --git a/api/clients/v2/test/relay_payload_retriever_test.go b/api/clients/v2/test/relay_payload_retriever_test.go index 96e93e46ca..96cdc8ea83 100644 --- a/api/clients/v2/test/relay_payload_retriever_test.go +++ b/api/clients/v2/test/relay_payload_retriever_test.go @@ -56,7 +56,7 @@ func buildRelayPayloadRetrieverTester(t *testing.T) RelayPayloadRetrieverTester mockRelayClient := clientsmock.MockRelayClient{} codec := codecs.NewDefaultBlobCodec() - random := testrandom.NewTestRandom(t) + random := testrandom.NewTestRandom() g1Srs, err := kzg.ReadG1Points(g1Path, 5, uint64(runtime.GOMAXPROCS(0))) require.NotNil(t, g1Srs) diff --git a/api/clients/v2/verification/commitment_utils_test.go b/api/clients/v2/verification/commitment_utils_test.go index 2c5fe499aa..6ca18ccf96 100644 --- a/api/clients/v2/verification/commitment_utils_test.go +++ b/api/clients/v2/verification/commitment_utils_test.go @@ -29,7 +29,7 @@ func getRandomPaddedBytes(testRandom *random.TestRandom, count int) []byte { } func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { - testRandom := random.NewTestRandom(t) + testRandom := random.NewTestRandom() randomBytes := getRandomPaddedBytes(testRandom, 100+testRandom.Intn(1000)) srsNumberToLoad := computeSrsNumber(len(randomBytes)) @@ -52,7 +52,7 @@ func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { } func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { - testRandom := random.NewTestRandom(t) + testRandom := random.NewTestRandom() randomBytes := getRandomPaddedBytes(testRandom, 100+testRandom.Intn(1000)) srsNumberToLoad := computeSrsNumber(len(randomBytes)) @@ -76,7 +76,7 @@ func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { } func TestGenerateBlobCommitmentEquality(t *testing.T) { - testRandom := random.NewTestRandom(t) + testRandom := random.NewTestRandom() randomBytes := getRandomPaddedBytes(testRandom, 100+testRandom.Intn(1000)) srsNumberToLoad := computeSrsNumber(len(randomBytes)) diff --git a/common/pubip/pubip_test.go b/common/pubip/pubip_test.go index 20715c3332..7362bae635 100644 --- a/common/pubip/pubip_test.go +++ b/common/pubip/pubip_test.go @@ -96,7 +96,7 @@ func (t *testProvider) PublicIPAddress(ctx context.Context) (string, error) { } func TestMultiProvider(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) diff --git a/common/testutils/random/test_random.go b/common/testutils/random/test_random.go index 18ae2d0785..f28790f1a2 100644 --- a/common/testutils/random/test_random.go +++ b/common/testutils/random/test_random.go @@ -7,11 +7,9 @@ import ( "github.com/Layr-Labs/eigenda/core" "github.com/consensys/gnark-crypto/ecc/bn254/fr" "github.com/ethereum/go-ethereum/crypto" - "github.com/stretchr/testify/require" "io" "math/big" "math/rand" - "testing" "time" ) @@ -23,18 +21,23 @@ type TestRandom struct { // The source of randomness *rand.Rand - // The testing object - t *testing.T - // The seed used to initialize the random number generator seed int64 } // NewTestRandom creates a new instance of TestRandom // This method may either be seeded, or not seeded. If no seed is provided, then current unix nano time is used. -// -// The testing.T object is optional, but if it is nil then this utility will panic if an internal error occurs. -func NewTestRandom(t *testing.T, fixedSeed ...int64) *TestRandom { +func NewTestRandom(fixedSeed ...int64) *TestRandom { + return newTestRandom(true, fixedSeed...) +} + +// NewTestRandomNoPrint is similar to NewTestRandom, but does not print the seed to stdout. +func NewTestRandomNoPrint(fixedSeed ...int64) *TestRandom { + return newTestRandom(false, fixedSeed...) +} + +// NewTestRandomNoSeed creates a new instance of TestRandom. +func newTestRandom(print bool, fixedSeed ...int64) *TestRandom { var seed int64 if len(fixedSeed) == 0 { seed = time.Now().UnixNano() @@ -44,10 +47,11 @@ func NewTestRandom(t *testing.T, fixedSeed ...int64) *TestRandom { panic("too many arguments, expected exactly one seed") } - fmt.Printf("Random seed: %d\n", seed) + if print { + fmt.Printf("Random seed: %d\n", seed) + } return &TestRandom{ Rand: rand.New(rand.NewSource(seed)), - t: t, seed: seed, } } @@ -144,32 +148,28 @@ func (r *TestRandom) IOReader() io.Reader { // **intentionally** imposed by the Go standard libraries. (╯°□°)╯︵ ┻━┻ // // NOT CRYPTOGRAPHICALLY SECURE!!! FOR TESTING PURPOSES ONLY. DO NOT USE THESE KEYS FOR SECURITY PURPOSES. -func (r *TestRandom) ECDSA() (*ecdsa.PublicKey, *ecdsa.PrivateKey) { +func (r *TestRandom) ECDSA() (*ecdsa.PublicKey, *ecdsa.PrivateKey, error) { key, err := ecdsa.GenerateKey(crypto.S256(), crand.Reader) - r.requireNoError(err) - return &key.PublicKey, key + if err != nil { + return nil, nil, fmt.Errorf("failed to generate key: %w", err) + } + return &key.PublicKey, key, nil } // BLS generates a random BLS key pair. // // NOT CRYPTOGRAPHICALLY SECURE!!! FOR TESTING PURPOSES ONLY. DO NOT USE THESE KEYS FOR SECURITY PURPOSES. -func (r *TestRandom) BLS() *core.KeyPair { +func (r *TestRandom) BLS() (*core.KeyPair, error) { //Max random value is order of the curve maxValue := new(big.Int) maxValue.SetString(fr.Modulus().String(), 10) //Generate cryptographically strong pseudo-random between 0 - max n, err := crand.Int(r.IOReader(), maxValue) - r.requireNoError(err) + if err != nil { + return nil, fmt.Errorf("failed to generate random number: %w", err) + } sk := new(core.PrivateKey).SetBigInt(n) - return core.MakeKeyPair(sk) -} - -func (r *TestRandom) requireNoError(err error) { - if r.t != nil { - require.NoError(r.t, err) - } else if err != nil { - panic(err) - } + return core.MakeKeyPair(sk), nil } diff --git a/common/testutils/random/test_random_test.go b/common/testutils/random/test_random_test.go index 52129f3470..e1dee4f2cd 100644 --- a/common/testutils/random/test_random_test.go +++ b/common/testutils/random/test_random_test.go @@ -10,26 +10,26 @@ import ( // Tests that random seeding produces random results, and that consistent seeding produces consistent results func TestSetup(t *testing.T) { - testRandom1 := NewTestRandom(t) + testRandom1 := NewTestRandom() x := testRandom1.Int() - testRandom2 := NewTestRandom(t) + testRandom2 := NewTestRandom() y := testRandom2.Int() require.NotEqual(t, x, y) seed := rand.Int63() - testRandom3 := NewTestRandom(t, seed) + testRandom3 := NewTestRandom(seed) a := testRandom3.Int() - testRandom4 := NewTestRandom(t, seed) + testRandom4 := NewTestRandom(seed) b := testRandom4.Int() require.Equal(t, a, b) } func TestReset(t *testing.T) { - random := NewTestRandom(t) + random := NewTestRandom() a := random.Uint64() b := random.Uint64() @@ -45,11 +45,13 @@ func TestReset(t *testing.T) { } func TestECDSAKeyGeneration(t *testing.T) { - random := NewTestRandom(t) + random := NewTestRandom() // We should not get the same key pair twice in a row - public1, private1 := random.ECDSA() - public2, private2 := random.ECDSA() + public1, private1, err := random.ECDSA() + require.NoError(t, err) + public2, private2, err := random.ECDSA() + require.NoError(t, err) assert.NotEqual(t, &public1, &public2) assert.NotEqual(t, &private1, &private2) @@ -57,8 +59,10 @@ func TestECDSAKeyGeneration(t *testing.T) { // Getting keys should result in deterministic generator state. generatorState := random.Uint64() random.Reset() - random.ECDSA() - random.ECDSA() + _, _, err = random.ECDSA() + require.NoError(t, err) + _, _, err = random.ECDSA() + require.NoError(t, err) require.Equal(t, generatorState, random.Uint64()) // Keypair should be valid. @@ -73,11 +77,13 @@ func TestECDSAKeyGeneration(t *testing.T) { } func TestBLSKeyGeneration(t *testing.T) { - random := NewTestRandom(t) + random := NewTestRandom() // We should not get the same key pair twice in a row - keypair1 := random.BLS() - keypair2 := random.BLS() + keypair1, err := random.BLS() + require.NoError(t, err) + keypair2, err := random.BLS() + require.NoError(t, err) require.False(t, keypair1.PrivKey.Equal(keypair2.PrivKey)) require.False(t, keypair1.PubKey.Equal(keypair2.PubKey.G1Affine)) @@ -85,13 +91,16 @@ func TestBLSKeyGeneration(t *testing.T) { // Getting keys should result in deterministic generator state. generatorState := random.Uint64() random.Reset() - random.BLS() - random.BLS() + _, err = random.BLS() + require.NoError(t, err) + _, err = random.BLS() + require.NoError(t, err) require.Equal(t, generatorState, random.Uint64()) // Keys should be deterministic. random.Reset() - keypair3 := random.BLS() + keypair3, err := random.BLS() + require.NoError(t, err) require.True(t, keypair1.PrivKey.Equal(keypair3.PrivKey)) require.True(t, keypair1.PubKey.Equal(keypair3.PubKey.G1Affine)) diff --git a/disperser/apiserver/server_v2_test.go b/disperser/apiserver/server_v2_test.go index 86017dcab3..274a0a9425 100644 --- a/disperser/apiserver/server_v2_test.go +++ b/disperser/apiserver/server_v2_test.go @@ -604,7 +604,7 @@ func TestInvalidLength(t *testing.T) { } func TestTooShortCommitment(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() c := newTestServerV2(t) ctx := peer.NewContext(context.Background(), c.Peer) diff --git a/disperser/controller/node_client_manager_test.go b/disperser/controller/node_client_manager_test.go index 070ff1490f..99ade23373 100644 --- a/disperser/controller/node_client_manager_test.go +++ b/disperser/controller/node_client_manager_test.go @@ -10,9 +10,10 @@ import ( ) func TestNodeClientManager(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() - _, private := rand.ECDSA() + _, private, err := rand.ECDSA() + require.NoError(t, err) requestSigner := mock.NewStaticRequestSigner(private) m, err := controller.NewNodeClientManager(2, requestSigner, nil) diff --git a/docker-bake.hcl b/docker-bake.hcl index 9f9b136c13..17c4a860e0 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -189,7 +189,7 @@ target "churner-internal" { target "traffic-generator" { context = "." - dockerfile = "./trafficgenerator.Dockerfile" + dockerfile = "./Dockerfile" target = "generator" tags = ["${REGISTRY}/${REPO}/traffic-generator:${BUILD_TAG}"] } @@ -205,7 +205,7 @@ target "traffic-generator-internal" { target "traffic-generator-v2" { context = "." - dockerfile = "./trafficgenerator-v2.Dockerfile" + dockerfile = "./Dockerfile" target = "generator2" tags = ["${REGISTRY}/${REPO}/traffic-generator-v2:${BUILD_TAG}"] } diff --git a/encoding/rs/bundle_builder_test.go b/encoding/rs/bundle_builder_test.go index dcfb270d19..dcf28877f6 100644 --- a/encoding/rs/bundle_builder_test.go +++ b/encoding/rs/bundle_builder_test.go @@ -11,7 +11,7 @@ import ( ) func TestParsingBundle(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() teardownSuite := setupSuite(t) defer teardownSuite(t) diff --git a/encoding/rs/frame_coeffs_test.go b/encoding/rs/frame_coeffs_test.go index 518d97f85c..9884575b3e 100644 --- a/encoding/rs/frame_coeffs_test.go +++ b/encoding/rs/frame_coeffs_test.go @@ -12,7 +12,7 @@ import ( ) func TestFrameCoeffsSliceSerialization(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() teardownSuite := setupSuite(t) defer teardownSuite(t) @@ -40,7 +40,7 @@ func TestFrameCoeffsSliceSerialization(t *testing.T) { } func TestSplitSerializedFrameCoeffs(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() teardownSuite := setupSuite(t) defer teardownSuite(t) diff --git a/encoding/rs/frame_proofs_test.go b/encoding/rs/frame_proofs_test.go index 9fe844000a..f1413c48c9 100644 --- a/encoding/rs/frame_proofs_test.go +++ b/encoding/rs/frame_proofs_test.go @@ -36,7 +36,7 @@ func TestSerializeFrameProof(t *testing.T) { } func TestSerializeFrameProofs(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() count := 10 + rand.Intn(10) proofs := make([]*encoding.Proof, count) @@ -59,7 +59,7 @@ func TestSerializeFrameProofs(t *testing.T) { } func TestSplitSerializedFrameProofs(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() count := 10 + rand.Intn(10) proofs := make([]*encoding.Proof, count) diff --git a/node/auth/authenticator_test.go b/node/auth/authenticator_test.go index 28ae0122ec..027fe058c5 100644 --- a/node/auth/authenticator_test.go +++ b/node/auth/authenticator_test.go @@ -15,11 +15,12 @@ import ( ) func TestValidRequest(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -46,11 +47,12 @@ func TestValidRequest(t *testing.T) { } func TestInvalidRequestWrongHash(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -80,11 +82,12 @@ func TestInvalidRequestWrongHash(t *testing.T) { } func TestInvalidRequestWrongKey(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, _ := rand.ECDSA() + publicKey, _, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -103,7 +106,8 @@ func TestInvalidRequestWrongKey(t *testing.T) { request := RandomStoreChunksRequest(rand) request.DisperserID = 0 - _, differentPrivateKey := rand.ECDSA() + _, differentPrivateKey, err := rand.ECDSA() + require.NoError(t, err) signature, err := SignStoreChunksRequest(differentPrivateKey, request) require.NoError(t, err) request.Signature = signature @@ -113,15 +117,17 @@ func TestInvalidRequestWrongKey(t *testing.T) { } func TestInvalidRequestInvalidDisperserID(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey0, privateKey0 := rand.ECDSA() + publicKey0, privateKey0, err := rand.ECDSA() + require.NoError(t, err) disperserAddress0 := crypto.PubkeyToAddress(*publicKey0) // This disperser will be loaded on chain (simulated), but will fail the valid disperser ID filter. - publicKey1, privateKey1 := rand.ECDSA() + publicKey1, privateKey1, err := rand.ECDSA() + require.NoError(t, err) disperserAddress1 := crypto.PubkeyToAddress(*publicKey1) chainReader := wmock.MockWriter{} @@ -173,11 +179,12 @@ func TestInvalidRequestInvalidDisperserID(t *testing.T) { } func TestAuthCaching(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -239,11 +246,12 @@ func TestAuthCaching(t *testing.T) { } func TestAuthCachingDisabled(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -283,11 +291,12 @@ func TestAuthCachingDisabled(t *testing.T) { } func TestKeyExpiry(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -336,11 +345,12 @@ func TestKeyExpiry(t *testing.T) { } func TestAuthCacheSize(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) chainReader := wmock.MockWriter{} @@ -423,7 +433,7 @@ func TestAuthCacheSize(t *testing.T) { } func TestKeyCacheSize(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() start := rand.Time() @@ -432,7 +442,8 @@ func TestKeyCacheSize(t *testing.T) { chainReader := wmock.MockWriter{} keyMap := make(map[uint32]*ecdsa.PrivateKey, cacheSize+1) for i := 0; i < cacheSize+1; i++ { - publicKey, privateKey := rand.ECDSA() + publicKey, privateKey, err := rand.ECDSA() + require.NoError(t, err) disperserAddress := crypto.PubkeyToAddress(*publicKey) keyMap[uint32(i)] = privateKey diff --git a/node/auth/request_signing_test.go b/node/auth/request_signing_test.go index 94e3f36988..0302b51393 100644 --- a/node/auth/request_signing_test.go +++ b/node/auth/request_signing_test.go @@ -10,7 +10,7 @@ import ( ) func TestHashing(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() request := RandomStoreChunksRequest(rand) originalRequestHash := hashing.HashStoreChunksRequest(request) @@ -139,9 +139,10 @@ func TestHashing(t *testing.T) { } func TestRequestSigning(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() - public, private := rand.ECDSA() + public, private, err := rand.ECDSA() + require.NoError(t, err) publicAddress := crypto.PubkeyToAddress(*public) request := RandomStoreChunksRequest(rand) @@ -154,7 +155,8 @@ func TestRequestSigning(t *testing.T) { require.NoError(t, err) // Using a different public key should make the signature invalid - otherPublic, _ := rand.ECDSA() + otherPublic, _, err := rand.ECDSA() + require.NoError(t, err) otherPublicAddress := crypto.PubkeyToAddress(*otherPublic) err = VerifyStoreChunksRequest(otherPublicAddress, request) require.Error(t, err) diff --git a/relay/server_test.go b/relay/server_test.go index b01f1038fd..ad3ce80b8a 100644 --- a/relay/server_test.go +++ b/relay/server_test.go @@ -112,7 +112,7 @@ func getChunks( } func TestReadWriteBlobs(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -201,7 +201,7 @@ func TestReadWriteBlobs(t *testing.T) { } func TestReadNonExistentBlob(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -254,7 +254,7 @@ func TestReadNonExistentBlob(t *testing.T) { } func TestReadWriteBlobsWithSharding(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -390,7 +390,7 @@ func TestReadWriteBlobsWithSharding(t *testing.T) { } func TestReadWriteChunks(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -406,7 +406,8 @@ func TestReadWriteChunks(t *testing.T) { operatorKeys := make(map[uint32]*core.KeyPair) operatorInfo := make(map[core.OperatorID]*core.IndexedOperatorInfo) for i := 0; i < operatorCount; i++ { - keypair := rand.BLS() + keypair, err := rand.BLS() + require.NoError(t, err) operatorKeys[uint32(i)] = keypair var operatorID core.OperatorID @@ -615,7 +616,7 @@ func TestReadWriteChunks(t *testing.T) { } func TestBatchedReadWriteChunks(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -631,7 +632,8 @@ func TestBatchedReadWriteChunks(t *testing.T) { operatorKeys := make(map[uint32]*core.KeyPair) operatorInfo := make(map[core.OperatorID]*core.IndexedOperatorInfo) for i := 0; i < operatorCount; i++ { - keypair := rand.BLS() + keypair, err := rand.BLS() + require.NoError(t, err) operatorKeys[uint32(i)] = keypair var operatorID core.OperatorID @@ -750,7 +752,7 @@ func TestBatchedReadWriteChunks(t *testing.T) { } func TestReadWriteChunksWithSharding(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -777,7 +779,8 @@ func TestReadWriteChunksWithSharding(t *testing.T) { operatorKeys := make(map[uint32]*core.KeyPair) operatorInfo := make(map[core.OperatorID]*core.IndexedOperatorInfo) for i := 0; i < operatorCount; i++ { - keypair := rand.BLS() + keypair, err := rand.BLS() + require.NoError(t, err) operatorKeys[uint32(i)] = keypair var operatorID core.OperatorID @@ -1050,7 +1053,7 @@ func TestReadWriteChunksWithSharding(t *testing.T) { } func TestBatchedReadWriteChunksWithSharding(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() logger, err := common.NewLogger(common.DefaultLoggerConfig()) require.NoError(t, err) @@ -1077,7 +1080,8 @@ func TestBatchedReadWriteChunksWithSharding(t *testing.T) { operatorKeys := make(map[uint32]*core.KeyPair) operatorInfo := make(map[core.OperatorID]*core.IndexedOperatorInfo) for i := 0; i < operatorCount; i++ { - keypair := rand.BLS() + keypair, err := rand.BLS() + require.NoError(t, err) operatorKeys[uint32(i)] = keypair var operatorID core.OperatorID diff --git a/synthetic-test-client.Dockerfile b/synthetic-test-client.Dockerfile deleted file mode 100644 index ada43f6eff..0000000000 --- a/synthetic-test-client.Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -# Use the official Go image as the base image -FROM golang:1.21.13-alpine3.20 as builder - -# Copy only the test file and necessary files to the container -COPY ./disperser /app/disperser -COPY ./test/synthetic-test /app -COPY go.mod /app -COPY go.sum /app -COPY api /app/api -COPY node /app/node -COPY common /app/common -COPY operators/churner /app/operators/churner -COPY core /app/core -COPY indexer /app/indexer -COPY contracts /app/contracts -COPY encoding /app/encoding -# Set the working directory inside the container -WORKDIR /app - -# TODO eventually this will be replaced with an executable -# Run the Go test command for the specific test file -CMD ["go", "test", "-v", "synthetic_client_test.go"] diff --git a/test/v2/client/test_client.go b/test/v2/client/test_client.go index 9ae62bd63a..ac230e21b1 100644 --- a/test/v2/client/test_client.go +++ b/test/v2/client/test_client.go @@ -31,15 +31,10 @@ import ( ) const ( - SRSPath = "srs" - SRSPathG1 = SRSPath + "/g1.point" - SRSPathG2 = SRSPath + "/g2.point" - SRSPathG2PowerOf2 = SRSPath + "/g2.point.powerOf2" - SRSPathSRSTables = SRSPath + "/SRSTables" - - G1URL = "https://eigenda.s3.amazonaws.com/srs/g1.point" - G2URL = "https://eigenda.s3.amazonaws.com/srs/g2.point" - G2PowerOf2URL = "https://eigenda.s3.amazonaws.com/srs/g2.point.powerOf2" + SRSPathG1 = "/g1.point" + SRSPathG2 = "/g2.point" + SRSPathG2PowerOf2 = "/g2.point.powerOf2" + SRSPathSRSTables = "/SRSTables" ) // TestClient encapsulates the various clients necessary for interacting with EigenDA. @@ -75,20 +70,12 @@ func NewTestClient( // Construct the disperser client - privateKeyFile, err := ResolveTildeInPath(config.KeyPath) + privateKey, err := loadPrivateKey(config.KeyPath, config.KeyVar) if err != nil { - return nil, fmt.Errorf("failed to resolve tilde in path: %w", err) + return nil, fmt.Errorf("failed to load private key: %w", err) } - privateKey, err := os.ReadFile(privateKeyFile) - if err != nil { - return nil, fmt.Errorf("failed to read private key file: %w", err) - } - - privateKeyString := string(privateKey) - privateKeyString = strings.Trim(privateKeyString, "\n \t") - privateKeyString, _ = strings.CutPrefix(privateKeyString, "0x") - signer, err := auth.NewLocalBlobRequestSigner(privateKeyString) + signer, err := auth.NewLocalBlobRequestSigner(privateKey) if err != nil { return nil, fmt.Errorf("failed to create signer: %w", err) } @@ -99,19 +86,19 @@ func NewTestClient( accountId := gethcommon.HexToAddress(signerAccountId) logger.Infof("Account ID: %s", accountId.String()) - g1Path, err := config.Path(SRSPathG1) + g1Path, err := config.ResolveSRSPath(SRSPathG1) if err != nil { return nil, fmt.Errorf("failed to get path to G1 file: %w", err) } - g2Path, err := config.Path(SRSPathG2) + g2Path, err := config.ResolveSRSPath(SRSPathG2) if err != nil { return nil, fmt.Errorf("failed to get path to G2 file: %w", err) } - g2PowerOf2Path, err := config.Path(SRSPathG2PowerOf2) + g2PowerOf2Path, err := config.ResolveSRSPath(SRSPathG2PowerOf2) if err != nil { return nil, fmt.Errorf("failed to get path to G2 power of 2 file: %w", err) } - srsTablesPath, err := config.Path(SRSPathSRSTables) + srsTablesPath, err := config.ResolveSRSPath(SRSPathSRSTables) if err != nil { return nil, fmt.Errorf("failed to get path to SRS tables: %w", err) } @@ -149,7 +136,7 @@ func NewTestClient( ethClientConfig := geth.EthClientConfig{ RPCURLs: config.EthRPCURLs, - PrivateKeyString: privateKeyString, + PrivateKeyString: privateKey, NumConfirmations: 0, NumRetries: 3, } @@ -185,8 +172,12 @@ func NewTestClient( // If the relay client attempts to call GetChunks(), it will use this bogus signer. // This is expected to be rejected by the relays, since this client is not authorized to call GetChunks(). - rand := random.NewTestRandom(nil) - keypair := rand.BLS() + rand := random.NewTestRandom() + keypair, err := rand.BLS() + if err != nil { + return nil, fmt.Errorf("failed to generate BLS keypair: %w", err) + } + var fakeSigner clients.MessageSigner = func(ctx context.Context, data [32]byte) (*core.Signature, error) { return keypair.SignMessage(data), nil } @@ -277,13 +268,45 @@ func NewTestClient( retrievalClient: retrievalClient, validatorPayloadRetriever: validatorPayloadRetriever, certVerifier: certVerifier, - privateKey: privateKeyString, + privateKey: privateKey, metricsRegistry: metrics.registry, metrics: metrics, blobCodec: blobCodec, }, nil } +// loadPrivateKey loads the private key from the file/env var specified in the config. +func loadPrivateKey(keyPath string, keyVar string) (string, error) { + if keyPath != "" { + privateKeyFile, err := ResolveTildeInPath(keyPath) + if err != nil { + return "", fmt.Errorf("failed to resolve tilde in path: %w", err) + } + privateKey, err := os.ReadFile(privateKeyFile) + if err != nil { + return "", fmt.Errorf("failed to read private key file: %w", err) + } + + return formatPrivateKey(string(privateKey)), nil + } + + if keyVar == "" { + return "", fmt.Errorf("either KeyPath or KeyVar must be set") + } + privateKey := os.Getenv(keyVar) + if privateKey == "" { + return "", fmt.Errorf("key not found in environment variable %s", keyVar) + } + return formatPrivateKey(privateKey), nil +} + +// formatPrivateKey formats the private key by removing leading/trailing whitespace and "0x" prefix. +func formatPrivateKey(privateKey string) string { + privateKey = strings.Trim(privateKey, "\n \t") + privateKey, _ = strings.CutPrefix(privateKey, "0x") + return privateKey +} + // GetConfig returns the test client's configuration. func (c *TestClient) GetConfig() *TestClientConfig { return c.config diff --git a/test/v2/client/test_client_config.go b/test/v2/client/test_client_config.go index 1a291bc583..1855bbc8b3 100644 --- a/test/v2/client/test_client_config.go +++ b/test/v2/client/test_client_config.go @@ -7,11 +7,17 @@ import ( // TestClientConfig is the configuration for the test client. type TestClientConfig struct { - // The location where persistent test data is stored (e.g. SRS files). Often private keys are stored here too. - TestDataPath string - // The location where the test client's private key is stored. - // This is the key for the account that is paying for dispersals. + // The location where the SRS files can be found. + SRSPath string + // The location where the test client's private key is stored. This is the key for the account that is + // paying for dispersals. + // + // Either this or KeyVar must be set. If both are set, KeyPath is used. KeyPath string + // The environment variable that contains the private key for the account that is paying for dispersals. + // + // This is used if KeyPath is not set. + KeyVar string // The disperser's hostname (url or IP address) DisperserHostname string // The disperser's port @@ -36,16 +42,11 @@ type TestClientConfig struct { MetricsPort int } -// Path returns the full path to a file in the test data directory. -func (c *TestClientConfig) Path(elements ...string) (string, error) { - root, err := ResolveTildeInPath(c.TestDataPath) +// ResolveSRSPath returns a path relative to the SRSPath root directory. +func (c *TestClientConfig) ResolveSRSPath(srsFile string) (string, error) { + root, err := ResolveTildeInPath(c.SRSPath) if err != nil { return "", fmt.Errorf("failed to resolve tilde in path: %w", err) } - - combinedElements := make([]string, 0, len(elements)+1) - combinedElements = append(combinedElements, root) - combinedElements = append(combinedElements, elements...) - - return path.Join(combinedElements...), nil + return path.Join(root, srsFile), nil } diff --git a/test/v2/client/test_client_setup.go b/test/v2/client/test_client_setup.go index bb075e0cf8..bad4b1b8bb 100644 --- a/test/v2/client/test_client_setup.go +++ b/test/v2/client/test_client_setup.go @@ -3,14 +3,13 @@ package client import ( "encoding/json" "fmt" + "github.com/Layr-Labs/eigenda/common" + "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/stretchr/testify/require" "os" "os/exec" "sync" "testing" - - "github.com/Layr-Labs/eigenda/common" - "github.com/Layr-Labs/eigensdk-go/logging" - "github.com/stretchr/testify/require" ) var ( @@ -24,6 +23,10 @@ var ( const ( PreprodEnv = "../config/environment/preprod.json" + + G1URL = "https://srs-mainnet.s3.amazonaws.com/kzg/g1.point" + G2URL = "https://srs-mainnet.s3.amazonaws.com/kzg/g2.point" + G2PowerOf2URL = "https://srs-mainnet.s3.amazonaws.com/kzg/g2.point.powerOf2" ) // GetConfig returns a TestClientConfig instance parsed from the config file. @@ -91,14 +94,13 @@ func GetClient(configPath string) (*TestClient, error) { loggerConfig = common.DefaultConsoleLoggerConfig() } - testLogger, err := common.NewLogger(loggerConfig) + logger, err = common.NewLogger(loggerConfig) if err != nil { return nil, fmt.Errorf("failed to create logger: %w", err) } - logger = testLogger // only do this stuff once - err = setupFilesystem(logger, testConfig) + err = setupFilesystem(testConfig) if err != nil { return nil, fmt.Errorf("failed to setup filesystem: %w", err) } @@ -124,24 +126,25 @@ func skipInCI(t *testing.T) { } } -// ensureFileIsPresent checks if a file exists at the given path. If it does not, it downloads the file from the +// ensureSRSFileIsPresent checks if a file exists at the given path. If it does not, it downloads the file from the // given URL into the given path. -func ensureFileIsPresent( +func ensureSRSFileIsPresent( config *TestClientConfig, - path string, + filePath string, url string) error { - path, err := config.Path(path) + var err error + filePath, err = config.ResolveSRSPath(filePath) if err != nil { - return fmt.Errorf("failed to get path: %w", err) + return fmt.Errorf("failed to resolve SRS path: %w", err) } - _, err = os.Stat(path) + _, err = os.Stat(filePath) if os.IsNotExist(err) { command := make([]string, 3) command[0] = "wget" command[1] = url - command[2] = "--output-document=" + path + command[2] = "--output-document=" + filePath logger.Info("executing %s", command) cmd := exec.Command(command[0], command[1:]...) @@ -158,52 +161,37 @@ func ensureFileIsPresent( return nil } -func setupFilesystem(logger logging.Logger, config *TestClientConfig) error { +func setupFilesystem(config *TestClientConfig) error { // Create the test data directory if it does not exist - err := os.MkdirAll(config.TestDataPath, 0755) + srsPath, err := ResolveTildeInPath(config.SRSPath) if err != nil { - return fmt.Errorf("failed to create test data directory: %w", err) - } - - // Create the SRS directories if they do not exist - srsPath, err := config.Path(SRSPath) - if err != nil { - return fmt.Errorf("failed to get SRS path: %w", err) + return fmt.Errorf("failed to resolve tilde in path: %w", err) } err = os.MkdirAll(srsPath, 0755) if err != nil { - return fmt.Errorf("failed to create SRS directory: %w", err) + return fmt.Errorf("failed to create test data directory: %w", err) } - srsTablesPath, err := config.Path(SRSPathSRSTables) + + // Create the SRS directories if they do not exist + srsTablesPath, err := config.ResolveSRSPath(SRSPathSRSTables) if err != nil { - return fmt.Errorf("failed to get SRS tables path: %w", err) + return fmt.Errorf("failed to resolve SRS tables path: %w", err) } err = os.MkdirAll(srsTablesPath, 0755) if err != nil { return fmt.Errorf("failed to create SRS tables directory: %w", err) } - // Check to see if the private key file exists. If not, stop the test. - filePath, err := ResolveTildeInPath(config.KeyPath) - if err != nil { - return fmt.Errorf("failed to resolve tilde in path: %w", err) - } - _, err = os.Stat(filePath) - if err != nil { - return fmt.Errorf("private key file %s does not exist. This file should "+ - "contain the private key for the account used in the test, in hex: %w", filePath, err) - } - // If any of the srs files do not exist, download them. - err = ensureFileIsPresent(config, SRSPathG1, G1URL) + err = ensureSRSFileIsPresent(config, SRSPathG1, G1URL) if err != nil { return fmt.Errorf("failed to locate G1 point: %w", err) } - err = ensureFileIsPresent(config, SRSPathG2, G2URL) + err = ensureSRSFileIsPresent(config, SRSPathG2, G2URL) if err != nil { return fmt.Errorf("failed to locate G2 point: %w", err) } - err = ensureFileIsPresent(config, SRSPathG2PowerOf2, G2PowerOf2URL) + err = ensureSRSFileIsPresent(config, SRSPathG2PowerOf2, G2PowerOf2URL) if err != nil { return fmt.Errorf("failed to locate G2 power of 2 point: %w", err) } diff --git a/test/v2/config/environment/preprod.json b/test/v2/config/environment/preprod.json index f6cbb6526a..60abcd46f5 100644 --- a/test/v2/config/environment/preprod.json +++ b/test/v2/config/environment/preprod.json @@ -1,5 +1,5 @@ { - "TestDataPath": "~/.test-v2", + "SRSPath": "~/.test-v2/srs", "KeyPath": "~/.test-v2/preprod-private-key.txt", "DisperserHostname": "disperser-preprod-holesky.eigenda.xyz", "DisperserPort": 443, diff --git a/test/v2/correctness/correctness_test.go b/test/v2/correctness/correctness_test.go index 0c7c8fd88e..da6b43c3c8 100644 --- a/test/v2/correctness/correctness_test.go +++ b/test/v2/correctness/correctness_test.go @@ -63,7 +63,7 @@ func TestEmptyBlobDispersal(t *testing.T) { // Disperse a 1 byte payload (no padding). func TestMicroscopicBlobDispersal(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() payload := []byte{1} err := testBasicDispersal(t, rand, payload, []core.QuorumID{0, 1}) require.NoError(t, err) @@ -71,7 +71,7 @@ func TestMicroscopicBlobDispersal(t *testing.T) { // Disperse a 1 byte payload (with padding). func TestMicroscopicBlobDispersalWithPadding(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() payload := []byte{1} err := testBasicDispersal(t, rand, payload, []core.QuorumID{0, 1}) require.NoError(t, err) @@ -79,7 +79,7 @@ func TestMicroscopicBlobDispersalWithPadding(t *testing.T) { // Disperse a small payload (between 1KB and 2KB). func TestSmallBlobDispersal(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() payload := rand.VariableBytes(units.KiB, 2*units.KiB) err := testBasicDispersal(t, rand, payload, []core.QuorumID{0, 1}) require.NoError(t, err) @@ -87,7 +87,7 @@ func TestSmallBlobDispersal(t *testing.T) { // Disperse a medium payload (between 100KB and 200KB). func TestMediumBlobDispersal(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() payload := rand.VariableBytes(100*units.KiB, 200*units.KiB) err := testBasicDispersal(t, rand, payload, []core.QuorumID{0, 1}) require.NoError(t, err) @@ -95,7 +95,7 @@ func TestMediumBlobDispersal(t *testing.T) { // Disperse a medium payload (between 1MB and 2MB). func TestLargeBlobDispersal(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() config, err := client.GetConfig(client.PreprodEnv) require.NoError(t, err) @@ -111,7 +111,7 @@ func TestLargeBlobDispersal(t *testing.T) { func TestSmallBlobDispersalSingleQuorum(t *testing.T) { t.Skip("TODO: validation is borked for single quorum dispersal") - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() payload := rand.VariableBytes(units.KiB, 2*units.KiB) err := testBasicDispersal(t, rand, payload, []core.QuorumID{0}) require.NoError(t, err) @@ -128,7 +128,7 @@ func TestMaximumSizedBlobDispersal(t *testing.T) { maxBlobSize := int(config.MaxBlobSize) dataLength := maxBlobSize - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() payload := rand.Bytes(dataLength) err = testBasicDispersal(t, rand, payload, quorums) require.NoError(t, err) @@ -136,7 +136,7 @@ func TestMaximumSizedBlobDispersal(t *testing.T) { // Disperse a blob that is too large (>16MB after padding) func TestTooLargeBlobDispersal(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() // TODO refactor this to use exactly 1 byte more than max size after padding and header data config, err := client.GetConfig(client.PreprodEnv) @@ -152,7 +152,7 @@ func TestTooLargeBlobDispersal(t *testing.T) { } func TestDoubleDispersal(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() c := client.GetTestClient(t, client.PreprodEnv) quorums := []core.QuorumID{0, 1} @@ -171,7 +171,7 @@ func TestDoubleDispersal(t *testing.T) { } func TestUnauthorizedGetChunks(t *testing.T) { - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() c := client.GetTestClient(t, client.PreprodEnv) quorums := []core.QuorumID{0, 1} @@ -202,7 +202,7 @@ func TestUnauthorizedGetChunks(t *testing.T) { func TestDispersalWithInvalidSignature(t *testing.T) { quorums := []core.QuorumID{0, 1} - rand := random.NewTestRandom(t) + rand := random.NewTestRandom() c := client.GetTestClient(t, client.PreprodEnv) diff --git a/test/v2/load/load_generator.go b/test/v2/load/load_generator.go index 0db3ded9c5..f9f0afff2f 100644 --- a/test/v2/load/load_generator.go +++ b/test/v2/load/load_generator.go @@ -4,17 +4,16 @@ import ( "context" "encoding/json" "fmt" - "os" - "sync/atomic" - "time" - - "github.com/docker/go-units" - "github.com/Layr-Labs/eigenda/api/clients/v2/verification" "github.com/Layr-Labs/eigenda/common/testutils/random" "github.com/Layr-Labs/eigenda/test/v2/client" + "github.com/docker/go-units" + "os" + "sync/atomic" + "time" ) +// LoadGenerator is a utility for generating read and write load for the target network. type LoadGenerator struct { ctx context.Context cancel context.CancelFunc @@ -23,8 +22,6 @@ type LoadGenerator struct { config *LoadGeneratorConfig // The test client to use for the load test. client *client.TestClient - // The random number generator to use for the load test. - rand *random.TestRandom // The time between starting each blob submission. submissionPeriod time.Duration // The channel to limit the number of parallel blob submissions. @@ -60,8 +57,7 @@ func ReadConfigFile(filePath string) (*LoadGeneratorConfig, error) { // NewLoadGenerator creates a new LoadGenerator. func NewLoadGenerator( config *LoadGeneratorConfig, - client *client.TestClient, - rand *random.TestRandom) *LoadGenerator { + client *client.TestClient) *LoadGenerator { bytesPerSecond := config.MBPerSecond * units.MiB averageBlobSize := config.AverageBlobSizeMB * units.MiB @@ -82,7 +78,6 @@ func NewLoadGenerator( cancel: cancel, config: config, client: client, - rand: rand, submissionPeriod: submissionPeriodAsDuration, parallelismLimiter: parallelismLimiter, alive: atomic.Bool{}, @@ -132,22 +127,24 @@ func (l *LoadGenerator) submitBlob() { // TODO: failure metrics - payloadSize := int(l.rand.BoundedGaussian( + rand := random.NewTestRandomNoPrint() + + payloadSize := int(rand.BoundedGaussian( l.config.AverageBlobSizeMB*units.MiB, l.config.BlobSizeStdDev*units.MiB, 1.0, float64(l.client.GetConfig().MaxBlobSize+1))) - payload := l.rand.Bytes(payloadSize) + payload := rand.Bytes(payloadSize) eigenDACert, err := l.client.DispersePayload(ctx, l.config.Quorums, payload) if err != nil { - fmt.Printf("failed to disperse blob: %v\n", err) + l.client.GetLogger().Errorf("failed to disperse blob: %v", err) return } blobKey, err := eigenDACert.ComputeBlobKey() if err != nil { - fmt.Printf("failed to compute blob key: %v\n", err) + l.client.GetLogger().Errorf("failed to compute blob key: %v", err) return } @@ -159,14 +156,15 @@ func (l *LoadGenerator) submitBlob() { eigenDACert.BlobInclusionInfo.BlobCertificate.RelayKeys, payload) if err != nil { - fmt.Printf("failed to read blob from relays: %v\n", err) + l.client.GetLogger().Errorf("failed to read blob from relays: %v", err) } } blobHeader := eigenDACert.BlobInclusionInfo.BlobCertificate.BlobHeader commitment, err := verification.BlobCommitmentsBindingToInternal(&blobHeader.Commitment) if err != nil { - fmt.Printf("failed to compute blob commitment: %v\n", err) + l.client.GetLogger().Errorf("failed to bind blob commitments: %v", err) + return } for i := uint64(0); i < l.config.ValidatorReadAmplification; i++ { @@ -178,7 +176,7 @@ func (l *LoadGenerator) submitBlob() { eigenDACert.BlobInclusionInfo.BlobCertificate.BlobHeader.QuorumNumbers, payload) if err != nil { - fmt.Printf("failed to read blob from validators: %v\n", err) + l.client.GetLogger().Errorf("failed to read blob from validators: %v", err) } } } diff --git a/test/v2/load/main/load_main.go b/test/v2/load/main/load_main.go index ffe31b77f8..7725dd5c8e 100644 --- a/test/v2/load/main/load_main.go +++ b/test/v2/load/main/load_main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "github.com/Layr-Labs/eigenda/common/testutils/random" "github.com/Layr-Labs/eigenda/test/v2/client" "github.com/Layr-Labs/eigenda/test/v2/load" "github.com/stretchr/testify/require" @@ -11,24 +10,37 @@ import ( func main() { if len(os.Args) != 3 { - panic(fmt.Sprintf("Expected 3 args, got %d. Usage: %s \n", + panic(fmt.Sprintf("Expected 3 args, got %d. Usage: %s .\n"+ + "If '-' is passed in lieu of a config file, the config file path is read from the environment variable "+ + "$GENERATOR_ENV or $GENERATOR_LOAD, respectively.\n", len(os.Args), os.Args[0])) } envFile := os.Args[1] + if envFile == "-" { + envFile = os.Getenv("GENERATOR_ENV") + if envFile == "" { + panic("$GENERATOR_ENV not set") + } + } + loadFile := os.Args[2] + if loadFile == "-" { + loadFile = os.Getenv("GENERATOR_LOAD") + if loadFile == "" { + panic("$GENERATOR_LOAD not set") + } + } c, err := client.GetClient(envFile) if err != nil { panic(err) } - rand := random.NewTestRandom(nil) - config, err := load.ReadConfigFile(loadFile) require.NoError(nil, err) - generator := load.NewLoadGenerator(config, c, rand) + generator := load.NewLoadGenerator(config, c) signals := make(chan os.Signal) go func() { diff --git a/trafficgenerator-v2.Dockerfile b/trafficgenerator-v2.Dockerfile deleted file mode 100644 index fff749abb5..0000000000 --- a/trafficgenerator-v2.Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM golang:1.21.13-alpine3.20 as builder - -RUN apk add --no-cache make musl-dev linux-headers gcc git jq bash - -WORKDIR /app - -# Copy Entire Repo here in order to not copy individual dependencies -COPY . . - -WORKDIR /app/tools/traffic - -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ - go build -o ./bin/generator ./cmd2 - -FROM alpine:3.18 AS generator2 - -COPY --from=builder /app/tools/traffic/bin/generator /usr/local/bin - -ENTRYPOINT ["generator"] diff --git a/trafficgenerator.Dockerfile b/trafficgenerator.Dockerfile deleted file mode 100644 index 7ec1bedde7..0000000000 --- a/trafficgenerator.Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM golang:1.21.13-alpine3.20 as builder - -RUN apk add --no-cache make musl-dev linux-headers gcc git jq bash - -WORKDIR /app - -# Copy Entire Repo here in order to not copy individual dependencies -COPY . . - -WORKDIR /app/tools/traffic - -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ - go build -o ./bin/generator ./cmd - -FROM alpine:3.18 AS generator - -COPY --from=builder /app/tools/traffic/bin/generator /usr/local/bin - -ENTRYPOINT ["generator"]