Skip to content

Commit

Permalink
Merge pull request #2507 from gobitfly/NOBIDS/HandleMissingBurnedFees…
Browse files Browse the repository at this point in the history
…InDatabase

(NOBIDS) Handle missing burned fees in database
  • Loading branch information
recy21 authored Aug 31, 2023
2 parents 6ec8d2f + b916302 commit 5201cbb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1510,16 +1510,23 @@ func getBurnPageData() (*types.BurnPageData, error) {
latestEpoch := LatestEpoch()
latestBlock := LatestEth1BlockNumber()

// Check db to have at least one entry (will error otherwise anyway)
burnedFeesCount := 0
if err := db.ReaderDb.Get(&burnedFeesCount, "SELECT COUNT(*) FROM chart_series WHERE indicator = 'BURNED_FEES'"); err != nil {
return nil, fmt.Errorf("error get BURNED_FEES count from chart_series: %w", err)
}
if burnedFeesCount <= 0 {
return data, nil
}

// Retrieve the total amount of burned Ether
err := db.ReaderDb.Get(&data.TotalBurned, "select sum(value) from chart_series where indicator = 'BURNED_FEES';")
if err != nil {
return nil, fmt.Errorf("error retrieving total burned amount from chart_series table: %v", err)
if err := db.ReaderDb.Get(&data.TotalBurned, "SELECT SUM(value) FROM chart_series WHERE indicator = 'BURNED_FEES'"); err != nil {
return nil, fmt.Errorf("error retrieving total burned amount from chart_series table: %w", err)
}

cutOff := time.Time{}
err = db.ReaderDb.Get(&cutOff, "select (select max(time) from chart_series where indicator = 'BURNED_FEES') + interval '24 hours';")
if err != nil {
return nil, fmt.Errorf("error retrieving cutoff date from chart_series table: %v", err)
if err := db.ReaderDb.Get(&cutOff, "SELECT ( SELECT MAX(time) FROM chart_series WHERE indicator = 'BURNED_FEES' ) + interval '24 hours'"); err != nil {
return nil, fmt.Errorf("error retrieving cutoff date from chart_series table: %w", err)
}

cutOffEpoch := utils.TimeToEpoch(cutOff)
Expand All @@ -1531,14 +1538,14 @@ func getBurnPageData() (*types.BurnPageData, error) {
// db.ReaderDb.Get(&blockLastDay)

additionalBurned := float64(0)
err = db.ReaderDb.Get(&additionalBurned, "select COALESCE(SUM(exec_base_fee_per_gas::numeric * exec_gas_used::numeric), 0) as burnedfees from blocks where epoch > $1", cutOffEpoch)
err := db.ReaderDb.Get(&additionalBurned, "SELECT COALESCE(SUM(exec_base_fee_per_gas::numeric * exec_gas_used::numeric), 0) AS burnedfees FROM blocks WHERE epoch > $1", cutOffEpoch)
if err != nil {
return nil, fmt.Errorf("error retrieving additional burned eth from blocks table: %v", err)
}
// logger.Infof("additonal burn: %v", additionalBurned)
data.TotalBurned += additionalBurned

err = db.ReaderDb.Get(&data.BurnRate1h, "select COALESCE(SUM(exec_base_fee_per_gas::numeric * exec_gas_used::numeric) / 60, 0) as burnedfees from blocks where epoch > $1", latestEpoch-10)
err = db.ReaderDb.Get(&data.BurnRate1h, "SELECT COALESCE(SUM(exec_base_fee_per_gas::numeric * exec_gas_used::numeric) / 60, 0) AS burnedfees FROM blocks WHERE epoch > $1", latestEpoch-10)
if err != nil {
return nil, fmt.Errorf("error retrieving burn rate (1h) from blocks table: %v", err)
}
Expand Down

0 comments on commit 5201cbb

Please sign in to comment.