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

771 read traffic generator #666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
af3ac59
Added comments to the generator config.
cody-littley Jul 17, 2024
8191b7f
Incremental progress.
cody-littley Jul 17, 2024
fff7c76
Incremental progress.
cody-littley Jul 18, 2024
3089bb0
Refactor blob writer.
cody-littley Jul 18, 2024
463f88f
Add ability to read from disperser.
cody-littley Jul 19, 2024
8a1b37b
Fix formatting.
cody-littley Jul 19, 2024
86eb80a
Incremental progress.
cody-littley Jul 19, 2024
f2591d6
Incremental progress.
cody-littley Jul 22, 2024
a60dfc5
Able to instiantiate retrieval client.
cody-littley Jul 23, 2024
9bf4333
Checkin.
cody-littley Jul 23, 2024
31cf1d5
Checkin.
cody-littley Jul 23, 2024
a04fef5
Working
cody-littley Jul 23, 2024
f57e677
Expose chunks in API.
cody-littley Jul 23, 2024
3c956d8
Extracting needed data.
cody-littley Jul 24, 2024
9c296bf
Added a few metrics.
cody-littley Jul 24, 2024
1307405
Added a bunch of new metrics.
cody-littley Jul 24, 2024
6fcc825
Fix bug.
cody-littley Jul 24, 2024
68a6a17
Added confirmation metric.
cody-littley Jul 24, 2024
c098c35
Cleanup.
cody-littley Jul 24, 2024
de4c7a7
Cleanup.
cody-littley Jul 24, 2024
c9de527
Renamed verifier.
cody-littley Jul 25, 2024
64c7ae9
Added some settings to the reader.
cody-littley Jul 25, 2024
85b542d
Incremental progress on config.
cody-littley Jul 25, 2024
47a3b7f
Add more config.
cody-littley Jul 25, 2024
8fafa51
Added config for the graph.
cody-littley Jul 25, 2024
04468fc
Added flags for the encoder.
cody-littley Jul 25, 2024
c0214a4
No more adhoc config in generator.go.
cody-littley Jul 25, 2024
8784124
Moar config.
cody-littley Jul 25, 2024
e2615e4
Converted remaining constants into configuration.
cody-littley Jul 25, 2024
6d4559d
Added overflow table.
cody-littley Jul 25, 2024
890c8ac
Fix metric names.
cody-littley Jul 25, 2024
75b160a
Compute checksum, data returned does not match.
cody-littley Jul 25, 2024
9972344
Fix checksum.
cody-littley Jul 25, 2024
1f64d67
Revert some files.
cody-littley Jul 25, 2024
a9d783c
Fixed a few remaining issues.
cody-littley Jul 25, 2024
b234794
Log formatting.
cody-littley Jul 25, 2024
9e6a3d2
Comment out old test, replace before merging.
cody-littley Jul 25, 2024
c305f00
Fix malformed sprintf
cody-littley Jul 25, 2024
8245ab0
Fixed linter issues.
cody-littley Jul 26, 2024
508e788
Move table to new package.
cody-littley Jul 26, 2024
eadce73
Moved metrics into package.
cody-littley Jul 26, 2024
5b9b3ac
Split worker config into new struct.
cody-littley Jul 26, 2024
088095d
Move workers to new package.
cody-littley Jul 26, 2024
b687785
Fixed worker config name.
cody-littley Jul 26, 2024
79e5274
Fix file name.
cody-littley Jul 26, 2024
0dfd5fd
Added tests for blob table.
cody-littley Jul 26, 2024
0c8de99
Created metrics interface.
cody-littley Jul 26, 2024
0de6b4f
Added interfaces for metric types.
cody-littley Jul 26, 2024
c5b6e70
Added mock metrics for testing.
cody-littley Jul 26, 2024
fd2d342
Created interceptable ticker.
cody-littley Jul 26, 2024
ed51c91
Incremental checkin.
cody-littley Jul 26, 2024
e68281e
Added unit test for writer.
cody-littley Jul 29, 2024
06055f0
Moved test methods to utility package.
cody-littley Jul 29, 2024
bc3d887
Reorganize code.
cody-littley Jul 29, 2024
3cb9811
Create test package.
cody-littley Jul 29, 2024
0d030cf
Added test for blob verifier.
cody-littley Jul 29, 2024
a953f02
Mostly finished tests for blob reader.
cody-littley Jul 30, 2024
e0b5d3a
lint
cody-littley Jul 30, 2024
0bc3dcd
Cleanup.
cody-littley Jul 30, 2024
d779162
Cleanup.
cody-littley Jul 30, 2024
2d88219
Moved config and flags to same directory.
cody-littley Jul 30, 2024
ee85c88
Move worker config into config directory.
cody-littley Jul 30, 2024
51cad43
Merge branch 'master' into 771-read-traffic-generator
cody-littley Jul 31, 2024
2e19a3d
Use disperser client config.
cody-littley Jul 31, 2024
16f785c
Refactored more config.
cody-littley Jul 31, 2024
6053d32
Refactored more config. Need to refactor flags.
cody-littley Jul 31, 2024
9b87f4f
Incremental progress.
cody-littley Jul 31, 2024
089b1a7
Finish changing config.
cody-littley Jul 31, 2024
0930b04
Merge branch 'master' into 771-read-traffic-generator
cody-littley Jul 31, 2024
e8d1057
Merge branch 'master' into 771-read-traffic-generator
cody-littley Aug 6, 2024
8bea855
Merge branch 'master' into 771-read-traffic-generator
cody-littley Aug 16, 2024
9d5c8b6
Refactored unit tests.
cody-littley Aug 19, 2024
7c37530
Merge branch 'master' into 771-read-traffic-generator
cody-littley Aug 22, 2024
247a077
Merge branch 'master' into 771-read-traffic-generator
cody-littley Sep 4, 2024
1dfe628
Debugging stuff.
cody-littley Sep 4, 2024
dc7d465
Merge branch 'master' into 771-read-traffic-generator
cody-littley Oct 3, 2024
75de082
Cleanup.
cody-littley Oct 3, 2024
54af37a
Merge branch 'master' into 771-read-traffic-generator
cody-littley Oct 3, 2024
8df796c
Revert unintentional changes.
cody-littley Oct 3, 2024
8d4caf6
Don't remove old generator yet.
cody-littley Oct 3, 2024
aac8c64
Cleanup.
cody-littley Oct 3, 2024
b2b4e63
Revert unecessary change.
cody-littley Oct 3, 2024
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
4 changes: 2 additions & 2 deletions inabox/deploy/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ func execForgeScript(script, privateKey string, deployer *ContractDeployer, extr
log.Println("Executing forge script with command: ", cmd.String())
err := cmd.Run()
if err != nil {
log.Print(fmt.Sprint(err) + ": " + stderr.String())
log.Panicf("Failed to execute forge script. Err: %s", err)
log.Panicf("Failed to execute forge script: %s\n Err: %s\n--- std out ---\n%s\n--- std err ---\n%s\n",
cmd, err, out.String(), stderr.String())
} else {
log.Print(out.String())
}
Expand Down
34 changes: 34 additions & 0 deletions tools/traffic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,37 @@ run: build
TRAFFIC_GENERATOR_DATA_SIZE=1000 \
TRAFFIC_GENERATOR_RANDOMIZE_BLOBS=true \
./bin/server

build2: clean
# cd ../.. && make protoc
go mod tidy
go build -o ./bin/server2 ./cmd2

run2: build2
TRAFFIC_GENERATOR_LOG_FORMAT=text \
TRAFFIC_GENERATOR_DISPERSER_HOSTNAME=localhost \
TRAFFIC_GENERATOR_DISPERSER_PORT=32003 \
RETRIEVER_HOSTNAME=localhost \
RETRIEVER_GRPC_PORT=32003 \
RETRIEVER_BLS_OPERATOR_STATE_RETRIVER=0x5f3f1dBD7B74C6B46e8c44f98792A1dAf8d69154 \
RETRIEVER_EIGENDA_SERVICE_MANAGER=0x851356ae760d987E095750cCeb3bC6014560891C \
RETRIEVER_TIMEOUT=10s \
TRAFFIC_GENERATOR_TIMEOUT=10s \
TRAFFIC_GENERATOR_NUM_WRITE_INSTANCES=1 \
TRAFFIC_GENERATOR_WRITE_REQUEST_INTERVAL=1s \
TRAFFIC_GENERATOR_DATA_SIZE=1000 \
TRAFFIC_GENERATOR_RANDOMIZE_BLOBS=true \
TRAFFIC_GENERATOR_SIGNER_PRIVATE_KEY_HEX=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \
TRAFFIC_GENERATOR_PRIVATE_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \
TRAFFIC_GENERATOR_METRICS_HTTP_PORT=9101 \
TRAFFIC_GENERATOR_GRAPH_URL=http://localhost:8000/subgraphs/name/Layr-Labs/eigenda-operator-state \
TRAFFIC_GENERATOR_THE_GRAPH_URL=http://localhost:8000/subgraphs/name/Layr-Labs/eigenda-operator-state \
TRAFFIC_GENERATOR_G1_PATH=../../inabox/resources/kzg/g1.point \
TRAFFIC_GENERATOR_G2_PATH=../../inabox/resources/kzg/g2.point \
TRAFFIC_GENERATOR_CACHE_PATH=../../inabox/resources/kzg/SRSTables \
TRAFFIC_GENERATOR_SRS_ORDER=3000 \
TRAFFIC_GENERATOR_SRS_LOAD=3000 \
TRAFFIC_GENERATOR_NUM_WORKERS=4 \
TRAFFIC_GENERATOR_CHAIN_RPC=http://localhost:8545 \
TRAFFIC_GENERATOR_NUM_RETRIES=2 \
./bin/server2
44 changes: 44 additions & 0 deletions tools/traffic/cmd2/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"log"
"os"

"github.com/Layr-Labs/eigenda/tools/traffic"
"github.com/Layr-Labs/eigenda/tools/traffic/config"
"github.com/urfave/cli"
)

var (
version = ""
gitCommit = ""
gitDate = ""
)

func main() {
app := cli.NewApp()
app.Version = fmt.Sprintf("%s-%s-%s", version, gitCommit, gitDate)
app.Name = "da-traffic-generator"
app.Usage = "EigenDA Traffic Generator"
app.Description = "Service for generating traffic to EigenDA disperser"
app.Flags = config.Flags
app.Action = trafficGeneratorMain
if err := app.Run(os.Args); err != nil {
log.Fatalf("application failed: %v", err)
}
}

func trafficGeneratorMain(ctx *cli.Context) error {
generatorConfig, err := config.NewConfig(ctx)
if err != nil {
return err
}

generator, err := traffic.NewTrafficGeneratorV2(generatorConfig)
if err != nil {
panic(fmt.Sprintf("failed to create new traffic generator\n%s", err))
}

return generator.Start()
}
217 changes: 217 additions & 0 deletions tools/traffic/generator_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package traffic

import (
"context"
"fmt"
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/core/auth"
"github.com/Layr-Labs/eigenda/core/eth"
"github.com/Layr-Labs/eigenda/core/thegraph"
"github.com/Layr-Labs/eigenda/encoding/kzg/verifier"
retrivereth "github.com/Layr-Labs/eigenda/retriever/eth"
"github.com/Layr-Labs/eigenda/tools/traffic/config"
"github.com/Layr-Labs/eigenda/tools/traffic/metrics"
"github.com/Layr-Labs/eigenda/tools/traffic/table"
"github.com/Layr-Labs/eigenda/tools/traffic/workers"
"github.com/Layr-Labs/eigensdk-go/logging"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"os"
"os/signal"
"sync"
"syscall"
"time"

"github.com/Layr-Labs/eigenda/api/clients"
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/core"
)

// Generator simulates read/write traffic to the DA service.
//
// ┌------------┐ ┌------------┐
// | writer |-┐ ┌----------------┐ | reader |-┐
// └------------┘ |-┐ -------> | status tracker | -------> └------------┘ |-┐
// └------------┘ | └----------------┘ └------------┘ |
// └------------┘ └------------┘
//
// The traffic generator is built from three principal components: one or more writers
// that write blobs, a statusTracker that polls the dispenser service until blobs are confirmed,
// and one or more readers that read blobs.
//
// When a writer finishes writing a blob, it sends information about that blob to the statusTracker.
// When the statusTracker observes that a blob has been confirmed, it sends information about the blob
// to the readers. The readers only attempt to read blobs that have been confirmed by the statusTracker.
type Generator struct {
ctx *context.Context
cancel *context.CancelFunc
waitGroup *sync.WaitGroup
generatorMetrics metrics.Metrics
logger *logging.Logger
disperserClient clients.DisperserClient
eigenDAClient *clients.EigenDAClient
config *config.Config

writers []*workers.BlobWriter
statusTracker *workers.BlobStatusTracker
readers []*workers.BlobReader
}

func NewTrafficGeneratorV2(config *config.Config) (*Generator, error) {
logger, err := common.NewLogger(config.LoggingConfig)
if err != nil {
return nil, err
}

var signer core.BlobRequestSigner
if config.EigenDAClientConfig.SignerPrivateKeyHex != "" {
signer = auth.NewLocalBlobRequestSigner(config.EigenDAClientConfig.SignerPrivateKeyHex)
}

logger2 := log.NewLogger(log.NewTerminalHandler(os.Stderr, true))
client, err := clients.NewEigenDAClient(logger2, *config.EigenDAClientConfig)
if err != nil {
return nil, err
}

ctx, cancel := context.WithCancel(context.Background())
waitGroup := sync.WaitGroup{}

generatorMetrics := metrics.NewMetrics(config.MetricsHTTPPort, logger)

blobTable := table.NewBlobStore()

unconfirmedKeyChannel := make(chan *workers.UnconfirmedKey, 100)

disperserClient := clients.NewDisperserClient(config.DisperserClientConfig, signer)
statusVerifier := workers.NewBlobStatusTracker(
&ctx,
&waitGroup,
logger,
&config.WorkerConfig,
unconfirmedKeyChannel,
blobTable,
disperserClient,
generatorMetrics)

writers := make([]*workers.BlobWriter, 0)
for i := 0; i < int(config.WorkerConfig.NumWriteInstances); i++ {
writer := workers.NewBlobWriter(
&ctx,
&waitGroup,
logger,
&config.WorkerConfig,
disperserClient,
unconfirmedKeyChannel,
generatorMetrics)
writers = append(writers, &writer)
}

retriever, chainClient := buildRetriever(config)

readers := make([]*workers.BlobReader, 0)
for i := 0; i < int(config.WorkerConfig.NumReadInstances); i++ {
reader := workers.NewBlobReader(
&ctx,
&waitGroup,
logger,
&config.WorkerConfig,
retriever,
chainClient,
blobTable,
generatorMetrics)
readers = append(readers, &reader)
}

return &Generator{
ctx: &ctx,
cancel: &cancel,
waitGroup: &waitGroup,
generatorMetrics: generatorMetrics,
logger: &logger,
disperserClient: clients.NewDisperserClient(config.DisperserClientConfig, signer),
eigenDAClient: client,
config: config,
writers: writers,
statusTracker: &statusVerifier,
readers: readers,
}, nil
}

// buildRetriever creates a retriever client for the traffic generator.
func buildRetriever(config *config.Config) (clients.RetrievalClient, retrivereth.ChainClient) {
loggerConfig := common.DefaultLoggerConfig()

logger, err := common.NewLogger(loggerConfig)
if err != nil {
panic(fmt.Sprintf("Unable to instantiate logger: %s", err))
}

gethClient, err := geth.NewMultiHomingClient(config.RetrievalClientConfig.EthClientConfig, gethcommon.Address{}, logger)
if err != nil {
panic(fmt.Sprintf("Unable to instantiate geth client: %s", err))
}

tx, err := eth.NewTransactor(
logger,
gethClient,
config.RetrievalClientConfig.BLSOperatorStateRetrieverAddr,
config.RetrievalClientConfig.EigenDAServiceManagerAddr)
if err != nil {
panic(fmt.Sprintf("Unable to instantiate transactor: %s", err))
}

cs := eth.NewChainState(tx, gethClient)

chainState := thegraph.MakeIndexedChainState(*config.TheGraphConfig, cs, logger)

var assignmentCoordinator core.AssignmentCoordinator = &core.StdAssignmentCoordinator{}

nodeClient := clients.NewNodeClient(config.NodeClientTimeout)

v, err := verifier.NewVerifier(&config.RetrievalClientConfig.EncoderConfig, true)
if err != nil {
panic(fmt.Sprintf("Unable to build statusTracker: %s", err))
}

retriever, err := clients.NewRetrievalClient(
logger,
chainState,
assignmentCoordinator,
nodeClient,
v,
config.RetrievalClientConfig.NumConnections)

if err != nil {
panic(fmt.Sprintf("Unable to build retriever: %s", err))
}

chainClient := retrivereth.NewChainClient(gethClient, logger)

return retriever, chainClient
}

// Start instantiates goroutines that generate read/write traffic, continues until a SIGTERM is observed.
func (generator *Generator) Start() error {

generator.generatorMetrics.Start()
generator.statusTracker.Start()

for _, writer := range generator.writers {
writer.Start()
time.Sleep(generator.config.InstanceLaunchInterval)
}

for _, reader := range generator.readers {
reader.Start()
time.Sleep(generator.config.InstanceLaunchInterval)
}

signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
<-signals

(*generator.cancel)()
generator.waitGroup.Wait()
return nil
}
Loading