Skip to content

Commit

Permalink
feat(eventindexer): Track proposer/prover rewards, + generate tasks f…
Browse files Browse the repository at this point in the history
…or total/per day (#14690)
  • Loading branch information
cyberhorsey authored Sep 14, 2023
1 parent 3ff0018 commit cc477b9
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 120 deletions.
3 changes: 2 additions & 1 deletion packages/eventindexer/.l1.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ RPC_URL=wss://l1ws.internal.taiko.xyz
CORS_ORIGINS=*
BLOCK_BATCH_SIZE=10
CACHE_INTERVAL_IN_SECONDS=60
LAYER=l1
LAYER=l1
GENESIS_DATE=2023-09-08
8 changes: 8 additions & 0 deletions packages/eventindexer/cmd/flags/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ var (
Category: generatorCategory,
EnvVars: []string{"GENESIS_DATE"},
}
Regenerate = &cli.StringFlag{
Name: "regenerate",
Usage: "True to delete all existing data and regenerate from genesis, false to not",
Required: false,
Category: generatorCategory,
EnvVars: []string{"REGENERATE"},
}
)
var GeneratorFlags = MergeFlags(CommonFlags, []cli.Flag{
GenesisDate,
Regenerate,
})
4 changes: 2 additions & 2 deletions packages/eventindexer/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func OpenDBConnection(opts DBConnectionOpts) (*DB, error) {
dsn := ""
if opts.Password == "" {
dsn = fmt.Sprintf(
"%v@tcp(%v)/%v?charset=utf8mb4&parseTime=True&loc=Local",
"%v@tcp(%v)/%v?charset=utf8mb4&parseTime=True",
opts.Name,
opts.Host,
opts.Database,
)
} else {
dsn = fmt.Sprintf(
"%v:%v@tcp(%v)/%v?charset=utf8mb4&parseTime=True&loc=Local",
"%v:%v@tcp(%v)/%v?charset=utf8mb4&parseTime=True",
opts.Name,
opts.Password,
opts.Host,
Expand Down
4 changes: 4 additions & 0 deletions packages/eventindexer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Event struct {
Address string `json:"address"`
BlockID sql.NullInt64 `json:"blockID"`
Amount decimal.NullDecimal `json:"amount"`
ProofReward decimal.NullDecimal `json:"proofReward"`
ProposerReward decimal.NullDecimal `json:"proposerReward"`
AssignedProver string `json:"assignedProver"`
To string `json:"to"`
TokenID sql.NullInt64 `json:"tokenID"`
Expand All @@ -50,6 +52,8 @@ type SaveEventOpts struct {
Address string
BlockID *int64
Amount *big.Int
ProposerReward *big.Int
ProofReward *big.Int
AssignedProver *string
To *string
TokenID *int64
Expand Down
2 changes: 2 additions & 0 deletions packages/eventindexer/generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
DatabaseMaxConnLifetime uint64
MetricsHTTPPort uint64
GenesisDate time.Time
Regenerate bool
OpenDBFunc func() (DB, error)
}

Expand All @@ -48,6 +49,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
DatabaseMaxConnLifetime: c.Uint64(flags.DatabaseConnMaxLifetime.Name),
MetricsHTTPPort: c.Uint64(flags.MetricsHTTPPort.Name),
GenesisDate: date,
Regenerate: c.Bool(flags.Regenerate.Name),
OpenDBFunc: func() (DB, error) {
return db.OpenDBConnection(db.DBConnectionOpts{
Name: c.String(flags.DatabaseUsername.Name),
Expand Down
2 changes: 2 additions & 0 deletions packages/eventindexer/generator/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestNewConfigFromCliContext(t *testing.T) {
assert.Equal(t, "dbpass", c.DatabasePassword)
assert.Equal(t, "dbname", c.DatabaseName)
assert.Equal(t, "dbhost", c.DatabaseHost)
assert.Equal(t, true, c.Regenerate)

wantTime, _ := time.Parse("2006-01-02", "2023-07-07")
assert.Equal(t, wantTime, c.GenesisDate)
Expand All @@ -52,5 +53,6 @@ func TestNewConfigFromCliContext(t *testing.T) {
"-" + flags.DatabaseHost.Name, "dbhost",
"-" + flags.DatabaseName.Name, "dbname",
"-" + flags.GenesisDate.Name, "2023-07-07",
"-" + flags.Regenerate.Name, "true",
}))
}
Loading

0 comments on commit cc477b9

Please sign in to comment.