-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add message gas economy processing
- Loading branch information
Showing
5 changed files
with
144 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package messages | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-pg/pg/v10" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type MessageGasEconomy struct { | ||
tableName struct{} `pg:"message_gas_economy"` | ||
StateRoot string `pg:",pk,notnull"` | ||
|
||
BaseFee float64 `pg:",use_zero"` | ||
BaseFeeChangeLog float64 `pg:",use_zero"` | ||
|
||
GasLimitTotal int64 `pg:",use_zero"` | ||
GasLimitUniqueTotal int64 `pg:",use_zero"` | ||
|
||
GasFillRatio float64 `pg:",use_zero"` | ||
GasCapacityRatio float64 `pg:",use_zero"` | ||
GasWasteRatio float64 `pg:",use_zero"` | ||
} | ||
|
||
func (g *MessageGasEconomy) PersistWithTx(ctx context.Context, tx *pg.Tx) error { | ||
if _, err := tx.ModelContext(ctx, g). | ||
OnConflict("do nothing"). | ||
Insert(); err != nil { | ||
return xerrors.Errorf("persisting derived gas economy: %w", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/go-pg/migrations/v8" | ||
) | ||
|
||
func init() { | ||
up := batch(` | ||
CREATE TABLE public.message_gas_economy ( | ||
"state_root" text NOT NULL, | ||
"gas_limit_total" double precision NOT NULL, | ||
"gas_limit_unique_total "double precision NULL, | ||
"base_fee" double precision NOT NULL, | ||
"base_fee_change_log" double precision NOT NULL, | ||
"gas_fill_ratio" double precision NULL, | ||
"gas_capacity_ratio" double precision NULL, | ||
"gas_waste_ratio" double precision NULL, | ||
PRIMARY KEY ("state_root") | ||
); | ||
`) | ||
down := batch(` | ||
DROP TABLE IF EXISTS public.message_gas_economy; | ||
`) | ||
|
||
migrations.MustRegisterTx(up, down) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters