Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion testbed/default-config.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5 /Users/tewodrosmitiku/Desktop/walrusgo/build/avalanchego
5 /Users/tewodrosmitiku/Desktop/avalanche-binaries/vanilla-binary/avalanchego
6 changes: 2 additions & 4 deletions testbed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func startTxSpamming(txChan chan worker.TxData, startMonitoring func()){
ctx, cancel := context.WithTimeout(context.Background(), txSpammingTimeout)
errc := make(chan error)
go func() {
errc <- worker.Run(ctx, cfg, keysDir, txChan)
errc <- worker.Run(ctx, cfg, keysDir, txChan, startMonitoring)
}()

sigs := make(chan os.Signal, 1)
Expand Down Expand Up @@ -338,10 +338,8 @@ func main() {
startMonitoring := func() {
toggleChan <- true
}
go startMonitoring()
// TODO averages\
go startTxListening(idMap, txChan, toggleChan)

go startTxListening(idMap, txChan, toggleChan)
startTxSpamming(txChan, startMonitoring)
for {}
}
1 change: 1 addition & 0 deletions testbed/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hash,Start,End,NodeID
Binary file added testbed/testbed
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

56 changes: 56 additions & 0 deletions testbed/tx-spammer/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,64 @@ import (

const (
checkInterval = 2 * time.Second
targetSecondsPerBlock = 2
targetGasUsage = 7_000_000
)

func CheckSaturation(ctx context.Context, client ethclient.Client, startMonitoring func()) error {
lastBlockNumber, err := client.BlockNumber(ctx)
if err != nil {
return fmt.Errorf("failed to get block number: %w", err)
}
startTime := uint64(time.Now().Unix())
currentTime := startTime
numBlocks := uint64(0)
currSecondsPerBlock := uint64(0)
gasUsed := uint64(0)

for ctx.Err() == nil {
newBlockNumber, err := client.BlockNumber(ctx)
if err != nil {
log.Printf("failed to get block number: %s", err)
time.Sleep(checkInterval)
continue
}

if newBlockNumber <= lastBlockNumber {
time.Sleep(checkInterval)
continue
}

var block *types.Block
for i := lastBlockNumber + 1; i <= newBlockNumber; i++ {
for ctx.Err() == nil {
block, err = client.BlockByNumber(ctx, new(big.Int).SetUint64(i))
if err != nil {
log.Printf("failed to get block at number %d: %s", i, err)
time.Sleep(checkInterval)
continue
}
numBlocks += 1
currSecondsPerBlock = (currentTime - startTime) / numBlocks
gasUsed = block.GasUsed()
if gasUsed >= targetGasUsage && currSecondsPerBlock >= targetSecondsPerBlock {
startMonitoring()
return ctx.Err()
}
}
}
lastBlockNumber = newBlockNumber
currentTime = block.Time()

// log 10s
diffMod := (currentTime - startTime) % 10
if diffMod == 0 {
log.Printf("[saturation stats]: seconds per block: %v, gas usage: %d\n", currSecondsPerBlock, gasUsed)
}
}
return ctx.Err()
}

// Monitor periodically prints metrics related to transaction activity on
// a given network.
func Monitor(ctx context.Context, client ethclient.Client) error {
Expand Down
5 changes: 4 additions & 1 deletion testbed/tx-spammer/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (w *worker) confirmTransaction(ctx context.Context, tx common.Hash) (*big.I

// Run attempts to apply load to a network specified in .simulator/config.yml
// and periodically prints metrics about the traffic it generates.
func Run(ctx context.Context, cfg *Config, keysDir string, txChan chan TxData) error {
func Run(ctx context.Context, cfg *Config, keysDir string, txChan chan TxData, startMonitoring func()) error {
rclient, err := ethclient.Dial(cfg.Endpoints[0])
if err != nil {
fmt.Println(cfg.Endpoints[0])
Expand All @@ -321,6 +321,9 @@ func Run(ctx context.Context, cfg *Config, keysDir string, txChan chan TxData) e
g.Go(func() error {
return metrics.Monitor(gctx, rclient)
})
g.Go(func()error {
return metrics.CheckSaturation(gctx, rclient, startMonitoring)
})
fundRequest := make(chan common.Address)
g.Go(func() error {
return master.fund(gctx, fundRequest)
Expand Down
Binary file added tx-spammer/tx-spammer
Binary file not shown.