Skip to content

Commit

Permalink
fix for LT block time calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbundalo committed Nov 4, 2024
1 parent 526a57b commit 35a5237
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions loadtest/runner/base_load_test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,22 @@ func (r *BaseLoadTestRunner) calculateResults(blockInfos map[uint64]*BlockInfo,

for block := range uniqueBlocks {
currentBlockTxsNum := 0
parentBlockNum := block - 1
nextBlockNum := block + 1

if _, exists := blockTimeMap[parentBlockNum]; !exists {
if parentBlockInfo, exists := blockInfos[parentBlockNum]; !exists {
parentBlock, err := r.client.GetBlockByNumber(jsonrpc.BlockNumber(parentBlockNum), false)
if _, exists := blockTimeMap[nextBlockNum]; !exists {
if nextBlockInfo, exists := blockInfos[nextBlockNum]; !exists {
nextBlock, err := r.client.GetBlockByNumber(jsonrpc.BlockNumber(nextBlockNum), false)
if err != nil {
return err
}

blockTimeMap[parentBlockNum] = parentBlock.Header.Timestamp
blockTimeMap[nextBlockNum] = nextBlock.Header.Timestamp
} else {
blockTimeMap[parentBlockNum] = parentBlockInfo.CreatedAt
blockTimeMap[nextBlockNum] = nextBlockInfo.CreatedAt
}
}

parentBlockTimestamp := blockTimeMap[parentBlockNum]
nextBlockTimestamp := blockTimeMap[nextBlockNum]

if _, ok := blockTimeMap[block]; !ok {
if currentBlockInfo, ok := blockInfos[block]; !ok {
Expand All @@ -553,7 +553,7 @@ func (r *BaseLoadTestRunner) calculateResults(blockInfos map[uint64]*BlockInfo,
}

currentBlockTimestamp := blockTimeMap[block]
blockTime := math.Abs(float64(currentBlockTimestamp - parentBlockTimestamp))
blockTime := math.Abs(float64(nextBlockTimestamp - currentBlockTimestamp))

currentBlockTxsPerSecond := float64(currentBlockTxsNum) / blockTime

Expand All @@ -579,7 +579,7 @@ func (r *BaseLoadTestRunner) calculateResults(blockInfos map[uint64]*BlockInfo,
}

for _, info := range blockInfos {
info.BlockTime = math.Abs(float64(info.CreatedAt - blockTimeMap[info.Number-1]))
info.BlockTime = math.Abs(float64(blockTimeMap[info.Number+1] - info.CreatedAt))
info.TPS = float64(info.NumTxs) / info.BlockTime
}

Expand Down

0 comments on commit 35a5237

Please sign in to comment.