Skip to content

Commit aabba10

Browse files
committed
(NOBIDS) add blobs-data to chart_series
1 parent 412f5ab commit aabba10

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

db/statistics.go

+40-4
Original file line numberDiff line numberDiff line change
@@ -1545,11 +1545,15 @@ func WriteExecutionChartSeriesForDay(day int64) error {
15451545
totalTxSavings := decimal.NewFromInt(0)
15461546
totalTxFees := decimal.NewFromInt(0)
15471547
totalBurned := decimal.NewFromInt(0)
1548+
totalBurnedBlob := decimal.NewFromInt(0)
15481549
totalGasUsed := decimal.NewFromInt(0)
1550+
totalBlobGasUsed := decimal.NewFromInt(0)
1551+
totalBlobCount := decimal.NewFromInt(0)
15491552

15501553
legacyTxCount := int64(0)
15511554
accessListTxCount := int64(0)
15521555
eip1559TxCount := int64(0)
1556+
blobTxCount := int64(0)
15531557
failedTxCount := int64(0)
15541558
successTxCount := int64(0)
15551559

@@ -1616,7 +1620,20 @@ func WriteExecutionChartSeriesForDay(day int64) error {
16161620
// totalMinerTips = totalMinerTips.Add(tipFee.Mul(gasUsed))
16171621
txFees = baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))
16181622
totalTxSavings = totalTxSavings.Add(maxFee.Mul(gasUsed).Sub(baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))))
1619-
// TODO: Handle type 3?
1623+
1624+
case 3:
1625+
// priority fee is capped because the base fee is filled first
1626+
tipFee = decimal.Min(prioFee, maxFee.Sub(baseFee))
1627+
blobTxCount += 1
1628+
// totalMinerTips = totalMinerTips.Add(tipFee.Mul(gasUsed))
1629+
txFees = baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))
1630+
totalTxSavings = totalTxSavings.Add(maxFee.Mul(gasUsed).Sub(baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))))
1631+
1632+
blobGasUsed := decimal.NewFromBigInt(new(big.Int).SetUint64(tx.BlobGasUsed), 0)
1633+
totalBlobGasUsed = totalBlobGasUsed.Add(blobGasUsed)
1634+
totalBurnedBlob = blobGasUsed.Mul(decimal.NewFromBigInt(new(big.Int).SetBytes(tx.BlobGasPrice), 0))
1635+
totalBlobCount = totalBlobCount.Add(decimal.NewFromInt(int64(len(tx.BlobVersionedHashes))))
1636+
16201637
default:
16211638
logger.Fatalf("error unknown tx type %v hash: %x", tx.Status, tx.Hash)
16221639
}
@@ -1633,7 +1650,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
16331650
logger.Fatalf("error unknown status code %v hash: %x", tx.Status, tx.Hash)
16341651
}
16351652
totalGasUsed = totalGasUsed.Add(gasUsed)
1636-
totalBurned = totalBurned.Add(baseFee.Mul(gasUsed))
1653+
totalBurned = totalBurned.Add(baseFee.Mul(gasUsed)).Add(totalBurnedBlob)
16371654
if blk.Number < 12244000 {
16381655
totalTips = totalTips.Add(gasUsed.Mul(gasPrice))
16391656
} else {
@@ -1657,22 +1674,35 @@ func WriteExecutionChartSeriesForDay(day int64) error {
16571674
logger.Infof("consensus rewards: %v", totalConsensusRewards)
16581675

16591676
logger.Infof("Exporting BURNED_FEES %v", totalBurned.String())
1660-
_, 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())
1677+
err = SaveChartSeriesPoint(dateTrunc, "BURNED_FEES", totalBurned.String())
16611678
if err != nil {
16621679
return fmt.Errorf("error calculating BURNED_FEES chart_series: %w", err)
16631680
}
16641681

1682+
logger.Infof("Exporting BURNED_BLOB_FEES %v", totalBurnedBlob.String())
1683+
err = SaveChartSeriesPoint(dateTrunc, "BURNED_BLOB_FEES", totalBurnedBlob.String())
1684+
if err != nil {
1685+
return fmt.Errorf("error calculating BURNED_BLOB_FEES chart_series: %w", err)
1686+
}
1687+
16651688
logger.Infof("Exporting NON_FAILED_TX_GAS_USAGE %v", totalGasUsed.Sub(totalFailedGasUsed).String())
16661689
err = SaveChartSeriesPoint(dateTrunc, "NON_FAILED_TX_GAS_USAGE", totalGasUsed.Sub(totalFailedGasUsed).String())
16671690
if err != nil {
16681691
return fmt.Errorf("error calculating NON_FAILED_TX_GAS_USAGE chart_series: %w", err)
16691692
}
1693+
16701694
logger.Infof("Exporting BLOCK_COUNT %v", blockCount)
16711695
err = SaveChartSeriesPoint(dateTrunc, "BLOCK_COUNT", blockCount)
16721696
if err != nil {
16731697
return fmt.Errorf("error calculating BLOCK_COUNT chart_series: %w", err)
16741698
}
16751699

1700+
logger.Infof("Exporting BLOB_COUNT %v", blockCount)
1701+
err = SaveChartSeriesPoint(dateTrunc, "BLOB_COUNT", totalBlobCount)
1702+
if err != nil {
1703+
return fmt.Errorf("error calculating BLOB_COUNT chart_series: %w", err)
1704+
}
1705+
16761706
// convert microseconds to seconds
16771707
logger.Infof("Exporting BLOCK_TIME_AVG %v", avgBlockTime.Div(decimal.NewFromInt(1e6)).Abs().String())
16781708
err = SaveChartSeriesPoint(dateTrunc, "BLOCK_TIME_AVG", avgBlockTime.Div(decimal.NewFromInt(1e6)).String())
@@ -1697,7 +1727,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
16971727

16981728
if totalGasPrice.GreaterThan(decimal.NewFromInt(0)) && decimal.NewFromInt(legacyTxCount).Add(decimal.NewFromInt(accessListTxCount)).GreaterThan(decimal.NewFromInt(0)) {
16991729
logger.Infof("Exporting AVG_GASPRICE")
1700-
_, 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())
1730+
err = SaveChartSeriesPoint(dateTrunc, "AVG_GASPRICE", totalGasPrice.Div((decimal.NewFromInt(legacyTxCount).Add(decimal.NewFromInt(accessListTxCount)))).String())
17011731
if err != nil {
17021732
return fmt.Errorf("error calculating AVG_GASPRICE chart_series err: %w", err)
17031733
}
@@ -1717,6 +1747,12 @@ func WriteExecutionChartSeriesForDay(day int64) error {
17171747
return fmt.Errorf("error calculating TOTAL_GASUSED chart_series: %w", err)
17181748
}
17191749

1750+
logger.Infof("Exporting TOTAL_BLOB_GASUSED %v", totalBlobGasUsed.String())
1751+
err = SaveChartSeriesPoint(dateTrunc, "TOTAL_BLOB_GASUSED", totalBlobGasUsed.String())
1752+
if err != nil {
1753+
return fmt.Errorf("error calculating TOTAL_BLOB_GASUSED chart_series: %w", err)
1754+
}
1755+
17201756
if blockCount > 0 {
17211757
logger.Infof("Exporting AVG_GASLIMIT %v", totalGasLimit.Div(decimal.NewFromInt(blockCount)))
17221758
err = SaveChartSeriesPoint(dateTrunc, "AVG_GASLIMIT", totalGasLimit.Div(decimal.NewFromInt(blockCount)))

0 commit comments

Comments
 (0)