Skip to content

Commit

Permalink
(NOBIDS) add blobs-data to chart_series
Browse files Browse the repository at this point in the history
  • Loading branch information
guybrush committed Jan 17, 2024
1 parent 412f5ab commit aabba10
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions db/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,11 +1545,15 @@ func WriteExecutionChartSeriesForDay(day int64) error {
totalTxSavings := decimal.NewFromInt(0)
totalTxFees := decimal.NewFromInt(0)
totalBurned := decimal.NewFromInt(0)
totalBurnedBlob := decimal.NewFromInt(0)
totalGasUsed := decimal.NewFromInt(0)
totalBlobGasUsed := decimal.NewFromInt(0)
totalBlobCount := decimal.NewFromInt(0)

legacyTxCount := int64(0)
accessListTxCount := int64(0)
eip1559TxCount := int64(0)
blobTxCount := int64(0)
failedTxCount := int64(0)
successTxCount := int64(0)

Expand Down Expand Up @@ -1616,7 +1620,20 @@ func WriteExecutionChartSeriesForDay(day int64) error {
// totalMinerTips = totalMinerTips.Add(tipFee.Mul(gasUsed))
txFees = baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))
totalTxSavings = totalTxSavings.Add(maxFee.Mul(gasUsed).Sub(baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))))
// TODO: Handle type 3?

case 3:
// priority fee is capped because the base fee is filled first
tipFee = decimal.Min(prioFee, maxFee.Sub(baseFee))
blobTxCount += 1
// totalMinerTips = totalMinerTips.Add(tipFee.Mul(gasUsed))
txFees = baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))
totalTxSavings = totalTxSavings.Add(maxFee.Mul(gasUsed).Sub(baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))))

blobGasUsed := decimal.NewFromBigInt(new(big.Int).SetUint64(tx.BlobGasUsed), 0)
totalBlobGasUsed = totalBlobGasUsed.Add(blobGasUsed)
totalBurnedBlob = blobGasUsed.Mul(decimal.NewFromBigInt(new(big.Int).SetBytes(tx.BlobGasPrice), 0))
totalBlobCount = totalBlobCount.Add(decimal.NewFromInt(int64(len(tx.BlobVersionedHashes))))

default:
logger.Fatalf("error unknown tx type %v hash: %x", tx.Status, tx.Hash)
}
Expand All @@ -1633,7 +1650,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
logger.Fatalf("error unknown status code %v hash: %x", tx.Status, tx.Hash)
}
totalGasUsed = totalGasUsed.Add(gasUsed)
totalBurned = totalBurned.Add(baseFee.Mul(gasUsed))
totalBurned = totalBurned.Add(baseFee.Mul(gasUsed)).Add(totalBurnedBlob)
if blk.Number < 12244000 {
totalTips = totalTips.Add(gasUsed.Mul(gasPrice))
} else {
Expand All @@ -1657,22 +1674,35 @@ func WriteExecutionChartSeriesForDay(day int64) error {
logger.Infof("consensus rewards: %v", totalConsensusRewards)

logger.Infof("Exporting BURNED_FEES %v", totalBurned.String())
_, err = WriterDb.Exec("INSERT INTO chart_series (time, indicator, value) VALUES ($1, 'BURNED_FEES', $2) on conflict (time, indicator) do update set time = excluded.time, indicator = excluded.indicator, value = excluded.value", dateTrunc, totalBurned.String())
err = SaveChartSeriesPoint(dateTrunc, "BURNED_FEES", totalBurned.String())
if err != nil {
return fmt.Errorf("error calculating BURNED_FEES chart_series: %w", err)
}

logger.Infof("Exporting BURNED_BLOB_FEES %v", totalBurnedBlob.String())
err = SaveChartSeriesPoint(dateTrunc, "BURNED_BLOB_FEES", totalBurnedBlob.String())
if err != nil {
return fmt.Errorf("error calculating BURNED_BLOB_FEES chart_series: %w", err)
}

logger.Infof("Exporting NON_FAILED_TX_GAS_USAGE %v", totalGasUsed.Sub(totalFailedGasUsed).String())
err = SaveChartSeriesPoint(dateTrunc, "NON_FAILED_TX_GAS_USAGE", totalGasUsed.Sub(totalFailedGasUsed).String())
if err != nil {
return fmt.Errorf("error calculating NON_FAILED_TX_GAS_USAGE chart_series: %w", err)
}

logger.Infof("Exporting BLOCK_COUNT %v", blockCount)
err = SaveChartSeriesPoint(dateTrunc, "BLOCK_COUNT", blockCount)
if err != nil {
return fmt.Errorf("error calculating BLOCK_COUNT chart_series: %w", err)
}

logger.Infof("Exporting BLOB_COUNT %v", blockCount)
err = SaveChartSeriesPoint(dateTrunc, "BLOB_COUNT", totalBlobCount)
if err != nil {
return fmt.Errorf("error calculating BLOB_COUNT chart_series: %w", err)
}

// convert microseconds to seconds
logger.Infof("Exporting BLOCK_TIME_AVG %v", avgBlockTime.Div(decimal.NewFromInt(1e6)).Abs().String())
err = SaveChartSeriesPoint(dateTrunc, "BLOCK_TIME_AVG", avgBlockTime.Div(decimal.NewFromInt(1e6)).String())
Expand All @@ -1697,7 +1727,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {

if totalGasPrice.GreaterThan(decimal.NewFromInt(0)) && decimal.NewFromInt(legacyTxCount).Add(decimal.NewFromInt(accessListTxCount)).GreaterThan(decimal.NewFromInt(0)) {
logger.Infof("Exporting AVG_GASPRICE")
_, err = WriterDb.Exec("INSERT INTO chart_series (time, indicator, value) VALUES($1, 'AVG_GASPRICE', $2) on conflict (time, indicator) do update set time = excluded.time, indicator = excluded.indicator, value = excluded.value", dateTrunc, totalGasPrice.Div((decimal.NewFromInt(legacyTxCount).Add(decimal.NewFromInt(accessListTxCount)))).String())
err = SaveChartSeriesPoint(dateTrunc, "AVG_GASPRICE", totalGasPrice.Div((decimal.NewFromInt(legacyTxCount).Add(decimal.NewFromInt(accessListTxCount)))).String())
if err != nil {
return fmt.Errorf("error calculating AVG_GASPRICE chart_series err: %w", err)
}
Expand All @@ -1717,6 +1747,12 @@ func WriteExecutionChartSeriesForDay(day int64) error {
return fmt.Errorf("error calculating TOTAL_GASUSED chart_series: %w", err)
}

logger.Infof("Exporting TOTAL_BLOB_GASUSED %v", totalBlobGasUsed.String())
err = SaveChartSeriesPoint(dateTrunc, "TOTAL_BLOB_GASUSED", totalBlobGasUsed.String())
if err != nil {
return fmt.Errorf("error calculating TOTAL_BLOB_GASUSED chart_series: %w", err)
}

if blockCount > 0 {
logger.Infof("Exporting AVG_GASLIMIT %v", totalGasLimit.Div(decimal.NewFromInt(blockCount)))
err = SaveChartSeriesPoint(dateTrunc, "AVG_GASLIMIT", totalGasLimit.Div(decimal.NewFromInt(blockCount)))
Expand Down

0 comments on commit aabba10

Please sign in to comment.