Skip to content

Commit

Permalink
feat(eventindexer): Timeseries data indexing + refactor to taiko-clie…
Browse files Browse the repository at this point in the history
…nt/relayer CLI approach and architecture (#14663)
  • Loading branch information
cyberhorsey authored and KorbinianK committed Sep 28, 2023
1 parent 073e46d commit c65f37d
Show file tree
Hide file tree
Showing 63 changed files with 2,594 additions and 1,025 deletions.
24 changes: 12 additions & 12 deletions packages/eventindexer/.l1.env
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
HTTP_PORT=4100
PROMETHEUS_HTTP_PORT=6063
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=eventindexer
MYSQL_HOST=localhost:3306
MYSQL_MAX_IDLE_CONNS=50
MYSQL_MAX_OPEN_CONNS=3000
MYSQL_CONN_MAX_LIFETIME_IN_MS=100000
L1_TAIKO_ADDRESS=0x6375394335f34848b850114b66A49D6F47f2cdA8
BRIDGE_ADDRESS=0x7D992599E1B8b4508Ba6E2Ba97893b4C36C23A28
PROVER_POOL_ADDRESS=0x7D992599E1B8b4508Ba6E2Ba97893b4C36C23A28
RPC_URL=wss://l1ws.test.taiko.xyz
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_NAME=eventindexer
DATABASE_HOST=localhost:3306
DATABASE_MAX_IDLE_CONNS=50
DATABASE_MAX_OPEN_CONNS=3000
DATABASE_CONN_MAX_LIFETIME_IN_MS=100000
L1_TAIKO_ADDRESS=0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82
BRIDGE_ADDRESS=0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE
RPC_URL=wss://l1ws.internal.taiko.xyz
CORS_ORIGINS=*
BLOCK_BATCH_SIZE=100
BLOCK_BATCH_SIZE=10
CACHE_INTERVAL_IN_SECONDS=60
LAYER=l1
25 changes: 12 additions & 13 deletions packages/eventindexer/.l2.env
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
HTTP_PORT=4100
PROMETHEUS_HTTP_PORT=6063
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=eventindexer
MYSQL_HOST=localhost:3306
MYSQL_MAX_IDLE_CONNS=50
MYSQL_MAX_OPEN_CONNS=3000
MYSQL_CONN_MAX_LIFETIME_IN_MS=100000
PROVER_POOL_ADDRESS=0x7D992599E1B8b4508Ba6E2Ba97893b4C36C23A28
SWAP_ADDRESSES=0x501f63210aE6D7Eeb50DaE74DA5Ae407515ee246,0x926815A3fb587DDF5e2d2A03ea235630c0A53a16,0x2223D60359736532958DF6a4E9A5e4A5a71729A1
RPC_URL=wss://ws.test.taiko.xyz
HTTP_PORT=4009
METRICS_HTTP_PORT=6067
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_NAME=eventindexer
DATABASE_HOST=localhost:3306
DATABASE_MAX_IDLE_CONNS=50
DATABASE_MAX_OPEN_CONNS=3000
DATABASE_CONN_MAX_LIFETIME_IN_MS=100000
RPC_URL=wss://ws.internal.taiko.xyz
CORS_ORIGINS=*
BLOCK_BATCH_SIZE=1000
BLOCK_BATCH_SIZE=100
CACHE_INTERVAL_IN_SECONDS=60
LAYER=l2
6 changes: 6 additions & 0 deletions packages/eventindexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ Catches events, stores them in the database to be queried via API.
run `cp .default.env .env`, and add your own private key as `RELAYER_ECDSA_KEY` in `.env`. You need to be running a MySQL instance, and replace all the `MYSQL_` env vars with yours.

Run `go run cmd/main.go --help` to see a list of possible configuration flags, or `go run cmd/main.go` to run with defaults, which will process messages from L1 to L2, and from L2 to L1, and start indexing blocks from 0.

# Block data

1. parse data
2. store
3. cron job that updates every 24 hours
18 changes: 18 additions & 0 deletions packages/eventindexer/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package eventindexer

import (
"context"
"time"

"github.com/ethereum/go-ethereum/common"
)

type Account struct {
ID int `json:"id"`
Address string `json:"address"`
TransactedAt time.Time `json:"transactedAt"`
}

type AccountRepository interface {
Save(ctx context.Context, address common.Address, transactedAt time.Time) error
}
28 changes: 21 additions & 7 deletions packages/eventindexer/block.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
package eventindexer

import (
"context"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

// Block is a database model representing simple header types
// ProcessedBlock is a database model representing simple header types
// to keep track of our most recently processed block number and hash.
type Block struct {
type ProcessedBlock struct {
ID int `json:"id"`
Height uint64 `json:"blockHeight" gorm:"column:block_height"`
Hash string `json:"hash"`
ChainID int64 `json:"chainID"`
}

// SaveBlockOpts is required to store a new block
type SaveBlockOpts struct {
// SaveProcessedBlockOpts is required to store a new block
type SaveProcessedBlockOpts struct {
Height uint64
Hash common.Hash
ChainID *big.Int
}

// BlockRepository defines methods necessary for interacting with
// ProcessedBlockRepository defines methods necessary for interacting with
// the block store.
type ProcessedBlockRepository interface {
Save(opts SaveProcessedBlockOpts) error
GetLatestBlockProcessed(chainID *big.Int) (*ProcessedBlock, error)
}

type Block struct {
ID int `json:"id"`
ChainID int64 `json:"chainID"`
BlockID int64 `json:"blockID"`
TransactedAt time.Time `json:"transactedAt"`
}

type BlockRepository interface {
Save(opts SaveBlockOpts) error
GetLatestBlockProcessed(chainID *big.Int) (*Block, error)
Save(ctx context.Context, tx *types.Block, chainID *big.Int) error
}
21 changes: 21 additions & 0 deletions packages/eventindexer/chart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package eventindexer

import "context"

type ChartResponse struct {
Chart []ChartItem `json:"chart"`
}

type ChartItem struct {
Date string `json:"date"`
Value string `json:"value"`
}

type ChartRepository interface {
Find(
ctx context.Context,
task string,
start string,
end string,
) (*ChartResponse, error)
}
Loading

0 comments on commit c65f37d

Please sign in to comment.